public async Task HandleAsync_GivenReturnId_ReturnShouldBeRetrieved() { var message = new SubmitReturn(Guid.NewGuid()); var @return = GetReturn(); A.CallTo(() => genericDataAccess.GetById <Return>(message.ReturnId)).Returns(@return); await handler.HandleAsync(message); A.CallTo(() => genericDataAccess.GetById <Return>(message.ReturnId)).MustHaveHappened(Repeated.Exactly.Once); }
public async Task HandleAsync_GivenReturn_StatusShouldBeUpdated(bool nilReturn) { var message = new SubmitReturn(Guid.NewGuid(), nilReturn); var @return = A.Fake <Return>(); var userId = Guid.NewGuid(); A.CallTo(() => @return.ReturnStatus).Returns(Domain.AatfReturn.ReturnStatus.Created); A.CallTo(() => genericDataAccess.GetById <Return>(message.ReturnId)).Returns(@return); A.CallTo(() => userContext.UserId).Returns(userId); await handler.HandleAsync(message); A.CallTo(() => @return.UpdateSubmitted(userId.ToString(), nilReturn)).MustHaveHappened(Repeated.Exactly.Once) .Then(A.CallTo(() => weeeContext.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once)); }
public async Task HandleAsync_GivenReturnThatIsAlreadySubmitted_StatusUpdateMustNotHaveHappened() { var message = new SubmitReturn(Guid.NewGuid()); var @return = A.Dummy <Return>(); var userId = Guid.NewGuid(); A.CallTo(() => @return.ReturnStatus).Returns(Domain.AatfReturn.ReturnStatus.Submitted); A.CallTo(() => genericDataAccess.GetById <Return>(message.ReturnId)).Returns(@return); A.CallTo(() => userContext.UserId).Returns(userId); await handler.HandleAsync(message); A.CallTo(() => @return.UpdateSubmitted(userId.ToString(), A <bool> ._)).MustNotHaveHappened(); A.CallTo(() => weeeContext.SaveChangesAsync()).MustNotHaveHappened(); }
public async Task HandleAsync_GivenReturnIsAatf_AatfsRecordsShouldBeAddedAgainstReturn() { var message = new SubmitReturn(Guid.NewGuid(), false); var @return = GetReturn(); @return.ReturnStatus = ReturnStatus.Created; var userId = Guid.NewGuid(); var aatfs = new List <Aatf>() { fixture.Build <Aatf>().Create() }; A.CallTo(() => genericDataAccess.GetById <Return>(message.ReturnId)).Returns(@return); A.CallTo(() => userContext.UserId).Returns(userId); A.CallTo(() => fetchAatfDataAccess.FetchAatfByReturnQuarterWindow(@return)).Returns(aatfs); await handler.HandleAsync(message); A.CallTo(() => genericDataAccess.AddMany <ReturnAatf>(A <IEnumerable <ReturnAatf> > .That.Matches(a => a.ElementAt(0).Return.Equals(@return) && a.ElementAt(0).Aatf.Equals(aatfs.ElementAt(0))))).MustHaveHappened() .Then(A.CallTo(() => weeeContext.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once)); }