private IVisitor GetVisitor <TRootType>() { var walker = TypeWalker <TRootType> .Create(); _walkerActions.ForEach(x => x(walker)); return(walker.Build(Depth, UsePropertyGuard ? new PropertyGuard() : null, SupportsCloning)); }
public void TypeWalker_StressTest_ComplexCircularReference_Build() { //Arrange var watch = new Stopwatch(); //Act watch.Start(); var visitor1 = TypeWalker <Document> .Create().ForProperty <DateTime>((x, m) => DateTime.Now).Build(10, new PropertyGuard(), false); watch.Stop(); //Assert Assert.IsTrue(watch.ElapsedMilliseconds <= 1000); }
public void TypeWalker_StressTest_ComplexCircularReference_Visit() { //Arrange var watch = new Stopwatch(); var visitor = TypeWalker <Document> .Create().ForProperty <DateTime>((x, m) => DateTime.Now.AddYears(10)).Build(10, new PropertyGuard(), false); var values = new HashSet <PropertyValue>(); var document = GetComplexSample(); //Act watch.Start(); visitor.Visit(document, depth: 10, guard: new InstanceGuard(), values: values); watch.Stop(); //Assert Assert.IsTrue(values.Count == 100 && values.All(x => ((DateTime)x.NewValue).Year == DateTime.Now.Year + 10)); }
public void TypeWalker_StressTest_SuppressedHierarchy_Visit() { //Arrange var visitor = TypeWalker <SuppressedHierarchy> .Create().ForProperty <DateTime>((x, m) => DateTime.Now.AddYears(10)).Build(10, new PropertyGuard()); var hierarchy = new Faker <SuppressedHierarchy>().StrictMode(false) .CustomInstantiator(x => SuppressedHierarchy.Build(6)) .Generate(); var values = new HashSet <PropertyValue>(); //Act visitor.Visit(hierarchy, depth: 10, guard: new InstanceGuard(), values: values); //Assert Assert.AreEqual(3, values.Count); }
public void TypeWalker_Visit_SimpleDict() { var bla = new Bla { Blas = new Dictionary <int, Bla1> { { 1, new Bla1 { Test = "t1" } }, { 2, new Bla1 { Test = "t2" } } } }; var visitor = TypeWalker <Bla> .Create().ForProperty <Bla1, string>(b1 => b1.Test, (v, m) => "visited").Build(1); visitor.Visit(bla, null, 1); Assert.IsTrue(bla.Blas[1].Test == "visited" && bla.Blas[2].Test == "visited"); }
public void TestInitialize() { _visitor = TypeWalker <Parent> .Create() .ForProperty <Parent, int>(p => p.TestInt, (x, m) => x * x) .ForProperty <Parent, string>(p => p.TestString, (x, m) => x + x + m) .ForProperty <Child, DateTime>(p => p.TestDate1, (x, m) => x.AddYears(10)) .ForProperty <CommonType>((x, m) => new CommonType { CommonString = "..." }) .ForProperty <ClassLevel1, string>(p => p.SomeString, (x, m) => "visited").Build(); _sample = new Parent { //level 0 TestString = "aaa", TestInt = 10, TestDate = DateTime.Now, CommonType1 = new CommonType { CommonString = "brlj" }, Child = new Child { //level1 TestString1 = "aaa1", TestInt1 = 10, TestDate1 = DateTime.Now, CommonType1 = new CommonType { CommonString = "njanja" }, ChildLevel1 = new ChildLevel1 { //level2 ChildLevel2 = new ChildLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } } } }, //level0 CollectionChild = new CollectionChild() { //level0 TestList = new List <ClassLevel1> { //level1 new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" }, new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" } }, //level0 TestCollection = new HashSet <ClassLevel1>(new[] { //level1 new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" }, new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" } }), //level0 TestIList = new List <ClassLevel1> { //level1 new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" }, new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" } }, //level0 TestICollection = new HashSet <ClassLevel1>(new[] { //level1 new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" }, new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" } }), //level0 TestArray = new ClassLevel1[] { //level1 new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" }, new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" } } }, //level0 DictionaryChild = new DictionaryChild() { //level0 TestDict = new Dictionary <int, ClassLevel1>() { { //level1 1, new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" } } , { //level1 2, new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" } } }, //level0 TestIDict = new Dictionary <int, ClassLevel1>() { { //level1 1, new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" } } , { //level1 2, new ClassLevel1 { //level2 ClassLevel2 = new ClassLevel2 { TestCommonType = new CommonType { CommonString = "njunjnu" } }, SomeString = "njenje" } } } } }; _sample.Child.Parent = _sample; _blueprint = new Parent(); _values = new HashSet <PropertyValue>(); }