public void NewEditExpenditureResponse_ValidParams_ReturnsResponse() { var test = assembler.NewEditExpenditureResponse(validDataModel, validGuid); Assert.IsNotNull(test); Assert.IsInstanceOf <EditExpenditureResponse>(test); Assert.IsNotNull(test.Expenditure); }
/// <summary> /// Updates an expenditure in the database. /// </summary> /// <param name="request">The request.</param> /// <returns> /// The response object. /// </returns> public async Task <EditExpenditureResponse> EditExpenditure(EditExpenditureRequest request) { return(await Orchestrate(async delegate { var dataModel = assembler.NewExpenditureDataModel(request.Expenditure); var newDataModel = await repository.EditExpenditure(dataModel); return assembler.NewEditExpenditureResponse(newDataModel, request.RequestReference); }, request)); }
public void SetUp() { userId = Guid.NewGuid(); expenditureId = Guid.NewGuid(); validData = new List <ExpenditureDataModel>(); invalidDeleteExpenditureRequest = new DeleteExpenditureRequest(); invalidEditExpenditureRequest = new EditExpenditureRequest(); invalidGetExpenditureForUserForMonthRequest = new GetExpenditureForUserForMonthRequest(); invalidGetExpenditureForUserRequest = new GetExpenditureForUserRequest(); invalidGetExpenditureRequest = new GetExpenditureRequest(); invalidAddExpenditureRequest = new AddExpenditureRequest(); validExpenditureDataModel = new ExpenditureDataModel { Amount = 1, Category = new CategoryDataModel { CreationTime = DateTime.Now, Id = Guid.NewGuid(), Name = "TEST" }, CreationTime = DateTime.Now, CategoryId = Guid.NewGuid(), DateOccurred = DateTime.Now, Description = "TEST", Id = Guid.NewGuid(), UserId = Guid.NewGuid() }; expenditureProxy = new ExpenditureProxy { Amount = 1.0, Category = new CategoryProxy { Id = Guid.NewGuid(), Name = "TEST" }, CategoryId = Guid.NewGuid(), DateOccurred = DateTime.Now, Description = "TEST", Id = Guid.NewGuid(), UserId = Guid.NewGuid() }; validDeleteExpenditureRequest = new DeleteExpenditureRequest { ExpenditureId = Guid.NewGuid(), Username = "******" }; validGetExpenditureForUserForMonthRequest = new GetExpenditureForUserForMonthRequest { MonthNumber = 1, UserId = userId, Username = "******" }; validAddExpenditureRequest = new AddExpenditureRequest { Expenditure = expenditureProxy, Username = "******" }; validGetExpenditureForUserRequest = new GetExpenditureForUserRequest { UserId = userId, Username = "******" }; validGetExpenditureRequest = new GetExpenditureRequest { ExpenditureId = expenditureId, Username = "******" }; validEditExpenditureRequest = new EditExpenditureRequest { Expenditure = expenditureProxy, Username = "******" }; validGetExpenditureForUserResponse = new GetExpenditureForUserResponse { Expenditure = new List <ExpenditureProxy> { expenditureProxy } }; validGetExpenditureResponse = new GetExpenditureResponse { Expenditure = expenditureProxy }; validAddExpenditureResponse = new AddExpenditureResponse { Expenditure = expenditureProxy }; validEditExpenditureResponse = new EditExpenditureResponse { Expenditure = expenditureProxy }; validDeleteExpenditureResponse = new DeleteExpenditureResponse { DeleteSuccess = true }; validGetExpenditureForUserForMonthResponse = new GetExpenditureForUserForMonthResponse { Data = new List <ExpenditureProxy> { expenditureProxy } }; assembler = Substitute.For <IExpenditureAssembler>(); repository = Substitute.For <IExpenditureRepository>(); repository.AddExpenditure(validExpenditureDataModel).Returns(validExpenditureDataModel); repository.AddExpenditure(null).Throws(new Exception("TEST")); repository.DeleteExpenditure(validDeleteExpenditureRequest.ExpenditureId).Returns(true); repository.DeleteExpenditure(invalidDeleteExpenditureRequest.ExpenditureId).Throws(new Exception("TEST")); repository.EditExpenditure(validExpenditureDataModel).Returns(validExpenditureDataModel); repository.EditExpenditure(null).Throws(new Exception("TEST")); repository.GetExpenditure(expenditureId).Returns(validExpenditureDataModel); repository.GetExpenditure(Guid.Empty).Throws(new Exception("TEST")); repository.GetExpenditureForUser(validGetExpenditureForUserRequest.UserId) .Returns(new List <ExpenditureDataModel> { validExpenditureDataModel }); repository.GetExpenditureForUser(Guid.Empty).Throws(new Exception("TEST")); repository.GetExpenditureForUserForMonth(userId) .Returns(new List <ExpenditureDataModel> { validExpenditureDataModel }); repository.GetExpenditureForUserForMonth(Guid.Empty).Throws(new Exception("TEST")); assembler.NewAddExpenditureResponse(validExpenditureDataModel, validAddExpenditureRequest.RequestReference) .Returns(validAddExpenditureResponse); assembler.NewDeleteExpenditureResponse(true, validDeleteExpenditureRequest.ExpenditureId) .Returns(validDeleteExpenditureResponse); assembler.NewEditExpenditureResponse( validExpenditureDataModel, validEditExpenditureRequest.RequestReference) .Returns(validEditExpenditureResponse); assembler.NewExpenditureDataModel(expenditureProxy).Returns(validExpenditureDataModel); assembler.NewGetExpenditureForUserForMonthResponse( Arg.Any <List <ExpenditureDataModel> >(), validGetExpenditureForUserForMonthRequest.RequestReference) .Returns(validGetExpenditureForUserForMonthResponse); assembler.NewGetExpenditureForUserResponse( Arg.Any <List <ExpenditureDataModel> >(), validGetExpenditureForUserRequest.RequestReference) .Returns(validGetExpenditureForUserResponse); assembler.NewDeleteExpenditureResponse(true, validDeleteExpenditureRequest.RequestReference) .Returns(validDeleteExpenditureResponse); assembler.NewGetExpenditureResponse(validExpenditureDataModel, validGetExpenditureRequest.RequestReference) .Returns(validGetExpenditureResponse); errorHelper = Substitute.For <IErrorHelper>(); errorHelper.Create(Arg.Any <Exception>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>()) .Returns(new ResponseErrorWrapper()); errorHelper.Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>()) .Returns(new ResponseErrorWrapper()); orchestrator = new ExpenditureOrchestrator(repository, assembler, errorHelper); }