public async Task UpsertOriginalContractXmlAsync_ExpectedResult_Test()
        {
            //Arrange
            var contractDocumentService = BuildContractDocumentService();
            var request = new UpdateConfirmApprovalRequest()
            {
                ContractNumber = "Main-0002", ContractVersion = 2, FileName = BlobHelper.BlobName
            };
            var contract = new DataModels.Contract()
            {
                Id = 7,
                ContractVersion = 2,
                ContractNumber  = "Main-0002",
                ContractData    = new DataModels.ContractData()
                {
                    Id = 7,
                    OriginalContractXml = "<contract>sample.xml.data</contract>"
                }
            };

            //Act
            await contractDocumentService.UpsertOriginalContractXmlAsync(contract, request);

            //Assert
            contractDocumentService.Should().NotBeNull();
            contract.ContractData.OriginalContractXml.Should().Be(BlobHelper.BlobSampleContent);
        }
        /// <inheritdoc/>
        public async Task UpsertOriginalContractXmlAsync(DataModels.Contract contract, ContractRequest request)
        {
            _logger.LogInformation($"[{nameof(UpsertOriginalContractXmlAsync)}] called with contract number: {request.ContractNumber} and version {request.ContractVersion}.");
            if (contract.ContractData is null)
            {
                contract.ContractData    = new DataModels.ContractData();
                contract.ContractData.Id = contract.Id;
            }

            contract.ContractData.OriginalContractXml = await GetDocumentContentAsync(request);
        }
 private DataModels.Contract GetClonedContract(DataModels.Contract contract)
 {
     return(new DataModels.Contract()
     {
         Id = contract.Id,
         Title = contract.Title,
         ContractNumber = contract.ContractNumber,
         ContractVersion = contract.ContractVersion,
         Ukprn = contract.Ukprn,
         Status = contract.Status
     });
 }
