예제 #1
0
        public void Run_Given_ClassWithChildClassesAndConcurrencyIssues_With_InitialisingAddingToChildEnumerableProperty_Should_ReturnReportWithIssue()
        {
            var instance = new ClassWithChildClassesAndConcurrencyIssues(new ChildClass(0, "zero", new { First = 0 }), new[]
            {
                new ChildClass(1, "one", new { First = 1 }),
                new ChildClass(2, "two", new { First = 2 })
            });

            var finder = new ConcurrencyChecker(instance);

            var report = finder.Run(5,
                                    () =>
            {
                instance.ChildEnumerableProp = new List <ChildClass>();
                instance.ChildEnumerableProp.Add(new ChildClass(99, "ninety nine", new { First = 99 }));
            },
                                    () =>
            {
                instance.ChildEnumerableProp = new List <ChildClass>();
                instance.ChildEnumerableProp.AddRange(new[]
                                                      { new ChildClass(100, "hundred", new { First = 100 }), new ChildClass(100, "hundred", new { First = 100 }) });
            });

            Console.WriteLine(report);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassesAndConcurrencyIssues->ChildEnumerableProp: Reference and actual number of value changes does not match."));
        }
예제 #2
0
        public void Run_Given_ClassWithChildClassesAndConcurrencyIssues_With_ChangePropertyOnChildArray_Should_ReturnReportWithIssue()
        {
            var instance =
                new ClassWithChildClassesAndConcurrencyIssues(new ChildClass(0, "zero", new { First = 0 }), null)
            {
                ChildEnumerableProp = new List <ChildClass>
                {
                    new ChildClass(1, "one", new { First = 1 }),
                    new ChildClass(2, "two", new { First = 2 })
                }
            };


            var finder = new ConcurrencyChecker(instance);

            instance.ChildProp = new ChildClass(3, "three", new { First = 3 });

            var report = finder.Run(20, () => { instance.ChildEnumerableProp[0].IntegerProp = 5; },
                                    () => { instance.ChildEnumerableProp[0].IntegerProp = 100; });

            Console.WriteLine(report);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassesAndConcurrencyIssues->ChildEnumerableProp[0]->IntegerProp: Reference and actual number of value changes does not match."));
        }
예제 #3
0
        public void Run_Given_ClassWithChildClassesAndConcurrencyIssues_With_ChangeMultiplePropertyOnMultipleChildArray_And_FullReportAsFalse_Should_ReturnReportWithIssue()
        {
            var instance =
                new ClassWithChildClassesAndConcurrencyIssues(new ChildClass(0, "zero", new { First = 0 }), null)
            {
                ChildEnumerableProp = new List <ChildClass>
                {
                    new ChildClass(1, "one", new { First = 1 }),
                    new ChildClass(2, "two", new { First = 2 })
                }
            };


            var finder = new ConcurrencyChecker(instance);

            instance.ChildProp = new ChildClass(3, "three", new { First = 3 });

            var report = finder.Run(20,
                                    () =>
            {
                instance.ChildEnumerableProp[0].IntegerProp = 5;
                instance.ChildEnumerableProp[0].StringProp  = "Five";
                instance.ChildEnumerableProp[0].ObjectProp  = new { First = 5 };
                instance.ChildEnumerableProp[1].IntegerProp = 6;
                instance.ChildEnumerableProp[1].StringProp  = "Six";
                instance.ChildEnumerableProp[1].ObjectProp  = new { First = 6 };
            },
                                    () =>
            {
                instance.ChildEnumerableProp[0].IntegerProp = 100;
                instance.ChildEnumerableProp[0].StringProp  = "Hundred";
                instance.ChildEnumerableProp[0].ObjectProp  = new { First = 100 };
                instance.ChildEnumerableProp[1].IntegerProp = 80;
                instance.ChildEnumerableProp[1].StringProp  = "Eighty";
                instance.ChildEnumerableProp[1].ObjectProp  = new { First = 80 };
            });

            Console.WriteLine(report);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassesAndConcurrencyIssues->ChildEnumerableProp[0]->IntegerProp: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassesAndConcurrencyIssues->ChildEnumerableProp[0]->StringProp: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassesAndConcurrencyIssues->ChildEnumerableProp[0]->ObjectProp: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassesAndConcurrencyIssues->ChildEnumerableProp[1]->IntegerProp: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassesAndConcurrencyIssues->ChildEnumerableProp[1]->StringProp: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassesAndConcurrencyIssues->ChildEnumerableProp[1]->ObjectProp: Reference and actual number of value changes does not match."));
        }
예제 #4
0
        public void Run_Given_ClassWithChildClassesAndConcurrencyIssues_With_ClassFieldWithIssue_Should_ReturnReportWithIssue()
        {
            var instance = new ClassWithChildClassesAndConcurrencyIssues(new ChildClass(0, "zero", new { First = 0 }), new[]
            {
                new ChildClass(1, "one", new { First = 1 }),
                new ChildClass(2, "two", new { First = 2 })
            });

            var finder = new ConcurrencyChecker(instance);

            var report = finder.Run(5, () => instance.SetChildField(new ChildClass(99, "ninety nine", new { First = 99 })),
                                    () => instance.SetChildField(new ChildClass(100, "hundred", new { First = 100 })));

            Console.WriteLine(report);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassesAndConcurrencyIssues->_childField: Reference and actual number of value changes does not match."));
        }
예제 #5
0
        public void Run_Given_ClassWithChildClassesAndConcurrencyIssues_With_ChangePropertyOnChildArray_AndIgnoreMember_Should_ReturnReportWithIssue()
        {
            var instance =
                new ClassWithChildClassesAndConcurrencyIssues(new ChildClass(0, "zero", new { First = 0 }), null)
            {
                ChildEnumerableProp = new List <ChildClass>
                {
                    new ChildClass(1, "one", new { First = 1 }),
                    new ChildClass(2, "two", new { First = 2 })
                }
            };

            var finder = new ConcurrencyChecker(instance, "ClassWithChildClassesAndConcurrencyIssues->ChildEnumerableProp[0]->IntegerProp");

            instance.ChildProp = new ChildClass(3, "three", new { First = 3 });

            var report = finder.Run(20, () => { instance.ChildEnumerableProp[0].IntegerProp = 5; },
                                    () => { instance.ChildEnumerableProp[0].IntegerProp = 100; });

            Console.WriteLine(report);

            Assert.IsNull(report);
        }