public void ShouldFindErrorMessageWithElse() { var builder = new Fluent.FluentBuilder(); builder.For <ClassC>() .If(c => c.C > 10) .Setup(c => c.C) .WithMessage("C is not valid. >10") .MustEqual(-1) .Else() .Setup(c => c.C) .WithMessage("C is not valid. <10") .MustEqual(-1) .EndIf(); var engine = builder.Build(); var o = new ClassC() { C = 5 }; var r = new ValidationReport(engine); r.Validate(o); Assert.AreEqual("C is not valid. <10", r.GetErrorMessage(o, f => f.C)); }
public static int M2() { ClassA a = new ClassA(); ClassA a2 = new ClassA(); ClassB b = new ClassB(); ClassC c = new ClassC(); if (a == a) { _root.trace_fn.trace("YAY!"); } if (a == a2) { _root.trace_fn.trace("YAY!"); } if (b == c) { _root.trace_fn.trace("YAY!"); } // if (a == b) { // ERROR! // _root.trace_fn.trace("YAY!"); // } return(0); }
public void GivenBuiltProxyWithTarget_WhenMemberIsCalled_ThenMemberIsIntercepted() { var subjectBuilder = new DynamicProxyBuilder(); // Given var cTarget = new ClassC { CP1 = 5 }; var aInterceptor = new InterceptorA(); var bInterceptor = new InterceptorB(); IClassC proxy = subjectBuilder .ForInterface <IClassC>() .WithTarget(cTarget) .AddInterceptors(aInterceptor, bInterceptor) .Build(); // When int aValue = 0; proxy.CMethod(() => aValue = 10); var ret1_CP1 = proxy.CP1; proxy.CP1 = 7; var ret2_CP1 = proxy.CP1; // Then Assert.IsTrue(ProxyUtil.IsProxy(proxy), "object is not a proxy"); Assert.AreEqual(4, aInterceptor.InterceptReceivedCall); Assert.AreEqual(4, bInterceptor.InterceptReceivedCall); Assert.AreEqual(10, aValue); Assert.AreEqual(5, ret1_CP1); Assert.AreEqual(7, ret2_CP1); }
static void Main(string[] args) { Person Eric = new Person(); Eric.ID = "402-1199587-6"; Eric.Name = "Eric"; Eric.LastName = "Robles"; Eric.Age = 19; Eric.ShowPerson(); Profesor Luis = new Profesor(); Luis.ID = "402-1199587-6"; Luis.Name = "Luis"; Luis.LastName = "Martes"; Luis.Age = 30; Luis.ShowPerson(); Luis.Salary = 25000; Luis.ShowSalary(); TestContacto.TestContacMain(); ClassC classC = new ClassC(); }
public ClassB(ClassC pClassC) { x = 1; y = 2; classC = pClassC; classX = new ClassX(); }
static void Main(string[] args) { Checker check = new Checker(); ClassA try1 = new ClassA(); ClassB try2 = new ClassB(); ClassC try3 = new ClassC(); ClassD try4 = new ClassD(); MyStruct try5 = new MyStruct(); //Box the struct value, getting a reference to a new instance of the try5 struct. object try6 = try5; WriteLine("Analyzing ClassA type variable:"); check.Check(try1); WriteLine("\nAnalyzing ClassB type variable:"); check.Check(try2); WriteLine("\nAnalyzing ClassC type variable:"); check.Check(try3); WriteLine("\nAnalyzing ClassD type variable:"); check.Check(try4); WriteLine("\nAnalyzing MyStruct type variable:"); check.Check(try5); WriteLine("\nAnalyzing boxed MyStruct type variable:"); check.Check(try6); ReadKey(); }
public static ProxyC CreateProxyC(ClassC cObject) { var c = new ProxyC(cObject.Name) { A = cObject.A, B = cObject.B, ListOfA = cObject.ListOfA, ListOfB = cObject.ListOfB }; c.AProxy = CreateProxyWithSelfReference(c.A); c.ListOfAProxies = new List <ProxyA> { c.AProxy, new ProxyA(cObject.Name) }; c.BProxy = CreateProxyBWithSelfReference(c.B); c.ListOfBProxies = new List <ProxyB> { c.BProxy, new ProxyB(cObject.Name) }; return(c); }
public void GivenBuiltProxyWithTargetInterface_WhenMemberIsCalled_ThenMemberIsIntercepted() { var subjectBuilder = new DynamicProxyBuilder(); // Given var cTarget1 = new ClassC { CP1 = 5 }; var cTarget2 = new ClassC { CP1 = 15 }; var interceptor1 = new Inteceptor1(); IClassC proxy = subjectBuilder .ForInterface<IClassC>() .WithTargetInterface(cTarget1) .AddInterceptor(interceptor1) .Build(); // When interceptor1.ChangeProxyTarget(cTarget2); interceptor1.ChangeInvocationTarget(cTarget2); int aValue = 0; proxy.CMethod(() => aValue = 10); var ret1_CP1 = proxy.CP1; proxy.CP1 = 17; var ret2_CP1 = proxy.CP1; // Then Assert.IsTrue(ProxyUtil.IsProxy(proxy), "object is not a proxy"); Assert.AreEqual(4, interceptor1.InterceptReceivedCall); Assert.AreEqual(10, aValue); Assert.AreEqual(15, ret1_CP1); Assert.AreEqual(17, ret2_CP1); }
public void FromType_AsType() { var mgr = SetUp(); ClassA test = new ClassA(); ClassC obj = new ClassC() { PropA = "test", PropAbstract = 2, PropC = test }; Dictionary <string, object> res = mgr.FromType(obj); Assert.Equal(new Dictionary <string, object>() { { "PropA", "test" }, { "PropAbstract", 2 }, { "PropC", test } }, res); ClassC obj2 = mgr.AsType <ClassC>(new Dictionary <string, object>() { { "PropA", "test--" }, { "PropAbstract", 20 }, { "PropC", test } }); Assert.Equal("test--", obj2.PropA); Assert.Equal(20, obj2.PropAbstract); Assert.Equal(test, obj2.PropC); }
// создание объектов private static void CreateObjects(IFaker faker) { ClassA a = faker.Create <ClassA>(); objectList.Add(a); ClassB b = faker.Create <ClassB>(); objectList.Add(b); ClassC c = faker.Create <ClassC>(); objectList.Add(c); ClassD d = faker.Create <ClassD>(); objectList.Add(d); ClassE e = faker.Create <ClassE>(); objectList.Add(e); ClassF f = faker.Create <ClassF>(); objectList.Add(f); ClassG g = faker.Create <ClassG>(); objectList.Add(g); ClassH h = faker.Create <ClassH>(); objectList.Add(h); ClassI i = faker.Create <ClassI>(); objectList.Add(i); }
public void TestInitialize() { _classA = new ClassA("Klasa A", 2.1, null); _classB = new ClassB("Klasa B", 3.7f, null); _classC = new ClassC("Klasa C", new DateTime(2020, 12, 24), null); _classA.B = _classB; _classB.C = _classC; _classC.A = _classA; _testC = new ClassC("", new DateTime(), null); _fileName = "own_results.txt"; OurFormatter formatter = new OurFormatter(); File.Delete(_fileName); _serializeStream = File.Open(_fileName, FileMode.Create, FileAccess.ReadWrite); formatter.Serialize(_serializeStream, _classC); _serializeStream.Close(); _deserializeStream = File.Open(_fileName, FileMode.Open, FileAccess.ReadWrite); _testC = (ClassC)formatter.Deserialize(_deserializeStream); _deserializeStream.Close(); _testA = _testC.A; _testB = _testA.B; }
public static void Run() { ClassC classC = new ClassC(); ClassA <ClassB> classA = new ClassA <ClassB>(); classC.Add(classA); }
public Genericitycs2() { this.Method1 <ClassA>(new ClassA()); Console.WriteLine((new ClassA()).ToString()); this.Method1 <ClassA>(new ClassD()); Console.WriteLine((new ClassD()).ToString()); ClassA b = new ClassA(); b.Field1 = 1; b.Field2 = "hi"; this.Method2(b as T); ClassC c = new ClassC(); c.Field1 = 1; c.Field2 = "hi"; c.Field3 = "you"; c.Field4 = 2; this.Method2(c as T); ClassC c1 = this.Method3(2) as ClassC; ClassA a1 = this.Method3(2); ClassA a = new ClassA(); a.Field1 = 10; a.Field2 = "plop"; a.Field3 = "plip"; ClassE e = this.Method4 <ClassE, ClassA, ClassC>(a, c); ClassD d = this.Method4 <ClassD, ClassA, ClassB>(a, c); }
public void execute() { ClassC<ClassA> ca = new ClassC<ClassA>(); ClassC<ClassA> ba = new ClassC<ClassA>(); }
static void Main(string[] args) { Checker check = new Checker(); ClassA try1 = new ClassA(); ClassB try2 = new ClassB(); ClassC try3 = new ClassC(); ClassD try4 = new ClassD(); MyStruct try5 = new MyStruct(); object try6 = try5; Console.WriteLine("Analyzing ClassA type variable:"); check.Check(try1); Console.WriteLine("\nAnalyzing ClassB type variable:"); check.Check(try2); Console.WriteLine("\nAnalyzing ClassC type variable:"); check.Check(try3); Console.WriteLine("\nAnalyzing ClassD type variable:"); check.Check(try4); Console.WriteLine("\nAnalyzing MyStruct type variable:"); check.Check(try5); Console.WriteLine("\nAnalyzing boxed MyStruct type variable:"); check.Check(try6); Console.ReadKey(); }
public void ClassASerializeTest() { ClassA classA = new ClassA("message from A class", 56.35345f, 65, false, null); ClassB classB = new ClassB("message from B class", 57.35345f, 66, true, null); ClassC classC = new ClassC("message from C class", 58.35345f, 67, false, null); classA.BProperty = classB; classB.CProperty = classC; classC.AProperty = classA; using (FileStream fs = new FileStream("test_output.txt", FileMode.Create)) { IFormatter ownSerializer = new Serializer(); ownSerializer.Serialize(fs, classA); } List <String> temp = new List <String>(); using (StreamReader reader = new StreamReader(new FileStream("test_output.txt", FileMode.Open))) { String l; while ((l = reader.ReadLine()) != null) { temp.Add(l); } } Assert.AreEqual(3, temp.Count); Assert.AreEqual(temp[0], "{ConsoleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null} {ConsoleApp.ClassA} {m_idGenerator:\"1\"}{System.String:StringProperty:\"message from A class\"}{System.Single:FloatProperty:\""+ 56.35345.ToString(CultureInfo) + "\"}{System.Int32:IntProperty:\"65\"}{System.Boolean:BoolProperty:\"False\"}{ConsoleApp.ClassB:BProperty:\"2\"}"); Assert.AreEqual(temp[1], "{ConsoleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null} {ConsoleApp.ClassB} {m_idGenerator:\"2\"}{System.String:StringProperty:\"message from B class\"}{System.Single:FloatProperty:\""+ 57.35345.ToString(CultureInfo) + "\"}{System.Int32:IntProperty:\"66\"}{System.Boolean:BoolProperty:\"True\"}{ConsoleApp.ClassC:CProperty:\"3\"}"); Assert.AreEqual(temp[2], "{ConsoleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null} {ConsoleApp.ClassC} {m_idGenerator:\"3\"}{System.String:StringProperty:\"message from C class\"}{System.Single:FloatProperty:\""+ 58.35345.ToString(CultureInfo) + "\"}{System.Int32:IntProperty:\"67\"}{System.Boolean:BoolProperty:\"False\"}{ConsoleApp.ClassA:AProperty:\"1\"}"); File.Delete("test_output.txt"); }
public void ClassCDeserializeTest() { ClassA classA = new ClassA("message from A class", 56.35345f, 65, false, null); ClassB classB = new ClassB("message from B class", 57.35345f, 66, true, null); ClassC classC = new ClassC("message from C class", 58.35345f, 67, false, null); classA.BProperty = classB; classB.CProperty = classC; classC.AProperty = classA; using (FileStream fs = new FileStream("test_output.txt", FileMode.Create)) { IFormatter ownSerializer = new Serializer(); ownSerializer.Serialize(fs, classC); } ClassC test; using (FileStream fs = new FileStream("test_output.txt", FileMode.Open)) { IFormatter ownSerializer = new Serializer(); test = ownSerializer.Deserialize(fs) as ClassC; } Assert.IsTrue(classC.Equals(test)); Assert.IsTrue(classA.Equals(test.AProperty)); Assert.IsTrue(classB.Equals(test.AProperty.BProperty)); File.Delete("test_output.txt"); }
public void ShouldFindErrorMessageWithNestedIF_Else() { var engine = new Engine(); engine.For <ClassC>() .If(c => c.C > 1) .If(c => c.C > 2) .If(c => c.C > 5) .Setup(c => c.C) .WithMessage("C is not valid. >5") .MustEqual(18) .Else() .Setup(c => c.C) .WithMessage("C is not valid. <5") .MustEqual(1); var o = new ClassC() { C = 4 }; var r = new ValidationReport(engine); r.Validate(o); Assert.AreEqual("C is not valid. <5", r.GetErrorMessage(o, f => f.C)); }
static void Main(string[] args) { Checker check = new Checker(); ClassA classA = new ClassA(); ClassB classB = new ClassB(); ClassC classC = new ClassC(); ClassD classD = new ClassD(); MyStruct myStruct = new MyStruct(); object obj = myStruct; WriteLine("Analyzing ClassA type variable"); check.Check(classA); WriteLine("\nAnalyzing ClassB type variable"); check.Check(classB); WriteLine("\nAnalyzing ClassC type variable"); check.Check(classC); WriteLine("\nAnalyzing ClassD type variable"); check.Check(classD); WriteLine("\nAnalzying MyStruct type variable"); check.Check(myStruct); WriteLine("\nAnalyzing boxed myStruct type variable"); check.Check(obj); ReadKey(); }
public void TestMessageInheritedClass2() { //NOTE: Same as TestMessageInheritedClass, with order of registrations changed. var builder = new Fluent.FluentBuilder(); builder.For <ClassC>() .Setup(m => m.A) .WithMessage("ClassC validation for A"); builder.For <ClassB>() .Setup(m => m.A) .WithMessage("ClassB validation for A"); builder.For <ClassA>() .Setup(m => m.A) .MustBeLessThanOrEqualTo(1) .WithMessage("ClassA validation for A"); var engine = builder.Build(); var report = new ValidationReport(engine); var obj = new ClassC(2, 0, 0); report.Validate(obj); Assert.AreEqual("ClassC validation for A", report.GetErrorMessage(obj, o => o.A)); }
public void TestMessageInheritedClass4() { //NOTE: This test is the same as No.3, with definition of rules order changed. var builder = new Fluent.FluentBuilder(); builder.For <ClassA>() .Setup(m => m.A) .MustBeLessThanOrEqualTo(1) .WithMessage("ClassA validation for A"); builder.For <ClassB>() .Setup(m => m.A) .WithMessage("ClassB validation for A"); builder.For <ClassC>() .Setup(m => m.A) .WithMessage("ClassC validation for A.1") .MustBeLessThan(-1) .WithMessage("ClassC validation for A.2"); var engine = builder.Build(); var report = new ValidationReport(engine); var obj = new ClassC(2, 0, 0); report.Validate(obj); //m=>m.A will hit A.1 because the rules for base types are executed first. m=>m.A will fail because of rule defined on ClassA!. Assert.AreEqual("ClassC validation for A.1", report.GetErrorMessage(obj, o => o.A)); report = new ValidationReport(engine); obj = new ClassC(1, 0, 0); engine.Validate(obj, report, ValidationReportDepth.FieldShortCircuit); //m=>m.A will hit A.2 because the rules for base types are fine. m=>m.A will fail because of rule defined on ClassC!. Assert.AreEqual("ClassC validation for A.2", report.GetErrorMessage(obj, o => o.A)); }
public void TestMessageInheritedClass3() { var builder = new Fluent.FluentBuilder(); builder.For <ClassA>() .Setup(m => m.A) .MustBeLessThanOrEqualTo(1) .WithMessage("ClassA validation for A"); builder.For <ClassB>() .Setup(m => m.A) .WithMessage("ClassB validation for A"); builder.For <ClassC>() .Setup(m => m.A) .WithMessage("ClassC validation for A.1") .MustBeLessThan(-1) .WithMessage("ClassC validation for A.2"); var engine = builder.Build(); var report = new ValidationReport(engine); var obj = new ClassC(2, 0, 0); report.Validate(obj); //m=>m.A will hit A.1 because the rules for base types are executed first. m=>m.A will fail because of rule defined on ClassA!. Assert.AreEqual("ClassC validation for A.1", report.GetErrorMessage(obj, o => o.A)); obj = new ClassC(1, 0, 0); report.Validate(obj); //m=>m.A will hit A.2 because the rules for base types are fine. m=>m.A will fail because of rule defined on ClassC!. Assert.AreEqual("ClassC validation for A.2", report.GetErrorMessage(obj, o => o.A)); }
public void ClassASerializtionTest() { ClassA a2; using (FileStream writeStream = new FileStream("testf2.csv", FileMode.Create)) { myFormatter.Serialize(writeStream, a1); } using (FileStream readStream = new FileStream("testf2.csv", FileMode.Open)) { a2 = (ClassA)myFormatter.Deserialize(readStream); } ClassB b2 = a2.ClassB; ClassC c2 = a2.ClassC; Assert.AreEqual(a1.Name, a2.Name); Assert.AreEqual(b1.Name, b2.Name); Assert.AreEqual(c1.Name, c2.Name); Assert.AreEqual(a1.Num, a2.Num); Assert.AreEqual(b1.Num, b2.Num); Assert.AreEqual(c1.Num, c2.Num); Assert.AreEqual(a1.Date, a2.Date); Assert.AreEqual(b1.Date, b2.Date); Assert.AreEqual(c1.Date, c2.Date); Assert.AreSame(b2.ClassA, a2); Assert.AreSame(b2.ClassC, c2); Assert.AreSame(c2.ClassA, a2); Assert.AreSame(c2.ClassB, b2); }
static void Main(string[] args) { Checker check = new Checker(); ClassA try1 = new ClassA(); ClassB try2 = new ClassB(); ClassC try3 = new ClassC(); ClassD try4 = new ClassD(); MyStruct try5 = new MyStruct(); object try6 = try5; Console.WriteLine("Analyzing ClassA type variable:"); // Анализ переменной типа ClassA check.Check(try1); Console.WriteLine("\nAnalyzing ClassB type variable:"); // Анализ переменной типа ClassB check.Check(try2); Console.WriteLine("\nAnalyzing ClassC type variable:"); // Анализ переменной типа ClassC check.Check(try3); Console.WriteLine("\nAnalyzing ClassD type variable:"); // Анализ переменной типа ClassD check.Check(try4); Console.WriteLine("\nAnalyzing MyStruct type variable:"); // Анализ переменной типа MyStruct check.Check(try5); Console.WriteLine("\nAnalyzing boxed MyStruct type variable:"); // Анализ упакованной check.Check(try6); Console.ReadKey(); }
public void ClassADeserializationATest() { ClassA classA = new ClassA(1.2f, new DateTime(1997, 1, 1, 0, 0, 0), "TestA", null); ClassB classB = new ClassB(2.2f, new DateTime(1997, 2, 1, 0, 0, 0), "testB", null); ClassC classC = new ClassC(3.2f, new DateTime(1997, 3, 1, 0, 0, 0), "testC", null); classA.ClassBProperty = classB; classB.ClassCProperty = classC; classC.ClassAProperty = classA; using (FileStream s = new FileStream("test.txt", FileMode.Create)) { IFormatter f = new OwnFormatter(); f.Serialize(s, classA); } using (FileStream s = new FileStream("test.txt", FileMode.Open)) { IFormatter f = new OwnFormatter(); ClassA testClass = (ClassA)f.Deserialize(s); Assert.IsTrue(testClass.ClassBProperty.ClassCProperty.ClassAProperty == testClass); } File.Delete("test.txt"); }
//ISA stands for inherits i.e. A ISA B static void Main(string[] args) { // Call the defalut constructor // theChecker is the name of the instance // The check() method is not static, it must be referenced by instance name Checker theChecker = new Checker(); // Created a new instance of the checker class that takes an object as an argument ClassA a = new ClassA(); // New instances (objects) of each class/ structure ClassB b = new ClassB(); ClassC c = new ClassC(); ClassD d = new ClassD(); MyStruct theStructure = new MyStruct(); //Structs cannot inherit from other structs or classes, it can implement an interface object o = theStructure; // Boxing - Initialize a variable type object with the value (the value is now stored in heap) // Static methods do not have to be instatiated3 Console.WriteLine("Analyzing ClassA type variable:"); Console.WriteLine($"{theChecker.check(a)} \n"); //The object "theChecker" is able to use the check method that takes an object as an argument Console.WriteLine("Analyzing ClassB type variable:"); Console.WriteLine($"{theChecker.check(b)} \n"); Console.WriteLine("Analyzing ClassC type variable:"); Console.WriteLine($"{theChecker.check(c)} \n"); Console.WriteLine("Analyzing ClassD type variable:"); Console.WriteLine($"{theChecker.check(d)} \n"); Console.WriteLine("Analyzing MyStruct type variable:"); Console.WriteLine($"{theChecker.check(theStructure)} \n"); Console.WriteLine("Analyzing boxed MyStruct type variable:"); Console.WriteLine($"{theChecker.check(o)} \n"); }
public void TestClassA() { DataContext data = new DataContext(); DataContext data2 = new DataContext(); ClassA ca1 = new ClassA("klasaAnazwa", 5.2F, true, DateTime.ParseExact("2019.12.12", "yyyy.MM.dd", CultureInfo.CurrentCulture), null); ClassB cb1 = new ClassB("klasaBnazwa", 6.5F, true, DateTime.ParseExact("2019.12.11", "yyyy.MM.dd", CultureInfo.CurrentCulture), null); ClassC cc1 = new ClassC("klasaCnazwa", 7.35F, false, DateTime.ParseExact("2019.12.10", "yyyy.MM.dd", CultureInfo.CurrentCulture), ca1); ca1.classB = cb1; cb1.classC = cc1; //serializacja String filename = "serialize.csv"; File.WriteAllText(filename, string.Empty); FormatterCSV fromatterCSV = new FormatterCSV(); fromatterCSV.Binder = new KnownTypesBinder(); fromatterCSV.objectIDGenerator = new ObjectIDGenerator(); fromatterCSV.Serialize(ca1); //deserializacja fromatterCSV.Binder = new KnownTypesBinder(); fromatterCSV.objectIDGenerator = new ObjectIDGenerator(); Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read); Dictionary <long, object> list = (Dictionary <long, object>)fromatterCSV.Deserialize(stream); Assert.AreEqual(ca1.ToString(), list[1].ToString()); Assert.AreEqual(cb1.ToString(), list[2].ToString()); Assert.AreEqual(cc1.ToString(), list[3].ToString()); }
public ClassB() { ClassA a = new ClassA(); ClassC c = new ClassC(); c.setValue(ref a.Property); // CS0206 }
public void PreserveReferencesTestForClassC() { ClassA classA = new ClassA(new DateTime(1997, 1, 1, 0, 0, 0), 1.2m, "TestA", null); ClassB classB = new ClassB(new DateTime(1997, 2, 1, 0, 0, 0), 2.2m, "testB", null); ClassC classC = new ClassC(new DateTime(1997, 3, 1, 0, 0, 0), 3.2m, "testC", null); classA.ClassBProperty = classB; classB.ClassCProperty = classC; classC.ClassAProperty = classA; CustomFormatter formatter = new CustomFormatter(); using (Stream stream = File.Open("test.txt", FileMode.Create, FileAccess.ReadWrite)) { formatter.Serialize(stream, classC); } ClassC classCDuplicate; using (Stream stream = File.Open("test.txt", FileMode.Open, FileAccess.Read)) { classCDuplicate = (ClassC)formatter.Deserialize(stream); } Assert.AreSame(classCDuplicate.ClassAProperty.ClassBProperty.ClassCProperty, classCDuplicate); }
public void execute() { ClassA a = new ClassA(); ClassB b = new ClassB(); ClassC<ClassA> ca = new ClassC<ClassA>(); ca.result(test); }
public void execute() { ClassC<ClassB> ba = new ClassC<ClassB>(); ClassA a = ba.ToString(); }
public void execute() { ClassC<ClassA> ba = new ClassC<ClassA>(); ba.ToString(); }
public void TestEncodeWithEnforceHeirarchyOrderEnabled() { var testClass = new ClassC { FieldA = 1, FieldB = 2, FieldC = 3, PropertyA = 4, PropertyB = 5, PropertyC = 6 }; var json = JSON.Dump(testClass, EncodeOptions.NoTypeHints | EncodeOptions.IncludePublicProperties | EncodeOptions.EnforceHierarchyOrder); Assert.AreEqual("{\"FieldA\":1,\"FieldB\":2,\"FieldC\":3,\"PropertyA\":4,\"PropertyB\":5,\"PropertyC\":6}", json); }
public CustomSerializerTests() { classA = new ClassA("Anna", "Kowalska", 24, 160.5); classB = new ClassB("Jan", "Kowalski", 54, 180.5); classC = new ClassC("Hermenegilda", "Nowak", 66, 157.5); classA.B = classB; classB.C = classC; classC.A = classA; }
public void execute() { ClassA a = new ClassA(); ClassB b = new ClassB(); ClassC<ClassA> ca = new ClassC<ClassA>(); }
public void execute() { ClassC<ClassB> ba = new ClassC<ClassB>(); ClassA a = ba.result(); }
public void ShouldInheritRules_2() { ClassC c = new ClassC() { ParamA = 999, ParamB = 999, ParamC = 999 }; Assert.IsFalse(_re.Validate(c), "Expected 'c' to be invalid because inherited ParamA is not valid."); }
public void execute() { ClassA a = new ClassA(); ClassC<ClassA> ba = new ClassC<ClassA>(); a = ba.result(a); }
public void ClassDXml() { SimplTypesScope.EnableGraphSerialization(); ClassC classC = new ClassC(); ClassD test = new ClassD(new ClassA(classC), new ClassB(classC)); SimplTypesScope tScope = SimplTypesScope.Get("classD", typeof (ClassA), typeof (ClassB), typeof (ClassC), typeof (ClassD), typeof (ClassX)); TestMethods.TestSimplObject(test, tScope, Format.Xml); SimplTypesScope.DisableGraphSerialization(); }
public void TestMessageInheritedClass4() { //NOTE: This test is the same as No.3, with definition of rules order changed. var builder = new Fluent.FluentBuilder(); builder.For<ClassA>() .Setup(m => m.A) .MustBeLessThanOrEqualTo(1) .WithMessage("ClassA validation for A"); builder.For<ClassB>() .Setup(m => m.A) .WithMessage("ClassB validation for A"); builder.For<ClassC>() .Setup(m => m.A) .WithMessage("ClassC validation for A.1") .MustBeLessThan(-1) .WithMessage("ClassC validation for A.2"); var engine = builder.Build(); var report = new ValidationReport(engine); var obj = new ClassC(2, 0, 0); report.Validate(obj); //m=>m.A will hit A.1 because the rules for base types are executed first. m=>m.A will fail because of rule defined on ClassA!. Assert.AreEqual("ClassC validation for A.1", report.GetErrorMessage(obj, o => o.A)); report = new ValidationReport(engine); obj = new ClassC(1, 0, 0); engine.Validate(obj, report, ValidationReportDepth.FieldShortCircuit); //m=>m.A will hit A.2 because the rules for base types are fine. m=>m.A will fail because of rule defined on ClassC!. Assert.AreEqual("ClassC validation for A.2", report.GetErrorMessage(obj, o => o.A)); }
public void ShouldFindErrorMessageWithNestedIF() { var builder = new Fluent.FluentBuilder(); builder.For<ClassC>() .If(c => c.C > 10) .If(c => c.C > 11) .If(c => c.C > 12) .Setup(c => c.C) .WithMessage("C is not valid. >12") .MustBeBetween(10, 15); var engine = builder.Build(); var o = new ClassC() { C = 20 }; var r = new ValidationReport(engine); r.Validate(o); Assert.AreEqual("C is not valid. >12", r.GetErrorMessage(o, f => f.C)); }
public ClassA(ClassC pClassC) { x = 1; y = 2; classC = pClassC; }
public void ShouldFindErrorMessageWithNestedIF_Else() { var builder = new Fluent.FluentBuilder(); builder.For<ClassC>() .If(c => c.C > 1) .If(c => c.C > 2) .If(c => c.C > 5) .Setup(c => c.C) .WithMessage("C is not valid. >5") .MustEqual(18) .Else() .Setup(c => c.C) .WithMessage("C is not valid. <5") .MustEqual(1); var engine = builder.Build(); var o = new ClassC() { C = 4 }; var r = new ValidationReport(engine); r.Validate(o); Assert.AreEqual("C is not valid. <5", r.GetErrorMessage(o, f => f.C)); }
public ClassB(ClassC dd) { logger.Info("Hi there B"); }
public void TestMessageInheritedClass3() { var builder = new Fluent.FluentBuilder(); builder.For<ClassA>() .Setup(m => m.A) .MustBeLessThanOrEqualTo(1) .WithMessage("ClassA validation for A"); builder.For<ClassB>() .Setup(m => m.A) .WithMessage("ClassB validation for A"); builder.For<ClassC>() .Setup(m => m.A) .WithMessage("ClassC validation for A.1") .MustBeLessThan(-1) .WithMessage("ClassC validation for A.2"); var engine = builder.Build(); var report = new ValidationReport(engine); var obj = new ClassC(2, 0, 0); report.Validate(obj); //m=>m.A will hit A.1 because the rules for base types are executed first. m=>m.A will fail because of rule defined on ClassA!. Assert.AreEqual("ClassC validation for A.1", report.GetErrorMessage(obj, o => o.A)); obj = new ClassC(1, 0, 0); report.Validate(obj); //m=>m.A will hit A.2 because the rules for base types are fine. m=>m.A will fail because of rule defined on ClassC!. Assert.AreEqual("ClassC validation for A.2", report.GetErrorMessage(obj, o => o.A)); }
public void TestMessageInheritedClass2() { //NOTE: Same as TestMessageInheritedClass, with order of registrations changed. var builder = new Fluent.FluentBuilder(); builder.For<ClassC>() .Setup(m => m.A) .WithMessage("ClassC validation for A"); builder.For<ClassB>() .Setup(m => m.A) .WithMessage("ClassB validation for A"); builder.For<ClassA>() .Setup(m => m.A) .MustBeLessThanOrEqualTo(1) .WithMessage("ClassA validation for A"); var engine = builder.Build(); var report = new ValidationReport(engine); var obj = new ClassC(2, 0, 0); report.Validate(obj); Assert.AreEqual("ClassC validation for A", report.GetErrorMessage(obj, o => o.A)); }
public void ShouldInheritRules_2() { ClassC c = new ClassC() { ParamA = 999, ParamB = 999, ParamC=999 }; Assert.IsFalse(_re.Validate(c), "Expected 'c' to be invalid because inherited ParamA is not valid."); }