public void FormattingADisputeCollectionAsHal_WithValidDisputesModelCollection_ReturnsExpectedCollection()
        {
            // Arrange
            const int numberOfItemsInCollection = 1000;
            const int numberOfPagesInCollection = 100;
            const int currentPage = 20;

            var collectionKey         = DomainResources.Disputes.ToLowerInvariant();
            var mockedRequestReader   = new Mock <IRequestReader>();
            var mockedAddressResolver = new Mock <IAddressResolver>();
            var mockedPagingLinks     = new Mock <IPagingLinks>();

            var disputes           = new List <DisputeModel>();
            var disputesCollection = new CollectionResource <DisputeModel>(
                new CollectionResourceInfo(numberOfItemsInCollection, numberOfPagesInCollection, currentPage), disputes);

            mockedPagingLinks
            .Setup(pagingLinks => pagingLinks.GetPagingLinks(It.IsAny <Uri>(), currentPage, numberOfPagesInCollection))
            .Returns(new List <Link>());

            var responseObject =
                new DisputeCollectionResponse(
                    mockedAddressResolver.Object,
                    mockedPagingLinks.Object,
                    mockedRequestReader.Object);

            var resultsToFormat = DisputeTestData.CreateDisputeActuals();

            // Act
            var halFormattedResponse = responseObject.FormatForHal(disputesCollection);

            // Assert
            halFormattedResponse.ShouldHaveEmbeddedCollection(collectionKey, resultsToFormat);
        }
        public async Task UsingGetAllAsync_WithDisplayedFilter_ReturnsExpectedRecords()
        {
            // Arrange
            var pageInformation   = new PageInformation(1, 100);
            var expectedRecords   = DisputeTestData.CreateDisputeExpecteds().Where(dispute => dispute.Displayed.Value);
            var insolvencyRecords = InsolvenciesTestData.CreateInsolvenciesActuals();
            var disputeRecords    = DisputeTestData.CreateDisputeActuals();
            var context           = TestDbContext.CreateContextWithSeededData(insolvencyRecords).Seed(disputeRecords);

            var operationDateProvider = new Mock <IOperationDateProvider>();

            operationDateProvider.Setup(x => x.GetOperationDate()).Returns(DateTime.Now);

            IOptions <RetentionOptions> retentionOptions =
                new ConfigurationOption(
                    new RetentionOptions()
            {
                RetentionPeriod = 10,
                CutOffPeriod    = 6
            });

            var disputesFilteredBaseData = new DisputeFilterContext(retentionOptions, operationDateProvider.Object);

            var disputeRepository = new DisputesRepository(context, disputesFilteredBaseData, mockTelemetryClient.Object);

            // Act
            var actualRecords = await disputeRepository.GetAllAsync(pageInformation);

            // Assert
            CollectionAssert.AreEqual(
                expectedRecords.OrderBy(x => x.DisputeId).ToList(),
                actualRecords.OrderBy(x => x.DisputeId).ToList(),
                new DisputeModelComparer());
        }
        public async Task GettingAllRecords_WithPageInformation_ReturnsExpectedNumberOfRecords(
            int currentPage,
            int pageSize,
            int expected)
        {
            // Arrange
            var pageInformation   = new PageInformation(currentPage, pageSize);
            var insolvencyRecords = InsolvenciesTestData.CreateInsolvenciesActuals();
            var disputeRecords    = DisputeTestData.CreateDisputeActuals();
            var context           = TestDbContext.CreateContextWithSeededData(insolvencyRecords).Seed(disputeRecords);

            var operationDateProvider = new Mock <IOperationDateProvider>();

            operationDateProvider.Setup(x => x.GetOperationDate()).Returns(DateTime.Now);

            IOptions <RetentionOptions> retentionOptions =
                new ConfigurationOption(
                    new RetentionOptions()
            {
                RetentionPeriod = 10,
                CutOffPeriod    = 6
            });

            var disputesFilteredBaseData = new DisputeFilterContext(retentionOptions, operationDateProvider.Object);

            var disputeRepository = new DisputesRepository(context, disputesFilteredBaseData, mockTelemetryClient.Object);

            // Act
            var actualCount = (await disputeRepository.GetAllAsync(pageInformation)).Count();

            // Assert
            Assert.AreEqual(expected, actualCount);
        }
        public async Task CountingRecordsById_WithSeededDisputeRecords_ReturnsCorrectCount()
        {
            // Arrange
            const int recordId          = 1;
            const int expectedCount     = 1;
            var       insolvencyRecords = InsolvenciesTestData.CreateInsolvenciesActuals();
            var       disputeRecords    = DisputeTestData.CreateDisputeActuals();
            var       context           = TestDbContext.CreateContextWithSeededData(insolvencyRecords).Seed(disputeRecords);

            var operationDateProvider = new Mock <IOperationDateProvider>();

            operationDateProvider.Setup(x => x.GetOperationDate()).Returns(DateTime.Now);

            IOptions <RetentionOptions> retentionOptions =
                new ConfigurationOption(
                    new RetentionOptions()
            {
                RetentionPeriod = 10,
                CutOffPeriod    = 6
            });

            var disputesFilteredBaseData = new DisputeFilterContext(retentionOptions, operationDateProvider.Object);

            var disputeRepository = new DisputesRepository(context, disputesFilteredBaseData, mockTelemetryClient.Object);

            // Act
            var actualCount = await disputeRepository.CountByAsync(recordId, record => record.DisputeId);

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
        }
        public async Task GettingRecordsByInsolvencyOrderId_WithPageInformation_ReturnsMappedModels(
            int currentPage,
            int pageSize,
            int insolvencyOrderId)
        {
            // Arrange
            var pageInformation   = new PageInformation(currentPage, pageSize);
            var expecteds         = DisputeTestData.GetExpectedsByInsolvencyOrderId(pageInformation, insolvencyOrderId);
            var insolvencyRecords = InsolvenciesTestData.CreateInsolvenciesActuals();
            var disputeRecords    = DisputeTestData.CreateDisputeActuals();
            var context           = TestDbContext.CreateContextWithSeededData(insolvencyRecords).Seed(disputeRecords);

            var operationDateProvider = new Mock <IOperationDateProvider>();

            operationDateProvider.Setup(x => x.GetOperationDate()).Returns(DateTime.Now);

            IOptions <RetentionOptions> retentionOptions =
                new ConfigurationOption(
                    new RetentionOptions()
            {
                RetentionPeriod = 10,
                CutOffPeriod    = 6
            });

            var disputesFilteredBaseData = new DisputeFilterContext(retentionOptions, operationDateProvider.Object);

            var disputeRepository = new DisputesRepository(context, disputesFilteredBaseData, mockTelemetryClient.Object);

            // Act
            var actuals =
                await disputeRepository.GetResultsByAsync(
                    insolvencyOrderId,
                    record => record.InsolvencyOrderDisputes.FirstOrDefault().InsolvencyOrderId,
                    pageInformation);

            // Assert
            CollectionAssert.AreEqual(
                expecteds.OrderBy(x => x.DisputeId).ToList(),
                actuals.OrderBy(x => x.DisputeId).ToList(),
                new DisputeModelComparer());
        }
        public async Task GettingRecordById_WithSeededDisputeRecords_ReturnsMappedModel()
        {
            // Arrange
            const int recordId = 1;

            var expectedRecord    = DisputeTestData.GetDisputeById(recordId);
            var insolvencyRecords = InsolvenciesTestData.CreateInsolvenciesActuals();
            var disputeRecords    = DisputeTestData.CreateDisputeActuals();
            var context           = TestDbContext.CreateContextWithSeededData(insolvencyRecords).Seed(disputeRecords);

            var operationDateProvider = new Mock <IOperationDateProvider>();

            operationDateProvider.Setup(x => x.GetOperationDate()).Returns(DateTime.Now);

            IOptions <RetentionOptions> retentionOptions =
                new ConfigurationOption(
                    new RetentionOptions()
            {
                RetentionPeriod = 10,
                CutOffPeriod    = 6
            });

            var disputesFilteredBaseData = new DisputeFilterContext(retentionOptions, operationDateProvider.Object);

            var disputeRepository = new DisputesRepository(context, disputesFilteredBaseData, mockTelemetryClient.Object);

            // Act
            var actualRecord = await disputeRepository.GetResultByAsync(recordId, record => record.DisputeId);

            // Assert
            Assert.AreEqual(expectedRecord.InsolvencyOrderId, actualRecord.InsolvencyOrderId);
            Assert.AreEqual(expectedRecord.DateRaised, actualRecord.DateRaised);
            Assert.AreEqual(expectedRecord.Displayed, actualRecord.Displayed);
            Assert.AreEqual(expectedRecord.DisputeId, actualRecord.DisputeId);
            Assert.AreEqual(expectedRecord.ReferenceNumber, actualRecord.ReferenceNumber);
        }