public void Hello( ComplexStructure person, int repeat) { Context.Logger.LogInformation($"person.Age:{person.Age} person.Name:{person.Name}"); Context.Logger.LogInformation($"repeat:{repeat}"); }
private object CreateK1() { ComplexStructure k1 = new ComplexStructure(); k1.Field1 = "F1"; k1.Field2 = Guid.NewGuid(); k1.Field3 = DateTime.UtcNow; return(k1); }
public void JsonSerializeObject4() { ComplexStructure cs = null; EntityUtils target = new EntityUtils(); string actual = target.JsonSerializeObject(cs); string expected = "null"; Assert.AreEqual(expected, actual); }
public void GetObjectFieldValueStringTest1() { EntityUtils target = new EntityUtils(); ComplexStructure obj = null; string fieldName = "Field1"; string expected = null; string actual; actual = target.GetObjectFieldValueString(obj, fieldName); Assert.AreEqual(expected, actual); }
public void ObjectHasPropertyTest2() { EntityUtils target = new EntityUtils(); object obj = new ComplexStructure(); string propertyName = "FakeFieldTest"; bool expected = false; bool actual; actual = target.ObjectHasProperty(obj, propertyName); Assert.AreEqual(expected, actual); }
public void JsonDeserializeObject1() { EntityUtils target = new EntityUtils(); string jsonString = "{\"Field1\":\"f1Value\",\"Field2\":\"0cf8f670-c742-4f12-ba0b-98d8f3b9077a\",\"Field3\":\"2013-01-01T00:00:00\"}"; object jsonObject = target.JsonDeserializeObject(jsonString, typeof(ComplexStructure)); ComplexStructure cs2 = (ComplexStructure)jsonObject; Assert.AreEqual("f1Value", cs2.Field1); Assert.AreEqual(new Guid("0cf8f670-c742-4f12-ba0b-98d8f3b9077a"), cs2.Field2); Assert.AreEqual(new DateTime(2013, 1, 1), cs2.Field3); }
public void InvokeObjectMethodTest1() { EntityUtils target = new EntityUtils(); string methodName = "EchoMethodTest"; object obj = new ComplexStructure(); object[] parameters = { "TestEcho!" }; object expected = "TestEcho!"; object actual; actual = target.InvokeObjectMethod(methodName, obj, parameters); Assert.AreEqual(expected, actual); }
public void JsonSerializeObject1() { ComplexStructure cs = new ComplexStructure(); cs.Field1 = "f1Value"; cs.Field2 = new Guid("0cf8f670-c742-4f12-ba0b-98d8f3b9077a"); cs.Field3 = new DateTime(2013, 1, 1); EntityUtils target = new EntityUtils(); string actual = target.JsonSerializeObject(cs); string expected = "{\"Field1\":\"f1Value\",\"Field2\":\"0cf8f670-c742-4f12-ba0b-98d8f3b9077a\",\"Field3\":\"2013-01-01T00:00:00Z\"}"; Assert.AreEqual(expected, actual); }
public void GetObjectFieldValueStringTest2() { EntityUtils target = new EntityUtils(); ComplexStructure obj = new ComplexStructure() { Field2 = Guid.NewGuid() }; string fieldName = "Field2"; string expected = obj.Field2.ToString(); string actual; actual = target.GetObjectFieldValueString(obj, fieldName); Assert.AreEqual(expected, actual); }
public void ConvertStringToObjectComplexFormat() { // testing a byte[] for all values from 0 to 255 string value = "{\"Field1\":\"f1Value\",\"Field2\":\"0cf8f670-c742-4f12-ba0b-98d8f3b9077a\",\"Field3\":\"2013-01-01T00:00:00\"}"; EntityUtils target = new EntityUtils(); object o = target.ConvertStringToObject(value, typeof(ComplexStructure)); Assert.IsTrue(o.GetType() == typeof(ComplexStructure)); ComplexStructure cs = (ComplexStructure)o; Assert.AreEqual("f1Value", cs.Field1); Assert.AreEqual(new Guid("0cf8f670-c742-4f12-ba0b-98d8f3b9077a"), cs.Field2); Assert.AreEqual(new DateTime(2013, 1, 1), cs.Field3); }
public void FastStructure_AllocHGlobalReadWrite() { IntPtr mem = Marshal.AllocHGlobal(FastStructure.SizeOf <ComplexStructure>()); ComplexStructure n = new ComplexStructure(); n.Compatible.Integer1 = 1; n.Compatible.Bookend = 2; n.FirstElement = 3; n.FinalElement = 9; unsafe { n.Compatible.Contents[0] = 4; n.Compatible.Contents[7] = 5; } FastStructure.StructureToPtr(ref n, mem); // Assert that the reading and writing result in same structure ComplexStructure m = FastStructure.PtrToStructure <ComplexStructure>(mem); Assert.AreEqual(n, m); Assert.AreEqual(n.Compatible.Integer1, m.Compatible.Integer1); Assert.AreEqual(n.Compatible.Bookend, m.Compatible.Bookend); unsafe { Assert.AreEqual(n.Compatible.Contents[0], m.Compatible.Contents[0]); Assert.AreEqual(n.Compatible.Contents[7], m.Compatible.Contents[7]); } // Assert that Marshal.PtrToStructure is compatible m = (ComplexStructure)Marshal.PtrToStructure(mem, typeof(ComplexStructure)); Assert.AreEqual(n, m); Assert.AreEqual(n.Compatible.Integer1, m.Compatible.Integer1); Assert.AreEqual(n.Compatible.Bookend, m.Compatible.Bookend); unsafe { Assert.AreEqual(n.Compatible.Contents[0], m.Compatible.Contents[0]); Assert.AreEqual(n.Compatible.Contents[7], m.Compatible.Contents[7]); } Marshal.FreeHGlobal(mem); }
public void CloneByFirstConstructorTest1() { ReflectionUtils target = new ReflectionUtils(); ComplexStructure c = new ComplexStructure(); c.Field1 = "SomeValue"; Type t = c.GetType(); ComplexStructure actual; try { actual = (ComplexStructure)target.CloneByFirstConstructor(t); Assert.AreEqual(null, actual.Field1); } catch (Exception) { Assert.Fail(); } }
public void JsonSerializeObject5() { // testing excluding properties ComplexStructure cs = new ComplexStructure(); cs.Field1 = null; cs.Field2 = new Guid("0cf8f670-c742-4f12-ba0b-98d8f3b9077a"); cs.Field3 = new DateTime(2013, 1, 1); EntityUtils target = new EntityUtils(); List <string> excludingProperties = new List <string>(); excludingProperties.Add("Field2"); bool ignoreNullValues = false; string actual = target.JsonSerializeObject(cs, ignoreNullValues, excludingProperties); string expected = "{\"Field1\":null,\"Field3\":\"2013-01-01T00:00:00Z\"}"; Assert.AreEqual(expected, actual); }
public void GetDBDataTypeFromDotNetTypeTest3() { DBTypeUtils target = new DBTypeUtils(); ComplexStructure targetValue = new ComplexStructure(); //object expectedValue = null; // don't expect anything just check for exception DBDataType actual; try { actual = target.GetDBDataTypeFromDotNetType(targetValue.GetType()); } catch (NotImplementedException) { } catch (Exception) { Assert.Fail(); } }
public void FindFirstElementInIEnumeratorTest3() { CommaSeperatedUtils target = new CommaSeperatedUtils(); List <ComplexStructure> source = new List <ComplexStructure>(); ComplexStructure c1 = new ComplexStructure() { Field1 = "F1", Field2 = Guid.NewGuid() }; ComplexStructure c2 = new ComplexStructure() { Field1 = "F1", Field2 = Guid.NewGuid() }; source.Add(c1); source.Add(c2); object expected = c1; object actual; actual = target.FindFirstElementInIEnumerator(source); Assert.AreEqual(expected, actual); }
public void GetOrCreateTest() { SimpleObjectCacheManagement <ComplexStructure> cache = new SimpleObjectCacheManagement <ComplexStructure>(); // get and saves an object from cache ComplexStructure obj1 = (ComplexStructure)cache.GetOrCreate("K1", (x) => CreateK1(), null); // make sure that newly created object is different ComplexStructure obj2 = (ComplexStructure)cache.GetOrCreate("K2", (x) => CreateK1(), null); Assert.AreNotEqual(obj1, obj2); //----------- // changes first object values obj1.Field1 = "F2"; obj1.Field2 = Guid.NewGuid(); obj1.Field3 = DateTime.UtcNow; // make sure that the object get from cache is the same object ComplexStructure obj3 = (ComplexStructure)cache.GetOrCreate("K1", (x) => CreateK1(), null); Assert.AreEqual(obj1, obj3); }