public ActionResult <InvoiceModel> GetInvoice(int jobId) { try { int? userId = Helpers.ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity); PaymentDAO paymentDAO = new PaymentDAO(_connection); InvoiceModel invoice = _mapper.Map <InvoiceModel>(paymentDAO.GetInvoiceByID((int)userId, jobId)); return(Ok(invoice)); } catch (Exception ex) { return(UnprocessableEntity(new ErrorMessageModel(ex.Message))); } }
public void CanGetInvoiceByIDTest() { IMateDAO <Mate> MateDAO = new MateDAO(_connection); Mate testMate = new Mate(); testMate.FirstName = "Miguel"; testMate.LastName = "Dev"; testMate.UserName = "******"; testMate.Password = "******"; testMate.Email = "*****@*****.**"; testMate.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."; testMate.Address = "Figueiró"; testMate.Categories = new[] { Categories.CLEANING, Categories.PLUMBING }; testMate.Rank = Ranks.SUPER_MATE; testMate.Range = 20; Mate returned = MateDAO.Create(testMate); IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection); Employer testEmployer = new Employer(); testEmployer.FirstName = "Marcelo"; testEmployer.LastName = "Carvalho"; testEmployer.UserName = "******"; testEmployer.Password = "******"; testEmployer.Email = "*****@*****.**"; testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."; testEmployer.Address = "Lixa"; Employer returnedEmp = EmployerDAO.Create(testEmployer); IJobDAO jobPostDAO = new JobDAO(_connection); JobPost testPost = new JobPost(); testPost.Title = "Canalização Estourada"; testPost.Category = Categories.PLUMBING; testPost.ImagePath = "path/image"; testPost.Description = "Grande estouro nos canos da sanita"; testPost.Tradable = false; testPost.InitialPrice = 60.6; testPost.Address = "Rua sem fim"; testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY }; JobPost jobReturned = jobPostDAO.Create(returnedEmp.Id, testPost); DateTime date = new DateTime(2020, 01, 16); Job job = new Job(); job.Date = date; job.Mate = returned.Id; job.JobPost = jobReturned.Id; job.FinishedConfirmedByEmployer = false; job.FinishedConfirmedByMate = false; job.Employer = returnedEmp.Id; IWorkDAO workDAO = new WorkDAO(_connection); Job returnedJob = workDAO.Create(returnedEmp.Id, job); workDAO.MarkJobAsDone(returnedJob.Id, returnedEmp.Id); workDAO.MarkJobAsDone(returnedJob.Id, returned.Id); Invoice invoice = new Invoice(); invoice.Value = 60.6; invoice.PaymentType = Payment.MONEY; PaymentDAO paymentDAO = new PaymentDAO(_connection); paymentDAO.makePayment(invoice, returnedJob.Id, returnedEmp.Id); paymentDAO.confirmPayment(returnedJob.Id, returned.Id); Invoice result = paymentDAO.GetInvoiceByID(returnedEmp.Id, returnedJob.Id); Assert.Equal(invoice.Value, result.Value); Assert.Equal(invoice.PaymentType, result.PaymentType); Assert.True(result.ConfirmedPayment); _fixture.Dispose(); }