public void TestCase03_MethodAccess()
        {
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.RetrieveTestValue());

            /* Situation 1: TextValue is equal, therefore result of RetrieveTestValue is equal */
            TestDummy dummyA = new TestDummy {
                TextValue = "Hello World"
            };
            TestDummy dummyB = new TestDummy {
                TextValue = "Hello World"
            };
            bool result = comparer.Equals(dummyA, dummyB);

            Assert.IsTrue(result);

            /* Situation 2: TextValue is not equal, therefore result of RetrieveTestValue is not equal */
            dummyA = new TestDummy {
                TextValue = "Hello World"
            };
            dummyB = new TestDummy {
                TextValue = "hello world"
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsFalse(result);
        }
示例#2
0
        public void IndexOfWithStartIndexAndCount_ComparerWithMultipleMatchesAfterStartIndexWithinCount_IndexOfFirstMatchedInstanceIsReturned()
        {
            List <TestDummy> collection = new List <TestDummy> {
                new TestDummy {
                    TextValue = "DummyA"
                },
                new TestDummy {
                    TextValue = "DummyB"
                },
                new TestDummy {
                    TextValue = "DummyC"
                },
                new TestDummy {
                    TextValue = "DummyD"
                },
                new TestDummy {
                    TextValue = "DummyC"
                },
                new TestDummy {
                    TextValue = "DummyF"
                }
            };

            TestDummy selectionDummy = new TestDummy {
                TextValue = "DummyC"
            };

            /* The extension method will be able to find the object because it uses a custom comparer */
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.TextValue);
            int result = collection.IndexOf(selectionDummy, 1, 5, comparer);

            Assert.AreEqual(2, result);
        }
示例#3
0
        public void IndexOfWithStartIndex_ComparerWithMatchBeforeAndAfterStartIndex_IndexOfMatchedInstanceAfterStartIndexIsReturned()
        {
            List <TestDummy> collection = new List <TestDummy> {
                new TestDummy {
                    TextValue = "DummyA"
                },
                new TestDummy {
                    TextValue = "DummyB"
                },
                new TestDummy {
                    TextValue = "DummyC"
                },
                new TestDummy {
                    TextValue = "DummyB"
                },
                new TestDummy {
                    TextValue = "DummyE"
                }
            };

            TestDummy selectionDummy = new TestDummy {
                TextValue = "DummyB"
            };

            /* The extension method will be able to find the object because it uses a custom comparer */
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.TextValue);
            int result = collection.IndexOf(selectionDummy, 2, comparer);

            Assert.AreEqual(3, result);
        }
        public void TestCase04_TreeMethodAccess()
        {
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.Leaf.RetrieveTestValue());

            /* Situation 1: leaf.TextValue is equal, therefore result of leaf.RetrieveTestValue is equal */
            TestDummy dummyA = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "Goodmorning"
                }
            };
            TestDummy dummyB = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "Goodmorning"
                }
            };
            bool result = comparer.Equals(dummyA, dummyB);

            Assert.IsTrue(result);

            /* Situation 2: leaf.TextValue is not equal, therefore result of leaf.RetrieveTestValue is not equal */
            dummyA = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "Goodmorning"
                }
            };
            dummyB = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "goodMorning"
                }
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsFalse(result);
        }
示例#5
0
        public void IndexOfWithStartIndexAndCount_ComparerWithNoMatch_NoIndexIsReturned()
        {
            List <TestDummy> collection = new List <TestDummy> {
                new TestDummy {
                    TextValue = "DummyA"
                },
                new TestDummy {
                    TextValue = "DummyB"
                },
                new TestDummy {
                    TextValue = "DummyC"
                },
                new TestDummy {
                    TextValue = "DummyD"
                },
                new TestDummy {
                    TextValue = "DummyE"
                },
                new TestDummy {
                    TextValue = "DummyF"
                }
            };

            TestDummy selectionDummy = new TestDummy {
                TextValue = "DummyG"
            };

            /* The extension method will be able to find the object because it uses a custom comparer */
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.TextValue);
            int result = collection.IndexOf(selectionDummy, 0, 6, comparer);

            Assert.AreEqual(-1, result);
        }
