public void VsSettingDoesNotCacheSolutionSettings()
        {
            // Arrange
            var solutionManager = new Mock <MockSolutionManager>();

            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\solution").Verifiable();
            var defaultSettings = new Mock <ISettings>(MockBehavior.Strict);

            var fileSystem = new MockFileSystem();

            fileSystem.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""bar"" /></solution></configuration>");

            var fileSystemProvider = new Mock <IFileSystemProvider>(MockBehavior.Strict);

            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\solution\.nuget")).Returns(fileSystem).Verifiable();

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var valueA     = vsSettings.GetValue("solution", "foo");

            fileSystem.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""qux"" /></solution></configuration>");
            var valueB = vsSettings.GetValue("solution", "foo");

            // Assert
            Assert.Equal("bar", valueA);
            Assert.Equal("qux", valueB);
        }
예제 #2
0
        public void VsSettingUsesSettingsFileFromSolutionRootIfExists()
        {
            // Arrange
            var solutionManager = new Mock <ISolutionManager>(MockBehavior.Strict);

            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\solution").Verifiable();
            var defaultSettings = new Mock <ISettings>(MockBehavior.Strict);

            var fileSystem = new MockFileSystem();

            fileSystem.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""bar"" /></solution></configuration>");
            var fileSystemProvider = new Mock <IFileSystemProvider>(MockBehavior.Strict);

            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\solution\.nuget", It.IsAny <bool>())).Returns(fileSystem).Verifiable();

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var value      = vsSettings.GetValue("solution", "foo");

            // Assert
            Assert.Equal("bar", value);
            solutionManager.VerifyAll();
            fileSystemProvider.VerifyAll();
        }
        public void VsSettingUsesValuesFromDefaultSettingsForNonSolutionProperties()
        {
            // Arrange
            var solutionManager = new Mock <ISolutionManager>(MockBehavior.Strict);

            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\solution").Verifiable();
            var defaultSettings = new Mock <ISettings>(MockBehavior.Strict);

            defaultSettings.Setup(d => d.GetValue("PackageSources", "foo")).Returns("qux").Verifiable();

            var fileSystem = new MockFileSystem();

            fileSystem.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""bar"" /></solution></configuration>");
            var fileSystemProvider = new Mock <IFileSystemProvider>(MockBehavior.Strict);

            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\solution\.nuget")).Returns(fileSystem).Verifiable();

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var value      = vsSettings.GetValue("PackageSources", "foo");

            // Assert
            Assert.Equal("qux", value);
            defaultSettings.Verify();
        }
예제 #4
0
        public void VsSettingSwitchesSettingsIfSolutionChanges()
        {
            // Arrange
            var solutionManager = new Mock <MockSolutionManager>();

            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\solution").Verifiable();
            solutionManager.Setup(s => s.SolutionFileSystem).Returns(new MockFileSystem(@"x:\solution"));
            var defaultSettings = new Mock <ISettings>(MockBehavior.Strict);

            var fileSystemA = new MockFileSystem();

            fileSystemA.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""barA"" /></solution></configuration>");

            var fileSystemB = new MockFileSystem();

            fileSystemB.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""barB"" /></solution></configuration>");

            var fileSystemProvider = new Mock <IFileSystemProvider>(MockBehavior.Strict);

            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\solution\.nuget")).Returns(fileSystemA).Verifiable();
            fileSystemProvider.Setup(f => f.GetFileSystem(@"y:\solution\.nuget")).Returns(fileSystemB).Verifiable();

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var valueA     = vsSettings.GetValue("solution", "foo", isPath: false);

            solutionManager.Object.CloseSolution();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"y:\solution").Verifiable();
            solutionManager.Object.CloseSolution();

            var valueB = vsSettings.GetValue("solution", "foo", isPath: false);

            // Assert
            Assert.Equal("barA", valueA);
            Assert.Equal("barB", valueB);
        }
예제 #5
0
        public void VsSettingUsesNullSettingsIfSolutionIsUnavailable()
        {
            // Arrange
            var solutionManager = new Mock<ISolutionManager>(MockBehavior.Strict);
            solutionManager.Setup(s => s.IsSolutionOpen).Returns(false).Verifiable();
            var defaultSettings = new Mock<ISettings>(MockBehavior.Strict);
            var fileSystemProvider = new Mock<IFileSystemProvider>(MockBehavior.Strict);
            fileSystemProvider.Setup(f => f.GetFileSystem(It.IsAny<string>(), It.IsAny<bool>())).Throws(new Exception("This method should not be called"));

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var value = vsSettings.GetValue("Solution", "Foo");

            // Assert
            Assert.Equal("", value);
            solutionManager.VerifyAll();
        }
