Skip to content

Commit

Permalink
Merge pull request #81 from SparkViewEngine/new-build
Browse files Browse the repository at this point in the history
New build
  • Loading branch information
RobertTheGrey authored Dec 5, 2024
2 parents 526a6ca + 4c4ac54 commit d7b703e
Show file tree
Hide file tree
Showing 117 changed files with 2,707 additions and 1,957 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Init()
.Stub(x => x.UnderlyingContext)
.Return(httpContext);

foreach (var key in HttpRuntime.Cache.OfType<DictionaryEntry>().Select(x=>x.Key))
foreach (var key in HttpRuntime.Cache.OfType<DictionaryEntry>().Select(x => x.Key))
HttpRuntime.Cache.Remove(Convert.ToString(key));
}

Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Console" Version="3.16.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit.Console" Version="3.18.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="RhinoMocks" Version="3.6.1" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Castle.MonoRail.Views.Spark.Tests/Constraints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override ConstraintResult ApplyTo<TActual>(TActual actual)

index = nextIndex + value.Length;
}

return new ConstraintResult(this, index, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void VerifyAppropriateMethodsPresent()
missingMethods.Add(neededMethod);
}

Assert.IsEmpty(string.Concat<MethodDescriptor>(missingMethods.ToArray()), "{0} methods not represented", missingMethods.Count);
Assert.That(string.Concat<MethodDescriptor>(missingMethods.ToArray()), Is.Empty, $"{missingMethods.Count} methods not represented");
}

class HelperDescriptor
Expand Down
11 changes: 7 additions & 4 deletions src/Castle.MonoRail.Views.Spark.Tests/ModelDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ public class ModelDictionaryTests
[Test]
public void AnonymousObjectPropertiesInDictionary()
{
IDictionary<string, object> args = new ModelDictionary(new {name = "foo", bar = "quux"});
Assert.AreEqual(2, args.Count);
Assert.AreEqual("foo", args["name"]);
Assert.AreEqual("quux", args["bar"]);
IDictionary<string, object> 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"));
});
}
}
}
22 changes: 11 additions & 11 deletions src/Castle.MonoRail.Views.Spark.Tests/Models/UserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<StubController>().Include("*").Include("_*"));

var state = new Hashtable();
Expand All @@ -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
Expand Down
119 changes: 64 additions & 55 deletions src/Castle.MonoRail.Views.Spark.Tests/SparkBatchCompilerTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -112,27 +115,30 @@ public void WildcardIncludeRules()
.For<StubController>().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]
Expand All @@ -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]
Expand All @@ -165,9 +174,9 @@ public void FileWithoutSparkExtensionAreIgnored()
var batch = new SparkBatchDescriptor();
batch.For<StubController>();
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]
Expand All @@ -176,12 +185,12 @@ public void ControllersWithHelpersGenerateAccessors()
var batch = new SparkBatchDescriptor();
batch.For<FooController>().Include("index");
_factory.Engine.ViewFolder = new InMemoryViewFolder { { string.Format("foo{0}index.spark", Path.DirectorySeparatorChar), "<p>foo</p>" } };

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"));
}
}

Expand Down
16 changes: 10 additions & 6 deletions src/Castle.MonoRail.Views.Spark.Tests/SparkViewDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SparkViewFactoryStrictNullBehaviourTests : SparkViewFactoryTestsBas
{
protected override void Configure()
{
var settings =
var settings =
new SparkSettings()
.SetBaseClassTypeName(typeof(SparkView));

Expand Down
Loading

0 comments on commit d7b703e

Please sign in to comment.