public void GetAsT_ShouldReturnNull_WhenValueIsNullAndNoDefaultValue() { var configValue = new ConfigurationValue(null, new JsonSerializer()); var configAsT = configValue.GetAs <Configurations>(); Assert.IsNull(configAsT); }
public void GetAsT_ShouldThrowSerializationException_WhenValueIsNotJsonReadable() { var value = "something"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var exception = Xunit.Assert.Throws <SerializationException>(() => configValue.GetAs <Configurations>()); Assert.IsNotNull(exception); }
public void GetAsT_ShouldThrowSerializationException_WhenValueIsNotSerializable() { var value = "{\"redisConnection\": \"192.168.2.2\"}"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var exception = Xunit.Assert.Throws <SerializationException>(() => configValue.GetAs <Configurations>()); Assert.IsNotNull(exception); }
public void GetAsT_ShouldReturnValue_WhenValueIsValid() { var value = "{\"redisConnection\":{\"ipAddress\":\"192.168.2.2\",\"port\":\"8600\"}}"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var configAsT = configValue.GetAs <Configurations>(); Assert.IsNotNull(configAsT); Assert.AreEqual(configAsT.RedisConnection.IpAddress, "192.168.2.2"); }
public void GetAsT_ShouldReturnEmptyObject_WhenValueIsInValid() { var value = "{\"firstKey\":\"firstValue\",\"secondKey\":\"secondValue\",\"thirdKey\":\"thirdValue\"}"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var configAsT = configValue.GetAs <Configurations>(); Assert.IsNotNull(configAsT); Assert.IsNull(configAsT.RedisConnection); Assert.IsNull(configAsT.ConsulConnection); }
public void GetAsT_ShouldReturnDefaultValue_WhenValueIsNull() { var defaultValue = new Configurations(); defaultValue.RedisConnection = new Connections("192.168.2.2", "8800"); var configValue = new ConfigurationValue(null, new JsonSerializer()); var configAsT = configValue.GetAs(defaultValue); Assert.IsNotNull(configAsT); Assert.AreEqual(configAsT.RedisConnection.IpAddress, defaultValue.RedisConnection.IpAddress); Assert.AreEqual(configAsT.RedisConnection.Port, defaultValue.RedisConnection.Port); }
public void GetAsT_ShouldReturnStringValue_WhenValueIsString() { var value = "stringValue"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var configAsT = configValue.GetAs <string>(); }