示例#6
0
        public void ShouldConvertObjectToJObject()
        {
            var testDummy = TestDummy.CreateDummy();
            var jObject   = testDummy.ToJObject();

            jObject.Should().NotBeNull();
            ((int)jObject[nameof(TestDummy.Age)]).Should().Be(testDummy.Age);
        }
        public void TestCase01_DirectPropertyAccess()
        {
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.TextValue);

            /* Situation 1: TextValue is equal, numeric value is not equal */
            TestDummy dummyA = new TestDummy {
                TextValue = "Hello World", NumericValue = 5
            };
            TestDummy dummyB = new TestDummy {
                TextValue = "Hello World", NumericValue = 6
            };
            bool result = comparer.Equals(dummyA, dummyB);

            Assert.IsTrue(result);

            /* Situation 2: TextValue is not equal, numeric value is not equal */
            dummyA = new TestDummy {
                TextValue = "Hello World", NumericValue = 5
            };
            dummyB = new TestDummy {
                TextValue = "hello world", NumericValue = 6
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsFalse(result);

            /* Situation 3: First TextValue is null, numeric value is not equal */
            dummyA = new TestDummy {
                TextValue = null, NumericValue = 5
            };
            dummyB = new TestDummy {
                TextValue = "hello world", NumericValue = 6
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsFalse(result);

            /* Situation 4: Second TextValue is null, numeric value is not equal */
            dummyA = new TestDummy {
                TextValue = "Hello World", NumericValue = 5
            };
            dummyB = new TestDummy {
                TextValue = null, NumericValue = 6
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsFalse(result);

            /* Situation 5: Both TextValues are null, numeric value is not equal */
            dummyA = new TestDummy {
                TextValue = null, NumericValue = 5
            };
            dummyB = new TestDummy {
                TextValue = null, NumericValue = 6
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsTrue(result);
        }
示例#8
0
        public void ShouldCreateCloneOfComplexObject()
        {
            var testDummy  = TestDummy.CreateDummyWithChild();
            var cloneDummy = testDummy.Clone();

            cloneDummy.Should().NotBeNull();
            cloneDummy.Child.Should().NotBeNull();
            cloneDummy.Child.Friends.Should().NotBeEmpty();
            cloneDummy.Should().NotBeSameAs(testDummy);
            cloneDummy.Child.Should().NotBeSameAs(testDummy.Child);
        }
示例#9
0
            /// <summary>Creates and returns a clone of this instance.</summary>
            /// <returns>The copy of this instance.</returns>
            public object Clone()
            {
                TestDummy clone = this.MemberwiseClone() as TestDummy;

                if (this.Leaf != null)
                {
                    clone.Leaf = this.Leaf.Clone <SubTestDummy>();
                }

                return(clone);
            }
示例#10
0
        public void TestDummy_Object_To_Dictionary()
        {
            var obj = new TestDummy
            {
                Name = "Thomas",
                Age  = 42
            };

            var dict = obj.AsDictionary();

            dict["Name"].Should().Be("Thomas");
            dict["Age"].Should().Be(42);
        }
示例#11
0
            public async Task WhenContentIsJson_ThenReturnObj()
            {
                var dummy = new TestDummy {
                    Name = "John"
                };
                var json = JsonSerializer.Serialize(dummy);

                var sut = new StringContent(json);

                var result = await sut.ReadAsJsonAsync <TestDummy>();

                Assert.That(result.Name, Is.EqualTo(dummy.Name));
            }
示例#12
0
            public async Task WhenContentIsXml_ThenReturnObj()
            {
                var dummy = new TestDummy {
                    Name = "John"
                };

                var xml = XmlDataSerializer.Serialize(dummy);

                var sut = new StringContent(xml);

                var result = await sut.ReadAsXmlAsync <TestDummy>();

                Assert.That(result.Name, Is.EqualTo(dummy.Name));
            }
示例#13
0
        public void IndexOf_EmptyCollection_NoIndexIsReturned()
        {
            IList <TestDummy> collection = new List <TestDummy>();

            TestDummy selectionDummy = new TestDummy {
                TextValue = "DummyF"
            };

            /* The extension method will be able to find the object because it uses a custom comparer */
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.TextValue);
            int result = collection.IndexOf(selectionDummy, comparer);

            Assert.AreEqual(-1, result);
        }
示例#14
0
        public void Compare_FirstLevelPropertyDescending_LeftEqualToRight_ZeroIsReturned()
        {
            Comparer <TestDummy> testSubject = new Comparer <TestDummy>("TextValue", SortOrder.Descending);

            TestDummy dummyA = new TestDummy {
                TextValue = "Hello World", NumericValue = 5
            };
            TestDummy dummyB = new TestDummy {
                TextValue = "Hello World", NumericValue = 6
            };
            int result = testSubject.Compare(dummyA, dummyB);

            Assert.AreEqual(0, result);
        }
示例#15
0
        public void Compare_FirstLevelPropertyDescending_LeftGreaterThanRight_NegativeNumberIsReturned()
        {
            Comparer <TestDummy> testSubject = new Comparer <TestDummy>("TextValue", SortOrder.Descending);

            TestDummy dummyA = new TestDummy {
                TextValue = "def", NumericValue = 5
            };
            TestDummy dummyB = new TestDummy {
                TextValue = "abc", NumericValue = 6
            };
            int result = testSubject.Compare(dummyA, dummyB);

            Assert.AreNotEqual(0, result);
            Assert.IsTrue(result < 0);
        }
示例#16
0
        public void Remove_EmptyCollection_NoInstanceIsRemovedFromCollection()
        {
            ICollection <TestDummy> collection = new List <TestDummy>();

            TestDummy selectionDummy = new TestDummy {
                TextValue = "DummyF"
            };

            /* The extension method will be able to remove the object because it uses a custom comparer */
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.TextValue);
            bool result = collection.Remove(selectionDummy, comparer);

            Assert.IsFalse(result);
            Assert.AreEqual(0, collection.Count);
        }
示例#17
0
        public void IbanValidator_Attribute()
        {
            TestDummy dummy = new TestDummy {
                AccountNumber = "NL80INGB0007321304"
            };

            EntLib.ValidationResults results = EntLib.Validation.Validate(dummy, "ValidationTest");
            Assert.IsTrue(results.IsValid);

            dummy.AccountNumber = "NL80INgB0007321304";
            results             = EntLib.Validation.Validate(dummy, "ValidationTest");
            Assert.IsFalse(results.IsValid);

            dummy.AccountNumber = null;
            results             = EntLib.Validation.Validate(dummy, "ValidationTest");
            Assert.IsTrue(results.IsValid);
        }
示例#18
0
        public void ShouldCreateCloneOfSimpleObject()
        {
            var testDummy  = TestDummy.CreateDummy();
            var cloneDummy = testDummy.Clone();

            cloneDummy.Should().NotBeNull();
            cloneDummy.Should().NotBe(testDummy);

            cloneDummy.Age.Should().Be(testDummy.Age);
            cloneDummy.Name.Should().Be(testDummy.Name);
            cloneDummy.IsDummy.Should().Be(testDummy.IsDummy);
            cloneDummy.BirthDate.Should().Be(testDummy.BirthDate);

            //test is not a ref object
            cloneDummy.Age = 101;
            cloneDummy.Age.Should().NotBe(testDummy.Age);
        }
示例#19
0
        public void Compare_SecondLevelPropertyDescending_LeftEqualToRight_ZeroIsReturned()
        {
            Comparer <TestDummy> testSubject = new Comparer <TestDummy>("Leaf.TextValue", SortOrder.Descending);

            /* Situation 1: TextValue is equal */
            TestDummy dummyA = new TestDummy {
                Leaf = new SubTestDummy {
                    TextValue = "Hello World"
                }
            };
            TestDummy dummyB = new TestDummy {
                Leaf = new SubTestDummy {
                    TextValue = "Hello World"
                }
            };
            int result = testSubject.Compare(dummyA, dummyB);

            Assert.AreEqual(0, result);
        }
示例#20
0
        public void Compare_SecondLevelPropertyDescending_LeftLowerThanRight_PositiveNumberIsReturned()
        {
            Comparer <TestDummy> testSubject = new Comparer <TestDummy>("Leaf.TextValue", SortOrder.Descending);

            TestDummy dummyA = new TestDummy {
                Leaf = new SubTestDummy {
                    TextValue = "abc"
                }
            };
            TestDummy dummyB = new TestDummy {
                Leaf = new SubTestDummy {
                    TextValue = "def"
                }
            };
            int result = testSubject.Compare(dummyA, dummyB);

            Assert.AreNotEqual(0, result);
            Assert.IsTrue(result > 0);
        }
示例#21
0
        public void Compare_ThirdLevelPropertyAscending_LeftEqualToRight_ZeroIsReturned()
        {
            Comparer <TestDummy> testSubject = new Comparer <TestDummy>("Leaf.Leaf.TextValue");

            TestDummy dummyA = new TestDummy {
                Leaf = new SubTestDummy {
                    Leaf = new SubTestDummy {
                        TextValue = "Hello World"
                    }
                }
            };
            TestDummy dummyB = new TestDummy {
                Leaf = new SubTestDummy {
                    Leaf = new SubTestDummy {
                        TextValue = "Hello World"
                    }
                }
            };
            int result = testSubject.Compare(dummyA, dummyB);

            Assert.AreEqual(0, result);
        }
示例#22
0
        public void Remove_ComparerWithNoMatch_NoInstanceIsRemovedFromCollection()
        {
            TestDummy dummyA = new TestDummy {
                TextValue = "DummyA"
            };
            TestDummy dummyB = new TestDummy {
                TextValue = "DummyB"
            };
            TestDummy dummyC = new TestDummy {
                TextValue = "DummyC"
            };
            TestDummy dummyD = new TestDummy {
                TextValue = "DummyD"
            };
            TestDummy dummyE = new TestDummy {
                TextValue = "DummyE"
            };

            List <TestDummy> collection = new List <TestDummy> {
                dummyA, dummyB, dummyC, dummyD, dummyE
            };

            TestDummy selectionDummy = new TestDummy {
                TextValue = "DummyF"
            };

            /* The extension method will be able to remove the object because it uses a custom comparer */
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.TextValue);
            bool result = collection.Remove(selectionDummy, comparer);

            Assert.IsFalse(result);
            Assert.AreEqual(5, collection.Count);
            CollectionAssert.Contains(collection, dummyA);
            CollectionAssert.Contains(collection, dummyB);
            CollectionAssert.Contains(collection, dummyC);
            CollectionAssert.Contains(collection, dummyD);
            CollectionAssert.Contains(collection, dummyE);
        }
