示例#1
0
        public void TestGetValueObjectNotModifiedIfCalledTwice()
        {
            var optimizelyJSONUsingString = new OptimizelyJSON(Payload, ErrorHandlerMock.Object, LoggerMock.Object);
            var expectedValue             = optimizelyJSONUsingString.GetValue <string>("field4.inner_field1");
            var expectedValue2            = optimizelyJSONUsingString.GetValue <string>("field4.inner_field1");

            Assert.AreEqual(expectedValue, expectedValue2);
        }
示例#2
0
        public void TestOptimizelyJsonGetVariablesWhenSetUsingString()
        {
            var optimizelyJSONUsingString = new OptimizelyJSON(Payload, ErrorHandlerMock.Object, LoggerMock.Object);

            Assert.AreEqual(optimizelyJSONUsingString.GetValue <long>("field1"), 1);
            Assert.AreEqual(optimizelyJSONUsingString.GetValue <double>("field2"), 2.5);
            Assert.AreEqual(optimizelyJSONUsingString.GetValue <string>("field3"), "three");
            Assert.AreEqual(optimizelyJSONUsingString.GetValue <long>("field4.inner_field1"), 3);
            Assert.True(TestData.CompareObjects(optimizelyJSONUsingString.GetValue <List <object> >("field4.inner_field2"), new List <object>()
            {
                "1", "2", 3, 4.23, true
            }));
        }
示例#3
0
        public void TestGetValueReturnsNullWhenJsonPathIsEmptyAndTypeIsOfObject()
        {
            var optimizelyJSONUsingString = new OptimizelyJSON(Payload, ErrorHandlerMock.Object, LoggerMock.Object);
            var expectedValue             = optimizelyJSONUsingString.GetValue <object>("");

            Assert.NotNull(expectedValue);
        }
示例#4
0
        public void TestGetValueReturnsCastedObject()
        {
            var optimizelyJson = new OptimizelyJSON(Map, ErrorHandlerMock.Object, LoggerMock.Object);
            var expectedValue  = optimizelyJson.ToDictionary();
            var actualValue    = optimizelyJson.GetValue <ParentJson>(null);

            Assert.IsTrue(TestData.CompareObjects(actualValue, expectedValue));
        }
示例#5
0
        public void TestGetValueReturnsDefaultValueWhenTypeIsInvalid()
        {
            var payload = "{ \"field1\" : {\"1\":\"Csharp\",\"2\":\"Java\"} }";
            var optimizelyJSONUsingString = new OptimizelyJSON(payload, ErrorHandlerMock.Object, LoggerMock.Object);
            var expectedValue             = optimizelyJSONUsingString.GetValue <Dictionary <float, string> >("field1");

            Assert.IsNotNull(expectedValue);
        }
示例#6
0
        public void TestOptimizelyJsonGetVariablesWhenSetUsingMap()
        {
            var optimizelyJSONUsingMap = new OptimizelyJSON(Map, ErrorHandlerMock.Object, LoggerMock.Object);

            Assert.AreEqual(optimizelyJSONUsingMap.GetValue <string>("strField"), "john doe");
            Assert.AreEqual(optimizelyJSONUsingMap.GetValue <int>("intField"), 12);
            Assert.AreEqual(optimizelyJSONUsingMap.GetValue <double>("doubleField"), 2.23);
            Assert.AreEqual(optimizelyJSONUsingMap.GetValue <bool>("boolField"), true);
            Assert.AreEqual(optimizelyJSONUsingMap.GetValue <int>("objectField.inner_field_int"), 3);
            Assert.AreEqual(optimizelyJSONUsingMap.GetValue <double>("objectField.inner_field_double"), 13.21);
            Assert.AreEqual(optimizelyJSONUsingMap.GetValue <string>("objectField.inner_field_string"), "john");
            Assert.AreEqual(optimizelyJSONUsingMap.GetValue <bool>("objectField.inner_field_boolean"), true);
            Assert.IsTrue(optimizelyJSONUsingMap.GetValue <Dictionary <string, object> >("objectField") is Dictionary <string, object>);
        }
示例#7
0
        public void TestGetValueReturnsDefaultValueWhenJsonPath2IsInvalid()
        {
            var optimizelyJSONUsingString = new OptimizelyJSON(Payload, ErrorHandlerMock.Object, LoggerMock.Object);
            var expectedValue             = optimizelyJSONUsingString.GetValue <string>("field4..inner_field1");

            Assert.IsNull(expectedValue);
            LoggerMock.Verify(log => log.Log(LogLevel.ERROR, "Value for JSON key not found."), Times.Once);
            ErrorHandlerMock.Verify(er => er.HandleError(It.IsAny <OptimizelyRuntimeException>()), Times.Once);
        }
示例#8
0
        public void TestGetValueReturnsDefaultValueWhenJsonPathIsEmptyAndTypeIsNotValid()
        {
            var optimizelyJSONUsingString = new OptimizelyJSON(Payload, ErrorHandlerMock.Object, LoggerMock.Object);
            var expectedValue             = optimizelyJSONUsingString.GetValue <string>("");

            Assert.IsNull(expectedValue);
            LoggerMock.Verify(log => log.Log(LogLevel.ERROR, "Value for path could not be assigned to provided type."), Times.Once);
            ErrorHandlerMock.Verify(er => er.HandleError(It.IsAny <OptimizelyRuntimeException>()), Times.Once);
        }
示例#9
0
        public void TestGetValueReturnsDefaultValueWhenJsonIsInvalid()
        {
            var payload = "{ \"field1\" : {1:\"Csharp\", 2:\"Java\"} }";
            var optimizelyJSONUsingString = new OptimizelyJSON(payload, ErrorHandlerMock.Object, LoggerMock.Object);
            var expectedValue             = optimizelyJSONUsingString.GetValue <Dictionary <float, string> >("field1");

            // Even though above given JSON is not valid, newtonsoft is parsing it so
            Assert.IsNotNull(expectedValue);
        }
示例#10
0
        public void TestGetValueReturnsEntireDictWhenJsonPathIsEmptyAndTypeIsValid()
        {
            var optimizelyJSONUsingString = new OptimizelyJSON(Payload, ErrorHandlerMock.Object, LoggerMock.Object);
            var actualDict    = optimizelyJSONUsingString.ToDictionary();
            var expectedValue = optimizelyJSONUsingString.GetValue <Dictionary <string, object> >("");

            Assert.NotNull(expectedValue);
            Assert.True(TestData.CompareObjects(expectedValue, actualDict));
        }
示例#11
0
        public void TestGetValueReturnsUsingGivenClassType()
        {
            var optimizelyJSONUsingString = new OptimizelyJSON(Payload, ErrorHandlerMock.Object, LoggerMock.Object);
            var expectedValue             = optimizelyJSONUsingString.GetValue <Field4>("field4");

            Assert.AreEqual(expectedValue.inner_field1, 3);
            Assert.AreEqual(expectedValue.inner_field2, new List <object>()
            {
                "1", "2", 3, 4.23, true
            });
        }