public void Write() { TestObject1 o = new TestObject1(); TypeAccessor.WriteConsole(o); TypeAccessor.WriteDebug(o); }
public void TestConstruction() { TestObject1 obj1 = new TestObject1("some value"); Variant v1 = new Variant(obj1); Assert.AreEqual(v1.Type, Variant.EnumType.Object); TestObject1 obj2 = v1.AsObject<TestObject1>(); Assert.AreEqual(obj1, obj2); Assert.Throws<VariantException>(delegate { v1.AsObject<TestObject2>(); }); Assert.Throws<VariantException>(delegate { v1.AsObject<VariantObjectProxy>(); }); VariantObjectProxy obj3 = new VariantObjectProxy(obj1.Class); obj3.Inflate(obj2.Deflate(), obj2.Version); Assert.AreEqual(obj3.Class, "TestObject1"); Assert.AreEqual(obj3.Version, 1); Assert.AreEqual(obj3.Deflate().Type, Variant.EnumType.Dictionary); Variant v2 = new Variant(obj3); Assert.IsInstanceOf<VariantObjectProxy>(v2.AsObject()); Assert.Throws<VariantException>(delegate { v1.AsObject<TestObject2>(); }); TestObject1 obj5 = v2.AsObject<TestObject1>(); Assert.AreEqual(obj5.Class, "TestObject1"); Assert.AreEqual(obj5.Version, 1); Assert.IsInstanceOf<TestObject1>(v2.AsObject()); }
public void ComparesObjectValuesIfObjectsHaveNoProperties() { var obj1 = new TestObject1(); var obj2 = new TestObject1(); var sut = new ObjectComparer(); var result = sut.Compare(obj1, obj2).ToList(); Assert.AreEqual(1, result.Count); CheckComparison(result[0], ComparisonResult.NotEqual, "", obj1, obj2); }
public void SimpleType() { var obj1 = new TestObject1 { Prop1 = "abc", Prop2 = 123 }; var obj2 = new TestObject1 { Prop1 = "abc", Prop2 = 345 }; var sut = new ObjectComparer(); var result = sut.Compare(obj1, obj2).ToList(); Assert.AreEqual(2, result.Count()); CheckComparison(result[0], ComparisonResult.Equal, ".Prop1", "abc", "abc"); CheckComparison(result[1], ComparisonResult.NotEqual, ".Prop2", 123, 345); }
public void TestObject() { TestObject1 o1 = new TestObject1("some value"); Variant v1 = new Variant(o1); string xml = XmlWriter.ToString(v1); Variant v2 = XmlReader.FromString(xml); Assert.AreEqual(v2.Type, Variant.EnumType.Object); TestObject1 o2 = v2.AsObject<TestObject1>(); Assert.AreEqual(o1.Class, o2.Class); Assert.AreEqual(o1.Version, o2.Version); Assert.IsTrue(o1.Deflate().Equals(o2.Deflate())); }
public void TestObjectBuffer() { TestObject1 o1 = new TestObject1("some value"); Variant v1 = new Variant(o1); var bufferSize = BinaryWriter.GetByteCount(v1); byte[] bytes = new byte[bufferSize]; BinaryWriter.GetBytes(v1, BinaryMode.Default, bytes, 0); Variant v2 = BinaryReader.FromBytes(bytes); Assert.AreEqual(v2.Type, Variant.EnumType.Object); TestObject1 o2 = v2.AsObject <TestObject1>(); Assert.AreEqual(o1.Class, o2.Class); Assert.AreEqual(o1.Version, o2.Version); Assert.IsTrue(o1.Deflate().Equals(o2.Deflate())); }
public void TestConstruction() { TestObject1 obj1 = new TestObject1("some value"); Variant v1 = new Variant(obj1); Assert.AreEqual(v1.Type, Variant.EnumType.Object); TestObject1 obj2 = v1.AsObject <TestObject1>(); Assert.AreEqual(obj1, obj2); Assert.Throws <VariantException>(delegate { v1.AsObject <TestObject2>(); }); Assert.Throws <VariantException>(delegate { v1.AsObject <VariantObjectProxy>(); }); VariantObjectProxy obj3 = new VariantObjectProxy(obj1.Class); obj3.Inflate(obj2.Deflate(), obj2.Version); Assert.AreEqual(obj3.Class, "TestObject1"); Assert.AreEqual(obj3.Version, 1); Assert.AreEqual(obj3.Deflate().Type, Variant.EnumType.Dictionary); Variant v2 = new Variant(obj3); Assert.IsInstanceOf <VariantObjectProxy>(v2.AsObject()); Assert.Throws <VariantException>(delegate { v1.AsObject <TestObject2>(); }); TestObject1 obj5 = v2.AsObject <TestObject1>(); Assert.AreEqual(obj5.Class, "TestObject1"); Assert.AreEqual(obj5.Version, 1); Assert.IsInstanceOf <TestObject1>(v2.AsObject()); }
public long Sum(TestObject2 obj1, TestObject1 obj2) { return(obj1.Count2 + obj2.Count1); }
public void ThrowsIfObjectsDoNotHaveSameType() { var obj1 = new TestObject1(); var obj2 = new TestObject2(); var sut = new ObjectComparer(); sut.Compare(obj1, obj2); }
public MFTestResults SystemType1_GetType_Test() { /// <summary> /// 1. Tests the GetType(String) method /// 2. Tests the GetType() method /// </summary> /// bool testResult = true; try { Int32 testInt32 = 0; Assembly Int32Assm = Assembly.Load("mscorlib"); Log.Comment("This tests the Assembly.GetType(String) by passing \"Namespace.Class\""); Type myType0 = Int32Assm.GetType("System.Int32"); Log.Comment("The full name is " + myType0.FullName); testResult &= (myType0 == testInt32.GetType()); Log.Comment("This tests the Type.GetType(String) by passing \"Namespace.Class\""); Type myType1 = Type.GetType("System.Int32"); Log.Comment("The full name is " + myType1.FullName); testResult &= (myType1 == testInt32.GetType()); Log.Comment("This tests the Type.GetType(String) by passing \"Namespace.Class, assembly\""); Type myType2 = Type.GetType("System.Int32, mscorlib"); Log.Comment("The full name is " + myType2.FullName); testResult &= (myType2 == testInt32.GetType()); Log.Comment("This tests the Type.GetType(String) by passing \"Namespace.Class, assembly, Version=\"a.b.c.d\"\""); string typeName3 = "System.Int32, mscorlib, Version=" + Int32Assm.GetName().Version.ToString(); Type myType3 = Type.GetType(typeName3); Log.Comment("The full name is " + myType3.FullName); testResult &= (myType3 == testInt32.GetType()); Log.Comment("This tests the Type.GetType() method for nested classes"); TestObject1 testTestObject1 = new TestObject1(); Type myType4 = testTestObject1.GetType(); Log.Comment("The full name is " + myType4.FullName); testResult &= (myType4 == Type.GetType("Microsoft.SPOT.Platform.Tests.SystemTypeTests+TestObject1")); Log.Comment("Since NoneSuch does not exist in this assembly, "); Log.Comment("GetType throws a TypeLoadException."); Type myType5 = Type.GetType("NoneSuch"); Log.Comment("The full name is " + myType5.FullName); } catch (Exception e) { Log.Comment("Typeless " + e.Message); } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }
public MFTestResults SystemType4_DeclaringType_Test() { /// <summary> /// 1. Tests the BaseType DeclaringType for system and user defined types /// </summary> /// bool testResult = true; try { Log.Comment("This tests the DeclaringType property"); //Assigned and manipulated to avoid compiler warning Int32 testInt32 = -1; testInt32++; Type myType1 = Type.GetType("System.Int32"); Log.Comment("The full name is " + myType1.FullName); testResult &= (myType1.DeclaringType == null); TestObject1 testTestObject1 = new TestObject1(); Type myType2 = testTestObject1.GetType(); Log.Comment("The full name is " + myType2.FullName); Type myType3 = this.GetType(); testResult &= (myType2.DeclaringType == myType3); } catch (Exception e) { Log.Comment("Typeless " + e.Message); testResult = false; } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }
public MFTestResults SystemType2_Assembly_Test() { /// <summary> /// 1. Tests the Assembly property for system and user defined types /// Fails if exception thrown /// </summary> /// bool testResult = true; try { Log.Comment("This tests the Assembly property"); //Assigned and manipulated to avoid compiler warning Int32 testInt32 = -1; testInt32++; Type myType1 = Type.GetType("System.Int32"); Log.Comment("The full name is " + myType1.Assembly.FullName); testResult &= (myType1.Assembly.FullName == "mscorlib, Version=" + myType1.Assembly.GetName().Version.ToString()); TestObject1 testTestObject1 = new TestObject1(); Type myType2 = testTestObject1.GetType(); Log.Comment("The full name is " + myType2.Assembly.FullName); testResult &= (myType2.Assembly.FullName == "Microsoft.SPOT.Platform.Tests.Systemlib2, Version=" + myType2.Assembly.GetName().Version.ToString()); } catch (Exception e) { Log.Comment("Typeless " + e.Message); testResult = false; } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }
public void ParamTest() { TestObject1 o = (TestObject1)TypeAccessor.CreateInstance(typeof(TestObject1)); Assert.AreEqual(58, o.IntField); }
public void Test_Issue2172_WritePortableArray() { var ss = new SerializationServiceBuilder().SetInitialOutputBufferSize(16).Build(); var testObject2s = new TestObject2[100]; for (var i = 0; i < testObject2s.Length; i++) { testObject2s[i] = new TestObject2(); } var testObject1 = new TestObject1(testObject2s); ss.ToData(testObject1); }
public void TestObject() { TestObject1 o1 = new TestObject1("some value"); Variant v1 = new Variant(o1); byte[] bytes = BinaryWriter.ToBytes(v1); Variant v2 = BinaryReader.FromBytes(bytes); Assert.AreEqual(v2.Type, Variant.EnumType.Object); TestObject1 o2 = v2.AsObject<TestObject1>(); Assert.AreEqual(o1.Class, o2.Class); Assert.AreEqual(o1.Version, o2.Version); Assert.IsTrue(o1.Deflate().Equals(o2.Deflate())); }
public void Test3() { TestObject1 o = (TestObject1)TypeAccessor.CreateInstance(typeof(TestObject1)); o.Foo3("str1", null, "str3"); }
public int Sum(TestObject1 obj1, TestObject2 obj2, TestObject2 obj3) { return(obj1.Count1 + obj2.Count2 + obj3.Count2 + 100); }
public void BasicRavenReposTest() { string realId; Guid realGuid; string refId; //using (var sess = _ds.OpenSession()) var curScope = _scope.Scope.IsRegistered <IAppScope>(); Assert.True(curScope); using (var scope = _core1.BeginScope()) using (var repos = scope.Resolve <IRepositoryWithGuid <TestObject> >()) using (var repos1 = scope.Resolve <IRepositoryWithGuid <TestObject1> >()) { var item1 = new TestObject1 { Name = "1233" }; repos1.Store(item1); var item2 = new TestObject1 { Name = "1233" }; //repos1.Store(item2); repos1.SaveChanges(); var ref1 = _scope.Resolve <Refrence <TestObject1> >(); var ref2 = _scope.Resolve <Refrence <TestObject1> >(); ref1.Object = item1; ref2.Object = item2; var item = new TestObject { Name = "123", Refrence = ref1, Refrence1 = ref2 }; repos.Store(item); repos.SaveChanges(); refId = item1.Id; realId = item.Id; realGuid = item.Guid; Assert.IsNotNullOrEmpty(realId); } using (var scope = _core1.BeginScope()) using (var repos = scope.Resolve <IRepositoryWithGuid <TestObject> >()) { TestObject item = repos.Find(realGuid); var clone = item; Assert.NotNull(repos.Find(clone.Guid)); item = repos.Find(clone.Guid); var item2 = repos.Find(new[] { realGuid }); TestObject item1 = repos.Find(realId + "123123123"); Assert.NotNull(item); //Assert.NotNull(item); //item.Refrence.RepositoryFactory = repos1; Assert.NotNull(item.Refrence); Assert.NotNull(item.Refrence.Object); Assert.AreEqual(item.Refrence.Object.Id, refId); Assert.Null(item1); repos.Delete(item); repos.SaveChanges(); } using (var repos = _scope.Resolve <IRepositoryWithGuid <TestObject> >()) using (var repos1 = _scope.Resolve <IRepositoryWithGuid <TestObject1> >()) { TestObject item = repos.Find(realId); Assert.Null(item); List <TestObject1> items = repos1.Query.ToList(); Assert.IsTrue(items.Count > 0); } var lst = new List <TestObject>(); using (var repos = _scope.Resolve <IRepositoryWithGuid <TestObject> >()) { for (int i = 0; i < 10; i++) { lst.Add(new TestObject { Name = i.ToString() }); } repos.StoreBulk(lst); repos.SaveChanges(); } using (var repos = _scope.Resolve <IRepositoryWithGuid <TestObject> >()) { List <TestObject> res = repos.Find(lst.Select(i => i.Id)).ToList(); Assert.AreEqual(res.Count, lst.Count); } }
public void Test_Null() { TestObject1 t1 = JsonConvert.DeserializeObject <TestObject1>("{'Obj':null}"); Assert.IsNull(t1.Obj); }
public int Sum(TestObject1 obj1, TestObject1 obj2) { return(obj1.Count1 + obj2.Count1); }
public void DeserializeTimeSpan() { TestObject1 to = JsonConvert.DeserializeObject <TestObject1>("{\"TTL\":\"5s\"}"); Assert.Equal(5, to.TTL.TotalSeconds); }