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); }
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 })); }
public void TestGetValueReturnsNullWhenJsonPathIsEmptyAndTypeIsOfObject() { var optimizelyJSONUsingString = new OptimizelyJSON(Payload, ErrorHandlerMock.Object, LoggerMock.Object); var expectedValue = optimizelyJSONUsingString.GetValue <object>(""); Assert.NotNull(expectedValue); }
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)); }
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); }
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>); }
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); }
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); }
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); }
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)); }
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 }); }