예제 #1
0
        public MatchAnyResult GetResult()
        {
            bool isMatch = IsMatch();

            if (isMatch)
            {
                return(MatchAnyResult.CreateMatch());
            }

            string message = GetMessage();

            return(MatchAnyResult.CreateNoMatch(message));
        }
예제 #2
0
        public void MatchAny_MultiplePropertiesComparedWithConstant_ReturnsComparedPropertyNameWithActualAndExpectedValue()
        {
            // Arrange
            var data = new List <Data>
            {
                new() { Title = "MyTitle", Amount = 2 }
            };

            // Act
            MatchAnyResult matchAnyResult = data.MatchAny(d => d.Title == "MyTitle" && d.Amount == 1);

            // Assert
            Assert.IsFalse(matchAnyResult.IsMatch);
            Assert.AreEqual("Expected 'Amount' to be '1', actual '2'", matchAnyResult.Message);
        }
예제 #3
0
        public void MatchAny_SinglePropertyComparedWithConstant_ReturnsComparedPropertyNameWithActualAndExpectedValue()
        {
            // Arrange
            var data = new List <Data>
            {
                new() { Title = "OtherTitle", Amount = 1 }
            };

            // Act
            MatchAnyResult matchAnyResult = data.MatchAny(d => d.Title == "MyTitle");

            // Assert
            Assert.IsFalse(matchAnyResult.IsMatch);
            Assert.AreEqual("Expected 'Title' to be 'MyTitle', actual 'OtherTitle'", matchAnyResult.Message);
        }
예제 #4
0
        public void MatchAny_MultipleObjectsInCollectionOneMatching_ReturnsIsMatchTrueAndMessageIsEmptyString()
        {
            // Arrange
            var expected = new Data {
                Title = "MyTitle", Amount = 1
            };

            var data = new List <Data>
            {
                new() { Title = "MyTitle", Amount = 1 },
                new() { Title = "MyTitle", Amount = 2 }
            };

            // Act
            MatchAnyResult matchAnyResult = data.MatchAny(d => d.Title == expected.Title && d.Amount == expected.Amount);

            // Assert
            Assert.IsTrue(matchAnyResult.IsMatch);
            Assert.AreEqual(string.Empty, matchAnyResult.Message);
        }
예제 #5
0
        public void MatchAny_MultipleObjectsInCollectionNoneMatching_ReturnsObjectWithMostMatchingProperties()
        {
            // Arrange
            var expected = new Data {
                Title = "MyTitle", Amount = 1, Published = DateTime.Today
            };

            var data = new List <Data>
            {
                new() { Title = "OtherTitle", Amount = 2, Published = DateTime.Today.AddDays(1) }, // 0 matching properties
                new() { Title = "MyTitle", Amount = 2, Published = DateTime.Today.AddDays(1) },    // 1 matching property
                new() { Title = "MyTitle", Amount = 2, Published = DateTime.Today } // 2 matching properties
            };

            // Act
            MatchAnyResult matchAnyResult = data.MatchAny(d => d.Title == expected.Title && d.Amount == expected.Amount && d.Published == expected.Published);

            // Assert
            Assert.IsFalse(matchAnyResult.IsMatch);
            Assert.AreEqual("Expected 'Amount' to be '1', actual '2'", matchAnyResult.Message);
        }
    }