public void Not_TwoDifferentPropsOneShouldNotMatch_ShouldFindOne() { //ARRANGE var expectedId = 1; var notExpectedOtherId = 2; var expected = new TestClass(expectedId, 1); var list = new List <TestClass> { expected, new TestClass(1, 2), new TestClass(1, 2), new TestClass(1, 2), new TestClass(1, 2), }; var idSpec = new TestIdSpecification(expectedId); var otherIdSpec = new TestOtherIdSpecification(notExpectedOtherId); var notSpec = idSpec.Not(otherIdSpec); //ACT var result = list.Where(notSpec); //ASSERT result.Single().Should().BeSameAs(expected); }
public void And_TwoDifferentPropsShouldMatch_MatchFound() { //ARRANGE var expectedId = 1; var expectedOtherId = 1; var expected = new TestClass(expectedId, expectedOtherId); var list = new List <TestClass> { expected, new TestClass(1, 2), new TestClass(1, 3), new TestClass(1, 4), new TestClass(1, 5), }; var idSpec = new TestIdSpecification(expectedId); var otherIdSpec = new TestOtherIdSpecification(expectedOtherId); var andSpec = idSpec.And(otherIdSpec); //ACT var result = list.Where(andSpec); //ASSERT result.Single().Should().BeSameAs(expected); }
public void Or_Scenario_ExpectedBehavior() { //ARRANGE var expectedIdOne = 1; var expectedIdTwo = 2; var expectedOne = new TestClass(expectedIdOne, 0); var expectedTwo = new TestClass(expectedIdTwo, 0); var list = new List <TestClass> { new TestClass(5, 1), new TestClass(4, 2), new TestClass(3, 3), expectedTwo, expectedOne }; var idSpecOne = new TestIdSpecification(expectedIdOne); var idSpecTwo = new TestIdSpecification(expectedIdTwo); var orSpec = idSpecOne.Or(idSpecTwo); //ACT var result = list.Where(orSpec).ToList(); //ASSERT result.Should().HaveCount(2); result.Should().Contain(new[] { expectedOne, expectedTwo }); }
public void SingleSpecification_FindById_ShouldNotFindAnything() { //ARRANGE var list = new List <TestClass> { new TestClass(1, 1), new TestClass(2, 1), new TestClass(3, 1), new TestClass(4, 1), new TestClass(5, 1), }; var idSpec = new TestIdSpecification(6); //ACT var result = list.Where(idSpec); //ASSERT result.Should().BeEmpty(); }
public void SingleSpecification_FindById_ShouldFindSingleResult() { //ARRANGE var expected = new TestClass(1, 1); var list = new List <TestClass> { expected, new TestClass(2, 1), new TestClass(3, 1), new TestClass(4, 1), new TestClass(5, 1), }; var idSpec = new TestIdSpecification(1); //ACT var result = list.Where(idSpec); //ASSERT result.Single().Should().BeSameAs(expected); }
public void Not_TwoDifferentPropsOneShouldNotMatch_ShouldNotFindAny() { //ARRANGE var list = new List <TestClass> { new TestClass(1, 2), new TestClass(1, 2), new TestClass(1, 2), new TestClass(1, 2), new TestClass(1, 2), }; var idSpec = new TestIdSpecification(1); var otherIdSpec = new TestOtherIdSpecification(2); var notSpec = idSpec.Not(otherIdSpec); //ACT var result = list.Where(notSpec); //ASSERT result.Should().BeEmpty(); }
public void And_TwoDifferentPropsShouldMatch_NoMatchFound() { //ARRANGE var list = new List <TestClass> { new TestClass(1, 1), new TestClass(1, 2), new TestClass(1, 3), new TestClass(1, 4), new TestClass(1, 5), }; var idSpec = new TestIdSpecification(0); var otherIdSpec = new TestOtherIdSpecification(0); var andSpec = idSpec.And(otherIdSpec); //ACT var result = list.Where(andSpec); //ASSERT result.Should().BeEmpty(); }