public void GivenDiamondReferencing_ThenConcatDependenciesReturnsEachReferencedModuleOnlyOnceInDependencyOrder() { var module1 = new Module("~/module-1"); var asset1 = new Mock<IAsset>(); SetupAsset("~/module-1/a.js", asset1); asset1.SetupGet(a => a.References) .Returns(new[] { new AssetReference("~/module-2/b.js", asset1.Object, 1, AssetReferenceType.DifferentModule), new AssetReference("~/module-3/c.js", asset1.Object, 1, AssetReferenceType.DifferentModule) }); module1.Assets.Add(asset1.Object); var module2 = new Module("~/module-2"); var asset2 = new Mock<IAsset>(); SetupAsset("~/module-2/b.js", asset2); asset2.SetupGet(a => a.References) .Returns(new[] { new AssetReference("~/module-4/d.js", asset2.Object, 1, AssetReferenceType.DifferentModule) }); module2.Assets.Add(asset2.Object); var module3 = new Module("~/module-3"); var asset3 = new Mock<IAsset>(); SetupAsset("~/module-3/c.js", asset3); asset3.SetupGet(a => a.References) .Returns(new[] { new AssetReference("~/module-4/d.js", asset3.Object, 1, AssetReferenceType.DifferentModule) }); module3.Assets.Add(asset3.Object); var module4 = new Module("~/module-4"); var asset4 = new Mock<IAsset>(); SetupAsset("~/module-4/d.js", asset4); module4.Assets.Add(asset4.Object); var container = new ModuleContainer<Module>(new[] { module1, module2, module3, module4 }); container.IncludeReferencesAndSortModules(new[] { module1, module2, module3, module4 }) .SequenceEqual(new[] { module4, module2, module3, module1 }).ShouldBeTrue(); }
public void GivenModulesWithNoDependenciesAreReferencedInNonAlphaOrder_WhenIncludeReferencesAndSortModules_ThenReferenceOrderIsMaintained() { var module1 = new Module("~/module1"); var module2 = new Module("~/module2"); var container = new ModuleContainer<Module>(new[] { module1, module2 }); var sorted = container.IncludeReferencesAndSortModules(new[] { module2, module1 }); sorted.SequenceEqual(new[] { module2, module1 }).ShouldBeTrue(); }
public void GivenModulesWithCyclicReferences_WhenIncludeReferencesAndSortModules_ThenExceptionThrown() { var module1 = new Module("~/module1"); var module2 = new Module("~/module2"); module1.AddReferences(new[] { "~/module2" }); module2.AddReferences(new[] { "~/module1" }); var container = new ModuleContainer<Module>(new[] { module1, module2 }); Assert.Throws<InvalidOperationException>(delegate { container.IncludeReferencesAndSortModules(new[] { module2, module1 }); }); }
public void SortModulesToleratesExternalModulesWhichAreNotInTheContainer() { var externalModule1 = new ExternalScriptModule("http://test.com/test1.js"); var externalModule2 = new ExternalScriptModule("http://test.com/test2.js"); var container = new ModuleContainer<ScriptModule>(Enumerable.Empty<ScriptModule>()); var results = container.IncludeReferencesAndSortModules(new[] { externalModule1, externalModule2 }); results.SequenceEqual(new[] { externalModule1, externalModule2 }).ShouldBeTrue(); }
public void ImplicitReferenceOrderingMustNotIntroduceCycles() { var ms = Enumerable.Range(0, 5).Select(i => new Module("~/" + i)).ToArray(); ms[1].AddReferences(new[] { "~/4" }); ms[4].AddReferences(new[] { "~/3" }); var container = new ModuleContainer<Module>(ms); var sorted = container.IncludeReferencesAndSortModules(ms).ToArray(); sorted[0].ShouldBeSameAs(ms[0]); sorted[1].ShouldBeSameAs(ms[2]); sorted[2].ShouldBeSameAs(ms[3]); sorted[3].ShouldBeSameAs(ms[4]); sorted[4].ShouldBeSameAs(ms[1]); }
public void GivenModuleWithReferenceToAnotherModule_ModulesAreSortedInDependencyOrder() { var module1 = new Module("~/module1"); var module2 = new Module("~/module2"); module1.AddReferences(new[] { "~/module2" }); var container = new ModuleContainer<Module>(new[] { module1, module2 }); var sorted = container.IncludeReferencesAndSortModules(new[] { module1, module2 }); sorted.SequenceEqual(new[] { module2, module1 }).ShouldBeTrue(); }