public void ShouldProcessFirmCategoryForecastFromFirmForecastDto() { // Arrange var repositoryFactory = new VerifiableRepositoryFactory(); var dto = new FirmForecastDto { ProjectId = 1, Firms = new[] { new FirmForecastDto.FirmDto { Id = 1, ForecastClick = 1, ForecastAmount = 1, Categories = new[] { new FirmForecastDto.CategoryDto { Id = 1, ForecastAmount = 1, ForecastClick = 1, } } } } }; SourceDb.Has(new Bit::FirmCategoryForecast { ProjectId = 1, FirmId = 1, CategoryId = 1 }, new Bit::FirmCategoryForecast { ProjectId = 2, FirmId = 2, CategoryId = 1 }); var importer = CreateProcessor <FirmForecastDto, Bit::FirmCategoryForecast>(repositoryFactory); // Act var operations = importer.Import(dto).ToArray(); // Assert Assert.That(operations.Count(), Is.EqualTo(1)); repositoryFactory.Verify <Bit::FirmCategoryForecast>( m => m.Delete(It.Is(Predicate.Match(new Bit::FirmCategoryForecast { ProjectId = 1, FirmId = 1, CategoryId = 1 }))), Times.AtLeastOnce); repositoryFactory.Verify <Bit::FirmCategoryForecast>( m => m.Delete(It.Is(Predicate.Match(new Bit::FirmCategoryForecast { ProjectId = 2, FirmId = 2, CategoryId = 1 }))), Times.Never); repositoryFactory.Verify <Bit::FirmCategoryForecast>( m => m.Add(It.Is(Predicate.Match(new Bit::FirmCategoryForecast { ProjectId = 1, FirmId = 1, CategoryId = 1, ForecastClick = 1, ForecastAmount = 1 }))), Times.AtLeastOnce); }
public bool TryParse(XElement xml, out IDataTransferObject dto) { try { dto = new FirmForecastDto { ProjectId = (long)xml.Attribute("BranchCode"), Firms = ParseFirms(xml.Descendants("Firm")) }; return(true); } catch (Exception) { dto = null; return(false); } }