Ejemplo n.º 1
0
        public async Task <string> CreateComplimentCase(ComplimentDetails model)
        {
            var events = _complimentsConfig.Value.ComplimentsConfigurations;

            var eventCode = string.IsNullOrEmpty(model.CouncilDepartmentSub)
                ? events.FirstOrDefault(_ => _.EventName == model.CouncilDepartment)?.EventCode ?? events.FirstOrDefault(_ => _.EventName == "none")?.EventCode
                  : events.FirstOrDefault(_ => _.EventName == model.CouncilDepartmentSub)?.EventCode ?? events.FirstOrDefault(_ => _.EventName == "none")?.EventCode;

            var name = string.IsNullOrEmpty(model.Name) ? "Not provided" : model.Name;

            var crmCase = new Case
            {
                EventCode   = (int)eventCode,
                EventTitle  = string.IsNullOrEmpty(model.CouncilDepartmentOther) ? "Compliment" : $"Compliment - {model.CouncilDepartmentOther}",
                Description = $"Name: {name} \n\nCompliment: {model.Compliment}"
            };

            try
            {
                var response = await _verintServiceGateway.CreateCase(crmCase);

                return(response.ResponseContent);
            }
            catch (Exception ex)
            {
                throw new Exception($"ComplimentsComplaintsService CreateComplimentCase an exception has occured while creating the case in verint service", ex);
            }
        }
        public async void CreateComplimentCase_ShouldThrowException()
        {
            // Arrange
            _mockGateway
            .Setup(_ => _.CreateCase(It.IsAny <Case>()))
            .Throws <Exception>();

            var model = new ComplimentDetails
            {
                EventCode  = "123456",
                Compliment = "test"
            };

            // Act & Assert
            await Assert.ThrowsAsync <Exception>(() => _service.CreateComplimentCase(model));
        }
        public async void CreateComplimentCase_ShouldReturnCaseId()
        {
            // Arrange
            _mockGateway
            .Setup(_ => _.CreateCase(It.IsAny <Case>()))
            .ReturnsAsync(new HttpResponse <string>
            {
                StatusCode      = HttpStatusCode.OK,
                ResponseContent = "123456"
            });

            var model = new ComplimentDetails
            {
                EventCode  = "123456",
                Compliment = "test"
            };

            // Act
            var response = await _service.CreateComplimentCase(model);

            // Assert
            Assert.Equal("123456", response);
        }
        public async void CreateComplimentCase_ShouldCallGateway()
        {
            // Arrange
            _mockGateway
            .Setup(_ => _.CreateCase(It.IsAny <Case>()))
            .ReturnsAsync(new HttpResponse <string>
            {
                StatusCode      = HttpStatusCode.OK,
                ResponseContent = "123456"
            });

            var model = new ComplimentDetails
            {
                EventCode  = "123456",
                Compliment = "test"
            };

            // Act
            await _service.CreateComplimentCase(model);

            // Assert
            _mockGateway.Verify(_ => _.CreateCase(It.IsAny <Case>()), Times.Once);
        }
        public async Task <IActionResult> CreateCase([FromBody] ComplimentDetails model)
        {
            var result = await _caseService.CreateComplimentCase(model);

            return(Ok(result));
        }
 public async Task <HttpResponse <string> > SubmitCompliment(ComplimentDetails model)
 => await PostAsync <string>($"{ComplimentEndpoint}/submit-compliment", model);