public void AddComplaint_CorrectArgs_Success(int _clientId, int _orderId, string _description) { DatabaseQueryProcessor.Erase(); Shared.FillTheDatabase(); var testSessionToken = SessionRepository.StartNewSession(_clientId); var addComplaintCommand = new AddComplaintCommand { sessionToken = testSessionToken, orderId = _orderId, description = _description }; var handler = new AddComplaintCommandHandler(); var result = (SuccessInfoDto)handler.Handle(addComplaintCommand); var receivedComplaint = DatabaseQueryProcessor.GetComplaint(_orderId); SessionRepository.RemoveSession(testSessionToken); DatabaseQueryProcessor.Erase(); Assert.AreEqual(receivedComplaint.description, _description); Assert.AreEqual(receivedComplaint.openDate, DateTime.Now.ToString("yyyy-MM-dd")); Assert.IsTrue(result.isSuccess); }
public IResult Handle(AddComplaintCommand command) { int clientId = SessionRepository.GetClientIdOfSession(command.sessionToken); if (clientId == -1) { throw new Exception(); } var order = DatabaseQueryProcessor.GetOrder(command.orderId); if (order == null) { throw new Exception(); } if (order.clientId != clientId) { throw new Exception(); } var foundComplaint = DatabaseQueryProcessor.GetComplaint(order.orderId); if (foundComplaint != null) { throw new Exception(); } DatabaseQueryProcessor.CreateNewComplaint( command.orderId, 0, command.description, DateTime.Now.ToString("yyyy-MM-dd"), false ); return(new SuccessInfoDto() { isSuccess = true }); }