public bool EditBill(HoaDon billToEdit) { if (!ValidateBill(billToEdit)) { return(false); } // Database logic try { _billrepository.EditBill(billToEdit); } catch { return(false); } return(true); }
/// <summary> /// Edits a bill. /// </summary> /// <param name="request">The request.</param> /// <returns>The response object.</returns> public async Task <EditBillResponse> EditBill(EditBillRequest request) { return(await Orchestrate(async delegate { var dataModel = assembler.NewBillDataModel(request.Bill); var model = await repository.EditBill(dataModel); return assembler.NewEditBillResponse(model, request.RequestReference); }, request)); }
public void SetUp() { userId = Guid.NewGuid(); expenditureId = Guid.NewGuid(); validData = new List <BillDataModel>(); invalidDeleteBillRequest = new DeleteBillRequest(); invalidEditBillRequest = new EditBillRequest(); invalidGetBillsForUserForMonthRequest = new GetBillsForUserForMonthRequest(); invalidGetBillsForUserRequest = new GetBillsForUserRequest(); invalidGetBillRequest = new GetBillRequest(); invalidAddBillRequest = new AddBillRequest(); validBillDataModel = new BillDataModel { Amount = 1, Category = new CategoryDataModel { CreationTime = DateTime.Now, Id = Guid.NewGuid(), Name = "TEST" }, CreationTime = DateTime.Now, CategoryId = Guid.NewGuid(), Id = Guid.NewGuid(), UserId = Guid.NewGuid() }; expenditureProxy = new BillProxy { Amount = 1.0, Category = new CategoryProxy { Id = Guid.NewGuid(), Name = "TEST" }, CategoryId = Guid.NewGuid(), Id = Guid.NewGuid(), UserId = Guid.NewGuid() }; validDeleteBillRequest = new DeleteBillRequest { BillId = Guid.NewGuid(), Username = "******" }; validGetBillsForUserForMonthRequest = new GetBillsForUserForMonthRequest { MonthNumber = 1, UserId = userId, Username = "******" }; validAddBillRequest = new AddBillRequest { Bill = expenditureProxy, Username = "******" }; validGetBillsForUserRequest = new GetBillsForUserRequest { UserId = userId, Username = "******" }; validGetBillRequest = new GetBillRequest { BillId = expenditureId, Username = "******" }; validEditBillRequest = new EditBillRequest { Bill = expenditureProxy, Username = "******" }; validGetBillsForUserResponse = new GetBillsForUserResponse { Bills = new List <BillProxy> { expenditureProxy } }; validGetBillResponse = new GetBillResponse { Bill = expenditureProxy }; validAddBillResponse = new AddBillResponse { Bill = expenditureProxy }; validEditBillResponse = new EditBillResponse { Bill = expenditureProxy }; validDeleteBillResponse = new DeleteBillResponse { DeleteSuccess = true }; validGetBillsForUserForMonthResponse = new GetBillsForUserForMonthResponse { Data = new List <KeyValuePair <DateTime, double> > { new KeyValuePair <DateTime, double>(DateTime.Now, 1.0) } }; assembler = Substitute.For <IBillAssembler>(); repository = Substitute.For <IBillRepository>(); dataTransformer = Substitute.For <IBillDataTransformer>(); repository.AddBill(validBillDataModel).Returns(validBillDataModel); repository.AddBill(null).Throws(new Exception("TEST")); repository.DeleteBill(validDeleteBillRequest.BillId).Returns(true); repository.DeleteBill(invalidDeleteBillRequest.BillId).Throws(new Exception("TEST")); repository.EditBill(validBillDataModel).Returns(validBillDataModel); repository.EditBill(null).Throws(new Exception("TEST")); repository.GetBill(expenditureId).Returns(validBillDataModel); repository.GetBill(Guid.Empty).Throws(new Exception("TEST")); repository.GetBillsForUser(validGetBillsForUserRequest.UserId) .Returns(new List <BillDataModel> { validBillDataModel }); repository.GetBillsForUser(Guid.Empty).Throws(new Exception("TEST")); dataTransformer.GetOutgoingBillsForMonth(Arg.Any <int>(), Arg.Any <List <BillDataModel> >()) .Returns( new List <KeyValuePair <DateTime, double> > { new KeyValuePair <DateTime, double>(DateTime.Now, 1.0) }); dataTransformer.GetBillCategoryChartData(Arg.Any <List <BillDataModel> >()) .Returns(new List <KeyValuePair <string, int> > { new KeyValuePair <string, int>() }); assembler.NewAddBillResponse(validBillDataModel, validAddBillRequest.RequestReference) .Returns(validAddBillResponse); assembler.NewDeleteBillResponse(true, validDeleteBillRequest.BillId) .Returns(validDeleteBillResponse); assembler.NewEditBillResponse( validBillDataModel, validEditBillRequest.RequestReference) .Returns(validEditBillResponse); assembler.NewBillDataModel(expenditureProxy).Returns(validBillDataModel); assembler.NewGetBillsForUserForMonthResponse( Arg.Any <List <KeyValuePair <DateTime, double> > >(), validGetBillsForUserForMonthRequest.RequestReference) .Returns(validGetBillsForUserForMonthResponse); assembler.NewGetBillsForUserResponse( Arg.Any <List <BillDataModel> >(), validGetBillsForUserRequest.RequestReference) .Returns(validGetBillsForUserResponse); assembler.NewDeleteBillResponse(true, validDeleteBillRequest.RequestReference) .Returns(validDeleteBillResponse); assembler.NewGetBillResponse(validBillDataModel, validGetBillRequest.RequestReference) .Returns(validGetBillResponse); 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 BillOrchestrator(assembler, repository, dataTransformer, errorHelper); }