public void UserUpdatesTicket()
        {
            var ticket = new Ticket
            {
                Name     = "Test_Name",
                Text     = "Test_Text",
                Priority = Priority.Medium,
                Status   = Status.InProgress
            };
            var updatedTicket = new TicketApiModel
            {
                Name     = "Updated_Test",
                Text     = "Updated_Test_Text",
                Priority = Priority.High,
                Status   = Status.InProgress
            };

            this.Given(s => s.GivenAnExistingTicketThatUserWantsToUpdate(ticket))
            .And(s => s.AndAnUpdatedVersionOfExistingTicketThatAUserWantsToUpdate(updatedTicket))
            .When(s => s.WhenUserUpdatesTicket())
            .Then(s => s.ThenTicketHasBeenUpdatedWithTheRightId())
            .And(s => s.AndWithTheRightName())
            .And(s => s.AndWithTheRightText())
            .And(s => s.AndWithTheRightPriority())
            .And(s => s.AndWithTheRightStatus())
            .BDDfy <UserManagesTickets>();
        }
Exemplo n.º 2
0
        public async Task Create_ReturnsStatusOk_WhenValidTicketViewModel()
        {
            var httpContextMock = new Mock <HttpContext>();

            var headersMock = new HeaderDictionary
            {
                new KeyValuePair <string, StringValues>(ContentTypeHeaderKey, "Content-Type_Header_Test_Value"),
                new KeyValuePair <string, StringValues>(AuthorizationHeaderKey, "Authorization_Header_Test_Value"),
                new KeyValuePair <string, StringValues>(CorrelationIdHeaderKey, "CorrelationId_Header_Test_Value")
            };

            httpContextMock.SetupGet(x => x.Request.Headers).Returns(headersMock);

            var actionContext = new ActionContext(
                httpContextMock.Object,
                new Mock <RouteData>().Object,
                new Mock <ActionDescriptor>().Object);

            _sut.ControllerContext = new ControllerContext(new ActionContext()
            {
                RouteData        = new RouteData(),
                HttpContext      = actionContext.HttpContext,
                ActionDescriptor = new ControllerActionDescriptor()
            });

            var ticketApiModel = new TicketApiModel();

            _ticketServiceMock
            .Setup(ticket => ticket.GetAsync(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .ReturnsAsync(new TicketDto());

            var result = await _sut.Create(It.IsAny <Guid>(), ticketApiModel);

            Assert.Equal(typeof(OkObjectResult), result.GetType());
        }
        private async Task WhenUserGetsThisTicketByTheSameId()
        {
            var jsonResult = await _sut.GetTicket(StubTeamId, _existingTicket.Id) as JsonResult;

            if (jsonResult != null)
            {
                _returnTicket = jsonResult.Value as TicketApiModel;
            }
        }
Exemplo n.º 4
0
        public async Task Create_ReturnsBadRequest_WhenValidTicketViewModel()
        {
            var model = new TicketApiModel();

            _sut.ModelState.AddModelError("Model", "Model is not valid");

            var result = await _sut.Create(It.IsAny <Guid>(), model);

            Assert.Equal(typeof(BadRequestObjectResult), result.GetType());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(Guid teamId, [FromBody] TicketApiModel ticketApiModel)
        {
            if (ModelState.IsValid)
            {
                var ticketDto       = _mapper.Map <TicketDto>(ticketApiModel);
                var createdTicketId = await _ticketService.CreateAsync(teamId, ticketDto);

                _logger.LogInformation($"Ticket with name {ticketApiModel.Name} was successfully created");
                return(Ok(createdTicketId));
            }

            return(BadRequest(ModelState));
        }
Exemplo n.º 6
0
        public TicketApiModel ToApiModel(Ticket ticket)
        {
            TicketApiModel ticketApiModel = new TicketApiModel();

            _mapper.Map(ticket, ticketApiModel);
            var parentCategoryId = ticket.TicketCategory.ParentCategoryId.HasValue ? ticket.TicketCategory.ParentCategoryId.Value : Guid.Empty;

            ticketApiModel.CategoryId    = parentCategoryId;
            ticketApiModel.SubCategoryId = ticket.TicketCategoryId;
            ticketApiModel.Priority      = ticket.TicketPriority.Name;
            ticketApiModel.Status        = ticket.TicketStatus == null ? "" : ticket.TicketStatus.Name;
            ticketApiModel.Rating        = ticket.TicketRating?.Rating;
            return(ticketApiModel);
        }
Exemplo n.º 7
0
 public ActionResult Post([FromBody] TicketApiModel ticketApiModel)
 {
     try
     {
         Ticket ticket = _ticketMapper.ToDomainModel(ticketApiModel);
         ticket.TicketStatus = new TicketStatus()
         {
             Name = "New"
         };
         ApiResponse serviceResponse = this._ticketService.Create(ticket);
         return(SendResponse(serviceResponse, "Ticket"));
     }
     catch (Exception ex)
     {
         return(new UnknownErrorResult(ex, base._errorEnabled));
     }
 }
        public void UserCreatesTicket()
        {
            var ticketToCreate = new TicketApiModel
            {
                Name     = "Test_Name",
                Text     = "Test_Text",
                Priority = Priority.Medium,
                Status   = Status.InProgress
            };

            this.Given(s => s.GivenATicketThatUserWantsToCreate(ticketToCreate))
            .When(s => s.WhenUserCreatesTicket())
            .Then(s => s.TheTicketWithTheSameNameWasCreated())
            .And(s => s.AndWithTheSameText())
            .And(s => s.AndWithTheSamePriority())
            .And(s => s.AndWithTheSameStatus())
            .BDDfy <UserManagesTickets>();
        }
Exemplo n.º 9
0
        public async Task Edit_ReturnsStatusOk_WhenCommunicationToUserSuccess()
        {
            var ticketId  = Guid.NewGuid();
            var ticketDto = new TicketDto {
                Id = ticketId
            };
            var model = new TicketApiModel();

            var httpContextMock = new Mock <HttpContext>();

            var headersMock = new HeaderDictionary
            {
                new KeyValuePair <string, StringValues>(ContentTypeHeaderKey, "Content-Type_Header_Test_Value"),
                new KeyValuePair <string, StringValues>(AuthorizationHeaderKey, "Authorization_Header_Test_Value"),
                new KeyValuePair <string, StringValues>(CorrelationIdHeaderKey, "CorrelationId_Header_Test_Value")
            };

            httpContextMock.SetupGet(x => x.Request.Headers).Returns(headersMock);

            var actionContext = new ActionContext(
                httpContextMock.Object,
                new Mock <RouteData>().Object,
                new Mock <ActionDescriptor>().Object);

            _sut.ControllerContext = new ControllerContext(new ActionContext()
            {
                RouteData        = new RouteData(),
                HttpContext      = actionContext.HttpContext,
                ActionDescriptor = new ControllerActionDescriptor()
            });

            _ticketServiceMock
            .Setup(manager => manager.GetAsync(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .ReturnsAsync(ticketDto);

            _communicationServiceMock
            .Setup(method => method.GetAsync <HttpStatusCode>(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <HeaderDictionary>(), It.IsAny <string>()))
            .ReturnsAsync(HttpStatusCode.OK);

            var result = await _sut.Update(It.IsAny <Guid>(), model);

            Assert.Equal(typeof(OkResult), result.GetType());
        }
Exemplo n.º 10
0
        public Ticket ToDomainModel(TicketApiModel ticketApiModel, Ticket ticket = null)
        {
            if (ticket == null)
            {
                ticket = new Ticket();
            }
            int ticketnNumber   = ticket.Number;
            var createdDateTime = ticket.Created;

            _mapper.Map(ticketApiModel, ticket);
            ticket.Number           = ticketnNumber;
            ticket.TicketCategoryId = ticketApiModel.SubCategoryId;
            ticket.TicketPriority   = new TicketPriority()
            {
                Name = ticketApiModel.Priority
            };
            ticket.Created = createdDateTime;
            return(ticket);
        }
Exemplo n.º 11
0
        public ActionResult Get(Guid id)
        {
            try
            {
                var serviceResponse = this._ticketService.GetParentChildById(id);
                if (serviceResponse.IsError())
                {
                    return(new ObjectNotFoundResult(serviceResponse));
                }

                Ticket         ticket         = serviceResponse.GetData <Ticket>();
                TicketApiModel ticketApiModel = _ticketMapper.ToApiModel(ticket);
                return(new ObjectFoundResult(new ApiResponse(ticketApiModel)));
            }
            catch (Exception ex)
            {
                return(new UnknownErrorResult(ex, base._errorEnabled));
            }
        }
Exemplo n.º 12
0
        public ActionResult Put(Guid id, [FromBody] TicketApiModel ticketApiModel)
        {
            try
            {
                ApiResponse serviceResponse = this._ticketService.GetById(id);
                if (serviceResponse.IsSuccess() == false)
                {
                    return(new ObjectNotFoundResult(serviceResponse));
                }

                Ticket ticket = serviceResponse.GetData <Ticket>();
                _ticketMapper.ToDomainModel(ticketApiModel, ticket);
                serviceResponse = this._ticketService.Update(id, ticket);

                return(SendResponse(serviceResponse));
            }
            catch (Exception ex)
            {
                return(new UnknownErrorResult(ex, base._errorEnabled));
            }
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Update(Guid teamId, [FromBody] TicketApiModel ticketApiModel)
        {
            var oldTicketDto = await _ticketService.GetAsync(teamId, ticketApiModel.Id);

            var oldTicketApiModel = _mapper.Map <TicketApiModel>(oldTicketDto);

            ticketApiModel.CreationDate = oldTicketApiModel.CreationDate;

            var ticketDto = _mapper.Map <TicketDto>(ticketApiModel);

            await _ticketService.UpdateAsync(teamId, ticketDto);

            var notificationApiModel = new NotificationInfoApiModel
            {
                OldTicket        = oldTicketApiModel,
                NewTicket        = ticketApiModel,
                NotificationType = NotificationType.TicketUpdated
            };

            try
            {
                await _communicationService.PostAsync <string, NotificationInfoApiModel>(
                    $"api/user/teams/{teamId}/tickets/{ticketApiModel.Id}/notify",
                    notificationApiModel,
                    FormHeaders("application/json"),
                    "NotificationService");
            }
            catch (ServiceCommunicationException)
            {
                _logger.LogError($"Ticket update notification with id: {ticketDto.Id} was not sent!");
            }

            _logger.LogInformation($"Ticket with id {ticketApiModel.Id} was successfully updated ");

            return(Ok());
        }
 private void ThenUserReceiveASerializableTicketApiModel(TicketApiModel model)
 {
     Assert.NotNull(model);
 }
 private void AndAnUpdatedVersionOfExistingTicketThatAUserWantsToUpdate(TicketApiModel apiModel)
 {
     apiModel.Id         = _existingUpdatedTicket.Id;
     _inputUpdatedTicket = apiModel;
 }
 private void GivenATicketThatUserWantsToCreate(TicketApiModel apiModel)
 {
     _inputCreateTicket = apiModel;
 }