public static TestRESTObject CreateTestObject(bool populateNulls) { var testObj = new TestRESTObject(); testObj.ID = ++_lastId; testObj.TestStringValue = TEST_STRING; testObj.TestBoolValue = TEST_BOOL; testObj.TestIntValue = TEST_INT; testObj.TestLongValue = TEST_LONG; testObj.TestByteValue = TEST_BYTE; testObj.TestFloatValue = TEST_FLOAT; testObj.TestUnsignedIntValue = TEST_UINT; testObj.TestDoubleValue = TEST_DOUBLE; testObj.TestCharValue = TEST_CHAR; testObj.TestDateTimeValue = TEST_DATETIME; if(populateNulls) { testObj.TestNullableStringValue = TEST_STRING; testObj.TestNullableBoolValue = TEST_BOOL; testObj.TestNullableIntValue = TEST_INT; testObj.TestNullableLongValue = TEST_LONG; testObj.TestNullableByteValue = TEST_BYTE; testObj.TestNullableFloatValue = TEST_FLOAT; testObj.TestNullableUIntValue = TEST_UINT; testObj.TestNullableDoubleValue = TEST_DOUBLE; testObj.TestNullableCharValue = TEST_CHAR; testObj.TestNullableDateTimeValue = TEST_DATETIME; } return testObj; }
public static RestObject<TestRESTObject> SerializeAndParseRESTObject(TestRESTObject testObject) { var json = JsonConvert.SerializeObject(testObject); var restObject = new RestObject<TestRESTObject>(json); //Check to make sure that serialization was correct Assert.IsTrue(restObject.ExplicitObject != null, "Explicit Object was not correctly populated"); return restObject; }
public static void AssertValidValuesForTestClass(TestRESTObject convertedTestObject, bool checkChildArray, bool checkChildList, bool isChildCheck, bool areNullsPopulated) { //Check to make sure that all values are correct Assert.AreEqual(convertedTestObject.TestStringValue, TEST_STRING); Assert.AreEqual(convertedTestObject.TestBoolValue, TEST_BOOL); Assert.AreEqual(convertedTestObject.TestIntValue, TEST_INT); Assert.AreEqual(convertedTestObject.TestLongValue, TEST_LONG); Assert.AreEqual(convertedTestObject.TestByteValue, TEST_BYTE); Assert.AreEqual(convertedTestObject.TestUnsignedIntValue, TEST_UINT); Assert.AreEqual(convertedTestObject.TestFloatValue, TEST_FLOAT); Assert.AreEqual(convertedTestObject.TestDoubleValue, TEST_DOUBLE); Assert.AreEqual(convertedTestObject.TestCharValue, TEST_CHAR); Assert.AreEqual(convertedTestObject.TestDateTimeValue, TEST_DATETIME); if(areNullsPopulated) { Assert.AreEqual(convertedTestObject.TestNullableStringValue, TEST_STRING); Assert.AreEqual(convertedTestObject.TestNullableBoolValue, TEST_BOOL); Assert.AreEqual(convertedTestObject.TestNullableIntValue, TEST_INT); Assert.AreEqual(convertedTestObject.TestNullableLongValue, TEST_LONG); Assert.AreEqual(convertedTestObject.TestNullableByteValue, TEST_BYTE); Assert.AreEqual(convertedTestObject.TestNullableFloatValue, TEST_FLOAT); Assert.AreEqual(convertedTestObject.TestNullableUIntValue, TEST_UINT); Assert.AreEqual(convertedTestObject.TestNullableDoubleValue, TEST_DOUBLE); Assert.AreEqual(convertedTestObject.TestNullableCharValue, TEST_CHAR); Assert.AreEqual(convertedTestObject.TestNullableDateTimeValue, TEST_DATETIME); } if (!checkChildArray || isChildCheck) { Assert.IsNull(convertedTestObject.ChildArray); } else { Assert.IsNotNull(convertedTestObject.ChildArray); Assert.IsTrue(convertedTestObject.ChildArray.Length > 0); for (int i = 0; i < convertedTestObject.ChildArray.Length; i++) { var childObject = convertedTestObject.ChildArray[i]; AssertValidValuesForTestClass(childObject, false, false, true, areNullsPopulated); } } if (!checkChildList || isChildCheck) { Assert.IsNull(convertedTestObject.ChildList); } else { Assert.IsNotNull(convertedTestObject.ChildList); Assert.IsTrue(convertedTestObject.ChildList.Count > 0); foreach (var childObject in convertedTestObject.ChildList) { AssertValidValuesForTestClass(childObject, false, false, true, areNullsPopulated); } } }