public void NormalizesContentRoot(string contentRoot, string expected) { var errorMessages = new List <string>(); var buildEngine = new Mock <IBuildEngine>(); buildEngine.Setup(e => e.LogErrorEvent(It.IsAny <BuildErrorEventArgs>())) .Callback <BuildErrorEventArgs>(args => errorMessages.Add(args.Message)); var task = new DiscoverStaticWebAssets { BuildEngine = buildEngine.Object, Candidates = new[] { CreateCandidate("wwwroot\\candidate.js") }, Pattern = "wwwroot\\**", SourceId = "MyProject", ContentRoot = contentRoot, BasePath = "base" }; // Act var result = task.Execute(); // Assert result.Should().Be(true); task.DiscoveredStaticWebAssets.Length.Should().Be(1); var asset = task.DiscoveredStaticWebAssets[0]; asset.ItemSpec.Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.js"))); asset.GetMetadata(nameof(StaticWebAsset.ContentRoot)).Should().Be(expected); }
public void FailsDiscoveringAssetsWhenThereIsAConflict( string copyToOutputDirectoryFirst, string copyToPublishDirectoryFirst, string firstKind, string copyToOutputDirectorySecond, string copyToPublishDirectorySecond, string secondKind) { var errorMessages = new List <string>(); var buildEngine = new Mock <IBuildEngine>(); buildEngine.Setup(e => e.LogErrorEvent(It.IsAny <BuildErrorEventArgs>())) .Callback <BuildErrorEventArgs>(args => errorMessages.Add(args.Message)); var task = new DiscoverStaticWebAssets { BuildEngine = buildEngine.Object, Candidates = new[] { CreateCandidate( Path.Combine("wwwroot", "candidate.js"), copyToOutputDirectory: copyToOutputDirectoryFirst, copyToPublishDirectory: copyToPublishDirectoryFirst), CreateCandidate( Path.Combine("wwwroot", "candidate.publish.js"), relativePath: "candidate.js", copyToOutputDirectory: copyToOutputDirectorySecond, copyToPublishDirectory: copyToPublishDirectorySecond) }, Pattern = "wwwroot\\**", SourceId = "MyProject", ContentRoot = "wwwroot", BasePath = "_content/Path" }; // Act var result = task.Execute(); // Assert result.Should().Be(false); errorMessages.Count.Should().Be(1); errorMessages[0].Should().Be($@"Two assets found targeting the same path with incompatible asset kinds: '{Path.GetFullPath(Path.Combine("wwwroot", "candidate.js"))}' with kind '{firstKind}' '{Path.GetFullPath(Path.Combine("wwwroot", "candidate.publish.js"))}' with kind '{secondKind}' for path 'candidate.js'"); }
public void RespectsItemRelativePathWhenExplicitlySpecified() { var errorMessages = new List <string>(); var buildEngine = new Mock <IBuildEngine>(); buildEngine.Setup(e => e.LogErrorEvent(It.IsAny <BuildErrorEventArgs>())) .Callback <BuildErrorEventArgs>(args => errorMessages.Add(args.Message)); var task = new DiscoverStaticWebAssets { BuildEngine = buildEngine.Object, Candidates = new[] { CreateCandidate(Path.Combine("wwwroot", "candidate.js"), relativePath: "subdir/candidate.js") }, Pattern = "wwwroot\\**", SourceId = "MyProject", ContentRoot = "wwwroot", BasePath = "_content/Path" }; // Act var result = task.Execute(); // Assert result.Should().Be(true); task.DiscoveredStaticWebAssets.Length.Should().Be(1); var asset = task.DiscoveredStaticWebAssets[0]; asset.ItemSpec.Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.js"))); asset.GetMetadata(nameof(StaticWebAsset.SourceId)).Should().Be("MyProject"); asset.GetMetadata(nameof(StaticWebAsset.SourceType)).Should().Be("Discovered"); asset.GetMetadata(nameof(StaticWebAsset.ContentRoot)).Should().Be(Path.GetFullPath("wwwroot") + Path.DirectorySeparatorChar); asset.GetMetadata(nameof(StaticWebAsset.BasePath)).Should().Be("_content/Path"); asset.GetMetadata(nameof(StaticWebAsset.RelativePath)).Should().Be("subdir/candidate.js"); asset.GetMetadata(nameof(StaticWebAsset.AssetKind)).Should().Be("All"); asset.GetMetadata(nameof(StaticWebAsset.AssetMode)).Should().Be("All"); asset.GetMetadata(nameof(StaticWebAsset.AssetRole)).Should().Be("Primary"); asset.GetMetadata(nameof(StaticWebAsset.RelatedAsset)).Should().Be(""); asset.GetMetadata(nameof(StaticWebAsset.AssetTraitName)).Should().Be(""); asset.GetMetadata(nameof(StaticWebAsset.AssetTraitValue)).Should().Be(""); asset.GetMetadata(nameof(StaticWebAsset.CopyToOutputDirectory)).Should().Be("Never"); asset.GetMetadata(nameof(StaticWebAsset.CopyToPublishDirectory)).Should().Be("PreserveNewest"); asset.GetMetadata(nameof(StaticWebAsset.OriginalItemSpec)).Should().Be(Path.Combine("wwwroot", "candidate.js")); }
public void AutomaticallyDetectsAssetKindWhenMultipleAssetsTargetTheSameRelativePath() { var errorMessages = new List <string>(); var buildEngine = new Mock <IBuildEngine>(); buildEngine.Setup(e => e.LogErrorEvent(It.IsAny <BuildErrorEventArgs>())) .Callback <BuildErrorEventArgs>(args => errorMessages.Add(args.Message)); var task = new DiscoverStaticWebAssets { BuildEngine = buildEngine.Object, Candidates = new[] { CreateCandidate(Path.Combine("wwwroot", "candidate.js"), copyToPublishDirectory: "Never"), CreateCandidate(Path.Combine("wwwroot", "candidate.publish.js"), relativePath: "candidate.js") }, Pattern = "wwwroot\\**", SourceId = "MyProject", ContentRoot = "wwwroot", BasePath = "_content/Path" }; // Act var result = task.Execute(); // Assert result.Should().Be(true); task.DiscoveredStaticWebAssets.Length.Should().Be(2); var buildAsset = task.DiscoveredStaticWebAssets.Single(a => a.ItemSpec == Path.GetFullPath(Path.Combine("wwwroot", "candidate.js"))); var publishAsset = task.DiscoveredStaticWebAssets.Single(a => a.ItemSpec == Path.GetFullPath(Path.Combine("wwwroot", "candidate.publish.js"))); buildAsset.ItemSpec.Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.js"))); buildAsset.GetMetadata(nameof(StaticWebAsset.AssetKind)).Should().Be("Build"); buildAsset.GetMetadata(nameof(StaticWebAsset.CopyToOutputDirectory)).Should().Be("Never"); buildAsset.GetMetadata(nameof(StaticWebAsset.CopyToPublishDirectory)).Should().Be("Never"); publishAsset.ItemSpec.Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.publish.js"))); publishAsset.GetMetadata(nameof(StaticWebAsset.AssetKind)).Should().Be("Publish"); publishAsset.GetMetadata(nameof(StaticWebAsset.CopyToOutputDirectory)).Should().Be("Never"); publishAsset.GetMetadata(nameof(StaticWebAsset.CopyToPublishDirectory)).Should().Be("PreserveNewest"); }