Ejemplo n.º 1
0
        public void Handle_WhenMSBuildProjectFullPathPropertyChanged_SetsProjectFilePath()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            context.ProjectFilePath = @"ProjectFilePath";

            var handler = CreateInstance(context: context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""ChangedProperties"": [ ""MSBuildProjectFullPath"" ]
    },
    ""After"": { 
        ""Properties"": {
            ""MSBuildProjectFullPath"": ""NewProjectFilePath""
        }
    }
}");

            Handle(handler, projectChange);

            Assert.Equal(@"NewProjectFilePath", context.ProjectFilePath);
        }
        public void Handle_RazorAndCshtmlFiles_AddsToContext()
        {
            var dynamicFiles = new HashSet <string>(StringComparers.Paths);

            void onDynamicFileAdded(string s) => Assert.True(dynamicFiles.Add(s));

            var project = UnconfiguredProjectFactory.Create(filePath: @"C:\Myproject.csproj");
            var context = IWorkspaceProjectContextMockFactory.CreateForDynamicFiles(project, onDynamicFileAdded);

            var handler = CreateInstance(project, context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""AddedItems"": [ ""File1.razor"", ""File1.cshtml"", ""File1.cs"" ]
    }
}");

            Handle(handler, projectChange);

            Assert.Equal(2, dynamicFiles.Count);
            Assert.Contains(@"C:\File1.razor", dynamicFiles);
            Assert.Contains(@"C:\File1.cshtml", dynamicFiles);
        }
Ejemplo n.º 3
0
        public void Handle_WhenTargetPathIsNotChanged_DoesNotSetBinOutputPath()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            context.BinOutputPath = @"BinOutputPath";

            var handler = CreateInstance(context: context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""ChangedProperties"": [ ]
    },
    ""After"": { 
        ""Properties"": {
            ""TargetPath"": ""NewBinOutputPath""
        }
    }
}");

            Handle(handler, projectChange);

            Assert.Equal("BinOutputPath", context.BinOutputPath);
        }
Ejemplo n.º 4
0
        public void Handle_WhenPropertyIsChanged_CallsSetProperty()
        {
            string?nameResult  = null;
            string?valueResult = null;
            var    context     = IWorkspaceProjectContextMockFactory.ImplementSetProperty((name, value) => { nameResult = name; valueResult = value; });

            var handler = CreateInstance(context: context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""ChangedProperties"": [ ""RootNamespace"" ]
    },
    ""After"": { 
        ""Properties"": {
            ""RootNamespace"": ""value""
        }
    }
}");

            Handle(handler, projectChange);

            Assert.Equal("RootNamespace", nameResult);
            Assert.Equal("value", valueResult);
        }
Ejemplo n.º 5
0
        public void Handle_RazorAndCshtmlFiles_InDifferentItemTypes_IgnoresDuplicates()
        {
            var dynamicFiles = new HashSet <string>(StringComparers.Paths);

            void onDynamicFileAdded(string s) => Assert.True(dynamicFiles.Add(s));

            var project = UnconfiguredProjectFactory.Create(fullPath: @"C:\Myproject.csproj");
            var context = IWorkspaceProjectContextMockFactory.CreateForDynamicFiles(project, onDynamicFileAdded);

            var handler = CreateInstance(project, context);

            var projectChanges = ImmutableDictionary <string, IProjectChangeDescription> .Empty.Add(
                "None", IProjectChangeDescriptionFactory.FromJson(
                    @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""AddedItems"": [ ""File1.razor"", ""File1.cs"" ]
    }
}")).Add(
                "Content", IProjectChangeDescriptionFactory.FromJson(
                    @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""AddedItems"": [ ""File1.razor"", ""File1.cshtml"", ""File2.cs"" ]
    }
}"));

            Handle(handler, projectChanges);

            Assert.Equal(2, dynamicFiles.Count);
            Assert.Contains(@"C:\File1.razor", dynamicFiles);
            Assert.Contains(@"C:\File1.cshtml", dynamicFiles);
        }
Ejemplo n.º 6
0
        public void Handle_WhenPropertyIsNotChanged_DoesNotCallSetProperty(string input)
        {
            int callCount = 0;
            var context   = IWorkspaceProjectContextMockFactory.ImplementSetProperty((name, value) => { callCount++; });

            var handler = CreateInstance(context: context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(input);

            Handle(handler, projectChange);

            Assert.Equal(0, callCount);
        }
Ejemplo n.º 7
0
        public void Handle_WhenMSBuildProjectFullPathPropertyNotChanged_DoesNothing()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            context.ProjectFilePath = @"ProjectFilePath";
            context.DisplayName     = "DisplayName";

            var handler = CreateInstance(context: context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                @"{
    ""Difference"": { 
        ""AnyChanges"": true
    }
}");

            Handle(handler, projectChange);

            Assert.Equal(@"ProjectFilePath", context.ProjectFilePath);
            Assert.Equal(@"DisplayName", context.DisplayName);
        }
Ejemplo n.º 8
0
        public void Handle_WhenMSBuildProjectFullPathPropertyChanged_SetsDisplayNameToFileNameWithoutExtension()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            var handler = CreateInstance(context: context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""ChangedProperties"": [ ""MSBuildProjectFullPath"" ]
    },
    ""After"": { 
        ""Properties"": {
            ""MSBuildProjectFullPath"": ""C:\\Project\\Project.csproj""
        }
    }
}");

            Handle(handler, projectChange);

            Assert.Equal(@"Project", context.DisplayName);
        }
Ejemplo n.º 9
0
        public void Handle_WhenMSBuildProjectFullPathPropertyChangedAndMultitargeting_IncludeDimensionValuesInDisplayName(string dimensionNames, string dimensionValues, string implicitDimensionNames, string expected)
        {
            var context = IWorkspaceProjectContextMockFactory.Create();
            var implicitlyActiveDimensionProvider = IImplicitlyActiveDimensionProviderFactory.ImplementGetImplicitlyActiveDimensions(n => implicitDimensionNames.SplitReturningEmptyIfEmpty('|'));
            var configuration = ProjectConfigurationFactory.Create(dimensionNames, dimensionValues);
            var handler       = CreateInstance(configuration, implicitlyActiveDimensionProvider, context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""ChangedProperties"": [ ""MSBuildProjectFullPath"" ]
    },
    ""After"": { 
        ""Properties"": {
            ""MSBuildProjectFullPath"": ""C:\\Project\\Project.csproj""
        }
    }
}");

            Handle(handler, projectChange);

            Assert.Equal(expected, context.DisplayName);
        }