public void ShouldMapFromFirmStatisticsDto() { var dto = new FirmStatisticsDto { ProjectId = 1, Firms = new[] { new FirmStatisticsDto.FirmDto { FirmId = 2, Categories = new[] { new FirmStatisticsDto.FirmDto.CategoryDto { CategoryId = 3, Hits = 4, Shows = 5 } } } } }; var entities = Specs.Map.Bit.FirmCategoryStatistics().Map(dto); Assert.That(entities.Count(), Is.EqualTo(1)); Assert.That(entities.Single().ProjectId, Is.EqualTo(1)); Assert.That(entities.Single().CategoryId, Is.EqualTo(3)); Assert.That(entities.Single().FirmId, Is.EqualTo(2)); Assert.That(entities.Single().Hits, Is.EqualTo(4)); Assert.That(entities.Single().Shows, Is.EqualTo(5)); }
public void ShouldProduceCalculateStatisticsOperationForFirmStatisticsDto() { // Arrange var repositoryFactory = new VerifiableRepositoryFactory(); var dto = new FirmStatisticsDto { ProjectId = 1, Firms = new[] { new FirmStatisticsDto.FirmDto { FirmId = 2, Categories = new[] { new FirmStatisticsDto.FirmDto.CategoryDto { CategoryId = 3, Hits = 4, Shows = 5 } } } } }; SourceDb.Has(new Bit::FirmCategoryStatistics { ProjectId = 1, FirmId = 7 }, new Bit::FirmCategoryStatistics { ProjectId = 2, FirmId = 8 }); var metadataSource = new ImportStatisticsMetadataSource(); IMetadataElement importStatisticsMetadata; if (!metadataSource.Metadata.Values.TryGetElementById(new Uri(typeof(FirmStatisticsDto).Name, UriKind.Relative), out importStatisticsMetadata)) { throw new NotSupportedException($"The aggregate of type '{typeof(FirmStatisticsDto).Name}' is not supported."); } var importer = new StatisticsFactImporter<Bit::FirmCategoryStatistics, FirmStatisticsDto>( (ImportStatisticsMetadata<Bit::FirmCategoryStatistics, FirmStatisticsDto>)importStatisticsMetadata, Query, repositoryFactory.Create<Bit::FirmCategoryStatistics>()); // Act var operations = importer.Import(dto).ToArray(); // Assert Assert.That(operations.Count(), Is.EqualTo(1)); repositoryFactory.Verify<Bit::FirmCategoryStatistics>( m => m.Delete(It.Is(Predicate.Match(new Bit::FirmCategoryStatistics { ProjectId = 1, FirmId = 7 }))), Times.AtLeastOnce); repositoryFactory.Verify<Bit::FirmCategoryStatistics>( m => m.Add(It.Is(Predicate.Match(new Bit::FirmCategoryStatistics { ProjectId = 1, FirmId = 2, CategoryId = 3, Hits = 4, Shows = 5 }))), Times.AtLeastOnce); }