示例#23
0
        public void Remove_ComparerWithMultipleMatches_FirstMatchedInstanceIsRemovedFromCollection()
        {
            TestDummy dummyA = new TestDummy {
                TextValue = "DummyA"
            };
            TestDummy dummyB1 = new TestDummy {
                TextValue = "DummyB"
            };
            TestDummy dummyC = new TestDummy {
                TextValue = "DummyC"
            };
            TestDummy dummyD = new TestDummy {
                TextValue = "DummyD"
            };
            TestDummy dummyB2 = new TestDummy {
                TextValue = "DummyB"
            };

            List <TestDummy> collection = new List <TestDummy> {
                dummyA, dummyB1, dummyC, dummyD, dummyB2
            };

            TestDummy selectionDummy = new TestDummy {
                TextValue = "DummyB"
            };

            /* The extension method will be able to remove the object because it uses a custom comparer */
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.TextValue);
            bool result = collection.Remove(selectionDummy, comparer);

            Assert.IsTrue(result);
            Assert.AreEqual(4, collection.Count);
            CollectionAssert.Contains(collection, dummyA);
            CollectionAssert.DoesNotContain(collection, dummyB1);
            CollectionAssert.Contains(collection, dummyC);
            CollectionAssert.Contains(collection, dummyD);
            CollectionAssert.Contains(collection, dummyB2);
        }
