Beispiel #1
0
        public void Compare_Object_With_Dictionary_Property()
        {
            var comparer = SutEngine.Get <HasDictionary>();
            var oldModel = new HasDictionary
            {
                Names = new Dictionary <string, string>
                {
                    { "fr", "Salut" },
                    { "en", "Hi" }
                }
            };
            var newModel = new HasDictionary
            {
                Names = new Dictionary <string, string>
                {
                    { "en", "Hello" },
                    { "es", "Hola" }
                }
            };

            var changes = comparer(oldModel, newModel);

            Assert.AreEqual(changes.Count(), 3);
            Assert.IsNotNull(changes.Single(x => x.Name == "Names.fr" && (string)x.OldValue == "Salut"));
            Assert.IsNotNull(changes.Single(x => x.Name == "Names.es" && (string)x.NewValue == "Hola"));
            Assert.IsNotNull(changes.Single(x => x.Name == "Names.en" && (string)x.OldValue == "Hi" && (string)x.NewValue == "Hello"));
        }
Beispiel #2
0
        public void Benchmark_Nested_Model()
        {
            var oldModel = new NestedModel
            {
                Id    = 1,
                Child = new ChildModel
                {
                    Id         = 2,
                    Name       = "Child",
                    GrandChild = new GrandChildModel
                    {
                        Id    = 3,
                        Name  = "GrandChild",
                        Value = 100,
                    }
                }
            };
            var newModel = new NestedModel
            {
                Id    = 1,
                Child = new ChildModel
                {
                    Id         = 2,
                    Name       = "Child 2",
                    GrandChild = new GrandChildModel
                    {
                        Id    = 4,
                        Name  = "GrandChild 2",
                        Value = 200,
                    }
                }
            };

            var sw = new Stopwatch();

            sw.Start();
            var comparer = SutEngine.Get <NestedModel>();

            sw.Stop();
            var compilation = sw.ElapsedMilliseconds;

            sw.Reset();

            sw.Start();
            var numIterations = 100000;

            for (var i = 0; i < numIterations; i++)
            {
                var updates = comparer(oldModel, newModel);
            }
            sw.Stop();

            var benchmark = sw.ElapsedMilliseconds;

            Console.WriteLine($"Compilation took {compilation} ms.");
            Console.WriteLine($"{numIterations} iterations took {benchmark} ms.");
            Assert.IsTrue(benchmark < 500);
        }
Beispiel #3
0
        public void Benchmark_Simple_Model()
        {
            var oldModel = new SimpleModel
            {
                Id       = 1,
                Check    = true,
                Name     = "Name",
                Value    = 1.23m,
                Date     = new DateTime(2015, 01, 01, 12, 50, 30),
                Time     = new TimeSpan(5, 4, 3),
                State    = State.Inactive,
                Nullable = null,
            };

            var newModel = new SimpleModel
            {
                Id       = 1,
                Check    = false,
                Name     = "Name?",
                Value    = 10.23m,
                Date     = new DateTime(2015, 01, 02, 12, 50, 30),
                Time     = new TimeSpan(5, 4, 1),
                State    = State.Active,
                Nullable = true,
            };

            var sw = new Stopwatch();

            sw.Start();
            var comparer = SutEngine.Get <SimpleModel>();

            sw.Stop();
            var compilation = sw.ElapsedMilliseconds;

            sw.Reset();

            sw.Start();
            var numIterations = 100000;

            for (var i = 0; i < numIterations; i++)
            {
                var updates = comparer(oldModel, newModel);
            }
            sw.Stop();

            var benchmark = sw.ElapsedMilliseconds;

            Console.WriteLine($"Compilation took {compilation} ms.");
            Console.WriteLine($"{numIterations} iterations took {benchmark} ms.");
            Assert.IsTrue(benchmark < 500);
        }
Beispiel #4
0
        public void Compile_Async()
        {
            Assert.IsFalse(SutEngine.IsTypeConfigured(typeof(SimpleModel)));

            SutEngine.Configure <SimpleModel>()
            .Compile.Async();

            Assert.IsTrue(SutEngine.IsTypeConfigured(typeof(SimpleModel)));
            Assert.IsFalse(SutEngine.IsTypeCompiled(typeof(SimpleModel)));

            var comparer = SutEngine.Get <SimpleModel>();

            Assert.IsTrue(SutEngine.IsTypeConfigured(typeof(SimpleModel)));
            Assert.IsTrue(SutEngine.IsTypeCompiled(typeof(SimpleModel)));
        }
