public IList <T> ToObjects <T>(DataRow[] dataRows, IDataTypeConverter dataTypeConverter, ExtendedPropertyInfo[] mappings, DataTableParserSettings settings) { Guard.ArgumentNotNull(dataRows); Guard.ArgumentNotNull(dataTypeConverter); Guard.ArgumentNotNull(mappings); Guard.ArgumentNotNull(settings); List <T> objectList = new List <T>(capacity: dataRows.Length); var dbNullConverter = new DbNullConverter(settings); IEnumerable <DelegateColumnMapping <T> > delegates = GetDelegatesForType <T>(mappings); for (int rowIndex = 0; rowIndex < dataRows.Length; rowIndex++) { T returnObject = ObjectInstantiator <T> .CreateNew(); foreach (var setterDelegate in delegates) { object value = dataTypeConverter.FieldToObject(dataRows[rowIndex][setterDelegate.ExtendedPropertyInfo.ColumnIndex], setterDelegate.ExtendedPropertyInfo.PropertyInfo.PropertyType, settings, dbNullConverter); setterDelegate.SetterDelegate(returnObject, value); } objectList.Add(returnObject); } return(objectList); }
private PricingStructure GetPricingStructure() { var pricingStructure = ObjectInstantiator <PricingStructure> .CreateNew(); ObjectInstantiator <PricingStructure> .SetProperty(x => x.CompetentAuthority, UKCompetentAuthority.England, pricingStructure); var activity = A.Fake <Activity>(); ObjectInstantiator <Activity> .SetProperty(x => x.TradeDirection, TradeDirection.Export, activity); ObjectInstantiator <Activity> .SetProperty(x => x.NotificationType, NotificationType.Recovery, activity); ObjectInstantiator <Activity> .SetProperty(x => x.IsInterim, false, activity); ObjectInstantiator <PricingStructure> .SetProperty(x => x.Activity, activity, pricingStructure); var shipmentQuantityRange = A.Fake <ShipmentQuantityRange>(); ObjectInstantiator <ShipmentQuantityRange> .SetProperty(x => x.RangeFrom, LowerRange, shipmentQuantityRange); ObjectInstantiator <ShipmentQuantityRange> .SetProperty(x => x.RangeTo, UpperRange, shipmentQuantityRange); ObjectInstantiator <PricingStructure> .SetProperty(x => x.ShipmentQuantityRange, shipmentQuantityRange, pricingStructure); ObjectInstantiator <PricingStructure> .SetProperty(x => x.Price, NotificationPrice, pricingStructure); return(pricingStructure); }
public virtual IList <T> ToObjects <T>(DataRow[] dataRows, IDataTypeConverter dataTypeConverter, ExtendedPropertyInfo[] mappings, DataTableParserSettings settings) { Guard.ArgumentNotNull(dataRows); Guard.ArgumentNotNull(dataTypeConverter); Guard.ArgumentNotNull(mappings); Guard.ArgumentNotNull(settings); var dbNullConverter = GetDbNullConverter(settings); var objectList = new T[dataRows.Length]; for (int rowIndex = 0; rowIndex < dataRows.Length; rowIndex++) { var returnObject = ObjectInstantiator <T> .CreateNew(); foreach (var mapping in mappings) { object value = dataTypeConverter.FieldToObject(dataRows[rowIndex][mapping.ColumnIndex], mapping.PropertyInfo.PropertyType, settings, dbNullConverter); mapping.PropertyInfo.SetValue(returnObject, value); } objectList[rowIndex] = returnObject; } return(objectList); }
public IList <T> ToObjects <T>(DataRow[] dataRows, IDataTypeConverter dataTypeConverter, ExtendedPropertyInfo[] mappings, DataTableParserSettings settings) { Guard.ArgumentNotNull(dataRows); Guard.ArgumentNotNull(dataTypeConverter); Guard.ArgumentNotNull(mappings); Guard.ArgumentNotNull(settings); ConcurrentBag <T> objectList = new ConcurrentBag <T>(); var dbNullConverter = new DbNullConverter(settings); Parallel.For(0, dataRows.Length, (rowIndex) => { T returnObject = ObjectInstantiator <T> .CreateNew(); foreach (var mapping in mappings) { object value = dataTypeConverter.FieldToObject(dataRows[rowIndex][mapping.ColumnIndex], mapping.PropertyInfo.PropertyType, settings, dbNullConverter); mapping.PropertyInfo.SetValue(returnObject, value); } objectList.Add(returnObject); }); return(objectList.ToList()); }
private CompetentAuthority GetTestCompetentAuthority(Country country) { var competentAuthority = ObjectInstantiator <CompetentAuthority> .CreateNew(); ObjectInstantiator <CompetentAuthority> .SetProperty(x => x.Country, country, competentAuthority); return(competentAuthority); }
private Country GetTestCountry(Guid id) { var country = ObjectInstantiator <Country> .CreateNew(); ObjectInstantiator <Country> .SetProperty(x => x.Id, id, country); return(country); }
private ImportNotification CreateImportNotification(NotificationType notificationType, Guid importNotificationId) { var instance = ObjectInstantiator <ImportNotification> .CreateNew(); EntityHelper.SetEntityId(instance, importNotificationId); ObjectInstantiator <ImportNotification> .SetProperty(x => x.NotificationType, notificationType, instance); return(instance); }
private EntryOrExitPoint GetTestEntryOrExitPoint(Country country, Guid?id = null) { var entryOrExitPoint = ObjectInstantiator <EntryOrExitPoint> .CreateNew(); ObjectInstantiator <EntryOrExitPoint> .SetProperty(x => x.Country, country, entryOrExitPoint); if (id != null) { ObjectInstantiator <EntryOrExitPoint> .SetProperty(x => x.Id, (Guid)id, entryOrExitPoint); } return(entryOrExitPoint); }
private static WasteCode GetTestWasteCode(Guid id, CodeType codeType) { var wasteCode = ObjectInstantiator <WasteCode> .CreateNew(); ObjectInstantiator <WasteCode> .SetProperty(x => x.Id, id, wasteCode); ObjectInstantiator <WasteCode> .SetProperty(x => x.CodeType, codeType, wasteCode); ObjectInstantiator <WasteCode> .SetProperty(x => x.Code, id.ToString(), wasteCode); ObjectInstantiator <WasteCode> .SetProperty(x => x.Description, id.ToString(), wasteCode); return(wasteCode); }
private WasteCode AnyWasteCode(CodeType codeType) { var wasteCode = ObjectInstantiator <WasteCode> .CreateNew(); ObjectInstantiator <WasteCode> .SetProperty(x => x.Id, new Guid("0C4D98DA-91F3-4F5D-922B-C7A6BE8B5008"), wasteCode); ObjectInstantiator <WasteCode> .SetProperty(x => x.Code, "WasteCode", wasteCode); ObjectInstantiator <WasteCode> .SetProperty(x => x.CodeType, codeType, wasteCode); ObjectInstantiator <WasteCode> .SetProperty(x => x.Description, "Description", wasteCode); return(wasteCode); }
public void StateOfExport_CountriesDifferent_Throws(string countryId, string competentAuthorityCountryId, string exitCountryId) { var country = GetTestCountry(new Guid(countryId)); var competentAuthority = ObjectInstantiator <CompetentAuthority> .CreateNew(); ObjectInstantiator <CompetentAuthority> .SetProperty(x => x.Country, GetTestCountry(new Guid(competentAuthorityCountryId)), competentAuthority); var exitPoint = ObjectInstantiator <EntryOrExitPoint> .CreateNew(); ObjectInstantiator <EntryOrExitPoint> .SetProperty(x => x.Country, GetTestCountry(new Guid(exitCountryId)), exitPoint); Assert.Throws <InvalidOperationException>(() => new StateOfExport(country, competentAuthority, exitPoint)); }
private Country GetTestCountry(Guid id, string name) { if (string.IsNullOrEmpty(name)) { return(null); } var country = ObjectInstantiator <Country> .CreateNew(); ObjectInstantiator <Country> .SetProperty(x => x.Id, id, country); ObjectInstantiator <Country> .SetProperty(x => x.Name, name, country); return(country); }
public void StateOfExport_AllCountriesMatch_ReturnsNewStateOfExport() { var country = GetTestCountry(Guid.Empty); var competentAuthority = ObjectInstantiator <CompetentAuthority> .CreateNew(); ObjectInstantiator <CompetentAuthority> .SetProperty(x => x.Country, country, competentAuthority); var exitPoint = ObjectInstantiator <EntryOrExitPoint> .CreateNew(); ObjectInstantiator <EntryOrExitPoint> .SetProperty(x => x.Country, country, exitPoint); var stateOfExport = new StateOfExport(country, competentAuthority, exitPoint); Assert.NotNull(stateOfExport); }
public WorkingDayCalculatorTests() { context = new TestIwsContext(); var bankHoliday = ObjectInstantiator <BankHoliday> .CreateNew(); ObjectInstantiator <BankHoliday> .SetProperty(bh => bh.CompetentAuthority, UKCompetentAuthority.England, bankHoliday); ObjectInstantiator <BankHoliday> .SetProperty(bh => bh.Date, Tuesday14thJuly2015BankHoliday, bankHoliday); var secondBankHoliday = ObjectInstantiator <BankHoliday> .CreateNew(); ObjectInstantiator <BankHoliday> .SetProperty(bh => bh.CompetentAuthority, UKCompetentAuthority.England, secondBankHoliday); ObjectInstantiator <BankHoliday> .SetProperty(bh => bh.Date, Friday24thJuly2015BankHoliday, secondBankHoliday); context.BankHolidays.AddRange(new[] { bankHoliday, secondBankHoliday }); calculator = new WorkingDayCalculator(context); }