public void ClassTracker_ChangedPublic()
        {
            var obj = new ValidTestObject();

            Tracker.Register(obj);

            obj.PublicField    = 10;
            obj.PublicProperty = 10;

            var changed = Tracker.CheckChanged(obj);

            Assert.IsTrue(changed.Any(x => x.name == "PublicField"), message: "Public field failed tracking");
            Assert.IsTrue(changed.Any(x => x.name == "PublicProperty"), message: "Public property failed tracking");

            Tracker.ResetTracker();
        }
Beispiel #2
0
        public static void DoExample()
        {
            Apple red_apple, green_apple;
            var   tracker = new ClassTracker <Apple>();

            // Create our apples
            green_apple = new Apple()
            {
                Color  = Color.Green,
                Weight = 10,
                Size   = new Size(50, 50)
            };
            red_apple = new Apple()
            {
                Color  = Color.Green,
                Weight = 10,
                Size   = new Size(50, 50)
            };

            // Register the state of red apple's marked members
            tracker.Register(red_apple);

            // Mutate our red_apple into a small red apple
            red_apple.Color  = Color.Red;
            red_apple.Weight = 1;
            red_apple.Size   = new Size(5, 5);

            // print state of the red apple
            Console.WriteLine($"Red Apple:\n\tColor - {red_apple.Color}\n\tWeight - {red_apple.Weight}\n\tSize - {red_apple.Size}");
            // print state of the green apple
            Console.WriteLine($"Green Apple:\n\tColor - {green_apple.Color}\n\tWeight - {green_apple.Weight}\n\tSize - {green_apple.Size}");

            Console.WriteLine("-------------------");

            Console.WriteLine("Whats changed in Red Apple...");
            foreach (var(name, _) in tracker.CheckChanged(red_apple))
            {
                Console.WriteLine(name);
            }

            Console.WriteLine("\nApplying the tracked state of the Red Apple to Green Apple...");
            // copy the tracked values over to green apple
            tracker.AssignTo(red_apple, green_apple);

            // print state of the red apple
            Console.WriteLine($"Red Apple:\n\tColor - {red_apple.Color}\n\tWeight - {red_apple.Weight}\n\tSize - {red_apple.Size}");
            // print state of the green apple
            Console.WriteLine($"Green Apple:\n\tColor - {green_apple.Color}\n\tWeight - {green_apple.Weight}\n\tSize - {green_apple.Size}");
        }