Beispiel #4
0
        public void Validate_ContractNotFoundException()
        {
            // Arrange
            DataModels.Contract contract = null;
            var contractRequest          = GetContractRequest();

            // Act
            Action act = () => contractValidationService.Validate(contract, contractRequest);

            // Assert
            act.Should().ThrowExactly <ContractNotFoundException>();
        }
        public async Task UpdateContractConfirmApprovalAsync_ReturnsExpectedResult_Test()
        {
            //Arrange
            SetMapperHelper();
            string       baseUrl        = $"https://localhost:5001";
            const string contractNumber = "Main-0001";
            const string title          = "Test Title";

            var working = new DataModels.Contract {
                Id = 1, Title = title, ContractNumber = contractNumber, ContractVersion = 1, Ukprn = 12345678, Status = (int)ContractStatus.ApprovedWaitingConfirmation
            };

            var request = new UpdateConfirmApprovalRequest()
            {
                ContractNumber = "Main-0001", ContractVersion = 1, FileName = BlobHelper.BlobName
            };

            ILoggerAdapter <ContractService>    logger     = new LoggerAdapter <ContractService>(new Logger <ContractService>(new LoggerFactory()));
            ILoggerAdapter <ContractRepository> loggerRepo = new LoggerAdapter <ContractRepository>(new Logger <ContractRepository>(new LoggerFactory()));

            MockAuditService();

            var inMemPdsDbContext = HelperExtensions.GetInMemoryPdsDbContext();
            var repo         = new Repository <DataModels.Contract>(inMemPdsDbContext);
            var work         = new SingleUnitOfWorkForRepositories(inMemPdsDbContext);
            var contractRepo = new ContractRepository(repo, work, loggerRepo);
            var uriService   = new UriService(baseUrl);
            var asposeDocumentManagementContractService = GetDocumentService();
            var contractValidationService = GetContractValidationService();
            var mediator = BuildMediator();
            var contractDocumentService = BuildContractDocumentService();
            var service = new ContractService(contractRepo, _mapper, uriService, logger, _mockAuditService.Object, _semaphoreOnEntity, asposeDocumentManagementContractService, contractValidationService, mediator, contractDocumentService);

            await repo.AddAsync(working);

            await work.CommitAsync();

            //Act
            var beforeUpdate = await contractRepo.GetByContractNumberAndVersionWithIncludesAsync(request.ContractNumber, request.ContractVersion, ContractDataEntityInclude.Datas);

            // assigning to a new variable before this is an in memory db so the
            // LastEmailReminderSent was being populated.
            var actualBeforeUpdate = new DataModels.Contract()
            {
                Id              = beforeUpdate.Id,
                Title           = beforeUpdate.Title,
                ContractNumber  = beforeUpdate.ContractNumber,
                ContractVersion = beforeUpdate.ContractVersion,
                Ukprn           = beforeUpdate.Ukprn,
                Status          = beforeUpdate.Status
            };

            var contract = await service.ConfirmApprovalAsync(request);

            var afterUpdate = await contractRepo.GetByContractNumberAndVersionWithIncludesAsync(request.ContractNumber, request.ContractVersion, ContractDataEntityInclude.Datas);

            //Assert
            contract.Should().NotBeNull();
            actualBeforeUpdate.Status.Should().Be((int)ContractStatus.ApprovedWaitingConfirmation);
            afterUpdate.Status.Should().Be((int)ContractStatus.Approved);
            afterUpdate.ContractData.OriginalContractXml.Should().Be(BlobHelper.BlobSampleContent);
        }
        public async Task UpdateLastEmailReminderSentAndLastUpdatedAtAsync_ReturnsExpectedResult_Test()
        {
            //Arrange
            SetMapperHelper();
            string       baseUrl        = $"https://localhost:5001";
            const string contractNumber = "main-000";
            const string title          = "Test Title";
            int          x = 0;

            var working = new List <DataModels.Contract>
            {
                new DataModels.Contract {
                    Id = 1, Title = title, ContractNumber = string.Empty, ContractVersion = 1, Ukprn = 12345678, LastEmailReminderSent = null
                }
            };

            var request = new UpdateLastEmailReminderSentRequest()
            {
                Id = 1, ContractNumber = "main-0001", ContractVersion = 1
            };

            foreach (var item in working)
            {
                item.ContractNumber        = $"{contractNumber}{x}";
                item.Ukprn                += x;
                item.LastEmailReminderSent = null;
                x += 1;
            }

            ILoggerAdapter <ContractService>    logger     = new LoggerAdapter <ContractService>(new Logger <ContractService>(new LoggerFactory()));
            ILoggerAdapter <ContractRepository> loggerRepo = new LoggerAdapter <ContractRepository>(new Logger <ContractRepository>(new LoggerFactory()));

            MockAuditService();

            var inMemPdsDbContext = HelperExtensions.GetInMemoryPdsDbContext();
            var repo         = new Repository <DataModels.Contract>(inMemPdsDbContext);
            var work         = new SingleUnitOfWorkForRepositories(inMemPdsDbContext);
            var contractRepo = new ContractRepository(repo, work, loggerRepo);
            var uriService   = new UriService(baseUrl);
            var asposeDocumentManagementContractService = GetDocumentService();
            var contractValidationService = GetContractValidationService();
            var mediator = BuildMediator();
            var contractDocumentService = BuildContractDocumentService();
            var service = new ContractService(contractRepo, _mapper, uriService, logger, _mockAuditService.Object, _semaphoreOnEntity, asposeDocumentManagementContractService, contractValidationService, mediator, contractDocumentService);

            foreach (var item in working)
            {
                await repo.AddAsync(item);
            }

            await work.CommitAsync();

            //Act
            var beforeUpdate = await contractRepo.GetAsync(request.Id);

            // assigning to a new variable before this is an in memory db so the
            // LastEmailReminderSent was being populated.
            var actualBeforeUpdate = new DataModels.Contract()
            {
                Id                    = beforeUpdate.Id,
                Title                 = beforeUpdate.Title,
                ContractNumber        = beforeUpdate.ContractNumber,
                ContractVersion       = beforeUpdate.ContractVersion,
                Ukprn                 = beforeUpdate.Ukprn,
                LastEmailReminderSent = beforeUpdate.LastEmailReminderSent
            };

            var contract = await service.UpdateLastEmailReminderSentAndLastUpdatedAtAsync(request);

            var afterUpdate = await contractRepo.GetAsync(request.Id);

            //Assert
            contract.Should().NotBeNull();
            actualBeforeUpdate.LastEmailReminderSent.Should().BeNull();
            afterUpdate.LastEmailReminderSent.Should().NotBeNull();
            afterUpdate.LastUpdatedAt.Should().BeExactly(afterUpdate.LastEmailReminderSent.Value.TimeOfDay);
        }