Exemplo n.º 1
0
        public IActionResult Post(NewTicketResponseDTO response)
        {
            TicketResponse createdResponse = mgr.AddTicketResponse(response.TicketNumber
                                                                   , response.ResponseText, response.IsClientResponse);

            if (createdResponse == null)
            {
                return(BadRequest("Er is iets misgelopen bij het registreren van het antwoord!"));
            }

            //return CreatedAtAction("Get", new { id = createdResponse.Id }, null);
            //return CreatedAtAction("Get", new { id = createdResponse.Id }, createdResponse); // -> serializing: circulaire referentie!!

            /* Oplossing 'DTO' */
            TicketResponseDTO responseData = new TicketResponseDTO()
            {
                Id                   = createdResponse.Id,
                Text                 = createdResponse.Text,
                Date                 = createdResponse.Date,
                IsClientResponse     = createdResponse.IsClientResponse,
                TicketNumberOfTicket = createdResponse.Ticket.TicketNumber
            };

            return(CreatedAtAction("Get", new { id = responseData.Id }, responseData));
        }
        public void AddTicketResponseToUnknownTicketThrowsArgumentException()
        {
            _repository = Substitute.For <ITicketRepository>();
            _mgr        = new TicketManager(_repository);

            Assert.Throws <KeyNotFoundException>(() => _mgr.AddTicketResponse(0, "Some response", false));
        }
Exemplo n.º 3
0
        public IHttpActionResult Post(NewTicketResponseDTO response)
        {
            TicketResponse createdResponse = mgr.AddTicketResponse(response.TicketNumber, response.ResponseText, response.IsClientResponse);

            if (createdResponse == null)
            {
                return(BadRequest("Er is iets misgelopen bij het registreren van het antwoord!"));
            }

            //// Circulaire referentie!! (TicketResponse <-> Ticket) -> can't be serialized!!
            //return CreatedAtRoute("DefaultApi",
            //                      new { Controller = "TicketResponse", id = createdResponse.Id },
            //                      createdResponse);

            // Gebruik DTO (Data Transfer Object)
            TicketResponseDTO responseData = new TicketResponseDTO()
            {
                Id                   = createdResponse.Id,
                Text                 = createdResponse.Text,
                Date                 = createdResponse.Date,
                IsClientResponse     = createdResponse.IsClientResponse,
                TicketNumberOfTicket = createdResponse.Ticket.TicketNumber
            };

            return(CreatedAtRoute("DefaultApi",
                                  new { Controller = "TicketResponse", id = responseData.Id },
                                  responseData));
        }
        public void AddTicketResponseWithInvalidResponseThrowsValidationException(string response)
        {
            _repository = Substitute.For <ITicketRepository>();
            _repository.ReadTicket(5).Returns(new Ticket());
            _mgr = new TicketManager(_repository);

            Assert.Throws <ValidationException>(() => _mgr.AddTicketResponse(5, response, true));
        }
Exemplo n.º 5
0
        private static void ActionAddResponseToTicket()
        {
            Console.Write("Ticketnummer: ");
            int ticketNumber = Int32.Parse(Console.ReadLine());

            Console.Write("Antwoord: ");
            string response = Console.ReadLine();

            mgr.AddTicketResponse(ticketNumber, response, false);
        }
Exemplo n.º 6
0
        private static void ActionAddResponseToTicket()
        {
            Write("Ticketnummer: ");
            var ticketNumber = int.Parse(ReadLine());

            Write("Antwoord: ");
            var response = ReadLine();

            mgr.AddTicketResponse(ticketNumber, response, false);
            // via WebAPI-service
            //srv.AddTicketResponse(ticketNumber, response, false);
        }
Exemplo n.º 7
0
        public TicketResponse AddResponse(NewTicketResponseDTO response)
        {
            TicketResponse createdResponse = mgr.AddTicketResponse(response.TicketNumber, response.ResponseText, response.IsClientResponse);

            TicketResponse responseData = new TicketResponse()
            {
                Id               = createdResponse.Id,
                Text             = createdResponse.Text,
                Date             = createdResponse.Date,
                IsClientResponse = createdResponse.IsClientResponse
            };

            return(responseData);
        }
        public void AddTicketResponseWithValidTicketResponseSetsTicketStateToAnsweredIfItWasNotAClientResponse()
        {
            Ticket t = new Ticket {
                State        = TicketState.Answered,
                Text         = "Some fake ticket",
                AccountId    = 23,
                TicketNumber = 1,
                DateOpened   = DateTime.Now
            };

            _repository = Substitute.For <ITicketRepository>();
            _repository.ReadTicket(1).Returns(t);
            _mgr = new TicketManager(_repository);

            _mgr.AddTicketResponse(1, "Valid response", false);

            Assert.Equal(TicketState.Answered, t.State);
        }
        public void AddTicketResponseWithValidTicketResponseCallsRepoMethodsCreateTicketResponseAndUpdateTicket()
        {
            Ticket t = new Ticket
            {
                State        = TicketState.Answered,
                Text         = "Some fake ticket",
                AccountId    = 23,
                TicketNumber = 1,
                DateOpened   = DateTime.Now
            };

            _repository = Substitute.For <ITicketRepository>();
            _repository.ReadTicket(1).Returns(t);
            _mgr = new TicketManager(_repository);

            _mgr.AddTicketResponse(1, "Valid response", false);

            _repository.Received(1).CreateTicketResponse(Arg.Any <TicketResponse>());
            _repository.Received(1).UpdateTicket(t);
        }
Exemplo n.º 10
0
        public IActionResult Post(NewTicketResponseDTO response)
        {
            var createdResponse =
                mgr.AddTicketResponse(response.TicketNumber, response.ResponseText, response.IsClientResponse);


            //// Circulaire referentie!! (TicketResponse <-> Ticket) -> can't be serialized!!
            //return CreatedAtRoute("DefaultApi",
            //                      new { Controller = "TicketResponse", id = createdResponse.Id },
            //                      createdResponse);

            // Gebruik DTO (Data Transfer Object)
            var responseData = new TicketResponseDTO {
                Id                   = createdResponse.Id,
                Text                 = createdResponse.Text,
                Date                 = createdResponse.Date,
                IsClientResponse     = createdResponse.IsClientResponse,
                TicketNumberOfTicket = createdResponse.Ticket.TicketNumber
            };

            return(CreatedAtRoute("DefaultApi",
                                  new { Controller = "TicketResponse", id = responseData.Id },
                                  responseData));
        }
Exemplo n.º 11
0
 public TicketResponseDTO AddResponse(int ticketNumber, string response, bool isClientResponse)
 {
     return(new TicketResponseDTO(mgr.AddTicketResponse(ticketNumber, response, isClientResponse)));
 }