本文整理汇总了C#中TestableBundle类的典型用法代码示例。如果您正苦于以下问题:C# TestableBundle类的具体用法?C# TestableBundle怎么用?C# TestableBundle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestableBundle类属于命名空间,在下文中一共展示了TestableBundle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConcatenateAssetsMergesAssetReferences
public void ConcatenateAssetsMergesAssetReferences()
{
var bundle = new TestableBundle("~");
var asset1 = new Mock<IAsset>();
var asset2 = new Mock<IAsset>();
asset1.Setup(a => a.OpenStream()).Returns(() => "asset1".AsStream());
asset1.SetupGet(a => a.References).Returns(new[]
{
new AssetReference("~\\other1.js", asset1.Object, 0, AssetReferenceType.DifferentBundle)
});
asset2.Setup(a => a.OpenStream()).Returns(() => "asset2".AsStream());
asset2.SetupGet(a => a.References).Returns(new[]
{
new AssetReference("~\\other1.js", asset2.Object, 0, AssetReferenceType.DifferentBundle),
new AssetReference("~\\other2.js", asset2.Object, 0, AssetReferenceType.DifferentBundle)
});
bundle.Assets.Add(asset1.Object);
bundle.Assets.Add(asset2.Object);
var processor = new ConcatenateAssets();
processor.Process(bundle, new CassetteSettings(""));
bundle.Assets[0].References
.Select(r => r.Path)
.OrderBy(f => f)
.SequenceEqual(new[] { "~\\other1.js", "~\\other1.js", "~\\other2.js" })
.ShouldBeTrue();
}
示例2: DiskBackedBundleCache_Tests
public DiskBackedBundleCache_Tests()
{
//The directory should never be called, always just passed into FileHelper which is mocked also, so strict
//with nothing setup
directory = new Mock<IDirectory>(MockBehavior.Strict);
fileHelper = new Mock<IFileHelper>(MockBehavior.Strict);
fileHelper.Setup(fh => fh.PrepareCachingDirectory(It.IsAny<string>(), It.IsAny<string>()));
fileHelper.Setup(fh => fh.CreateDirectory(It.IsAny<string>()));
uncachedToCachedFiles = new Mock<IDictionary<string, string>>(MockBehavior.Strict);
diskBackedBundleCache = new DiskBackedBundleCache(fileHelper.Object);
unprocessedAssetPaths = new List<string>();
fileBundle = new TestableBundle("~/file");
concatenatedBundle = new TestableBundle("~/concatenated");
emptyBundle = new TestableBundle("~/empty");
var stubFileCreation = typeof(Asset_Tests).GetMethod("StubFile", BindingFlags.NonPublic | BindingFlags.Instance);
fileAsset = new FileAsset((IFile)stubFileCreation.Invoke(new Asset_Tests(), new object[] { "asset content", Type.Missing }), fileBundle);
fileBundle.Assets.Add(fileAsset);
var file = (IFile)stubFileCreation.Invoke(new Asset_Tests(), new object[] { "asset content", Type.Missing });
fileHelper.Setup(fh => fh.GetFileSystemFile(It.IsAny<IDirectory>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns(file);
concatenatedAsset = new ConcatenatedAsset(new List<IAsset> {fileAsset} );
concatenatedBundle.Assets.Add(concatenatedAsset);
AddToDiskMethodInfo = typeof(DiskBackedBundleCache).GetMethod("AddToDisk", BindingFlags.NonPublic | BindingFlags.Instance);
GetFromDiskMethodInfo = typeof(DiskBackedBundleCache).GetMethod("GetFromDisk", BindingFlags.NonPublic | BindingFlags.Instance);
}
示例3: GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenBundleAssetsReplacedWithCachedAsset
public void GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenBundleAssetsReplacedWithCachedAsset()
{
using (var cacheDir = new TempDirectory())
{
File.WriteAllText(
Path.Combine(cacheDir, "container.xml"),
"<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"1\"><Bundle Path=\"~/test\" Hash=\"01\"/></Container>"
);
File.WriteAllText(
Path.Combine(cacheDir, "test.bundle"),
"asset"
);
var bundleWithAsset = new TestableBundle("~/test");
var asset = StubAsset();
bundleWithAsset.Assets.Add(asset.Object);
var sourceBundles = new[] { bundleWithAsset };
var settings = new CassetteSettings
{
SourceDirectory = Mock.Of<IDirectory>(),
CacheDirectory = new FileSystemDirectory(cacheDir)
};
var cache = new BundleCache("VERSION", settings);
var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);
result.ShouldBeTrue();
bundleWithAsset.Assets[0].OpenStream().ReadToEnd().ShouldEqual("asset");
}
}
示例4: GivenBundleAdded_WhenGetByPartialPath_ThenBundleReturned
public void GivenBundleAdded_WhenGetByPartialPath_ThenBundleReturned()
{
var bundle = new TestableBundle("~/test");
bundles.Add(bundle);
var actualBundle = bundles.Get("test");
actualBundle.ShouldBeSameAs(bundle);
}
示例5: GivenBundleAdded_WhenAddAnotherWithSamePath_ThenExceptionIsThrown
public void GivenBundleAdded_WhenAddAnotherWithSamePath_ThenExceptionIsThrown()
{
var bundle = new TestableBundle("~/test");
bundles.Add(bundle);
Assert.Throws<ArgumentException>(
() => bundles.Add(new TestableBundle("~/test"))
);
}
示例6: SetupTestBundle
protected void SetupTestBundle()
{
var bundle = new TestableBundle("~/test");
var asset = new StubAsset("~/asset.js", "asset-content");
bundle.Assets.Add(asset);
bundle.Hash = new byte[] { 1, 2, 3 };
bundles.Add(bundle);
bundles.BuildReferences();
bundle.Process(new CassetteSettings());
}
示例7: ProcessAddsAssetMinifierToAssetInBundle
public void ProcessAddsAssetMinifierToAssetInBundle()
{
var bundle = new TestableBundle("~");
var asset = new Mock<IAsset>();
bundle.Assets.Add(asset.Object);
processor.Process(bundle);
asset.Verify(a => a.AddAssetTransformer(minifier.Object));
}
示例8: GivenBundlesAdded_WhenEnumerated_ThenBundlesReturned
public void GivenBundlesAdded_WhenEnumerated_ThenBundlesReturned()
{
var bundle1 = new TestableBundle("~/test1");
var bundle2 = new TestableBundle("~/test2");
bundles.Add(bundle1);
bundles.Add(bundle2);
var set = new HashSet<Bundle>(bundles);
set.SetEquals(new[] { bundle1, bundle2 }).ShouldBeTrue();
}
示例9: GivenCacheOutOfDate_WhenCreateWithBundle_ThenContainerSavedToCache
public void GivenCacheOutOfDate_WhenCreateWithBundle_ThenContainerSavedToCache()
{
var bundles = new TestableBundle[0];
var application = CreateSettings();
CacheIsOutOfDate(bundles);
var factory = CreateFactory();
factory.Create(bundles, application);
cache.Verify(c => c.SaveBundleContainer(It.IsAny<IBundleContainer>()));
}
示例10: GivenCacheOutOfDate_WhenCreateWithBundle_ThenBundleIsProcessed
public void GivenCacheOutOfDate_WhenCreateWithBundle_ThenBundleIsProcessed()
{
var bundle = new TestableBundle("~/test");
var bundles = new[] { bundle };
var application = CreateSettings();
CacheIsOutOfDate(bundles);
var factory = CreateFactory();
factory.Create(bundles, application);
bundle.WasProcessed.ShouldBeTrue();
}
示例11: RawFileRequestHandler_Tests
public RawFileRequestHandler_Tests()
{
var bundle = new TestableBundle("~");
var asset = new Mock<IAsset>();
asset.Setup(a => a.Accept(It.IsAny<IBundleVisitor>()))
.Callback<IBundleVisitor>(v => v.Visit(asset.Object));
asset.SetupGet(a => a.References).Returns(new[]
{
new AssetReference("~/test.png", asset.Object, -1, AssetReferenceType.RawFilename)
});
bundle.Assets.Add(asset.Object);
bundles = new[] { bundle };
}
示例12: GivenCacheOutOfDate_WhenCreateWithBundle_ThenBundlesInitializedFromNewCache
public void GivenCacheOutOfDate_WhenCreateWithBundle_ThenBundlesInitializedFromNewCache()
{
var bundles = new TestableBundle[0];
var application = CreateSettings();
CacheIsOutOfDate(bundles);
var factory = CreateFactory();
factory.Create(bundles, application);
// InitializeBundlesFromCacheIfUpToDate should be called a second time.
// This is to make the bundles get their content from the cached, optimized, data.
// Otherwise the first time the app runs the bundles are running from their original sources.
cache.Verify(c => c.InitializeBundlesFromCacheIfUpToDate(bundles), Times.Exactly(2));
}
示例13: WhenProcessBundleContainingJavaScriptAsset_ThenNoTransformsAreAddedToAsset
public void WhenProcessBundleContainingJavaScriptAsset_ThenNoTransformsAreAddedToAsset()
{
var bundle = new TestableBundle("~");
var coffeeScriptAsset = new Mock<IAsset>();
coffeeScriptAsset.SetupGet(a => a.SourceFile.FullPath).Returns("test.js");
bundle.Assets.Add(coffeeScriptAsset.Object);
step.Process(bundle, new CassetteSettings(""));
coffeeScriptAsset.Verify(
a => a.AddAssetTransformer(
It.IsAny<IAssetTransformer>()
),
Times.Never()
);
}
示例14: WhenProcessBundleContainingCoffeeScriptAsset_ThenCompileCoffeeScriptAssetTransformIsAddedToAsset
public void WhenProcessBundleContainingCoffeeScriptAsset_ThenCompileCoffeeScriptAssetTransformIsAddedToAsset()
{
var bundle = new TestableBundle("~");
var coffeeScriptAsset = new Mock<IAsset>();
coffeeScriptAsset.SetupGet(a => a.SourceFile.FullPath).Returns("test.coffee");
bundle.Assets.Add(coffeeScriptAsset.Object);
step.Process(bundle, new CassetteSettings(""));
coffeeScriptAsset.Verify(
a => a.AddAssetTransformer(
It.Is<IAssetTransformer>(
t => t is CompileAsset
)
)
);
}
示例15: GivenTwoAssetsWhereADependsOnB_WhenSorted_ThenBIsBeforeAInBundle
public void GivenTwoAssetsWhereADependsOnB_WhenSorted_ThenBIsBeforeAInBundle()
{
var bundle = new TestableBundle("~/test");
var assetA = new Mock<IAsset>();
assetA.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/a.js");
assetA.SetupGet(a => a.References)
.Returns(new[] { new AssetReference("~/test/b.js", assetA.Object, 1, AssetReferenceType.SameBundle) });
var assetB = new Mock<IAsset>();
assetB.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/b.js");
bundle.Assets.Add(assetA.Object);
bundle.Assets.Add(assetB.Object);
var sorter = new SortAssetsByDependency();
sorter.Process(bundle, new CassetteSettings());
bundle.Assets[0].ShouldBeSameAs(assetB.Object);
bundle.Assets[1].ShouldBeSameAs(assetA.Object);
}