Beispiel #5
0
        public void Compare_Nestted_Objects()
        {
            var comparer = SutEngine.Get <NestedModel>();
            var oldModel = new NestedModel
            {
                Id    = 1,
                Child = new ChildModel
                {
                    Id         = 2,
                    Name       = "Child",
                    GrandChild = new GrandChildModel
                    {
                        Id    = 3,
                        Name  = "GrandChild",
                        Value = 100,
                    }
                }
            };
            var newModel = new NestedModel
            {
                Id    = 1,
                Child = new ChildModel
                {
                    Id         = 2,
                    Name       = "Child 2",
                    GrandChild = new GrandChildModel
                    {
                        Id    = 4,
                        Name  = "GrandChild 2",
                        Value = 200,
                    }
                }
            };

            var changes = comparer(oldModel, newModel);

            Assert.AreEqual(changes.Count(), 4);
            Assert.IsNotNull(changes.Single(x => x.Name == "Child.Name" && (string)x.OldValue == "Child" && (string)x.NewValue == "Child 2"));
            Assert.IsNotNull(changes.Single(x => x.Name == "Child.GrandChild.Name" && (string)x.OldValue == "GrandChild" && (string)x.NewValue == "GrandChild 2"));
            Assert.IsNotNull(changes.Single(x => x.Name == "Child.GrandChild.Id" && (long)x.OldValue == 3 && (long)x.NewValue == 4));
            Assert.IsNotNull(changes.Single(x => x.Name == "Child.GrandChild.Value" && (int)x.OldValue == 100 && (int)x.NewValue == 200));
        }
Beispiel #6
0
        public void Compare_Object_With_List_Property()
        {
            var comparer = SutEngine.Get <HasList>();
            var oldModel = new HasList
            {
                Ids = new List <int> {
                    1, 2, 3, 4, 5
                }
            };
            var newModel = new HasList
            {
                Ids = new List <int> {
                    1, 3, 4, 5, 6
                }
            };
            var changes = comparer(oldModel, newModel);

            Assert.AreEqual(changes.Count(), 2);
            Assert.IsNotNull(changes.Single(x => x.Name == "Ids" && x.OldValue is int && (int)x.OldValue == 2));
            Assert.IsNotNull(changes.Single(x => x.Name == "Ids" && x.NewValue is int && (int)x.NewValue == 6));
        }
Beispiel #7
0
        public void Compare_Simple_Model()
        {
            var comparer = SutEngine.Get <SimpleModel>();
            var oldModel = new SimpleModel
            {
                Id       = 1,
                Check    = true,
                Name     = "Name",
                Value    = 1.23m,
                Date     = new DateTime(2015, 01, 01, 12, 50, 30),
                Time     = new TimeSpan(5, 4, 3),
                State    = State.Inactive,
                Nullable = null,
            };

            var newModel = new SimpleModel
            {
                Id       = 1,
                Check    = false,
                Name     = "Name?",
                Value    = 10.23m,
                Date     = new DateTime(2015, 01, 02, 12, 50, 30),
                Time     = new TimeSpan(5, 4, 1),
                State    = State.Active,
                Nullable = true,
            };

            var changes = comparer(oldModel, newModel);

            Assert.AreEqual(changes.Count(), 7);
            Assert.IsNotNull(changes.Single(x => x.Name == "Check" && (bool)x.OldValue == true && (bool)x.NewValue == false));
            Assert.IsNotNull(changes.Single(x => x.Name == "Name" && (string)x.OldValue == "Name" && (string)x.NewValue == "Name?"));
            Assert.IsNotNull(changes.Single(x => x.Name == "Value" && (decimal)x.OldValue == 1.23m && (decimal)x.NewValue == 10.23m));
            Assert.IsNotNull(changes.Single(x => x.Name == "Date" && (DateTime)x.OldValue != (DateTime)x.NewValue));
            Assert.IsNotNull(changes.Single(x => x.Name == "Time" && (TimeSpan)x.OldValue != (TimeSpan)x.NewValue));
            Assert.IsNotNull(changes.Single(x => x.Name == "State" && (State)x.OldValue != (State)x.NewValue));
            Assert.IsNotNull(changes.Single(x => x.Name == "Nullable" && (bool?)x.OldValue == null && (bool?)x.NewValue == true));
        }