Ejemplo n.º 1
0
        public void GetConfigValue_WhenConfigKeyIsValid_ReturnsThePertinentConfigValue(string configKey, string expectedConfigValue)
        {
            // Arrange
            var mockOptions = new Mock <IOptions <ExternalApiSettings> >();

            mockOptions
            .Setup(o => o.Value)
            .Returns(new ExternalApiSettings()
            {
                Token = TokenValue, BaseUrl = BaseUrlValue
            });

            var sutConfigProvider = new ConfigProvider(mockOptions.Object);
            // Act
            var result = sutConfigProvider.GetConfigValue(configKey);

            // Assert
            result.Should().Be(expectedConfigValue);
        }
Ejemplo n.º 2
0
        public void GetConfigValue_WhenConfigKeyIsNullOrEmptyOrWhiteSpace_ThrowsProperArgumentException(string configKey)
        {
            // Arrange
            var mockOptions = new Mock <IOptions <ExternalApiSettings> >();

            mockOptions
            .Setup(o => o.Value)
            .Returns(new ExternalApiSettings()
            {
                Token = TokenValue, BaseUrl = BaseUrlValue
            });

            var sutConfigProvider = new ConfigProvider(mockOptions.Object);
            // Act
            Action action = () => sutConfigProvider.GetConfigValue(configKey);

            // Assert
            var expectedErrorMessage = "ConfigKey cannot be null or empty or only whitespace.";

            action.Should()
            .ThrowExactly <ArgumentException>()
            .WithMessage(expectedErrorMessage);
        }
Ejemplo n.º 3
0
        public void GetConfigValue_WhenConfigKeyIsInvalid_ThrowsProperArgumentException()
        {
            // Arrange
            var configKey   = "InvalidKey";
            var mockOptions = new Mock <IOptions <ExternalApiSettings> >();

            mockOptions
            .Setup(o => o.Value)
            .Returns(new ExternalApiSettings()
            {
                Token = TokenValue, BaseUrl = BaseUrlValue
            });

            var sutConfigProvider = new ConfigProvider(mockOptions.Object);
            // Act
            Action action = () => sutConfigProvider.GetConfigValue(configKey);

            // Assert
            var expectedErrorMessage = $"ConfigKey '{configKey}' is not valid.";

            action.Should()
            .ThrowExactly <ArgumentException>()
            .WithMessage(expectedErrorMessage);
        }