Exemplo n.º 1
0
        public void GetMongoConfiguration_GivenValidJson_ReturnsExpectedSettings()
        {
            // Arrange
            var testFilePath = "anyFilePath.json";

            var fakeFileSystem = Substitute.For <IFileSystem>();

            fakeFileSystem
            .ReadAllText(Arg.Any <string>())
            .Returns(this.TestSettingsString);
            fakeFileSystem
            .FileExists(Arg.Any <string>())
            .Returns(true);
            fakeFileSystem
            .GetFileExtension(testFilePath)
            .Returns(".json");

            var expected = this.TestSettings;

            var classUnderTest = new SettingsLoader(fakeFileSystem);


            // Act
            var result =
                classUnderTest.GetMongoConfiguration(testFilePath);


            // Assert
            Assert.Equal(expected, result, Comparers.HarnessConfigurationComparer());
        }
Exemplo n.º 2
0
        public void GetMongoConfiguration_PassNullEmptyOrWhiteSpace_ThrowsSettingsManagerException(string testValue)
        {
            // Arrange
            var fakeFileSystem = Substitute.For <IFileSystem>();
            var classUnderTest = new SettingsLoader(fakeFileSystem);

            // Act / Assert
            Assert.Throws <SettingsLoaderException>(
                () => classUnderTest.GetMongoConfiguration(testValue));
        }
Exemplo n.º 3
0
        public void GetMongoConfiguration_WhenFileDoesNotExist_ThrowsSettingsManagerException()
        {
            // Arrange
            var fakeFileSystem = Substitute.For <IFileSystem>();

            fakeFileSystem
            .FileExists(Arg.Any <string>())
            .Returns(false);

            var classUnderTest = new SettingsLoader(fakeFileSystem);

            // Act / Assert
            Assert.Throws <SettingsLoaderException>(
                () => classUnderTest.GetMongoConfiguration("anyFilePath.json"));
        }
Exemplo n.º 4
0
        public void GetMongoConfiguration_PassPathThatDoesNotHaveJsonExtension_ThrowsArgumentOutOfRangeException()
        {
            // Arrange
            var fakeFileSystem = Substitute.For <IFileSystem>();

            fakeFileSystem
            .FileExists(Arg.Any <string>())
            .Returns(true);
            fakeFileSystem
            .GetFileExtension(Arg.Any <string>())
            .Returns("doc");

            var classUnderTest = new SettingsLoader(fakeFileSystem);

            // Act / Assert
            Assert.Throws <ArgumentOutOfRangeException>(
                () => classUnderTest.GetMongoConfiguration("anyFilePath.doc"));
        }
Exemplo n.º 5
0
        public void GetMongoConfiguration_GivenMalformedJson_ThrowsArgumentExcpetion()
        {
            // Arrange
            var testFilePath = "anyFilePath.json";
            var badJson      = "{\"SaveOutput\": false \"SomethigElse\": true";

            var fakeFileSystem = Substitute.For <IFileSystem>();

            fakeFileSystem
            .ReadAllText(Arg.Any <string>())
            .Returns(badJson);
            fakeFileSystem
            .FileExists(Arg.Any <string>())
            .Returns(true);
            fakeFileSystem
            .GetFileExtension(testFilePath)
            .Returns(".json");

            var classUnderTest = new SettingsLoader(fakeFileSystem);

            // Act / Assert
            Assert.Throws <Newtonsoft.Json.JsonReaderException>(
                () => classUnderTest.GetMongoConfiguration(testFilePath));
        }