/// <summary> /// Builds and sends a request to add a bill to the database. /// </summary> /// <param name="model">The model.</param> /// <param name="username">The username.</param> /// <returns> /// The response object. /// </returns> public async Task <OrchestratorResponseWrapper <BillViewModel> > AddBill(BillViewModel model, string username) { var response = new OrchestratorResponseWrapper <BillViewModel>(); try { var request = assembler.NewAddBillRequest(model, username); var apiResponse = await dataAccess.AddBill(request); if (!apiResponse.Success) { response.AddErrors(apiResponse.Errors); return(response); } response.AddWarnings(apiResponse.Warnings); response.Model = assembler.NewBillViewModel(apiResponse); } catch (Exception ex) { var err = ErrorHelper.Create(ex, username, GetType(), "AddBill"); response.AddError(err); } return(response); }
public void NewAddBillRequest_NullParams_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(delegate { assembler.NewAddBillRequest(null, validUsername); }); Assert.Throws <ArgumentNullException>(delegate { assembler.NewAddBillRequest(validBillViewModel, null); }); }
public void SetUp() { validViewModel = new BillViewModel { Amount = 10, Category = "TEST", Id = Guid.NewGuid(), Name = "TEST", ReoccurringPeriod = TimePeriod.Daily, StartDate = DateTime.Now, UserId = Guid.NewGuid() }; validBillProxy = new BillProxy { Amount = 10, Category = new CategoryProxy { Id = Guid.NewGuid(), Name = "TEST" }, CategoryId = Guid.NewGuid(), Id = Guid.NewGuid(), Name = "TEST", ReoccurringPeriod = 1, StartDate = DateTime.Now, UserId = Guid.NewGuid() }; validManageBillsViewModel = new ManageBillsViewModel(); validDeleteBillRequest = new DeleteBillRequest { BillId = validBillProxy.Id }; validDeleteBillResponse = new DeleteBillResponse { DeleteSuccess = true }; validAddBillRequest = new AddBillRequest { Bill = validBillProxy }; validAddBillResponse = new AddBillResponse { Bill = validBillProxy }; validGetBillRequest = new GetBillRequest { BillId = validBillProxy.Id }; validGetBillResponse = new GetBillResponse { Bill = validBillProxy }; validGetBillsForUserRequest = new GetBillsForUserRequest { UserId = validBillProxy.Id }; validGetBillsForUserResponse = new GetBillsForUserResponse { Bills = new List <BillProxy> { validBillProxy } }; validEditBillRequest = new EditBillRequest { Bill = validBillProxy }; validEditBillResponse = new EditBillResponse { Bill = validBillProxy }; validGetBillsForUserForMonthRequest = new GetBillsForUserForMonthRequest { UserId = validBillProxy.Id }; validGetBillsForUserForMonthResponse = new GetBillsForUserForMonthResponse { Data = new List <KeyValuePair <DateTime, double> >() }; invalidBillViewModel = new BillViewModel { Id = Guid.NewGuid() }; invalidAddBillRequest = new AddBillRequest(); invalidAddBillResponse = new AddBillResponse { Errors = { new ResponseErrorWrapper() } }; invalidGetBillRequest = new GetBillRequest(); invalidGetBillResponse = new GetBillResponse { Errors = { new ResponseErrorWrapper() } }; invalidDeleteBillRequest = new DeleteBillRequest(); invalidDeleteBillResponse = new DeleteBillResponse { Errors = { new ResponseErrorWrapper() } }; invalidGetBillsForUserRequest = new GetBillsForUserRequest(); invalidGetBillsForUserResponse = new GetBillsForUserResponse { Errors = { new ResponseErrorWrapper() } }; invalidEditBillRequest = new EditBillRequest(); invalidEditBillResponse = new EditBillResponse { Errors = { new ResponseErrorWrapper() } }; invalidGetBillsForUserForMonthRequest = new GetBillsForUserForMonthRequest(); invalidGetBillsForUserForMonthResponse = new GetBillsForUserForMonthResponse { Errors = { new ResponseErrorWrapper() } }; assembler = Substitute.For <IBillAssembler>(); dataAccess = Substitute.For <IBillDataAccess>(); 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()); assembler.NewAddBillRequest(validViewModel, validUsername).Returns(validAddBillRequest); assembler.NewAddBillRequest(invalidBillViewModel, validUsername).Returns(invalidAddBillRequest); assembler.NewAddBillRequest(null, validUsername).Throws(new Exception("TEST EXCEPTION")); assembler.NewBillViewModel(validAddBillResponse).Returns(validViewModel); assembler.NewBillViewModel(validEditBillResponse).Returns(validViewModel); assembler.NewDeleteBillRequest(validViewModel.Id, validUsername).Returns(validDeleteBillRequest); assembler.NewDeleteBillRequest(invalidBillViewModel.Id, validUsername).Returns(invalidDeleteBillRequest); assembler.NewDeleteBillRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION")); assembler.NewGetBillRequest(validViewModel.Id, validUsername).Returns(validGetBillRequest); assembler.NewGetBillRequest(invalidBillViewModel.Id, validUsername).Returns(invalidGetBillRequest); assembler.NewGetBillRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION")); assembler.NewGetBillsForUserRequest(validViewModel.Id, validUsername).Returns(validGetBillsForUserRequest); assembler.NewGetBillsForUserRequest(invalidBillViewModel.Id, validUsername) .Returns(invalidGetBillsForUserRequest); assembler.NewGetBillsForUserRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION")); assembler.NewEditBillRequest(validViewModel, validUsername).Returns(validEditBillRequest); assembler.NewEditBillRequest(invalidBillViewModel, validUsername).Returns(invalidEditBillRequest); assembler.NewEditBillRequest(null, validUsername).Throws(new Exception("TEST EXCEPTION")); assembler.NewGetBillsForUserForMonthRequest(1, validViewModel.Id, validUsername) .Returns(validGetBillsForUserForMonthRequest); assembler.NewGetBillsForUserForMonthRequest(1, invalidBillViewModel.Id, validUsername) .Returns(invalidGetBillsForUserForMonthRequest); assembler.NewManageBillsViewModel(validGetBillsForUserResponse).Returns(validManageBillsViewModel); assembler.NewExportViewModel(ExportType.Json, Arg.Any <IList <BillProxy> >()).Throws(new Exception("TEST")); dataAccess.AddBill(validAddBillRequest).Returns(validAddBillResponse); dataAccess.AddBill(invalidAddBillRequest).Returns(invalidAddBillResponse); dataAccess.DeleteBill(validDeleteBillRequest).Returns(validDeleteBillResponse); dataAccess.DeleteBill(invalidDeleteBillRequest).Returns(invalidDeleteBillResponse); dataAccess.GetBill(validGetBillRequest).Returns(validGetBillResponse); dataAccess.GetBill(invalidGetBillRequest).Returns(invalidGetBillResponse); dataAccess.GetBillsForUser(validGetBillsForUserRequest).Returns(validGetBillsForUserResponse); dataAccess.GetBillsForUser(invalidGetBillsForUserRequest).Returns(invalidGetBillsForUserResponse); dataAccess.EditBill(validEditBillRequest).Returns(validEditBillResponse); dataAccess.EditBill(invalidEditBillRequest).Returns(invalidEditBillResponse); dataAccess.GetBillsForUserForMonth(validGetBillsForUserForMonthRequest) .Returns(validGetBillsForUserForMonthResponse); dataAccess.GetBillsForUserForMonth(invalidGetBillsForUserForMonthRequest) .Returns(invalidGetBillsForUserForMonthResponse); assembler.NewExportViewModel(ExportType.Csv, new List <BillProxy> { validBillProxy }) .Returns(new ExportViewModel()); orchestrator = new BillOrchestrator(assembler, dataAccess, errorHelper); }