示例#24
0
        public void IbanAttribute_Attribute()
        {
            TestDummy dummy = new TestDummy {
                AccountNumber = this.TestContext.DataRow["AccountNumber"].ToString()
            };
            ValidationContext       validationContext = new ValidationContext(dummy, null, null);
            List <ValidationResult> validationResults = new List <ValidationResult>();

            bool expected = Convert.ToBoolean(this.TestContext.DataRow["IsValid"]);

            bool result = Validator.TryValidateObject(dummy, validationContext, validationResults, true);

            Assert.AreEqual(expected, result, dummy.AccountNumber);
            if (expected)
            {
                Assert.AreEqual(0, validationResults.Count, dummy.AccountNumber);
            }
            else
            {
                Assert.AreEqual(1, validationResults.Count, dummy.AccountNumber);
                Assert.AreEqual("The property AccountNumber is not a valid IBAN account number.", validationResults[0].ErrorMessage);
            }
        }
示例#25
0
        public void Compare_ThirdLevelPropertyAscending_LeftLowerThanRight_NegativeNumberIsReturned()
        {
            Comparer <TestDummy> testSubject = new Comparer <TestDummy>("Leaf.Leaf.TextValue");

            TestDummy dummyA = new TestDummy {
                Leaf = new SubTestDummy {
                    Leaf = new SubTestDummy {
                        TextValue = "abc"
                    }
                }
            };
            TestDummy dummyB = new TestDummy {
                Leaf = new SubTestDummy {
                    Leaf = new SubTestDummy {
                        TextValue = "def"
                    }
                }
            };
            int result = testSubject.Compare(dummyA, dummyB);

            Assert.AreNotEqual(0, result);
            Assert.IsTrue(result < 0);
        }
        public void TestCase02_TreePropertyAccess()
        {
            LambdaEqualityComparer <TestDummy, string> comparer = new LambdaEqualityComparer <TestDummy, string>(td => td.Leaf.TextValue);

            /* Situation 1: TextValue is equal, leaf.TextValue is equal */
            TestDummy dummyA = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "Goodmorning"
                }
            };
            TestDummy dummyB = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "Goodmorning"
                }
            };
            bool result = comparer.Equals(dummyA, dummyB);

            Assert.IsTrue(result);

            /* Situation 2: TextValue is equal, leaf.TextValue is not equal */
            dummyA = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "Goodmorning"
                }
            };
            dummyB = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "goodMorning"
                }
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsFalse(result);

            /* Situation 3: TextValue is equal, first leaf.TextValue is null */
            dummyA = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = null
                }
            };
            dummyB = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "Goodmorning"
                }
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsFalse(result);

            /* Situation 4: TextValue is equal, second leaf.TextValue is null */
            dummyA = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = "Goodmorning"
                }
            };
            dummyB = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = null
                }
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsFalse(result);

            /* Situation 5: TextValue is equal, both leaf.TextValues are null */
            dummyA = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = null
                }
            };
            dummyB = new TestDummy {
                TextValue = "Hello World", Leaf = new SubTestDummy {
                    TextValue = null
                }
            };
            result = comparer.Equals(dummyA, dummyB);
            Assert.IsTrue(result);
        }
示例#27
0
 public void ShouldReturnTrueIfObjectIsNotNull()
 {
     TestDummy.CreateDummy().IsNotNull().Should().BeTrue();
 }
示例#28
0
 public void ShouldConvertObjectToJsonString()
 {
     TestDummy.CreateDummyWithChild().ToJson().Should().NotBeNullOrEmpty();
 }
示例#29
0
        public void ShouldReturnFalseIfObjectIsNull()
        {
            TestDummy testDummy = null;

            testDummy.IsNotNull().Should().BeFalse();
        }
示例#30
0
 public void ShouldSerializeToXml()
 {
     TestDummy.CreateDummy().SerializeToXml().Should().NotBeNullOrEmpty();
 }