public void CanUserAddReportTest() { 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 returnedMate = 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 returnedEmployer = EmployerDAO.Create(testEmployer); IReportDAO ReportDAO = new ReportDAO(_connection); Report reportTest = new Report(); reportTest.Id = 1; reportTest.Reason = Reasons.INADEQUATE_BEHAVIOUR; reportTest.ReportedId = 35; reportTest.ReporterId = 34; reportTest.Comment = "O trabalho que fez nao presta"; Report repReturned = ReportDAO.ReportUser(returnedEmployer.Id, returnedMate.Id, reportTest); Assert.Equal(reportTest.Id, repReturned.Id); Assert.Equal(reportTest.Reason, repReturned.Reason); Assert.Equal(reportTest.ReportedId, repReturned.ReportedId); Assert.Equal(reportTest.ReporterId, repReturned.ReporterId); Assert.Equal(reportTest.Comment, repReturned.Comment); _fixture.Dispose(); }
public ActionResult <ReportModel> ReportUser(int userId, ReportModel repModel) { int?userID = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity); // Caso o user seja nulo if (userID == null) { return(Unauthorized(new ErrorMessageModel("Utilizador não existe!"))); } // Caso o user dê report a si mesmo if (userID == userId) { return(BadRequest(new ErrorMessageModel("Nao se pode reportar a si proprio"))); } Report report = _mapper.Map <Report>(repModel); IReportDAO ReportDAO = new ReportDAO(_connection); ReportModel reportModel = _mapper.Map <ReportModel>(ReportDAO.ReportUser((int)userID, userId, report)); return(Ok(reportModel)); }