Exemplo n.º 1
0
        public void Get_document_changes_from_multiple_data_sources()
        {
            var mockOperationsLogs = new[]
            {
                new OperationLogEntity {
                    ModifiedDate = new DateTime(2018, 11, 01), ObjectId = "1", ObjectType = nameof(PriceEntity)
                },
                new OperationLogEntity {
                    ModifiedDate = new DateTime(2018, 11, 01), ObjectId = "2", ObjectType = nameof(PriceEntity)
                },
                new OperationLogEntity {
                    ModifiedDate = new DateTime(2018, 11, 01), ObjectId = "3", ObjectType = nameof(PriceEntity)
                },
            };
            var mockPrices = new PriceEntity[] {
                //Without from/till dates (unbounded)
                new PriceEntity {
                    Id = "1", ProductId = "1"
                },
                //Without from date (unbounded)
                new PriceEntity {
                    Id = "2", ProductId = "2", EndDate = new DateTime(2018, 06, 01)
                },
                //Without till date (bounded)
                new PriceEntity {
                    Id = "3", ProductId = "3", StartDate = new DateTime(2018, 06, 01)
                },
                //with from/till dates (bounded)
                new PriceEntity {
                    Id = "4", ProductId = "4", StartDate = new DateTime(2018, 06, 01), EndDate = new DateTime(2018, 12, 01)
                }
            }.AsQueryable().BuildMock();
            var mockPricingRepository = new Mock <IPricingRepository>();

            mockPricingRepository.SetupGet(x => x.Prices).Returns(mockPrices.Object);
            mockPricingRepository.Setup(x => x.GetPricesByIdsAsync(It.IsAny <string[]>())).ReturnsAsync(mockPrices.Object.ToArray());
            var mockPlatformRepository = new Mock <IPlatformRepository>();

            mockPlatformRepository.SetupGet(x => x.OperationLogs).Returns(mockOperationsLogs.AsQueryable());
            var mockSettingManager = new Mock <ISettingsManager>();

            mockSettingManager.Setup(s => s.GetObjectSettingAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new ObjectSettingEntry()
            {
                Value = DateTime.MinValue
            });
            var mockChangeLogSearchService = new Mock <IChangeLogSearchService>();

            mockChangeLogSearchService.Setup(x => x.SearchAsync(It.IsAny <ChangeLogSearchCriteria>()))
            .ReturnsAsync(new ChangeLogSearchResult {
                Results = mockOperationsLogs.Select(o => o.ToModel(AbstractTypeFactory <OperationLog> .TryCreateInstance())).ToList()
            });
            var changesProvider = new ProductPriceDocumentChangesProvider(mockChangeLogSearchService.Object, mockSettingManager.Object, () => mockPricingRepository.Object);

            var startDate  = new DateTime(2018, 06, 01);
            var endDate    = new DateTime(2018, 12, 01);
            var totalCount = changesProvider.GetTotalChangesCountAsync(startDate, endDate).GetAwaiter().GetResult();
            var changes    = changesProvider.GetChangesAsync(startDate, endDate, 0, 5).GetAwaiter().GetResult();

            Assert.Equal(5, totalCount);
            Assert.Equal(new[] { "1", "2", "3", "3", "4" }, changes.Select(x => x.DocumentId));
            //Do not return calendar changes for not determined date interval
            changes = changesProvider.GetChangesAsync(startDate, null, 0, 5).GetAwaiter().GetResult();
            Assert.Equal(new[] { "1", "2", "3" }, changes.Select(x => x.DocumentId));

            mockSettingManager.Setup(s => s.GetObjectSettingAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new ObjectSettingEntry()
            {
                Value = DateTime.MinValue
            });
            //Paginated request for  multiple data sources (skip 2 from OperationLogEntity and take 3 from both data sources (OperationLogEntity, CalendarChanges))
            changes = changesProvider.GetChangesAsync(startDate, endDate, 2, 3).GetAwaiter().GetResult();
            Assert.Equal(new[] { "3", "3", "4" }, changes.Select(x => x.DocumentId));
        }
Exemplo n.º 2
0
        public void Get_document_changes_from_multiple_data_sources()
        {
            var mockOperationsLogs = new[]
            {
                new OperationLogEntity {
                    ModifiedDate = new DateTime(2018, 11, 01), ObjectId = "1", ObjectType = nameof(PriceEntity)
                },
                new OperationLogEntity {
                    ModifiedDate = new DateTime(2018, 11, 01), ObjectId = "2", ObjectType = nameof(PriceEntity)
                },
                new OperationLogEntity {
                    ModifiedDate = new DateTime(2018, 11, 01), ObjectId = "3", ObjectType = nameof(PriceEntity)
                },
            };
            var mockPrices = new[] {
                //Without from/till dates (unbounded)
                new PriceEntity {
                    Id = "1", ProductId = "1"
                },
                //Without from date (unbounded)
                new PriceEntity {
                    Id = "2", ProductId = "2", EndDate = new DateTime(2018, 06, 01)
                },
                //Without till date (bounded)
                new PriceEntity {
                    Id = "3", ProductId = "3", StartDate = new DateTime(2018, 06, 01)
                },
                //with from/till dates (bounded)
                new PriceEntity {
                    Id = "4", ProductId = "4", StartDate = new DateTime(2018, 06, 01), EndDate = new DateTime(2018, 12, 01)
                }
            };
            var mockPricingRepository = new Mock <IPricingRepository>();

            mockPricingRepository.SetupGet(x => x.Prices).Returns(mockPrices.AsQueryable());
            mockPricingRepository.Setup(x => x.GetPricesByIds(It.IsAny <string[]>())).Returns((string[] ids) => ids.Select(x => new PriceEntity {
                ProductId = x
            }).ToArray());
            var mockPlatformRepository = new Mock <IPlatformRepository>();

            mockPlatformRepository.SetupGet(x => x.OperationLogs).Returns(mockOperationsLogs.AsQueryable());
            var mockSettingManager = new Mock <ISettingsManager>();

            mockSettingManager.Setup(x => x.GetValue(It.IsAny <string>(), It.IsAny <string>())).Returns(DateTime.MinValue.ToString());
            var changesProvider = new ProductPriceDocumentChangesProvider(() => mockPricingRepository.Object, () => mockPlatformRepository.Object, mockSettingManager.Object);

            var startDate  = new DateTime(2018, 06, 01);
            var endDate    = new DateTime(2018, 12, 01);
            var totalCount = changesProvider.GetTotalChangesCountAsync(startDate, endDate).GetAwaiter().GetResult();
            var changes    = changesProvider.GetChangesAsync(startDate, endDate, 0, 5).GetAwaiter().GetResult();

            Assert.Equal(5, totalCount);
            Assert.Equal(new[] { "1", "2", "3", "3", "4" }, changes.Select(x => x.DocumentId));
            //Do not return calendar changes for not determined date interval
            changes = changesProvider.GetChangesAsync(startDate, null, 0, 5).GetAwaiter().GetResult();
            Assert.Equal(new[] { "1", "2", "3" }, changes.Select(x => x.DocumentId));

            //Paginated request for  multiple data sources (skip 2 from OperationLogEntity and take 3 from both data sources (OperationLogEntity, CalendarChanges))
            changes = changesProvider.GetChangesAsync(startDate, endDate, 2, 3).GetAwaiter().GetResult();
            Assert.Equal(new[] { "3", "3", "4" }, changes.Select(x => x.DocumentId));
        }