public void GivenAssetWithUrlReferenceAndSameBundleLevelUrlReference_WhenCreate_ThenExternalBundleInContainer() { var asset = new Mock <IAsset>(); asset.SetupGet(a => a.References) .Returns(new[] { new AssetReference("http://test.com/", asset.Object, -1, AssetReferenceType.Url) }); var externalBundle = new TestableBundle("http://test.com/"); var factory = new Mock <IBundleFactory <Bundle> >(); factory.Setup(f => f.CreateBundle("http://test.com/", It.IsAny <IEnumerable <IFile> >(), It.IsAny <BundleDescriptor>())) .Returns(externalBundle); var factories = new Dictionary <Type, IBundleFactory <Bundle> >(); factories[typeof(TestableBundle)] = factory.Object; var containerFactory = CreateFactory(factories); var bundle = new TestableBundle("~/test"); bundle.AddReference("http://test.com/"); bundle.Assets.Add(asset.Object); var settings = CreateSettings(); var container = containerFactory.Create(new[] { bundle }, settings); container.FindBundleContainingPath <Bundle>("http://test.com/").ShouldBeSameAs(externalBundle); }
public void WhenCreateWithBundleHavingExternalReference_ThenAnExternalBundleIsAlsoAddedToContainer() { var externalBundle = new TestableBundle("http://external.com/api.js"); var bundle = new TestableBundle("~/test"); bundle.AddReference("http://external.com/api.js"); var factory = new Mock <IBundleFactory <Bundle> >(); factory.Setup(f => f.CreateBundle("http://external.com/api.js", It.IsAny <IEnumerable <IFile> >(), It.IsAny <BundleDescriptor>())) .Returns(externalBundle); Settings.BundleFactories[typeof(TestableBundle)] = factory.Object; var builder = CreateFactory(new[] { bundle }); var container = builder.CreateBundleContainer(); container.FindBundlesContainingPath("http://external.com/api.js").First().ShouldBeSameAs(externalBundle); }
public void GivenBundleWithReference_WhenSaveContainer_ThenXmlHasReferenceElement() { using (var cacheDir = new TempDirectory()) { var settings = new CassetteSettings { SourceDirectory = Mock.Of <IDirectory>(), CacheDirectory = new FileSystemDirectory(cacheDir) }; var cache = new BundleCache("VERSION", settings); var bundle = new TestableBundle("~/test"); bundle.AddReference("~/other"); cache.SaveBundleContainer(new BundleContainer(new[] { bundle, new TestableBundle("~/other") })); var xml = File.ReadAllText(Path.Combine(cacheDir, "container.xml")); xml.ShouldContain("<Reference Path=\"~/other\""); } }
public void GivenBundleWithAdHocUrlReference_WhenCreate_ThenExternalBundleIsCreatedAndProcessed() { var externalBundle = new TestableBundle("http://test.com/"); var factory = new Mock <IBundleFactory <Bundle> >(); factory.Setup(f => f.CreateBundle("http://test.com/", It.IsAny <IEnumerable <IFile> >(), It.IsAny <BundleDescriptor>())) .Returns(externalBundle); Settings.BundleFactories[typeof(TestableBundle)] = factory.Object; var bundle = new TestableBundle("~/test"); bundle.AddReference("http://test.com/"); var containerFactory = CreateFactory(new[] { bundle }); containerFactory.CreateBundleContainer(); externalBundle.WasProcessed.ShouldBeTrue(); }
public void GivenAssetWithUrlReferenceAndSameBundleLevelUrlReference_WhenCreate_ThenExternalBundleInContainer() { var asset = new Mock<IAsset>(); asset.SetupGet(a => a.References) .Returns(new[] { new AssetReference("http://test.com/", asset.Object, -1, AssetReferenceType.Url) }); asset.Setup(a => a.OpenStream()).Returns(Stream.Null); var externalBundle = new TestableBundle("http://test.com/"); var factory = new Mock<IBundleFactory<Bundle>>(); factory.Setup(f => f.CreateBundle("http://test.com/", It.IsAny<IEnumerable<IFile>>(), It.IsAny<BundleDescriptor>())) .Returns(externalBundle); Settings.BundleFactories[typeof(TestableBundle)] = factory.Object; var containerFactory = CreateFactory(); var bundle = new TestableBundle("~/test"); bundle.AddReference("http://test.com/"); bundle.Assets.Add(asset.Object); var container = containerFactory.Create(new[] { bundle }); container.FindBundlesContainingPath("http://test.com/").First().ShouldBeSameAs(externalBundle); }
public void WhenExternalModuleReferencedTwice_ThenContainerOnlyHasTheExternalModuleOnce() { var externalBundle = new TestableBundle("http://external.com/api.js"); var bundle1 = new TestableBundle("~/test1"); bundle1.AddReference("http://external.com/api.js"); var bundle2 = new TestableBundle("~/test2"); bundle2.AddReference("http://external.com/api.js"); var bundles = new[] { bundle1, bundle2 }; var factories = new Dictionary <Type, IBundleFactory <Bundle> >(); var factory = new Mock <IBundleFactory <Bundle> >(); factory.Setup(f => f.CreateBundle("http://external.com/api.js", It.IsAny <IEnumerable <IFile> >(), It.IsAny <BundleDescriptor>())) .Returns(externalBundle); factories[typeof(TestableBundle)] = factory.Object; var builder = CreateFactory(factories); var container = builder.Create(bundles, CreateSettings()); container.Bundles.Count().ShouldEqual(3); }
public void GivenBundleWithAdHocUrlReference_WhenCreate_ThenExternalBundleIsCreatedAndProcessed() { var externalBundle = new TestableBundle("http://test.com/"); var factory = new Mock<IBundleFactory<Bundle>>(); factory.Setup(f => f.CreateBundle("http://test.com/", It.IsAny<IEnumerable<IFile>>(), It.IsAny<BundleDescriptor>())) .Returns(externalBundle); var factories = new Dictionary<Type, IBundleFactory<Bundle>>(); factories[typeof(TestableBundle)] = factory.Object; var containerFactory = CreateFactory(factories); var bundle = new TestableBundle("~/test"); bundle.AddReference("http://test.com/"); var settings = CreateSettings(); containerFactory.Create(new[] { bundle }, settings); externalBundle.WasProcessed.ShouldBeTrue(); }
public void WhenExternalModuleReferencedTwice_ThenContainerOnlyHasTheExternalModuleOnce() { var externalBundle = new TestableBundle("http://external.com/api.js"); var bundle1 = new TestableBundle("~/test1"); bundle1.AddReference("http://external.com/api.js"); var bundle2 = new TestableBundle("~/test2"); bundle2.AddReference("http://external.com/api.js"); var bundles = new[] { bundle1, bundle2 }; var factories = new Dictionary<Type, IBundleFactory<Bundle>>(); var factory = new Mock<IBundleFactory<Bundle>>(); factory.Setup(f => f.CreateBundle("http://external.com/api.js", It.IsAny<IEnumerable<IFile>>(), It.IsAny<BundleDescriptor>())) .Returns(externalBundle); factories[typeof(TestableBundle)] = factory.Object; var builder = CreateFactory(factories); var container = builder.Create(bundles, CreateSettings()); container.Bundles.Count().ShouldEqual(3); }
public void WhenCreateWithBundleHavingExternalReference_ThenAnExternalBundleIsAlsoAddedToContainer() { var externalBundle = new TestableBundle("http://external.com/api.js"); var bundle = new TestableBundle("~/test"); bundle.AddReference("http://external.com/api.js"); var factories = new Dictionary<Type, IBundleFactory<Bundle>>(); var factory = new Mock<IBundleFactory<Bundle>>(); factory.Setup(f => f.CreateBundle("http://external.com/api.js", It.IsAny<IEnumerable<IFile>>(), It.IsAny<BundleDescriptor>())) .Returns(externalBundle); factories[typeof(TestableBundle)] = factory.Object; var builder = CreateFactory(factories); var container = builder.Create(new[] { bundle }, CreateSettings()); container.FindBundlesContainingPath("http://external.com/api.js").First().ShouldBeSameAs(externalBundle); }
public void GivenBundleWithReference_WhenSaveContainer_ThenXmlHasReferenceElement() { using (var cacheDir = new TempDirectory()) { var settings = new CassetteSettings { SourceDirectory = Mock.Of<IDirectory>(), CacheDirectory = new FileSystemDirectory(cacheDir) }; var cache = new BundleCache("VERSION", settings); var bundle = new TestableBundle("~/test"); bundle.AddReference("~/other"); cache.SaveBundleContainer(new BundleContainer(new[] { bundle, new TestableBundle("~/other") })); var xml = File.ReadAllText(Path.Combine(cacheDir, "container.xml")); xml.ShouldContain("<Reference Path=\"~/other\""); } }