public async Task CreateNotesWithAttachment_ShouldAttachDocumentToCase_AsNote()
        {
            var casRef = 123456789123;
            // Arrange
            var fileRequest = new NoteWithAttachments
            {
                Attachments = new System.Collections.Generic.List <StockportGovUK.NetStandard.Models.FileManagement.File>
                {
                    new StockportGovUK.NetStandard.Models.FileManagement.File
                    {
                        Content = "abc",
                        TrustedOriginalFileName = "file.txt"
                    },
                    new StockportGovUK.NetStandard.Models.FileManagement.File
                    {
                        Content = "cba",
                        TrustedOriginalFileName = "second.txt"
                    },
                },
                AttachmentsDescription = "description",
                CaseRef = casRef
            };

            _mockClient
            .Setup(client => client.addDocumentToRepositoryAsync(It.IsAny <FWTDocument>())).ReturnsAsync(new addDocumentToRepositoryResponse {
                FWTDocumentRef = "123REF"
            });

            // Act
            await _caseService.CreateNotesWithAttachment(fileRequest);

            // Assert
            _mockClient.Verify(client => client.addDocumentToRepositoryAsync(It.IsAny <FWTDocument>()), Times.Exactly(2));
            _mockClient.Verify(client => client.createNotesAsync(It.Is <FWTCreateNoteToParent>(x => x.ParentId == casRef && x.NoteDetails.NoteAttachments.Length == 2)), Times.Once);
        }
        public async Task AddNoteWithAttachments_ShouldReturnOk_OnSuccessfulServiceCall()
        {
            var model = new NoteWithAttachments
            {
                Attachments            = new List <StockportGovUK.NetStandard.Models.FileManagement.File>(),
                AttachmentsDescription = "description",
                CaseRef = 123456789123
            };

            var result = await _caseController.AddNoteWithAttachments(model);

            _mockCaseService.Verify(service => service.CreateNotesWithAttachment(It.IsAny <NoteWithAttachments>()), Times.Once);
            var okResult = Assert.IsType <OkResult>(result);

            Assert.Equal(200, okResult.StatusCode);
        }
        public async Task AddNoteWithAttachments_ShouldReturn500StatusCode_WhenServiceThrowsException()
        {
            var model = new NoteWithAttachments
            {
                Attachments            = new List <StockportGovUK.NetStandard.Models.FileManagement.File>(),
                AttachmentsDescription = "description",
                CaseRef = 123456789123
            };

            _mockCaseService.Setup(service => service.CreateNotesWithAttachment(It.IsAny <NoteWithAttachments>()))
            .ThrowsAsync(new Exception());

            var result = await _caseController.AddNoteWithAttachments(model);

            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal(500, statusCodeResult.StatusCode);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddNoteWithAttachments([FromBody] NoteWithAttachments model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                await _caseService.CreateNotesWithAttachment(model);

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError("CaseController.AddNoteWithAttachments: Failed to create note with attachments", ex.InnerException);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task CreateNotesWithAttachment_ShouldCallRepository_ToAddUploadedFile()
        {
            var file1Name    = "file.txt";
            var file1Content = "cba";
            var file2Name    = "second.txt";
            var file2Content = "abc";

            // Arrange
            var fileRequest = new NoteWithAttachments
            {
                Attachments = new System.Collections.Generic.List <StockportGovUK.NetStandard.Models.FileManagement.File>
                {
                    new StockportGovUK.NetStandard.Models.FileManagement.File
                    {
                        Content = file1Content,
                        TrustedOriginalFileName = file1Name
                    },
                    new StockportGovUK.NetStandard.Models.FileManagement.File
                    {
                        Content = file2Content,
                        TrustedOriginalFileName = file2Name
                    },
                },
                AttachmentsDescription = "description",
                CaseRef = 123456789123
            };

            _mockClient
            .Setup(client => client.addDocumentToRepositoryAsync(It.IsAny <FWTDocument>())).ReturnsAsync(new addDocumentToRepositoryResponse {
                FWTDocumentRef = "123REF"
            });

            // Act
            await _caseService.CreateNotesWithAttachment(fileRequest);

            // Assert
            _mockClient.Verify(client => client.addDocumentToRepositoryAsync(It.IsAny <FWTDocument>()), Times.Exactly(2));
            _mockClient.Verify(client => client.addDocumentToRepositoryAsync(It.Is <FWTDocument>(x => x.DocumentName == file1Name && x.Document == file1Content)), Times.Once);
            _mockClient.Verify(client => client.addDocumentToRepositoryAsync(It.Is <FWTDocument>(x => x.DocumentName == file2Name && x.Document == file2Content)), Times.Once);
        }
Exemplo n.º 6
0
        public async Task CreateNotesWithAttachment(NoteWithAttachments note)
        {
            try
            {
                var repositoryResult = await AddDocumentToRepository(note.Attachments);

                var attachedFileReferences = new List <FWTNoteDetailAttachment>();

                repositoryResult.ForEach(r =>
                {
                    attachedFileReferences.Add(new FWTNoteDetailAttachment
                    {
                        AttachmentIdentifier    = r.documentReference,
                        AttachmentName          = r.documentName,
                        AttachmentTypeSpecified = false
                    });
                });

                var noteWithAttachments = new FWTCreateNoteToParent
                {
                    NoteDetails = new FWTCreateNoteDetail
                    {
                        Text            = note.AttachmentsDescription,
                        NoteAttachments = attachedFileReferences.ToArray()
                    },
                    ParentId   = note.CaseRef,
                    ParentType = note.Interaction
                };

                await _verintConnection.createNotesAsync(noteWithAttachments);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                _logger.LogError(exception, "Error when adding attachment");
                throw;
            }
        }
Exemplo n.º 7
0
 public async Task <HttpResponseMessage> AddNoteWithAttachments(NoteWithAttachments model)
 => await PostAsync($"{CaseEndpoint}/add-note-with-attachments", model);
        public async Task <string> CreateCase(ParkingPermitsRequest parkingPermitsRequest)
        {
            if (!string.IsNullOrEmpty(parkingPermitsRequest.CaseReference))
            {
                HttpResponse <Case> existingVerintCase = await _verintServiceGateway.GetCase(parkingPermitsRequest.CaseReference);

                if (existingVerintCase != null)
                {
                    if (!_permitHelper.hasCaseModified(parkingPermitsRequest, existingVerintCase.ResponseContent))
                    {
                        return(parkingPermitsRequest.CaseReference);
                    }

                    HttpResponse <string> caseClosedResponse = await _verintServiceGateway.CloseCase(new CloseCaseRequest()
                    {
                        CaseReference = parkingPermitsRequest.CaseReference,
                        Description   = PermitConstants.STATUS_CLOSED,
                        ReasonTitle   = PermitConstants.STATUS_CLOSED,
                    });

                    if (!caseClosedResponse.IsSuccessStatusCode)
                    {
                        throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                        $"{nameof(ParkingPermitsService)}: {nameof(CreateCase)}: " +
                                                        $"{nameof(_verintServiceGateway)} {nameof(_verintServiceGateway.CloseCase)} " +
                                                        $"failed with {caseClosedResponse.StatusCode}");
                    }
                }
            }

            var verintCase = _permitHelper.ConvertPermitRequestToVerintCase(parkingPermitsRequest);

            HttpResponse <string> response = await _verintServiceGateway.CreateCase(verintCase);

            if (!response.IsSuccessStatusCode || string.IsNullOrEmpty(response.ResponseContent))
            {
                throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                $"{nameof(ParkingPermitsService)}: {nameof(CreateCase)}: " +
                                                $"{nameof(_verintServiceGateway)} {nameof(_verintServiceGateway.CreateCase)} " +
                                                $"failed with {response.StatusCode}");
            }

            var caseRef = response.ResponseContent;

            try
            {
                if (parkingPermitsRequest.File != null && parkingPermitsRequest.File.Any())
                {
                    foreach (var file in parkingPermitsRequest.File)
                    {
                        var attachment = file;
                        var note       = new NoteWithAttachments
                        {
                            CaseRef = long.Parse(caseRef),
                            AttachmentsDescription = attachment.TrustedOriginalFileName,
                            Attachments            = new List <File> {
                                file
                            }
                        };

                        var noteResponse = await _verintServiceGateway.AddNoteWithAttachments(note);

                        if (!noteResponse.IsSuccessStatusCode || noteResponse == null)
                        {
                            throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                            $"{nameof(ParkingPermitsService)}: {nameof(CreateCase)}: " +
                                                            $"{nameof(_verintServiceGateway)} {nameof(_verintServiceGateway.AddNoteWithAttachments)} " +
                                                            $"failed with {noteResponse.StatusCode}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"ParkingEnforcementService::AddNoteWithAttachments, an exception has occurred while adding note with attachment to case: {response.ResponseContent}", ex);
            }

            if (!parkingPermitsRequest.CalculatedCost.Equals(PermitConstants.FREE_PRICE))
            {
                try
                {
                    await _distributedCache.SetStringAsync(caseRef, JsonSerializer.Serialize(parkingPermitsRequest),
                                                           new DistributedCacheEntryOptions { AbsoluteExpiration = DateTime.Now.AddMinutes(60) });
                }
                catch (Exception exception)
                {
                    throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                    $"{nameof(ParkingPermitsService)}: {nameof(CreateCase)}: " +
                                                    $"{nameof(_distributedCache)} failed - Verint Case Ref: " +
                                                    $"{caseRef}, message: {exception.Message}");
                }
            }

            if (parkingPermitsRequest.CalculatedCost.Equals(PermitConstants.FREE_PRICE))
            {
                _mailHelper.SendParkingPermitEmail(EMailTemplate.GenericReport, caseRef, parkingPermitsRequest);
            }

            return(caseRef);
        }