Example #1
0
        public void GetAsT_ShouldReturnNull_WhenValueIsNullAndNoDefaultValue()
        {
            var configValue = new ConfigurationValue(null, new JsonSerializer());
            var configAsT   = configValue.GetAs <Configurations>();

            Assert.IsNull(configAsT);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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");
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
 public void GetAsT_ShouldReturnStringValue_WhenValueIsString()
 {
     var value       = "stringValue";
     var configValue = new ConfigurationValue(value, new JsonSerializer());
     var configAsT   = configValue.GetAs <string>();
 }