public async Task <ActionResult <InteractionReadDto> > CreateInteraction(InteractionCreateDto interactionCreateDto)
        {
            var interaction = _mapper.Map <InteractionCreateDto, Interaction>(interactionCreateDto);

            if (interaction.CustomerStatus == CustomerStatus.VIP)
            {
                // send email to John
            }

            _interactionRepo.CreateInteraction(interaction);

            try
            {
                await _interactionRepo.SaveChanges();

                var allInteractions = _interactionRepo.GetAllInteractions().ToList().OrderByDescending(i => i.Timestamp).ToList();
                var dailyReport     = ReportGenerator.GenerateReport(allInteractions.Where(i => i.Timestamp.ToLocalTime() >= DateTime.Today && i.Timestamp.ToLocalTime() < DateTime.Today.AddDays(1)));
                await _hub.Clients.All.SendAsync("InteractionsAdded", allInteractions);

                await _hub.Clients.All.SendAsync("DailyReportUpdated", dailyReport);
            }
            catch (Exception e)
            {
                return(BadRequest());
            }

            var interactionReadDto = _mapper.Map <Interaction, InteractionReadDto>(interaction);

            return(CreatedAtRoute(nameof(GetInteractionById), new { Id = interactionReadDto.CallId }, interactionReadDto));
        }
        public async Task CreateInteraction_DuplicateCallId_ReturnsBadRequest()
        {
            var expectedInteractionCreateDto = new InteractionCreateDto()
            {
                CallId = "NewCallId", CustomerStatus = CustomerStatus.VIP
            };
            var expectedInteraction = new Interaction()
            {
                CallId = expectedInteractionCreateDto.CallId, CustomerStatus = expectedInteractionCreateDto.CustomerStatus
            };

            _mockMapper.Setup(x => x.Map <InteractionCreateDto, Interaction>(expectedInteractionCreateDto)).Returns(expectedInteraction);
            _mockRepo.Setup(x => x.SaveChanges()).Throws(new Exception());

            var response = await _interactionsController.CreateInteraction(expectedInteractionCreateDto);

            Assert.IsInstanceOfType(response.Result, typeof(BadRequestResult));
        }
        public async Task CreateInteraction_ReturnsCreatedAtRouteStatus()
        {
            var expectedInteractionCreateDto = new InteractionCreateDto()
            {
                CallId = "NewCallId", CustomerStatus = CustomerStatus.VIP
            };
            var expectedInteraction = new Interaction()
            {
                CallId = expectedInteractionCreateDto.CallId, CustomerStatus = expectedInteractionCreateDto.CustomerStatus
            };
            var expectedInteractionReadDto = new InteractionReadDto()
            {
                CallId = expectedInteractionCreateDto.CallId, CustomerStatus = expectedInteractionCreateDto.CustomerStatus
            };

            _mockMapper.Setup(x => x.Map <InteractionCreateDto, Interaction>(expectedInteractionCreateDto)).Returns(expectedInteraction);
            _mockMapper.Setup(x => x.Map <Interaction, InteractionReadDto>(expectedInteraction)).Returns(expectedInteractionReadDto);

            var response = await _interactionsController.CreateInteraction(expectedInteractionCreateDto);

            Assert.IsInstanceOfType(response.Result, typeof(CreatedAtRouteResult));
        }
Beispiel #4
0
        public async Task <ActionResult <Interaction> > PostInteraction(InteractionCreateDto interactionCreateDto)
        {
            var interaction = _mapper.Map <Interaction>(interactionCreateDto);

            _context.Interaction.Add(interaction);
            try {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException) {
                if (InteractionExists(interaction.InteractionId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            await _context.SaveChangesAsync();

            return(CreatedAtRoute(nameof(GetInteraction), new { id = interaction.InteractionId }, interaction));
        }