Esempio n. 1
0
        public async Task UpdateLastEmailReminderSentAndLastUpdatedAtAsync_Test()
        {
            //Arrange
            var inMemPdsDbContext = HelperExtensions.GetInMemoryPdsDbContext();
            var repo         = new Repository <DataModels.Contract>(inMemPdsDbContext);
            var work         = new SingleUnitOfWorkForRepositories(inMemPdsDbContext);
            var contractRepo = new ContractRepository(repo, work, _logger);

            int          contractId            = 1;
            const string contractNumber        = "main-0001";
            const string title                 = "Test Title";
            DateTime     lastEmailReminderSent = DateTime.UtcNow;

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

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

            await work.CommitAsync();

            await contractRepo.UpdateLastEmailReminderSentAndLastUpdatedAtAsync(contractId);

            //Act
            var actual = await contractRepo.GetAsync(contractId);

            //Assert
            actual.LastEmailReminderSent.Should().NotBeNull();
        }
Esempio n. 2
0
        public async Task GetAsync_TestAsync()
        {
            //Arrange
            var inMemPdsDbContext = HelperExtensions.GetInMemoryPdsDbContext();
            var repo         = new Repository <DataModels.Contract>(inMemPdsDbContext);
            var work         = new SingleUnitOfWorkForRepositories(inMemPdsDbContext);
            var contractRepo = new ContractRepository(repo, work, _logger);
            var expected     = new DataModels.Contract
            {
                Id              = 1,
                ContractNumber  = "Test",
                ContractVersion = 1,
                Year            = "2021"
            };

            //Act
            await repo.AddAsync(expected);

            await work.CommitAsync();

            var actual = await contractRepo.GetAsync(expected.Id);

            //Assert
            actual.Should().Be(expected);
        }
Esempio n. 3
0
        public async Task ExampleCreateContractAsync_TestAsync()
        {
            //Arrange
            var inMemPdsDbContext = HelperExtensions.GetInMemoryPdsDbContext();
            var repo         = new Repository <DataModels.Contract>(inMemPdsDbContext);
            var work         = new SingleUnitOfWorkForRepositories(inMemPdsDbContext);
            var contractRepo = new ContractRepository(repo, work, _logger);
            var contract     = new DataModels.Contract
            {
                Id              = 1,
                ContractNumber  = "Test",
                ContractVersion = 1,
                Year            = "2021"
            };

            //Act
            var before = await repo.GetByIdAsync(1);

            await contractRepo.CreateAsync(contract);

            var after = await repo.GetByIdAsync(1);

            //Assert
            before.Should().BeNull();
            after.Should().BeEquivalentTo(contract);
        }
