예제 #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__ClassWithPropertyConcurrencyIssues_And_MultipleIgnoreMemberPath_Should_ReturnReportWithNoIssues()
        {
            var instance = new ClassWithPropertiesConcurrencyIssue();
            var finder   = new ConcurrencyChecker(instance, "ClassWithPropertiesConcurrencyIssue->AddressLine1", "ClassWithPropertiesConcurrencyIssue->AddressLine2");

            var report = finder.Run(4, () => instance.ChangeAddress("Ring Road", "Johannesburg"),
                                    () => instance.ChangeAddress("Justice Street", "Polokwane"));

            Console.WriteLine(report);

            Assert.IsNull(report);
        }
예제 #5
0
        public void Run_Given_ClassWithNoConcurrencyIssue_When_Calling_StaticMethod_Should_ReturnWithNoIssues()
        {
            var instance = new ClassWithNoConcurrencyIssues();
            var finder   = new ConcurrencyChecker(instance);

            var report = finder.Run(5, () => ClassWithNoConcurrencyIssues.DoSomeWorkAndReturnResponseStatic(),
                                    () => ClassWithNoConcurrencyIssues.DoSomeWorkAndReturnResponseStatic());

            Console.WriteLine(report);

            Assert.IsNull(report);
        }
        public void Run_Given_ClassWithMultipleConcurrencyIssuesAndUsingMoq_Should_ReturnReportWithIssues()
        {
            var instance = new Mock <ClassWithMultipleConcurrencyIssues>();
            var finder   = new ConcurrencyChecker(instance.Object);

            var report = finder.Run(5,
                                    () =>
            {
                instance.Object.ChangeNameAndSurnameTo("Jane", "");
                instance.Object.ChangeDob(new DateTime(1986, 2, 3));
                instance.Object.Age = 33;
            },
                                    () =>
            {
                instance.Object.ChangeNameAndSurnameTo("Some", "One");
                instance.Object.ChangeDob(new DateTime(1987, 2, 3));
                instance.Object.Age = 35;
            });

            Console.WriteLine(report);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.Contains(
                              "ClassWithMultipleConcurrencyIssues->_name: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithMultipleConcurrencyIssues->_name: Reference Value Changes: \n0: String = John\n1: String = Jane"));
            Assert.IsTrue(report.Contains(
                              "ClassWithMultipleConcurrencyIssues->_name: Actual Value Changes: \n0: String = John\n1: String = Jane\n2: String = Some"));
            Assert.IsTrue(report.Contains(
                              "ClassWithMultipleConcurrencyIssues->_surname: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithMultipleConcurrencyIssues->_surname: Reference Value Changes: \n0: String = Doe\n1: String = "));
            Assert.IsTrue(report.Contains(
                              "ClassWithMultipleConcurrencyIssues->_surname: Actual Value Changes: \n0: String = Doe\n1: String = \n2: String = One"));
            Assert.IsTrue(report.Contains(
                              "ClassWithMultipleConcurrencyIssues->_dob: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              $"ClassWithMultipleConcurrencyIssues->_dob: Reference Value Changes: \n0: DateTime = {new DateTime(1986, 1, 1)}\n1: DateTime = {new DateTime(1986, 2, 3)}"));
            Assert.IsTrue(report.Contains(
                              $"ClassWithMultipleConcurrencyIssues->_dob: Actual Value Changes: \n0: DateTime = {new DateTime(1986, 1, 1)}\n1: DateTime = {new DateTime(1986, 2, 3)}\n2: DateTime = {new DateTime(1987, 2, 3)}"));
            Assert.IsTrue(report.Contains(
                              "ClassWithMultipleConcurrencyIssues->Age: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains("ClassWithMultipleConcurrencyIssues->Age: Reference Value Changes: \n0: Int32 = 0\n1: Int32 = 33"));
            Assert.IsTrue(report.Contains(
                              "ClassWithMultipleConcurrencyIssues->Age: Actual Value Changes: \n0: Int32 = 0\n1: Int32 = 33\n2: Int32 = 35"));
        }
예제 #7
0
        public void Run_Given_ClassWithFieldConcurrencyIssue_Should_ReturnReportWithIssue()
        {
            var instance = new ClassWithFieldConcurrencyIssue();
            var finder   = new ConcurrencyChecker(instance);

            var report = finder.Run(10, () => instance.ChangeNameTo("Jane"), () => instance.ChangeNameTo("Peter"));

            Console.WriteLine(report);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.Contains(
                              "ClassWithFieldConcurrencyIssue->_name: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithFieldConcurrencyIssue->_name: Reference Value Changes: \n0: String = John\n1: String = Jane"));
            Assert.IsTrue(report.Contains(
                              "ClassWithFieldConcurrencyIssue->_name: Actual Value Changes: \n0: String = John\n1: String = Jane\n2: String = Peter"));
        }
예제 #8
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."));
        }
예제 #9
0
        public void Run_Given_ClassWithChildClassPropertyAndConcurrencyIssues_With_ChangePropertyOnChild_Should_ReturnReportWithIssue()
        {
            var instance = new ClassWithChildClassPropertyWithConcurrencyIssues();

            var finder = new ConcurrencyChecker(instance);

            instance.ChildProp = new ChildClass(1, "one", new { First = 1 });

            var report = finder.Run(20, () =>
            {
                instance.ChildProp.IntegerProp = 2;
                Thread.Sleep(0);
            }, () => { instance.ChildProp.IntegerProp = 3; });

            Console.WriteLine(report);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.Contains(
                              "ClassWithChildClassPropertyWithConcurrencyIssues->ChildProp->IntegerProp: Reference and actual number of value changes does not match."));
        }
예제 #10
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);
        }
        public void Run_Given_ClassUsingMoq_Should_ReturnReportWithIssues()
        {
            var instance = new Mock <ClassWithPropertiesConcurrencyIssue>();
            var finder   = new ConcurrencyChecker(instance.Object);

            var report = finder.Run(10, () => instance.Object.ChangeAddress("Ring Road", "Johannesburg"),
                                    () => instance.Object.ChangeAddress("Justice Street", "Polokwane"));

            Console.WriteLine(report);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.Contains(
                              "ClassWithPropertiesConcurrencyIssue->AddressLine1: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithPropertiesConcurrencyIssue->AddressLine1: Reference Value Changes: \n0: String = 111 Church Street\n1: String = Ring Road"));
            Assert.IsTrue(report.Contains(
                              "ClassWithPropertiesConcurrencyIssue->AddressLine1: Actual Value Changes: \n0: String = 111 Church Street\n1: String = Ring Road\n2: String = Justice Street"));
            Assert.IsTrue(report.Contains(
                              "ClassWithPropertiesConcurrencyIssue->AddressLine2: Reference and actual number of value changes does not match."));
            Assert.IsTrue(report.Contains(
                              "ClassWithPropertiesConcurrencyIssue->AddressLine2: Reference Value Changes: \n0: String = Pretoria\n1: String = Johannesburg"));
            Assert.IsTrue(report.Contains(
                              "ClassWithPropertiesConcurrencyIssue->AddressLine2: Actual Value Changes: \n0: String = Pretoria\n1: String = Johannesburg\n2: String = Polokwane"));
        }