예제 #6
0
        public void VsSettingUsesNullSettingsIfConfigFileDoesNotExistInRootOfSolution()
        {
            // Arrange
            var solutionManager = new Mock<ISolutionManager>(MockBehavior.Strict);
            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\").Verifiable();
            var defaultSettings = new Mock<ISettings>(MockBehavior.Strict);
            var fileSystemProvider = new Mock<IFileSystemProvider>(MockBehavior.Strict);
            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\.nuget", It.IsAny<bool>())).Returns(new MockFileSystem());

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var value = vsSettings.GetValue("Solution", "Foo");

            // Assert
            Assert.Equal("", value);
            solutionManager.VerifyAll();
        }
        public void VsSettingUsesNullSettingsIfSolutionIsUnavailable()
        {
            // Arrange
            var solutionManager = new Mock <ISolutionManager>(MockBehavior.Strict);

            solutionManager.Setup(s => s.IsSolutionOpen).Returns(false).Verifiable();
            var defaultSettings    = new Mock <ISettings>(MockBehavior.Strict);
            var fileSystemProvider = new Mock <IFileSystemProvider>(MockBehavior.Strict);

            fileSystemProvider.Setup(f => f.GetFileSystem(It.IsAny <string>())).Throws(new Exception("This method should not be called"));

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var value      = vsSettings.GetValue("Solution", "Foo");

            // Assert
            Assert.Equal("", value);
            solutionManager.VerifyAll();
        }
        public void VsSettingUsesNullSettingsIfConfigFileDoesNotExistInRootOfSolution()
        {
            // Arrange
            var solutionManager = new Mock <ISolutionManager>(MockBehavior.Strict);

            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\").Verifiable();
            var defaultSettings    = new Mock <ISettings>(MockBehavior.Strict);
            var fileSystemProvider = new Mock <IFileSystemProvider>(MockBehavior.Strict);

            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\.nuget")).Returns(new MockFileSystem());

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var value      = vsSettings.GetValue("Solution", "Foo");

            // Assert
            Assert.Equal("", value);
            solutionManager.VerifyAll();
        }
예제 #9
0
        public void VsSettingUsesSettingsFileFromSolutionRootIfExists()
        {
            // Arrange
            var solutionManager = new Mock<ISolutionManager>(MockBehavior.Strict);
            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\solution").Verifiable();
            var defaultSettings = new Mock<ISettings>(MockBehavior.Strict);

            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""bar"" /></solution></configuration>");
            var fileSystemProvider = new Mock<IFileSystemProvider>(MockBehavior.Strict);
            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\solution\.nuget", It.IsAny<bool>())).Returns(fileSystem).Verifiable();

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var value = vsSettings.GetValue("solution", "foo");

            // Assert
            Assert.Equal("bar", value);
            solutionManager.VerifyAll();
            fileSystemProvider.VerifyAll();
        }
예제 #10
0
        public void VsSettingSwitchesSettingsIfSolutionChanges()
        {
            // Arrange
            var solutionManager = new Mock<MockSolutionManager>();
            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\solution").Verifiable();
            var defaultSettings = new Mock<ISettings>(MockBehavior.Strict);

            var fileSystemA = new MockFileSystem();
            fileSystemA.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""barA"" /></solution></configuration>");

            var fileSystemB = new MockFileSystem();
            fileSystemB.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""barB"" /></solution></configuration>");

            var fileSystemProvider = new Mock<IFileSystemProvider>(MockBehavior.Strict);
            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\solution\.nuget", It.IsAny<bool>())).Returns(fileSystemA).Verifiable();
            fileSystemProvider.Setup(f => f.GetFileSystem(@"y:\solution\.nuget", It.IsAny<bool>())).Returns(fileSystemB).Verifiable();

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var valueA = vsSettings.GetValue("solution", "foo");
            solutionManager.Object.CloseSolution();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"y:\solution").Verifiable();
            solutionManager.Object.CloseSolution();

            var valueB = vsSettings.GetValue("solution", "foo");

            // Assert
            Assert.Equal("barA", valueA);
            Assert.Equal("barB", valueB);
        }
예제 #11
0
        public void VsSettingDoesNotCacheSolutionSettings()
        {
            // Arrange
            var solutionManager = new Mock<MockSolutionManager>();
            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\solution").Verifiable();
            var defaultSettings = new Mock<ISettings>(MockBehavior.Strict);

            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""bar"" /></solution></configuration>");

            var fileSystemProvider = new Mock<IFileSystemProvider>(MockBehavior.Strict);
            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\solution\.nuget")).Returns(fileSystem).Verifiable();

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var valueA = vsSettings.GetValue("solution", "foo");
            fileSystem.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""qux"" /></solution></configuration>");
            var valueB = vsSettings.GetValue("solution", "foo");

            // Assert
            Assert.Equal("bar", valueA);
            Assert.Equal("qux", valueB);
        }
예제 #12
0
        public void VsSettingUsesValuesFromDefaultSettingsForNonSolutionProperties()
        {
            // Arrange
            var solutionManager = new Mock<ISolutionManager>(MockBehavior.Strict);
            solutionManager.Setup(s => s.IsSolutionOpen).Returns(true).Verifiable();
            solutionManager.Setup(s => s.SolutionDirectory).Returns(@"x:\solution").Verifiable();
            var defaultSettings = new Mock<ISettings>(MockBehavior.Strict);
            defaultSettings.Setup(d => d.GetValue("PackageSources", "foo")).Returns("qux").Verifiable();

            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("nuget.config", @"<?xml version=""1.0"" ?><configuration><solution><add key=""foo"" value=""bar"" /></solution></configuration>");
            var fileSystemProvider = new Mock<IFileSystemProvider>(MockBehavior.Strict);
            fileSystemProvider.Setup(f => f.GetFileSystem(@"x:\solution\.nuget")).Returns(fileSystem).Verifiable();

            // Act
            var vsSettings = new VsSettings(solutionManager.Object, defaultSettings.Object, fileSystemProvider.Object);
            var value = vsSettings.GetValue("PackageSources", "foo");

            // Assert
            Assert.Equal("qux", value);
            defaultSettings.Verify();
        }