public void ShouldThrowConfigurationValidationException_WhenConfigurationIsInvalid() { // Arrange var configuration = GetInMemoryConfigurationObject(new Dictionary <string, string> { { "TestProperty1", "Hi" }, { "TestProperty3", "0" } }); // Act Func <TestConfiguration> result = () => ConfigurationExtensions.GetValidated <TestConfiguration>(configuration); // Act And Assert result.Should().Throw <ConfigurationValidationException>() .WithMessage("Configuration section TestConfiguration has an invalid setting"); }
public void ShouldReturnConfigurationObject_WhenConfigurationIsValid() { // Arrange var expectedConfig = new TestConfiguration { TestProperty1 = "Hello", TestProperty2 = "Goodbye", TestProperty3 = 0, }; var configuration = GetInMemoryConfigurationObject(new Dictionary <string, string> { { "TestProperty1", "Hello" }, { "TestProperty2", "Goodbye" }, { "TestProperty3", "0" } }); // Act var result = ConfigurationExtensions.GetValidated <TestConfiguration>(configuration); // Assert result.Should().BeEquivalentTo(expectedConfig); }
public void ShouldThrowArgumentNullException_WhenConfigurationIsNull() { Assert.Throws <ArgumentNullException>(() => ConfigurationExtensions.GetValidated <int>(null)); }