public void OrBusinessSpec_Push_Success() { //arrange: first spec var firstSpecMock = new Mock <IBusinessSpec <object> >(); var settledMocks = new List <Mock>() { firstSpecMock }; var failResult = new BusinessSpecResult(isSatisfied: false, status: BusinessResultStatus.InvalidInputs); firstSpecMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return((BusinessSpecResult)failResult.Clone()); }) .Verifiable(); //arrange: second spec var secondSpecMock = new Mock <IBusinessSpec <object> >(); settledMocks.Add(secondSpecMock); secondSpecMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return((BusinessSpecResult)failResult.Clone()); }) .Verifiable(); //arrange: third spec var thirdSpecMock = new Mock <IBusinessSpec <object> >(); settledMocks.Add(thirdSpecMock); thirdSpecMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return(new BusinessSpecResult(isSatisfied: true, status: BusinessResultStatus.Success)); }) .Verifiable(); //arrange composed spec: var bo = new object(); var composedSpec = new OrBusinessSpec <object>(firstSpecMock.Object, secondSpecMock.Object); Assert.IsFalse(composedSpec.IsSatisfiedBy(bo).IsSatisfied); //act: composedSpec = composedSpec.Push(thirdSpecMock.Object); //assert: Assert.IsTrue(composedSpec.IsSatisfiedBy(bo).IsSatisfied); Mock.Verify(settledMocks.ToArray()); }
public void BusinessSpecResult_Clone_Success() { //arrange: var messages = new List <BusinessSpecMessage> { new BusinessSpecMessage(status: BusinessResultStatus.InternalError, message: "internal error") }; var result = new BusinessSpecResult(isSatisfied: false, messages: messages); //act: var cloned = (BusinessSpecResult)result.Clone(); //assert: var comparison = new CompareLogic(); Assert.IsFalse(result == cloned); Assert.IsTrue(comparison.Compare(result, cloned).AreEqual); }
public void AndBusiness_IsSatisfied_Success() { //arrange: first spec var firstMock = new Mock <IBusinessSpec <object> >(); var settledMocks = new List <Mock>() { firstMock }; var firstResult = new BusinessSpecResult ( isSatisfied: true, status: BusinessResultStatus.Success, messages: new BusinessSpecMessage[] { new BusinessSpecMessage ( status: BusinessResultStatus.Success, message: "info message" ) } ); firstMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return((BusinessSpecResult)firstResult.Clone()); }) .Verifiable(); //arrange: second spec var secondMock = new Mock <IBusinessSpec <object> >(); settledMocks.Add(secondMock); var secondResult = new BusinessSpecResult ( isSatisfied: false, messages: new BusinessSpecMessage[] { new BusinessSpecMessage ( status: BusinessResultStatus.InvalidInputs, message: "invalid input" ) } ); secondMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return((BusinessSpecResult)secondResult.Clone()); }) .Verifiable(); //arrange: expected result var expectedResult = new BusinessSpecResult ( isSatisfied: false, status: secondResult.Status, messages: firstResult.Messages.Concat(secondResult.Messages) ); //act: var spec = new AndBusinessSpec <object>(first: firstMock.Object, second: secondMock.Object); var result = spec.IsSatisfiedBy(new object()); //assert: var comparison = new CompareLogic(); Assert.IsTrue(comparison.Compare(expectedResult, result).AreEqual); Mock.Verify(settledMocks.ToArray()); }
public void AndBusiness_Push_Success() { //arrange: first spec var firstMock = new Mock <IBusinessSpec <object> >(); var settledMocks = new List <Mock>() { firstMock }; var successResult = new BusinessSpecResult(isSatisfied: true, status: BusinessResultStatus.Success); firstMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return((BusinessSpecResult)successResult.Clone()); }) .Verifiable(); //arrange: second spec var secondMock = new Mock <IBusinessSpec <object> >(); settledMocks.Add(secondMock); secondMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return((BusinessSpecResult)successResult.Clone()); }) .Verifiable(); //arrange: create spec var spec = new AndBusinessSpec <object>(first: firstMock.Object, second: secondMock.Object); var bo = new object(); Assert.IsTrue(spec.IsSatisfiedBy(bo).IsSatisfied); //arrange: third spec var thirdMock = new Mock <IBusinessSpec <object> >(); settledMocks.Add(thirdMock); var errorResult = new BusinessSpecResult ( isSatisfied: false, messages: new BusinessSpecMessage[] { new BusinessSpecMessage ( status: BusinessResultStatus.InvalidInputs, message: "invalid name" ) } ); thirdMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return((BusinessSpecResult)errorResult.Clone()); }) .Verifiable(); //act: var result = spec.Push(thirdMock.Object).IsSatisfiedBy(bo); //assert: Assert.IsFalse(result.IsSatisfied); Mock.VerifyAll(settledMocks.ToArray()); }
public void OrBusinessSpec_IsStatisfied_Should_Return_Invalid_Inputs_Result() { //arrange: first spec var firstSpecMock = new Mock <IBusinessSpec <object> >(); var settledMocks = new List <Mock>() { firstSpecMock }; var firstResult = new BusinessSpecResult ( isSatisfied: false, messages: new BusinessSpecMessage[] { new BusinessSpecMessage(status: BusinessResultStatus.InvalidInputs, message: "invalid inputs") } ); firstSpecMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return((BusinessSpecResult)firstResult.Clone()); }) .Verifiable(); //arrange: second spec var secondSpecMock = new Mock <IBusinessSpec <object> >(); settledMocks.Add(secondSpecMock); var secondResult = new BusinessSpecResult ( isSatisfied: false, messages: new BusinessSpecMessage[] { new BusinessSpecMessage(status: BusinessResultStatus.InternalError, message: "internal error") } ); secondSpecMock .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(() => { return((BusinessSpecResult)secondResult.Clone()); }) .Verifiable(); //arrange: var expectedResult = new BusinessSpecResult ( isSatisfied: false, status: BusinessResultStatus.InvalidInputs, messages: firstResult.Messages.Concat(secondResult.Messages) ); //act: var composedSpec = new OrBusinessSpec <object>(first: firstSpecMock.Object, second: secondSpecMock.Object); var result = composedSpec.IsSatisfiedBy(bo: new object()); //assert: var comparison = new CompareLogic(); Assert.IsTrue(comparison.Compare(expectedResult, result).AreEqual); Mock.Verify(settledMocks.ToArray()); }