using UnitTestSharp; namespace Ariadne.Vellum.UnitTests { public class ArcPartListTests : TestFixture { public class ScopeTests : TestFixture { public void ListsTheCallsLocalsInAListOfItsOwn() { var parts = new ArcPartList(); parts.Local("Run.count"); parts.Scope("Run.first/", typeof(int)).Local("Step.name"); CheckEqual(new[] { "Run.count" }, parts.Keys); CheckEqual(new[] { "Run.first/" }, parts.ScopeNames); CheckEqual(new[] { "Step.name" }, parts.Scopes[0].Keys); CheckEqual(new[] { typeof(string) }, parts.Scopes[0].Types); CheckEqual(new[] { true }, parts.Scopes[0].IsLocal); } public void SameNameTwice_AddsToTheSameList() { var parts = new ArcPartList(); parts.Scope("Run.first/").Local("Step.count"); parts.Scope("Run.first/").Local("Step.name"); CheckEqual(1, parts.Scopes.Count); CheckEqual(new[] { "Step.count", "Step.name" }, parts.Scopes[0].Keys); } public void DifferentNames_AreKeptApartInTheOrderNamed() { var parts = new ArcPartList(); parts.Scope("Run.second/"); parts.Scope("Run.first/"); CheckEqual(new[] { "Run.second/", "Run.first/" }, parts.ScopeNames); } public void CallRunningTheFramesOfACallAbove_ReturnsNullAndHoldsThatCallsList() { var parts = new ArcPartList(); IArcPartLister outer = parts.Scope("Run.first/", typeof(int), typeof(string)); IArcPartLister repeat = outer.Scope("Again.wait/", typeof(int), typeof(string)); CheckNull(repeat); CheckTrue(ReferenceEquals(parts.Scopes[0], parts.Scopes[0].Scopes[0])); CheckEqual(new[] { "Again.wait/" }, parts.Scopes[0].ScopeNames); } public void CallRunningFramesBeyondTheOnesAbove_IsAListOfItsOwn() { var parts = new ArcPartList(); IArcPartLister outer = parts.Scope("Run.first/", typeof(int), typeof(string)); IArcPartLister inner = outer.Scope("Again.wait/", typeof(int), typeof(long)); CheckNotNull(inner); CheckFalse(ReferenceEquals(parts.Scopes[0], parts.Scopes[0].Scopes[0])); } public void CallRepeatingAnAncestorFurtherUp_ReturnsNull() { var parts = new ArcPartList(); IArcPartLister outer = parts.Scope("Run.first/", typeof(int)); IArcPartLister middle = outer.Scope("A.call/", typeof(string)); CheckNull(middle.Scope("B.call/", typeof(int))); CheckTrue(ReferenceEquals(parts.Scopes[0], parts.Scopes[0].Scopes[0].Scopes[0])); } public void NamingARepeatAgain_ReturnsNullAgain() { var parts = new ArcPartList(); IArcPartLister outer = parts.Scope("Run.first/", typeof(int)); outer.Scope("Again.wait/", typeof(int)); CheckNull(outer.Scope("Again.wait/", typeof(int))); CheckEqual(1, parts.Scopes[0].Scopes.Count); } public void CallInsideACall_IsAListInsideThatCallsList() { var parts = new ArcPartList(); parts.Scope("Run.first/").Scope("Step.second/").Local("Inner.count"); CheckEqual(new[] { "Inner.count" }, parts.Scopes[0].Scopes[0].Keys); } } } }