From d2f57e386e6b710db56f2d7672f996e94d2d189d Mon Sep 17 00:00:00 2001 From: bounav Date: Wed, 10 Jul 2024 09:49:35 +0100 Subject: [PATCH 1/5] Added a LoadBatchCompilation override that accepts a list of types --- src/Spark/Compiler/BatchCompiler.cs | 2 -- src/Spark/ISparkViewEngine.cs | 16 ++++++++++++++++ src/Spark/SparkViewEngine.cs | 20 +++++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/Spark/Compiler/BatchCompiler.cs b/src/Spark/Compiler/BatchCompiler.cs index b004cc74..8e61fb1a 100644 --- a/src/Spark/Compiler/BatchCompiler.cs +++ b/src/Spark/Compiler/BatchCompiler.cs @@ -338,8 +338,6 @@ public Assembly Compile(bool debug, string languageOrExtension, string outputAss this.AddNetCoreDefaultReferences(); #endif - // TODO: Is this needed? - //this.AddAssembly(typeof(System.Drawing.Color)); foreach(var assemblyLocation in settings.UseAssemblies) { // Assumes full path to assemblies diff --git a/src/Spark/ISparkViewEngine.cs b/src/Spark/ISparkViewEngine.cs index c0fd1ef5..be4a51ec 100644 --- a/src/Spark/ISparkViewEngine.cs +++ b/src/Spark/ISparkViewEngine.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. // + +using System; using System.Collections.Generic; using System.Reflection; using Spark.FileSystem; @@ -34,6 +36,20 @@ public interface ISparkViewEngine Assembly BatchCompilation(IList descriptors); Assembly BatchCompilation(string outputAssembly, IList descriptors); + + /// + /// Get all the exported types in the assembly and loads the ones assignable from . + /// + /// + /// + /// A list of for every loaded type. IList LoadBatchCompilation(Assembly assembly); + + /// + /// Loads the specified types (when assignable from ) into the implemenation. + /// + /// + /// A list of for every loaded type. + IList LoadBatchCompilation(Type[] assembly); } } diff --git a/src/Spark/SparkViewEngine.cs b/src/Spark/SparkViewEngine.cs index f5a6010c..9bf250e2 100644 --- a/src/Spark/SparkViewEngine.cs +++ b/src/Spark/SparkViewEngine.cs @@ -229,11 +229,29 @@ public Assembly BatchCompilation(string outputAssembly, IList + /// Get all the exported types in the assembly and loads the ones assignable from . + /// + /// + /// + /// A list of for every loaded type. public IList LoadBatchCompilation(Assembly assembly) + { + var exportedTypes = assembly.GetExportedTypes(); + + return LoadBatchCompilation(exportedTypes); + } + + /// + /// Loads the specified types (when assignable from ) into the implemenation. + /// + /// + /// A list of for every loaded type. + public IList LoadBatchCompilation(Type[] types) { var descriptors = new List(); - foreach (var type in assembly.GetExportedTypes()) + foreach (var type in types) { if (!typeof(ISparkView).IsAssignableFrom(type)) { From 5108d6b7bbf0acef59ad77a26e58f8d1835039a7 Mon Sep 17 00:00:00 2001 From: bounav Date: Tue, 27 Aug 2024 11:05:04 +0100 Subject: [PATCH 2/5] Updated github actions versions - Added src/global.json file for global dotnet settings - Added aspnetcore project to spark-spark-pack.slnf - Added package metatags to Spark.AspNetCore.Mvc.csproj --- .github/workflows/ci.yml | 4 ++-- .../Spark.AspNetCore.Mvc.csproj | 17 ++++++++++++++++- src/global.json | 6 ++++++ src/spark-pack.slnf | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/global.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57f03d8c..3951621c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,9 +15,9 @@ jobs: runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - name: Restore dependencies diff --git a/src/Spark.AspNetCore.Mvc/Spark.AspNetCore.Mvc.csproj b/src/Spark.AspNetCore.Mvc/Spark.AspNetCore.Mvc.csproj index e541238c..4a1946cc 100644 --- a/src/Spark.AspNetCore.Mvc/Spark.AspNetCore.Mvc.csproj +++ b/src/Spark.AspNetCore.Mvc/Spark.AspNetCore.Mvc.csproj @@ -1,5 +1,20 @@  - + + False + ..\SparkKey.snk + Louis DeJardin + https://github.com/SparkViewEngine/ + README.md + https://github.com/SparkViewEngine/spark + git + True + snupkg + license.txt + True + spark;view engine + Copyright (c) Louis DeJardin 2008-2024 + Spark is a view engine allowing the HTML to dominate the flow and any code to fit seamlessly. + net8.0 enable diff --git a/src/global.json b/src/global.json new file mode 100644 index 00000000..9c4908f7 --- /dev/null +++ b/src/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "rollForward": "feature", + "version": "8.0.400" + } +} \ No newline at end of file diff --git a/src/spark-pack.slnf b/src/spark-pack.slnf index 58575004..d0e0a80a 100644 --- a/src/spark-pack.slnf +++ b/src/spark-pack.slnf @@ -2,6 +2,7 @@ "solution": { "path": "Spark.sln", "projects": [ + "Spark.AspNetCore.Mvc\\Spark.AspNetCore.Mvc.csproj", "Spark.Web.Mvc\\Spark.Web.Mvc.csproj", "Spark.Web\\Spark.Web.csproj", "Spark\\Spark.csproj" From 1c83ab8b580c71491627632a1e9efbbf5114a098 Mon Sep 17 00:00:00 2001 From: bounav Date: Wed, 4 Dec 2024 14:08:19 +0000 Subject: [PATCH 3/5] Updated unit test dependencies - Added dependency NUnit.Analyser v3 so that we can convert the Classic Assert to Constraint Model syntax - Added missing teardowns (enforced by NUnit.Analyser) - Used "dotnet format ./Spark.Xxx.Tests.csproj --severity info -v diag --exclude-diagnostics IDE0130" to upgrade the syntax - Some other minor formatting discrepancies have been fixed --- .../HybridCacheServiceProviderTests.cs | 11 +- .../Castle.MonoRail.Views.Spark.Tests.csproj | 8 +- .../Constraints.cs | 2 +- .../HelperExtensionMethodsTests.cs | 2 +- .../ModelDictionaryTests.cs | 11 +- .../Models/UserInfo.cs | 22 +- .../PrecompileInstallerTests.cs | 11 +- .../SparkBatchCompilerTester.cs | 119 ++--- .../SparkViewDataTests.cs | 16 +- ...parkViewFactoryStrictNullBehaviourTests.cs | 2 +- .../SparkViewFactoryTests.cs | 43 +- .../SparkViewFactoryTestsBase.cs | 18 +- .../Stubs/StubController.cs | 2 +- .../AllFrameworkComponentTests.cs | 26 +- .../ViewComponents/BaseViewComponentTests.cs | 20 +- .../ViewComponentExtensionTests.cs | 127 ++--- .../ViewComponentRenderBodyTests.cs | 31 +- .../ViewComponentRenderViewTests.cs | 20 +- ...omponentSectionChunkBuilderVisitorTests.cs | 11 +- .../ViewComponentSectionTests.cs | 51 +- .../Castle.Monorail.Pdf.Tests.csproj | 6 +- .../FormatReturnBinderTests.cs | 39 +- .../Stubs/InjectableStubViewEngineManager.cs | 2 +- .../PythonViewCompilerTests.cs | 103 ++-- .../ScriptingLanguageFactoryTests.cs | 4 +- .../ScriptingViewSymbolDictionaryTests.cs | 8 +- .../Spark.Python.Tests.csproj | 8 +- src/Spark.Ruby.Tests/RubyEngineTests.cs | 2 +- src/Spark.Ruby.Tests/RubyViewCompilerTests.cs | 167 +++---- src/Spark.Ruby.Tests/Spark.Ruby.Tests.csproj | 8 +- .../Bindings/BindingExpansionVisitorTester.cs | 8 +- .../Bindings/BindingGrammarTester.cs | 139 ++++-- .../ViewFolderBindingProviderTester.cs | 32 +- src/Spark.Tests/CompiledViewHolderTester.cs | 33 +- .../Compiler/ExpressionBuilderTester.cs | 8 +- .../Compiler/ForEachInspectorTester.cs | 9 +- .../Compiler/SourceWriterTester.cs | 68 +-- src/Spark.Tests/Constraints.cs | 2 +- src/Spark.Tests/InMemoryServiceTest.cs | 14 +- src/Spark.Tests/Models/Comment.cs | 8 +- src/Spark.Tests/Parser/CharGrammarTester.cs | 2 +- src/Spark.Tests/Parser/CodeGrammarTester.cs | 84 ++-- .../JavascriptAnonymousTypeGrammarTester.cs | 103 ++-- src/Spark.Tests/Parser/MarkupGrammarTester.cs | 461 +++++++++++------- src/Spark.Tests/Parser/PaintTester.cs | 77 +-- src/Spark.Tests/Parser/PositionTester.cs | 240 +++++---- src/Spark.Tests/Parser/TypeInspectorTester.cs | 28 +- src/Spark.Tests/Parser/ViewLoaderTester.cs | 76 +-- src/Spark.Tests/Spark.Tests.csproj | 8 +- src/Spark.Tests/Spool/SpoolPageTester.cs | 46 +- src/Spark.Tests/Spool/SpoolReaderTester.cs | 16 +- src/Spark.Tests/Spool/SpoolWriterTester.cs | 71 +-- src/Spark.Tests/Stubs/StubViewContext.cs | 14 +- src/Spark.Tests/Stubs/StubViewData.cs | 3 +- src/Spark.Tests/ValueHolderTester.cs | 28 +- src/Spark.Tests/Visitors/BaseVisitorTester.cs | 6 +- .../Visitors/ChunkBuilderVisitorTester.cs | 91 ++-- .../ConditionalAttributeVisitorTester.cs | 20 +- .../Visitors/NamespaceVisitorTester.cs | 96 ++-- .../Visitors/SpecialNodeVisitorTester.cs | 21 +- .../PdfViewResultTests.cs | 23 +- .../Spark.Web.Mvc.Pdf.Tests.csproj | 8 +- .../HtmlHelperExtensionsTester.cs | 19 +- .../Spark.Web.Mvc.Ruby.Tests.csproj | 8 +- .../Compiler/CSharpViewCompilerTester.cs | 57 ++- .../Compiler/VisualBasicViewCompilerTester.cs | 51 +- .../Controllers/FailureController.cs | 14 +- .../DescriptorBuildingTester.cs | 58 +-- .../DescriptorFilterTester.cs | 3 +- .../LanguageKitFolderTester.cs | 70 ++- .../Spark.Web.Mvc.Tests.csproj | 6 +- .../SparkBatchCompilerTester.cs | 78 +-- .../SparkViewFactoryTester.cs | 204 ++++---- src/Spark.Web.Mvc.Tests/SparkViewTester.cs | 20 +- .../VisualBasicViewTester.cs | 4 +- src/Spark.Web.Tests/BatchCompilationTester.cs | 30 +- .../Bindings/BindingExecutionTester.cs | 18 +- .../Caching/CacheElementTester.cs | 180 ++++--- .../Caching/CacheOriginatorTester.cs | 75 ++- .../Caching/CacheSignalTester.cs | 2 +- .../Caching/CacheUtilitiesTester.cs | 4 +- .../Caching/TextWriterOriginatorTester.cs | 14 +- .../ClientsideCompilerTester.cs | 12 +- .../Compiler/SourceMappingTester.cs | 61 +-- .../SparkSectionHandlerTester.cs | 26 +- .../DefaultResourcePathManagerTester.cs | 37 +- .../Extensions/ServiceCollectionExtensions.cs | 4 +- .../FileSystem/CombinedViewFolderTester.cs | 49 +- .../FileSystem/EmbeddedViewFolderTester.cs | 31 +- .../FileSystem/FileSystemViewFolderTester.cs | 24 +- .../FileSystem/InMemoryViewFolderTester.cs | 59 ++- .../FileSystem/SubViewFolderTester.cs | 65 +-- .../FileSystem/ViewFolderSettingsTester.cs | 12 +- src/Spark.Web.Tests/ImportAndIncludeTester.cs | 68 +-- .../Parser/AutomaticEncodingTester.cs | 42 +- .../Parser/CSharpSyntaxProviderTester.cs | 6 +- src/Spark.Web.Tests/PartialProviderTester.cs | 12 +- .../ComplexPrecompileController.cs | 2 +- .../Precompiled/SimplePrecompileController.cs | 2 +- src/Spark.Web.Tests/Precompiled/View1.cs | 2 +- src/Spark.Web.Tests/Precompiled/View3.cs | 2 +- src/Spark.Web.Tests/PrefixSupportTester.cs | 12 +- src/Spark.Web.Tests/Spark.Web.Tests.csproj | 10 +- .../SparkBatchDescriptorTester.cs | 28 +- src/Spark.Web.Tests/SparkDecoratorTester.cs | 2 +- src/Spark.Web.Tests/SparkExtensionTester.cs | 4 +- src/Spark.Web.Tests/SparkViewFactoryTester.cs | 234 +++++---- src/Spark.Web.Tests/Stubs/StubCacheService.cs | 5 +- src/Spark.Web.Tests/Stubs/StubSparkView2.cs | 2 +- src/Spark.Web.Tests/Stubs/StubViewFactory.cs | 4 +- src/Spark.Web.Tests/ViewActivatorTester.cs | 16 +- .../Visitors/DetectCodeExpressionTester.cs | 51 +- 112 files changed, 2637 insertions(+), 1905 deletions(-) diff --git a/src/Castle.MonoRail.Views.Spark.Tests/Caching/HybridCacheServiceProviderTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/Caching/HybridCacheServiceProviderTests.cs index 2c77cf86..76d478c0 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/Caching/HybridCacheServiceProviderTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/Caching/HybridCacheServiceProviderTests.cs @@ -36,7 +36,7 @@ public void Init() .Stub(x => x.UnderlyingContext) .Return(httpContext); - foreach (var key in HttpRuntime.Cache.OfType().Select(x=>x.Key)) + foreach (var key in HttpRuntime.Cache.OfType().Select(x => x.Key)) HttpRuntime.Cache.Remove(Convert.ToString(key)); } @@ -115,9 +115,12 @@ public void StoreAndGetToBothMonorailAndHttpCacheWorkSideBySide() cacheService.Store("xfoo1", null, null, "bar1"); cacheService.Store("xfoo2", null, signal, "bar2"); - Assert.That(cacheService.Get("xfoo1"), Is.EqualTo("bar1")); - Assert.That(cacheService.Get("xfoo2"), Is.EqualTo("bar2")); - Assert.That(cacheService.Get("xfoo3"), Is.Null); + Assert.Multiple(() => + { + Assert.That(cacheService.Get("xfoo1"), Is.EqualTo("bar1")); + Assert.That(cacheService.Get("xfoo2"), Is.EqualTo("bar2")); + Assert.That(cacheService.Get("xfoo3"), Is.Null); + }); _context.Services.CacheProvider.VerifyAllExpectations(); diff --git a/src/Castle.MonoRail.Views.Spark.Tests/Castle.MonoRail.Views.Spark.Tests.csproj b/src/Castle.MonoRail.Views.Spark.Tests/Castle.MonoRail.Views.Spark.Tests.csproj index 779bb8fc..9bab6cdb 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/Castle.MonoRail.Views.Spark.Tests.csproj +++ b/src/Castle.MonoRail.Views.Spark.Tests/Castle.MonoRail.Views.Spark.Tests.csproj @@ -28,10 +28,14 @@ - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - + diff --git a/src/Castle.MonoRail.Views.Spark.Tests/Constraints.cs b/src/Castle.MonoRail.Views.Spark.Tests/Constraints.cs index bae527a8..c02e4807 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/Constraints.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/Constraints.cs @@ -85,7 +85,7 @@ public override ConstraintResult ApplyTo(TActual actual) index = nextIndex + value.Length; } - + return new ConstraintResult(this, index, true); } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/HelperExtensionMethodsTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/HelperExtensionMethodsTests.cs index 669ddf9a..821b273c 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/HelperExtensionMethodsTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/HelperExtensionMethodsTests.cs @@ -72,7 +72,7 @@ public void VerifyAppropriateMethodsPresent() missingMethods.Add(neededMethod); } - Assert.IsEmpty(string.Concat(missingMethods.ToArray()), "{0} methods not represented", missingMethods.Count); + Assert.That(string.Concat(missingMethods.ToArray()), Is.Empty, $"{missingMethods.Count} methods not represented"); } class HelperDescriptor diff --git a/src/Castle.MonoRail.Views.Spark.Tests/ModelDictionaryTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/ModelDictionaryTests.cs index 3f993692..5a9204f3 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/ModelDictionaryTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/ModelDictionaryTests.cs @@ -23,10 +23,13 @@ public class ModelDictionaryTests [Test] public void AnonymousObjectPropertiesInDictionary() { - IDictionary args = new ModelDictionary(new {name = "foo", bar = "quux"}); - Assert.AreEqual(2, args.Count); - Assert.AreEqual("foo", args["name"]); - Assert.AreEqual("quux", args["bar"]); + IDictionary args = new ModelDictionary(new { name = "foo", bar = "quux" }); + Assert.That(args.Count, Is.EqualTo(2)); + Assert.Multiple(() => + { + Assert.That(args["name"], Is.EqualTo("foo")); + Assert.That(args["bar"], Is.EqualTo("quux")); + }); } } } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/Models/UserInfo.cs b/src/Castle.MonoRail.Views.Spark.Tests/Models/UserInfo.cs index 4cc0a643..6845df4e 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/Models/UserInfo.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/Models/UserInfo.cs @@ -20,17 +20,17 @@ namespace Castle.MonoRail.Views.Spark.Tests.Models { - public class UserInfo - { - public string Name { get; set; } - public UserType UserType { get; set; } - } + public class UserInfo + { + public string Name { get; set; } + public UserType UserType { get; set; } + } - public enum UserType - { - Anonymous, - Registered, - Administrator, - } + public enum UserType + { + Anonymous, + Registered, + Administrator, + } } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/PrecompileInstallerTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/PrecompileInstallerTests.cs index 7cbdef4e..1c2bb0fa 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/PrecompileInstallerTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/PrecompileInstallerTests.cs @@ -35,10 +35,11 @@ public void RunPrecompiler() File.Delete(targetFile); var parent = new ParentInstaller(); - var precompile = new PrecompileInstaller(); - - precompile.TargetAssemblyFile = targetFile; - precompile.ViewPath = "MonoRail.Tests.Views"; + var precompile = new PrecompileInstaller + { + TargetAssemblyFile = targetFile, + ViewPath = "MonoRail.Tests.Views" + }; precompile.DescribeBatch += ((sender, e) => e.Batch.For().Include("*").Include("_*")); var state = new Hashtable(); @@ -54,7 +55,7 @@ public void RunPrecompiler() var views = result.GetTypes().Where(x => x.BaseType == typeof(SparkView)) .ToArray(); - Assert.AreEqual(3, views.Length); + Assert.That(views.Length, Is.EqualTo(3)); } public class ParentInstaller : Installer diff --git a/src/Castle.MonoRail.Views.Spark.Tests/SparkBatchCompilerTester.cs b/src/Castle.MonoRail.Views.Spark.Tests/SparkBatchCompilerTester.cs index 3ae4bb27..b6ebdc62 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/SparkBatchCompilerTester.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/SparkBatchCompilerTester.cs @@ -59,8 +59,8 @@ public void CompileBatchDescriptor() var assembly = _factory.Precompile(batch); - Assert.IsNotNull(assembly); - Assert.AreEqual(3, assembly.GetTypes().Count(x => x.BaseType == typeof(SparkView))); + Assert.That(assembly, Is.Not.Null); + Assert.That(assembly.GetTypes().Count(x => x.BaseType == typeof(SparkView)), Is.EqualTo(3)); } [Test] @@ -72,20 +72,23 @@ public void DefaultEntryBehavior() var descriptors = _factory.CreateDescriptors(batch); - Assert.AreEqual(2, descriptors.Count); - Assert.AreEqual(2, descriptors[0].Templates.Count); - Assert.AreEqual(2, descriptors[1].Templates.Count); - - Assert.That( - descriptors.Any( - d => - d.Templates.Contains(string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar)) && - d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); - Assert.That( - descriptors.Any( - d => - d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && - d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); + Assert.That(descriptors.Count, Is.EqualTo(2)); + Assert.Multiple(() => + { + Assert.That(descriptors[0].Templates.Count, Is.EqualTo(2)); + Assert.That(descriptors[1].Templates.Count, Is.EqualTo(2)); + + Assert.That( + descriptors.Any( + d => + d.Templates.Contains(string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar)) && + d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); + Assert.That( + descriptors.Any( + d => + d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && + d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); + }); } [Test] @@ -98,8 +101,8 @@ public void MultipleLayoutFiles() var assembly = _factory.Precompile(batch); - Assert.IsNotNull(assembly); - Assert.AreEqual(4, assembly.GetTypes().Count(x => x.BaseType == typeof(SparkView))); + Assert.That(assembly, Is.Not.Null); + Assert.That(assembly.GetTypes().Count(x => x.BaseType == typeof(SparkView)), Is.EqualTo(4)); } [Test] @@ -112,27 +115,30 @@ public void WildcardIncludeRules() .For().Layout("ajax").Include("_*"); var descriptors = _factory.CreateDescriptors(batch); - Assert.AreEqual(3, descriptors.Count); - Assert.That( - descriptors.Any( - d => - d.Templates.Contains(string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar)) && - d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); - Assert.That( - descriptors.Any( - d => - d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && - d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); - Assert.That( - descriptors.Any( - d => - d.Templates.Contains(string.Format("Stub{0}_Widget.spark", Path.DirectorySeparatorChar)) && - d.Templates.Contains(string.Format("Shared{0}ajax.spark", Path.DirectorySeparatorChar)))); + Assert.That(descriptors.Count, Is.EqualTo(3)); + Assert.Multiple(() => + { + Assert.That( + descriptors.Any( + d => + d.Templates.Contains(string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar)) && + d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); + Assert.That( + descriptors.Any( + d => + d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && + d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); + Assert.That( + descriptors.Any( + d => + d.Templates.Contains(string.Format("Stub{0}_Widget.spark", Path.DirectorySeparatorChar)) && + d.Templates.Contains(string.Format("Shared{0}ajax.spark", Path.DirectorySeparatorChar)))); + }); var assembly = _factory.Precompile(batch); - Assert.IsNotNull(assembly); - Assert.AreEqual(3, assembly.GetTypes().Count(x => x.BaseType == typeof(SparkView))); + Assert.That(assembly, Is.Not.Null); + Assert.That(assembly.GetTypes().Count(x => x.BaseType == typeof(SparkView)), Is.EqualTo(3)); } [Test] @@ -144,19 +150,22 @@ public void ExcludeRules() var descriptors = _factory.CreateDescriptors(batch); - Assert.AreEqual(2, descriptors.Count); - Assert.AreEqual(2, descriptors[0].Templates.Count); - Assert.AreEqual(2, descriptors[1].Templates.Count); - Assert.That( - descriptors.Any( - d => - d.Templates.Contains(string.Format("Stub{0}_Widget.spark", Path.DirectorySeparatorChar)) && - d.Templates.Contains(string.Format("Shared{0}ajax.spark", Path.DirectorySeparatorChar)))); - Assert.That( - descriptors.Any( - d => - d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && - d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); + Assert.That(descriptors.Count, Is.EqualTo(2)); + Assert.Multiple(() => + { + Assert.That(descriptors[0].Templates.Count, Is.EqualTo(2)); + Assert.That(descriptors[1].Templates.Count, Is.EqualTo(2)); + Assert.That( + descriptors.Any( + d => + d.Templates.Contains(string.Format("Stub{0}_Widget.spark", Path.DirectorySeparatorChar)) && + d.Templates.Contains(string.Format("Shared{0}ajax.spark", Path.DirectorySeparatorChar)))); + Assert.That( + descriptors.Any( + d => + d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && + d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); + }); } [Test] @@ -165,9 +174,9 @@ public void FileWithoutSparkExtensionAreIgnored() var batch = new SparkBatchDescriptor(); batch.For(); var descriptors = _factory.CreateDescriptors(batch); - + // no templates - Assert.That(descriptors.SelectMany(d=>d.Templates).All(t=>!t.Contains("Helper"))); + Assert.That(descriptors.SelectMany(d => d.Templates).All(t => !t.Contains("Helper"))); } [Test] @@ -176,12 +185,12 @@ public void ControllersWithHelpersGenerateAccessors() var batch = new SparkBatchDescriptor(); batch.For().Include("index"); _factory.Engine.ViewFolder = new InMemoryViewFolder { { string.Format("foo{0}index.spark", Path.DirectorySeparatorChar), "

foo

" } }; - + var descriptors = _factory.CreateDescriptors(batch); - Assert.AreEqual(1, descriptors.Count); - Assert.AreEqual(1, descriptors[0].Accessors.Count); - Assert.AreEqual(typeof(FooHelper).FullName + " Foo", descriptors[0].Accessors[0].Property); + Assert.That(descriptors.Count, Is.EqualTo(1)); + Assert.That(descriptors[0].Accessors.Count, Is.EqualTo(1)); + Assert.That(descriptors[0].Accessors[0].Property, Is.EqualTo(typeof(FooHelper).FullName + " Foo")); } } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/SparkViewDataTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/SparkViewDataTests.cs index 9a06af17..3f03a951 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/SparkViewDataTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/SparkViewDataTests.cs @@ -48,7 +48,7 @@ public void PropertyBagAvailable() mocks.ReplayAll(); view.Contextualize(engineContext, controllerContext, null, null, null); - Assert.AreEqual("bar", view.ViewData["foo"]); + Assert.That(view.ViewData["foo"], Is.EqualTo("bar")); } [Test] @@ -73,11 +73,15 @@ public void MergingCollectionsLikeVelocity() view.Contextualize(engineContext, controllerContext, null, null, null); - Assert.AreEqual("controllerPropertyBagValue", view.ViewData["controllerPropertyBagKey"]); - Assert.AreEqual("contextFlashValue", view.ViewData["contextFlashKey"]); - Assert.AreEqual("controllerHelpersValue", view.ViewData["controllerHelpersKey"]); - Assert.AreEqual("contextParamsValue", view.ViewData["contextParamsKey"]); - Assert.AreSame(resource, view.ViewData["controllerResourcesKey"]); + Assert.Multiple(() => + { + Assert.That(view.ViewData["controllerPropertyBagKey"], Is.EqualTo("controllerPropertyBagValue")); + Assert.That(view.ViewData["contextFlashKey"], Is.EqualTo("contextFlashValue")); + Assert.That(view.ViewData["controllerHelpersKey"], Is.EqualTo("controllerHelpersValue")); + Assert.That(view.ViewData["contextParamsKey"], Is.EqualTo("contextParamsValue")); + + Assert.That(view.ViewData["controllerResourcesKey"], Is.SameAs(resource)); + }); } } } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryStrictNullBehaviourTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryStrictNullBehaviourTests.cs index 0f0078c6..71243b04 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryStrictNullBehaviourTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryStrictNullBehaviourTests.cs @@ -27,7 +27,7 @@ public class SparkViewFactoryStrictNullBehaviourTests : SparkViewFactoryTestsBas { protected override void Configure() { - var settings = + var settings = new SparkSettings() .SetBaseClassTypeName(typeof(SparkView)); diff --git a/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryTests.cs index 043f055e..4ff8e82b 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryTests.cs @@ -24,7 +24,7 @@ namespace Castle.MonoRail.Views.Spark.Tests using Castle.MonoRail.Framework.Services; using NUnit.Framework; using global::Spark; - + [TestFixture] public class SparkViewFactoryTests : SparkViewFactoryTestsBase { @@ -44,7 +44,7 @@ protected override void Configure() manager.Service(serviceProvider); serviceProvider.ViewEngineManager = manager; serviceProvider.AddService(typeof(IViewEngineManager), manager); - + manager.RegisterEngineForExtesionLookup(factory); manager.RegisterEngineForView(factory); } @@ -53,7 +53,7 @@ protected override void Configure() public void ExtensionIsSpark() { mocks.ReplayAll(); - Assert.AreEqual("spark", factory.ViewFileExtension); + Assert.That(factory.ViewFileExtension, Is.EqualTo("spark")); } [Test] @@ -61,7 +61,7 @@ public void ProcessBasicTemplate() { mocks.ReplayAll(); manager.Process(string.Format("Home{0}Index", Path.DirectorySeparatorChar), output, engineContext, controller, controllerContext); - Assert.That(output.ToString().Contains("

Simple test

")); + Assert.That(output.ToString(), Does.Contain("

Simple test

")); } [Test] @@ -69,19 +69,23 @@ public void ContextAndControllerContextAvailable() { mocks.ReplayAll(); manager.Process(string.Format("Home{0}Index", Path.DirectorySeparatorChar), output, engineContext, controller, controllerContext); - + var descriptor = new SparkViewDescriptor(); descriptor.Templates.Add(string.Format("Home{0}Index.spark", Path.DirectorySeparatorChar)); descriptor.Templates.Add(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)); var entry = factory.Engine.GetEntry(descriptor); var view = (SparkView)entry.CreateInstance(); view.Contextualize(engineContext, controllerContext, serviceProvider.GetService(), factory, null); - + var result = new StringWriter(); view.RenderView(result); - Assert.AreEqual(result.ToString(), output.ToString()); - Assert.AreSame(engineContext, view.Context); - Assert.AreSame(controllerContext, view.ControllerContext); + Assert.Multiple(() => + { + Assert.That(output.ToString(), Is.EqualTo(result.ToString())); + + Assert.That(view.Context, Is.SameAs(engineContext)); + Assert.That(view.ControllerContext, Is.SameAs(controllerContext)); + }); } [Test, Ignore("Need to get the helpers to function again using the stub objects")] @@ -121,7 +125,7 @@ public void NullBehaviourConfiguredToLenient() mocks.ReplayAll(); manager.Process(string.Format("Home{0}NullBehaviourConfiguredToLenient", Path.DirectorySeparatorChar), output, engineContext, controller, controllerContext); var content = output.ToString(); - Assert.IsFalse(content.Contains("default")); + Assert.That(content.Contains("default"), Is.False); ContainsInOrder(content, "

name kaboom *${user.Name}*

", @@ -134,7 +138,7 @@ public void TerseHtmlEncode() { mocks.ReplayAll(); manager.Process(string.Format("Home{0}TerseHtmlEncode", Path.DirectorySeparatorChar), output, engineContext, controller, controllerContext); - + // See AutomaticEncoding = true in Configure() method ContainsInOrder(output.ToString(), "

This <contains/> html

"); @@ -149,8 +153,8 @@ public void IncludingStatementsDirectly() "

was true

"); - Assert.IsFalse(output.ToString().Contains("

was false

")); - + Assert.That(output.ToString().Contains("

was false

"), Is.False); + } [Test] @@ -161,8 +165,11 @@ public void Rescue404Rendering() mocks.ReplayAll(); var handler = new MonoRailHttpHandlerFactory.NotFoundHandler("", "nosuchcontroller", engineContext); handler.ProcessRequest(null); - Assert.AreEqual(404, response.StatusCode); - Assert.AreEqual("

404 message rendered

\r\n", output.ToString()); + Assert.Multiple(() => + { + Assert.That(response.StatusCode, Is.EqualTo(404)); + Assert.That(output.ToString(), Is.EqualTo("

404 message rendered

\r\n")); + }); } [Test, Ignore("Controller Type effects are no longer supported in 1.1")] @@ -173,7 +180,7 @@ public void ControllerHelperAttributeCanBeUsed() controllerContext.Helpers.Add("bar", new Helpers.TestingHelper()); mocks.ReplayAll(); manager.Process(string.Format("Home{0}ControllerHelperAttributeCanBeUsed", Path.DirectorySeparatorChar), output, engineContext, controller, controllerContext); - Assert.That(output.ToString().Contains("

Hello

")); + Assert.That(output.ToString(), Does.Contain("

Hello

")); } [Test, Ignore("No way to mock HttpContext.Current")] @@ -184,7 +191,7 @@ public void ControllerHelpersCanBeUsedWhenRenderingMailView() controllerContext.Helpers.Add("bar", new Helpers.TestingHelper()); mocks.ReplayAll(); manager.Process(string.Format("Home{0}ControllerHelperAttributeCanBeUsed", Path.DirectorySeparatorChar), null, output, null); - Assert.That(output.ToString().Contains("

Hello

")); + Assert.That(output.ToString(), Does.Contain("

Hello

")); } [Test] @@ -216,4 +223,4 @@ public void Dispose() } } } - + diff --git a/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryTestsBase.cs b/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryTestsBase.cs index 7256eb4f..6031a4f2 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryTestsBase.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/SparkViewFactoryTestsBase.cs @@ -38,7 +38,6 @@ public abstract class SparkViewFactoryTestsBase protected SparkViewFactory factory; protected StubMonoRailServices serviceProvider; - [SetUp] public void Init() { @@ -54,8 +53,8 @@ public void Init() controllerContext = new ControllerContext(); propertyBag = controllerContext.PropertyBag; - - controllerContext.LayoutNames = new []{"default"}; + + controllerContext.LayoutNames = new[] { "default" }; output = new StringWriter(); server = new StubServerUtility(); @@ -69,20 +68,24 @@ public void Init() response = engineContext.Response; } + [TearDown] + public void TearDown() + { + output.Dispose(); + } protected abstract void Configure(); - protected void InitUrlInfo(string areaName, string controllerName, string actionName) { - var urlInfo = new UrlInfo(areaName, controllerName, actionName, "/", "castle"); + _ = new UrlInfo(areaName, controllerName, actionName, "/", "castle"); engineContext = new StubEngineContext(); engineContext.AddService(typeof(IUrlBuilder), serviceProvider.UrlBuilder); engineContext.CurrentController = controller; engineContext.CurrentControllerContext = controllerContext; engineContext.Services.ViewEngineManager = serviceProvider.ViewEngineManager; - output = (StringWriter) engineContext.Response.Output; + output = (StringWriter)engineContext.Response.Output; var routeMatch = new RouteMatch(); controllerContext.RouteMatch = routeMatch; @@ -95,7 +98,8 @@ protected static void ContainsInOrder(string content, params string[] values) foreach (string value in values) { int nextIndex = content.IndexOf(value, index); - Assert.GreaterOrEqual(nextIndex, 0, string.Format("Looking for {0}", value)); + + Assert.That(nextIndex, Is.GreaterThanOrEqualTo(0), () => $"Looking for {value}"); index = nextIndex + value.Length; } } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/Stubs/StubController.cs b/src/Castle.MonoRail.Views.Spark.Tests/Stubs/StubController.cs index 9572c999..08de0aef 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/Stubs/StubController.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/Stubs/StubController.cs @@ -23,7 +23,7 @@ public class StubController : SmartDispatcherController public void Index() { } - + public void List() { } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/AllFrameworkComponentTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/AllFrameworkComponentTests.cs index 80daaed1..81d0c052 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/AllFrameworkComponentTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/AllFrameworkComponentTests.cs @@ -26,8 +26,8 @@ public void AuthenticatedContent() { var content = ExecuteView(string.Format("Home{0}AllFrameworkComponents-AuthenticatedContent.spark", Path.DirectorySeparatorChar)); - Assert.That(content.Contains("two")); - Assert.IsFalse(content.Contains("one")); + Assert.That(content, Does.Contain("two")); + Assert.That(content.Contains("one"), Is.False); } [Test] @@ -35,7 +35,7 @@ public void CaptureFor() { var content = ExecuteView(string.Format("Home{0}AllFrameworkComponents-CaptureFor.spark", Path.DirectorySeparatorChar)); - Assert.That(content.Contains("onetwothreefour")); + Assert.That(content, Does.Contain("onetwothreefour")); } [Test] @@ -69,43 +69,43 @@ public void ColumnRenderer() [Test, Ignore("Creating a test for each built-in component")] public void DiggStylePagination() { - var content = ExecuteView(string.Format("Home{0}AllFrameworkComponents-DiggStylePagination.spark", Path.DirectorySeparatorChar)); + _ = ExecuteView(string.Format("Home{0}AllFrameworkComponents-DiggStylePagination.spark", Path.DirectorySeparatorChar)); } [Test, Ignore("Creating a test for each built-in component")] public void Security() { - var content = ExecuteView(string.Format("Home{0}AllFrameworkComponents-Security.spark", Path.DirectorySeparatorChar)); + _ = ExecuteView(string.Format("Home{0}AllFrameworkComponents-Security.spark", Path.DirectorySeparatorChar)); } [Test, Ignore("Creating a test for each built-in component")] public void SelectStylePagination() { - var content = ExecuteView(string.Format("Home{0}AllFrameworkComponents-SelectStylePagination.spark", Path.DirectorySeparatorChar)); + _ = ExecuteView(string.Format("Home{0}AllFrameworkComponents-SelectStylePagination.spark", Path.DirectorySeparatorChar)); } [Test, Ignore("Creating a test for each built-in component")] public void SiteMap() { - var content = ExecuteView(string.Format("Home{0}AllFrameworkComponents-SiteMap.spark", Path.DirectorySeparatorChar)); + _ = ExecuteView(string.Format("Home{0}AllFrameworkComponents-SiteMap.spark", Path.DirectorySeparatorChar)); } [Test, Ignore("Creating a test for each built-in component")] public void TreeMaker() { - var content = ExecuteView(string.Format("Home{0}AllFrameworkComponents-TreeMaker.spark", Path.DirectorySeparatorChar)); + _ = ExecuteView(string.Format("Home{0}AllFrameworkComponents-TreeMaker.spark", Path.DirectorySeparatorChar)); } [Test, Ignore("Creating a test for each built-in component")] public void UpdatePage() { - var content = ExecuteView(string.Format("Home{0}AllFrameworkComponents-UpdatePage.spark", Path.DirectorySeparatorChar)); + _ = ExecuteView(string.Format("Home{0}AllFrameworkComponents-UpdatePage.spark", Path.DirectorySeparatorChar)); } [Test, Ignore("Creating a test for each built-in component")] public void UpdateTag() { - var content = ExecuteView(string.Format("Home{0}AllFrameworkComponents-UpdateTag.spark", Path.DirectorySeparatorChar)); + _ = ExecuteView(string.Format("Home{0}AllFrameworkComponents-UpdateTag.spark", Path.DirectorySeparatorChar)); } string ExecuteView(string page) @@ -117,8 +117,8 @@ string ExecuteView(string page) mocks.VerifyAll(); - Assert.IsNotNull(writer.ToString()); - Assert.IsNotEmpty(writer.ToString()); + Assert.That(writer.ToString(), Is.Not.Null); + Assert.That(writer.ToString(), Is.Not.Empty); return writer.ToString(); } @@ -128,7 +128,7 @@ static void ContainsInOrder(string content, params string[] values) foreach (string value in values) { int nextIndex = content.IndexOf(value, index); - Assert.GreaterOrEqual(nextIndex, 0, string.Format("Looking for {0}", value)); + Assert.That(nextIndex, Is.GreaterThanOrEqualTo(0), () => $"Looking for {value}"); index = nextIndex + value.Length; } } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/BaseViewComponentTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/BaseViewComponentTests.cs index 68ccc496..8ac85e11 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/BaseViewComponentTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/BaseViewComponentTests.cs @@ -29,14 +29,16 @@ public class BaseViewComponentTests protected StubEngineContext engineContext; protected SparkViewFactory factory; protected IController controller; - + [SetUp] public virtual void Init() { mocks = new MockRepository(); - var services = new StubMonoRailServices(); - services.ViewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views"); + var services = new StubMonoRailServices + { + ViewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views") + }; services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader); viewComponentFactory = new DefaultViewComponentFactory(); @@ -55,12 +57,20 @@ public virtual void Init() controller = MockRepository.GenerateMock(); controllerContext = new ControllerContext(); - var request = new StubRequest(); - request.FilePath = ""; + var request = new StubRequest + { + FilePath = "" + }; var response = new StubResponse(); engineContext = new StubEngineContext(request, response, new UrlInfo("", "Home", "Index", "/", "castle")); engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory); engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); } + + [TearDown] + public virtual void TearDown() + { + controller.Dispose(); + } } } \ No newline at end of file diff --git a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentExtensionTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentExtensionTests.cs index 2d7a7994..a2e5777f 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentExtensionTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentExtensionTests.cs @@ -26,14 +26,14 @@ namespace Castle.MonoRail.Views.Spark.Tests.ViewComponents [TestFixture] public class ViewComponentExtensionTests : BaseViewComponentTests { - + [Test] public void DiggPaginationComponent() { var writer = new StringWriter(); IList dataSource = new List(); - for(int i = 100; i != 200; i++) + for (int i = 100; i != 200; i++) dataSource.Add(i.ToString()); controllerContext.PropertyBag["items"] = PaginationHelper.CreatePagination(dataSource, 10, 3); @@ -51,69 +51,72 @@ static void ContainsInOrder(string content, params string[] values) foreach (string value in values) { int nextIndex = content.IndexOf(value, index); - Assert.GreaterOrEqual(nextIndex, 0, string.Format("Looking for {0}", value)); + Assert.That(nextIndex, Is.GreaterThanOrEqualTo(0), () => $"Looking for {value}"); index = nextIndex + value.Length; } } - [ViewComponentDetails("Simple")] - public class SimpleViewComponent : ViewComponent - { - [ViewComponentParam] - public string Caption { get; set; } - - public override void Render() - { - RenderText("

" + Caption + "

"); - } - } - - [Test] - public void ComponentsSupportEachAttribute() - { - viewComponentFactory.Registry.AddViewComponent("Simple", typeof(SimpleViewComponent)); - - var writer = new StringWriter(); - factory.Process(string.Format("Home{0}ComponentsSupportEachAttribute", Path.DirectorySeparatorChar), writer, - engineContext, controller, controllerContext); - - ContainsInOrder(writer.ToString(), - "

alpha

", - "

beta

", - "

gamma

"); - } - - [Test] - public void ComponentsSupportIfAttribute() - { - viewComponentFactory.Registry.AddViewComponent("Simple", typeof(SimpleViewComponent)); - - var writer = new StringWriter(); - factory.Process(string.Format("Home{0}ComponentsSupportIfAttribute", Path.DirectorySeparatorChar), writer, - engineContext, controller, controllerContext); - - ContainsInOrder(writer.ToString(), - "

foo1

", - "

alpha

", - "

gamma

"); - Assert.IsFalse(writer.ToString().Contains("foo2")); - Assert.IsFalse(writer.ToString().Contains("beta")); - } - - [Test] - public void ComponentsSupportOnceAttribute() - { - viewComponentFactory.Registry.AddViewComponent("Simple", typeof(SimpleViewComponent)); - - var writer = new StringWriter(); - factory.Process(string.Format("Home{0}ComponentsSupportOnceAttribute", Path.DirectorySeparatorChar), writer, - engineContext, controller, controllerContext); - - ContainsInOrder(writer.ToString(), - "

foo1

", - "

foo2

"); - Assert.IsFalse(writer.ToString().Contains("foo3")); - } - } + [ViewComponentDetails("Simple")] + public class SimpleViewComponent : ViewComponent + { + [ViewComponentParam] + public string Caption { get; set; } + + public override void Render() + { + RenderText("

" + Caption + "

"); + } + } + + [Test] + public void ComponentsSupportEachAttribute() + { + viewComponentFactory.Registry.AddViewComponent("Simple", typeof(SimpleViewComponent)); + + var writer = new StringWriter(); + factory.Process(string.Format("Home{0}ComponentsSupportEachAttribute", Path.DirectorySeparatorChar), writer, + engineContext, controller, controllerContext); + + ContainsInOrder(writer.ToString(), + "

alpha

", + "

beta

", + "

gamma

"); + } + + [Test] + public void ComponentsSupportIfAttribute() + { + viewComponentFactory.Registry.AddViewComponent("Simple", typeof(SimpleViewComponent)); + + var writer = new StringWriter(); + factory.Process(string.Format("Home{0}ComponentsSupportIfAttribute", Path.DirectorySeparatorChar), writer, + engineContext, controller, controllerContext); + + ContainsInOrder(writer.ToString(), + "

foo1

", + "

alpha

", + "

gamma

"); + Assert.Multiple(() => + { + Assert.That(writer.ToString().Contains("foo2"), Is.False); + Assert.That(writer.ToString().Contains("beta"), Is.False); + }); + } + + [Test] + public void ComponentsSupportOnceAttribute() + { + viewComponentFactory.Registry.AddViewComponent("Simple", typeof(SimpleViewComponent)); + + var writer = new StringWriter(); + factory.Process(string.Format("Home{0}ComponentsSupportOnceAttribute", Path.DirectorySeparatorChar), writer, + engineContext, controller, controllerContext); + + ContainsInOrder(writer.ToString(), + "

foo1

", + "

foo2

"); + Assert.That(writer.ToString().Contains("foo3"), Is.False); + } + } } \ No newline at end of file diff --git a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentRenderBodyTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentRenderBodyTests.cs index aeaee085..706c606c 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentRenderBodyTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentRenderBodyTests.cs @@ -45,9 +45,12 @@ public void ComponentBodySimpleHtml() mocks.VerifyAll(); var content = writer.ToString(); - Assert.That(content.Contains("

This is text

")); - Assert.IsFalse(content.Contains("")); - Assert.IsFalse(content.Contains("")); + Assert.That(content, Does.Contain("

This is text

")); + Assert.Multiple(() => + { + Assert.That(content.Contains(""), Is.False); + Assert.That(content.Contains(""), Is.False); + }); } @@ -63,13 +66,16 @@ public void ComponentBodyHtmlHasAttributes() mocks.VerifyAll(); var content = writer.ToString(); - Assert.That(content.Contains("")); - Assert.That(content.Contains("")); - Assert.IsFalse(content.Contains("")); - Assert.IsFalse(content.Contains("")); + Assert.That(content, Does.Contain("")); + Assert.That(content, Does.Contain("")); + Assert.Multiple(() => + { + Assert.That(content.Contains(""), Is.False); + Assert.That(content.Contains(""), Is.False); + }); } - + [Test] public void RenderingComponentWithBodyAndNoDetailsAttrib() { @@ -83,9 +89,12 @@ public void RenderingComponentWithBodyAndNoDetailsAttrib() mocks.VerifyAll(); var content = writer.ToString(); - Assert.That(content.Contains("

This is text

")); - Assert.IsFalse(content.Contains("")); - Assert.IsFalse(content.Contains("")); + Assert.That(content, Does.Contain("

This is text

")); + Assert.Multiple(() => + { + Assert.That(content.Contains(""), Is.False); + Assert.That(content.Contains(""), Is.False); + }); } } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentRenderViewTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentRenderViewTests.cs index c4dbf1dd..251d36a4 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentRenderViewTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentRenderViewTests.cs @@ -41,7 +41,7 @@ public void ComponentCallingRenderView() writer, engineContext, controller, controllerContext); var output = writer.ToString(); - Assert.IsTrue(output.Contains("This is a widget")); + Assert.That(output, Does.Contain("This is a widget")); } [Test] @@ -55,8 +55,8 @@ public void ComponentRenderViewWithParameters() engineContext, controller, controllerContext); var output = writer.ToString(); - Assert.IsTrue(output.Contains("Mode Alpha and 123")); - Assert.IsTrue(output.Contains("Mode Beta and 456")); + Assert.That(output, Does.Contain("Mode Alpha and 123")); + Assert.That(output, Does.Contain("Mode Beta and 456")); } [Test] @@ -69,8 +69,8 @@ public void ComponentRenderViewWithContent() writer, engineContext, controller, controllerContext); var output = writer.ToString(); - Assert.IsTrue(output.Contains("Mode Delta and 789")); - Assert.IsTrue(output.Contains("

!!Delta!!

")); + Assert.That(output, Does.Contain("Mode Delta and 789")); + Assert.That(output, Does.Contain("

!!Delta!!

")); } [Test] @@ -94,7 +94,7 @@ public void ComponentRenderViewFromEmbeddedResource() mocks.VerifyAll(); var content = writer.ToString(); - Assert.That(content.Contains("

This was embedded

")); + Assert.That(content, Does.Contain("

This was embedded

")); } [Test] @@ -112,9 +112,9 @@ public void ComponentRenderViewSharesOnceFlags() mocks.VerifyAll(); var content = writer.ToString(); - Assert.That(content.Contains("

ok1

")); - Assert.That(content.Contains("

ok2

")); - Assert.IsFalse(content.Contains("fail")); + Assert.That(content, Does.Contain("

ok1

")); + Assert.That(content, Does.Contain("

ok2

")); + Assert.That(content.Contains("fail"), Is.False); } [Test] @@ -132,7 +132,7 @@ public void ComponentRenderViewUsesGlobalSpark() mocks.VerifyAll(); var content = writer.ToString(); - Assert.That(content.Contains("

ok1

")); + Assert.That(content, Does.Contain("

ok1

")); } [ViewComponentDetails("WidgetComponent")] diff --git a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentSectionChunkBuilderVisitorTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentSectionChunkBuilderVisitorTests.cs index a6dce210..79905963 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentSectionChunkBuilderVisitorTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentSectionChunkBuilderVisitorTests.cs @@ -31,13 +31,16 @@ public void CorrectSectionsCreated() var nodes = grammar.Nodes(new Position(new SourceContext( "123 456 stuff yadda"))); var details = new ViewComponentDetailsAttribute("Testing") { Sections = "foo,baaz,bar,quux" }; - var visitor = new ViewComponentVisitor(new ChunkBuilderVisitor(new VisitorContext{Paint=nodes.Rest.GetPaint()}), new ViewComponentInfo { Details = details }); + var visitor = new ViewComponentVisitor(new ChunkBuilderVisitor(new VisitorContext { Paint = nodes.Rest.GetPaint() }), new ViewComponentInfo { Details = details }); visitor.Accept(nodes.Value); - Assert.AreEqual(3, visitor.Sections.Count); + Assert.That(visitor.Sections.Count, Is.EqualTo(3)); - Assert.AreEqual(1, visitor.Sections["foo"].Count); + Assert.Multiple(() => + { + Assert.That(visitor.Sections["foo"].Count, Is.EqualTo(1)); - Assert.AreEqual("123", ((SendLiteralChunk)visitor.Sections["foo"][0]).Text); + Assert.That(((SendLiteralChunk)visitor.Sections["foo"][0]).Text, Is.EqualTo("123")); + }); } diff --git a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentSectionTests.cs b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentSectionTests.cs index e222aac5..ecdf9717 100644 --- a/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentSectionTests.cs +++ b/src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentSectionTests.cs @@ -44,9 +44,9 @@ public void ComponentWithSimpleSections() writer, engineContext, controller, controllerContext); var output = writer.ToString(); - Assert.IsTrue(output.Contains("this-is-a-header")); - Assert.IsTrue(output.Contains("this-is-a-body")); - Assert.IsTrue(output.Contains("this-is-a-footer")); + Assert.That(output, Does.Contain("this-is-a-header")); + Assert.That(output, Does.Contain("this-is-a-body")); + Assert.That(output, Does.Contain("this-is-a-footer")); } [Test] @@ -59,9 +59,12 @@ public void ComponentWithIfConditionInSection() writer, engineContext, controller, controllerContext); var output = writer.ToString(); - Assert.IsTrue(output.Contains("this-should-show-up")); - Assert.IsFalse(output.Contains("this-should-not-show-up")); - Assert.IsFalse(output.Contains("if condition")); + Assert.That(output, Does.Contain("this-should-show-up")); + Assert.Multiple(() => + { + Assert.That(output.Contains("this-should-not-show-up"), Is.False); + Assert.That(output.Contains("if condition"), Is.False); + }); } [Test] @@ -79,8 +82,11 @@ public void ComponentWithForEachInSection() "10", "9", "8")); - Assert.IsFalse(output.Contains("for each")); - Assert.IsFalse(output.Contains("span each")); + Assert.Multiple(() => + { + Assert.That(output.Contains("for each"), Is.False); + Assert.That(output.Contains("span each"), Is.False); + }); } [Test] @@ -93,7 +99,7 @@ public void ComponentWithPartialsInSection() engineContext, controller, controllerContext); var output = writer.ToString(); - Assert.IsTrue(output.Contains("this is some text: test123")); + Assert.That(output, Does.Contain("this is some text: test123")); } [Test] @@ -106,20 +112,23 @@ public void NestedComponentInSection() engineContext, controller, controllerContext); var output = writer.ToString(); - Assert.IsTrue(output.Contains("header1")); - Assert.IsTrue(output.Contains("header2")); - Assert.IsTrue(output.Contains("body1")); - Assert.IsTrue(output.Contains("body2")); - Assert.IsTrue(output.Contains("footer1")); - Assert.IsTrue(output.Contains("footer2")); - - Assert.IsFalse(output.Contains("
")); - Assert.IsFalse(output.Contains("")); - Assert.IsFalse(output.Contains("