Example #1
0
        public void AllowsAssetsHavingTheSameContentRootAndDifferentBasePathsAcrossDifferentSources_WhenTheirFinalDestinationPathIsDifferent()
        {
            // Arrange
            var task = new ValidateStaticWebAssetsUniquePaths
            {
                StaticWebAssets = new TaskItem[]
                {
                    CreateItem(Path.Combine("wwwroot", "sample.js"), new Dictionary <string, string>
                    {
                        ["BasePath"]     = "MyLibrary",
                        ["SourceId"]     = "MyLibrary",
                        ["RelativePath"] = "sample.js",
                        ["ContentRoot"]  = Path.Combine(".", "MyLibrary")
                    }),
                    CreateItem(Path.Combine("wwwroot", "otherLib.js"), new Dictionary <string, string>
                    {
                        ["BasePath"]     = "MyOtherLibrary",
                        ["SourceId"]     = "MyOtherLibrary",
                        ["RelativePath"] = "otherlib.js",
                        ["ContentRoot"]  = Path.Combine(".", "MyLibrary")
                    })
                },
                WebRootFiles = Array.Empty <TaskItem>()
            };

            // Act
            var result = task.Execute();

            // Assert
            Assert.True(result);
        }
Example #2
0
        public void ReturnsError_WhenMultipleStaticWebAssetsHaveTheSameWebRootPath()
        {
            // Arrange
            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 ValidateStaticWebAssetsUniquePaths
            {
                BuildEngine     = buildEngine.Object,
                StaticWebAssets = new TaskItem[]
                {
                    CreateItem(Path.Combine(".", "Library", "wwwroot", "sample.js"), new Dictionary <string, string>
                    {
                        ["BasePath"]     = "/",
                        ["RelativePath"] = "/sample.js",
                    }),
                    CreateItem(Path.Combine(".", "Library", "bin", "dist", "sample.js"), new Dictionary <string, string>
                    {
                        ["BasePath"]     = "/",
                        ["RelativePath"] = "/sample.js",
                    })
                }
            };

            // Act
            var result = task.Execute();

            // Assert
            result.Should().Be(false);
            errorMessages.Should().NotBeEmpty().And.HaveCount(1);
            errorMessages.Should().Contain($"Conflicting assets with the same path '/wwwroot/sample.js' for content root paths '{Path.Combine(".", "Library", "bin", "dist", "sample.js")}' and '{Path.Combine(".", "Library", "wwwroot", "sample.js")}'.");
        }
Example #3
0
        public void ReturnsError_WhenStaticWebAssetsWebRootPathMatchesExistingContentItemPath()
        {
            // Arrange
            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 ValidateStaticWebAssetsUniquePaths
            {
                BuildEngine     = buildEngine.Object,
                StaticWebAssets = new TaskItem[]
                {
                    CreateItem(Path.Combine("wwroot", "js", "project-transitive-dep.js"), new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/ClassLibrary",
                        ["RelativePath"] = "js/project-transitive-dep.js",
                        ["SourceId"]     = "ClassLibrary",
                        ["SourceType"]   = "Project",
                    }),
                },
                WebRootFiles = new TaskItem[]
                {
                    CreateItem(Path.Combine("wwwroot", "_content", "ClassLibrary", "js", "project-transitive-dep.js"), new Dictionary <string, string>
                    {
                        ["CopyToPublishDirectory"] = "PreserveNewest",
                        ["ExcludeFromSingleFile"]  = "true",
                        ["OriginalItemSpec"]       = Path.Combine("wwwroot", "_content", "ClassLibrary", "js", "project-transitive-dep.js"),
                        ["TargetPath"]             = Path.Combine("wwwroot", "_content", "ClassLibrary", "js", "project-transitive-dep.js"),
                    })
                }
            };

            var expectedMessage = $"The static web asset '{Path.Combine("wwroot", "js", "project-transitive-dep.js")}' " +
                                  "has a conflicting web root path '/wwwroot/_content/ClassLibrary/js/project-transitive-dep.js' with the " +
                                  $"project file '{Path.Combine("wwwroot", "_content", "ClassLibrary", "js", "project-transitive-dep.js")}'.";

            // Act
            var result = task.Execute();

            // Assert
            Assert.False(result);
            var message = Assert.Single(errorMessages);

            Assert.Equal(expectedMessage, message);
        }
        public void ReturnsError_WhenStaticWebAssetsWebRootPathMatchesExistingContentItemPath()
        {
            // Arrange
            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 ValidateStaticWebAssetsUniquePaths
            {
                BuildEngine     = buildEngine.Object,
                StaticWebAssets = new TaskItem[]
                {
                    CreateItem(Path.Combine(".", "Library", "wwwroot", "sample.js"), new Dictionary <string, string>
                    {
                        ["BasePath"]     = "/",
                        ["RelativePath"] = "/sample.js",
                    })
                },
                WebRootFiles = new TaskItem[]
                {
                    CreateItem(Path.Combine(".", "App", "wwwroot", "sample.js"), new Dictionary <string, string>
                    {
                        ["TargetPath"] = "/SAMPLE.js",
                    })
                }
            };

            // Act
            var result = task.Execute();

            // Assert
            Assert.False(result);
            var message = Assert.Single(errorMessages);

            Assert.Equal($"The static web asset '{Path.Combine(".", "Library", "wwwroot", "sample.js")}' has a conflicting web root path '/SAMPLE.js' with the project file '{Path.Combine(".", "App", "wwwroot", "sample.js")}'.", message);
        }
        public void ReturnsSuccess_WhenStaticWebAssetsDontConflictWithApplicationContentItems()
        {
            // Arrange
            var errorMessages = new List <string>();
            var buildEngine   = new Mock <IBuildEngine>();

            var task = new ValidateStaticWebAssetsUniquePaths
            {
                BuildEngine     = buildEngine.Object,
                StaticWebAssets = new TaskItem[]
                {
                    CreateItem(Path.Combine(".", "Library", "wwwroot", "sample.js"), new Dictionary <string, string>
                    {
                        ["BasePath"]     = "/_library",
                        ["RelativePath"] = "/sample.js",
                    }),
                    CreateItem(Path.Combine(".", "Library", "wwwroot", "sample.js"), new Dictionary <string, string>
                    {
                        ["BasePath"]     = "/_library",
                        ["RelativePath"] = "/sample.js",
                    })
                },
                WebRootFiles = new TaskItem[]
                {
                    CreateItem(Path.Combine(".", "App", "wwwroot", "sample.js"), new Dictionary <string, string>
                    {
                        ["TargetPath"] = "/SAMPLE.js",
                    })
                }
            };

            // Act
            var result = task.Execute();

            // Assert
            Assert.True(result);
        }