Esempio n. 4
0
        public async Task GetByContractNumberAsync_TestAsync()
        {
            //Arrange
            var          inMemPdsDbContext = HelperExtensions.GetInMemoryPdsDbContext();
            var          repo           = new Repository <DataModels.Contract>(inMemPdsDbContext);
            var          work           = new SingleUnitOfWorkForRepositories(inMemPdsDbContext);
            var          contractRepo   = new ContractRepository(repo, work, _logger);
            const string ContractNumber = "Test";
            var          expected       = new List <DataModels.Contract>
            {
                new DataModels.Contract {
                    Id = 1, ContractNumber = ContractNumber, ContractVersion = 1
                },
                new DataModels.Contract {
                    Id = 2, ContractNumber = ContractNumber, ContractVersion = 2
                },
                new DataModels.Contract {
                    Id = 3, ContractNumber = ContractNumber, ContractVersion = 3
                },
            };

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

            await work.CommitAsync();

            //Act
            var actual = await contractRepo.GetByContractNumberAsync(ContractNumber);

            //Assert
            actual.Should().BeEquivalentTo(expected);
        }
        public async Task CreateAsync_WhenInputIsValid_Then_CreatesContractSuccessfullyTest()
        {
            // Arrange
            string baseUrl = $"https://localhost:5001";

            SetMapperHelper();
            var request = Generate_CreateContractRequest();

            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);

            // Act
            var before = await contractRepo.GetByContractNumberAsync(request.ContractNumber);

            await service.CreateAsync(request);

            var after = await contractRepo.GetByContractNumberAsync(request.ContractNumber);

            // Assert
            before.Should().BeEmpty();
            after.Should().HaveCount(1).And.Subject.First().ContractVersion.Should().Be(request.ContractVersion);
        }
        private async Task <ContractRepository> GetContractRepository(List <DataModels.Contract> contracts)
        {
            ILoggerAdapter <ContractRepository> loggerRepo = new LoggerAdapter <ContractRepository>(new Logger <ContractRepository>(new LoggerFactory()));
            var inMemPdsDbContext = HelperExtensions.GetInMemoryPdsDbContext();
            var repo         = new Repository <DataModels.Contract>(inMemPdsDbContext);
            var work         = new SingleUnitOfWorkForRepositories(inMemPdsDbContext);
            var contractRepo = new ContractRepository(repo, work, loggerRepo);

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

            await work.CommitAsync();

            return(contractRepo);
        }
        public async Task CommitAsyncTestAsync()
        {
            //Arrange
            var mockDbContext = Mock.Of <DbContext>(MockBehavior.Strict);

            Mock.Get(mockDbContext)
            .Setup(db => db.SaveChangesAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(1)
            .Verifiable();

            //Act
            var repo = new SingleUnitOfWorkForRepositories(mockDbContext);
            await repo.CommitAsync();

            //Assert
            Mock.Get(mockDbContext)
            .Verify(db => db.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once);
        }
Esempio n. 8
0
        public async Task UpdateContractConfirmApprovalAsync_Test()
        {
            //Arrange
            ContractStatus requiredContractStatus = ContractStatus.ApprovedWaitingConfirmation;
            ContractStatus newContractStatus      = ContractStatus.Approved;
            var            inMemPdsDbContext      = HelperExtensions.GetInMemoryPdsDbContext();
            var            repo         = new Repository <DataModels.Contract>(inMemPdsDbContext);
            var            work         = new SingleUnitOfWorkForRepositories(inMemPdsDbContext);
            var            contractRepo = new ContractRepository(repo, work, _logger);

            int          contractId          = 1;
            const string contractNumber      = "main-0001";
            const string title               = "Test Title";
            DateTime     expectedUpdatedDate = DateTime.UtcNow;
            DateTime     lastUpdatedDate     = expectedUpdatedDate.AddDays(40);

            var working = new List <DataModels.Contract>
            {
                new DataModels.Contract {
                    Id = contractId, Title = title, ContractNumber = contractNumber, ContractVersion = 1, Ukprn = 12345678, Status = (int)requiredContractStatus, LastUpdatedAt = lastUpdatedDate
                }
            };

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

            await work.CommitAsync();

            await contractRepo.UpdateContractStatusAsync(contractId, requiredContractStatus, newContractStatus);

            //Act
            var actual = await contractRepo.GetAsync(contractId);

            //Assert
            actual.Should().NotBeNull();
            actual.Status.Should().Be((int)newContractStatus);
            actual.LastUpdatedAt.Should().BeSameDateAs(expectedUpdatedDate);
        }
Esempio n. 9
0
        public async Task GetContractRemindersAsync_ReturnsExpectedResultTest()
        {
            //Arrange
            var inMemPdsDbContext = HelperExtensions.GetInMemoryPdsDbContext();
            var repo         = new Repository <DataModels.Contract>(inMemPdsDbContext);
            var work         = new SingleUnitOfWorkForRepositories(inMemPdsDbContext);
            var contractRepo = new ContractRepository(repo, work, _logger);

            const string contractNumber        = "Test-Contract-Number";
            const string title                 = "Test Title";
            DateTime     lastEmailReminderSent = DateTime.UtcNow;

            var working = new List <DataModels.Contract>
            {
                new DataModels.Contract {
                    Id = 1, Title = title, ContractNumber = contractNumber, ContractVersion = 1, LastEmailReminderSent = lastEmailReminderSent, Status = (int)ContractStatus.PublishedToProvider, FundingType = (int)ContractFundingType.AdvancedLearnerLoans
                },
                new DataModels.Contract {
                    Id = 2, Title = title, ContractNumber = contractNumber, ContractVersion = 2, LastEmailReminderSent = lastEmailReminderSent.AddDays(-14), Status = (int)ContractStatus.PublishedToProvider, FundingType = (int)ContractFundingType.AdvancedLearnerLoans
                },
                new DataModels.Contract {
                    Id = 3, Title = title, ContractNumber = contractNumber, ContractVersion = 3, LastEmailReminderSent = lastEmailReminderSent.AddDays(-15), Status = (int)ContractStatus.PublishedToProvider, FundingType = (int)ContractFundingType.AdvancedLearnerLoans
                },
            };
            var expected = working.Skip(1);

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

            await work.CommitAsync();

            //Act
            var actual = await contractRepo.GetContractRemindersAsync(DateTime.UtcNow.AddDays(-14), 1, 10, ContractSortOptions.LastUpdatedAt, SortDirection.Asc);

            //Assert
            actual.Items.Should().BeEquivalentTo(expected);
        }
        public async Task GetContractRemindersAsync_ReturnsExpectedTest()
        {
            //Arrange
            SetMapperHelper();
            int reminderInterval               = 14;
            int pageNumber                     = 1;
            int pageSize                       = 1;
            ContractSortOptions sort           = ContractSortOptions.LastUpdatedAt;
            SortDirection       order          = SortDirection.Asc;
            string       baseUrl               = $"https://localhost:5001";
            string       routeTemplateUrl      = $"/api/contractReminders?reminderInterval={reminderInterval}&pageNumber={pageNumber}&pageSize={pageSize}&sort={sort}&order={order}";
            const string contractNumber        = "Test-Contract-Number";
            const string title                 = "Test Title";
            DateTime     lastEmailReminderSent = DateTime.UtcNow;

            var working = new List <DataModels.Contract>
            {
                new DataModels.Contract {
                    Id = 1, Title = title, ContractNumber = contractNumber, ContractVersion = 1, Ukprn = 12345678, LastEmailReminderSent = lastEmailReminderSent, Status = (int)ContractStatus.PublishedToProvider, FundingType = (int)ContractFundingType.AdvancedLearnerLoans
                },
                new DataModels.Contract {
                    Id = 2, Title = title, ContractNumber = contractNumber, ContractVersion = 2, Ukprn = 12345678, LastEmailReminderSent = lastEmailReminderSent.AddDays(-14), Status = (int)ContractStatus.PublishedToProvider, FundingType = (int)ContractFundingType.AdvancedLearnerLoans
                },
                new DataModels.Contract {
                    Id = 3, Title = title, ContractNumber = contractNumber, ContractVersion = 3, Ukprn = 12345678, LastEmailReminderSent = lastEmailReminderSent.AddDays(-15), Status = (int)ContractStatus.PublishedToProvider, FundingType = (int)ContractFundingType.AdvancedLearnerLoans
                },
            };

            var expectedList = new List <ContractReminderItem>
            {
                new ContractReminderItem {
                    Id = 2, Title = title, ContractNumber = contractNumber, ContractVersion = 2, Ukprn = 12345678, Status = ContractStatus.PublishedToProvider, FundingType = ContractFundingType.AdvancedLearnerLoans
                }
            };

            var expected = new ContractReminderResponse <IEnumerable <ContractReminderItem> >(expectedList)
            {
                Paging = new Metadata()
                {
                    CurrentPage     = pageNumber,
                    HasNextPage     = true,
                    HasPreviousPage = false,
                    NextPageUrl     = baseUrl + $"/api/contractReminders?reminderInterval={reminderInterval}&pageNumber={pageNumber}&pageSize={pageSize}&sort={sort}&order={order}",
                    PageSize        = pageSize,
                    PreviousPageUrl = string.Empty,
                    TotalCount      = 2,
                    TotalPages      = 2
                }
            };

            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 result = await service.GetContractRemindersAsync(reminderInterval, pageNumber, pageSize, sort, order, routeTemplateUrl);

            //Assert
            result.Should().BeEquivalentTo(expected);
        }
        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);
        }