public void ProvinceCollectionCanGet() { ProvinceCollection col = new ProvinceCollection(); col.Add(new Province(1)); col.Add(new Province(2)); Assert.That(col.Get(1).Id, Is.EqualTo(1)); }
public void ProvinceCollectionUniqueIds() { ProvinceCollection pc = new ProvinceCollection(); pc.Add(new SaveProvince(1)); Assert.Throws <ArgumentException>(() => pc.Add(new SaveProvince(1))); }
public void ProvinceCollectionCanAdd() { ProvinceCollection col = new ProvinceCollection(); col.Add(new Province(1)); col.Add(new Province(2)); Assert.That(col.Count(), Is.EqualTo(2)); }
public void ProvinceCollectionGetCorrectGaps() { ProvinceCollection pc = new ProvinceCollection(); pc.Add(new SaveProvince(3)); pc.Add(new SaveProvince(5)); pc.Add(new SaveProvince(1)); CollectionAssert.AreEqual(new[] { 1, 3, 5 }, pc.Select(x => x.Id)); Assert.AreEqual(1, pc.Get(1).Id); Assert.AreEqual(3, pc.Get(3).Id); Assert.AreEqual(5, pc.Get(5).Id); }
public void ProvinceCollectionGetCorrectOutOfOrder() { ProvinceCollection pc = new ProvinceCollection(); pc.Add(new SaveProvince(2)); pc.Add(new SaveProvince(3)); pc.Add(new SaveProvince(1)); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, pc.Select(x => x.Id)); Assert.AreEqual(1, pc.Get(1).Id); Assert.AreEqual(2, pc.Get(2).Id); Assert.AreEqual(3, pc.Get(3).Id); }
public ITaxMethod BuildEntity(TaxMethodDto dto) { var deserialized = JsonConvert.DeserializeObject <ProvinceCollection <TaxProvince> >(dto.ProvinceData); var provinces = new ProvinceCollection <ITaxProvince>(); foreach (var p in deserialized) { provinces.Add(p); } var countryTaxRate = new TaxMethod(dto.ProviderKey, dto.CountryCode) { Key = dto.Key, Name = dto.Name, PercentageTaxRate = dto.PercentageTaxRate, Provinces = provinces, ProductTaxMethod = dto.ProductTaxMethod, UpdateDate = dto.UpdateDate, CreateDate = dto.CreateDate }; countryTaxRate.ResetDirtyProperties(); return(countryTaxRate); }
public IShipMethod BuildEntity(ShipMethodDto dto) { var deserialized = JsonConvert.DeserializeObject <ProvinceCollection <ShipProvince> >(dto.ProvinceData); // TODO : fix this mapping var provinces = new ProvinceCollection <IShipProvince>(); foreach (var p in deserialized) { provinces.Add(p); } var shipMethod = new ShipMethod(dto.ProviderKey, dto.ShipCountryKey) { Key = dto.Key, Name = dto.Name, Surcharge = dto.Surcharge, ServiceCode = dto.ServiceCode, Taxable = dto.Taxable, Provinces = provinces, UpdateDate = dto.UpdateDate, CreateDate = dto.CreateDate }; shipMethod.ResetDirtyProperties(); return(shipMethod); }
public void AddRecordToRepo(Province p) { if (p == null) { throw new ArgumentNullException("Error: The argument is Null"); } ProvinceCollection.Add(p); }
/// <summary> /// Maps changes made in the <see cref="FixedRateShipMethodDisplay"/> to the <see cref="IFixedRateShippingGatewayMethod"/> /// </summary> /// <param name="fixedRateShipMethodDisplay">The <see cref="FixedRateShipMethodDisplay"/> to map</param> /// <param name="destination">The <see cref="IFixedRateShippingGatewayMethod"/> to have changes mapped to</param> /// <returns>The updated <see cref="IFixedRateShippingGatewayMethod"/></returns> /// <remarks> /// /// Note: after calling this mapping, the changes are still not persisted to the database as the .Save() method is not called. /// /// * For testing you will have to use the static .Save(IGatewayProviderService ..., as MerchelloContext.Current will likely be null /// /// </remarks> internal static IFixedRateShippingGatewayMethod ToFixedRateShipMethod(this FixedRateShipMethodDisplay fixedRateShipMethodDisplay, IFixedRateShippingGatewayMethod destination) { // RUSTY HELP: Cannot assign to these properties. How should I do this mapping? // Shipmethod destination.ShipMethod.Name = fixedRateShipMethodDisplay.ShipMethod.Name; if (destination.ShipMethod.Provinces.Any() && fixedRateShipMethodDisplay.ShipMethod.Provinces.Any()) { var provinceCollection = new ProvinceCollection <IShipProvince>(); foreach (var province in fixedRateShipMethodDisplay.ShipMethod.Provinces) { provinceCollection.Add( new ShipProvince(province.Code, province.Name) { AllowShipping = province.AllowShipping, RateAdjustment = province.RateAdjustment, RateAdjustmentType = province.RateAdjustmentType } ); } destination.ShipMethod.Provinces = provinceCollection; } // Rate table var existingRows = fixedRateShipMethodDisplay.RateTable.Rows.Where(x => !x.Key.Equals(Guid.Empty)).ToArray(); foreach (var mapRow in existingRows) { var row = destination.RateTable.Rows.FirstOrDefault(x => x.Key == mapRow.Key); if (row != null) { row.Rate = mapRow.Rate; } } // remove existing rows that previously existed but were deleted in the UI var removers = destination.RateTable.Rows.Where( row => !row.Key.Equals(Guid.Empty) && existingRows.All(x => x.Key != row.Key && !x.Key.Equals(Guid.Empty))); foreach (var remove in removers) { destination.RateTable.DeleteRow(remove); } // add any new rows foreach (var newRow in fixedRateShipMethodDisplay.RateTable.Rows.Where(x => x.Key == Guid.Empty)) { destination.RateTable.AddRow(newRow.RangeLow, newRow.RangeHigh, newRow.Rate); } return(destination); }
/// <summary> /// Converts a collection of <see cref="IProvince"/> to a new collection of <see cref="ITaxProvince"/> /// </summary> /// <param name="provinces">A collection of <see cref="IProvince"/></param> /// <returns>A collection of <see cref="ITaxProvince"/></returns> public static ProvinceCollection<ITaxProvince> ToTaxProvinceCollection(this IEnumerable<IProvince> provinces) { var provinceCollection = new ProvinceCollection<ITaxProvince>(); foreach (var p in provinces) { provinceCollection.Add(new TaxProvince(p.Code, p.Name)); } return provinceCollection; }
public static ProvinceCollection GetProvinces() { ProvinceCollection provinces; using (SqlConnection conn = new SqlConnection(connString)) { string query = $@"SELECT ProvinceId, Sort, Abbreviation, Name FROM {provinceTableName} ORDER BY Abbreviation"; using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = query; cmd.Connection = conn; conn.Open(); provinces = new ProvinceCollection(); using (SqlDataReader reader = cmd.ExecuteReader()) { int provinceId; int sort; string abbreviation; string name = null; while (reader.Read()) { provinceId = (int)reader["ProvinceId"]; sort = (int)reader["Sort"]; abbreviation = reader["Abbreviation"] as string; if (!reader.IsDBNull(3)) { name = reader["Name"] as string; } provinces.Add(new Province { ProvinceId = provinceId, Sort = sort, Abbreviation = abbreviation, Name = name }); name = null; } } return(provinces); } } }
/// <summary> /// Converts a collection of <see cref="IProvince"/> to a new collection of <see cref="ITaxProvince"/> /// </summary> /// <param name="provinces">A collection of <see cref="IProvince"/></param> /// <returns>A collection of <see cref="ITaxProvince"/></returns> public static ProvinceCollection <ITaxProvince> ToTaxProvinceCollection(this IEnumerable <IProvince> provinces) { var provinceCollection = new ProvinceCollection <ITaxProvince>(); foreach (var p in provinces) { provinceCollection.Add(new TaxProvince(p.Code, p.Name)); } return(provinceCollection); }
/// <summary> /// Loads a collection of Province objects from the database. /// </summary> /// <returns>A collection containing all of the Province objects in the database.</returns> public static ProvinceCollection LoadCollection(string spName, SqlParameter[] parms) { ProvinceCollection result = new ProvinceCollection(); using (SqlDataReader reader = SqlHelper.Default.ExecuteReader(spName, parms)) { while (reader.Read()) { Province tmp = new Province(); tmp.LoadFromReader(reader); result.Add(tmp); } } return(result); }
//get all province from customer database public static ProvinceCollection GetProvince() { ProvinceCollection customerProvince; //connect to database using (SqlConnection conn = new SqlConnection(connString)) { //query to retrieve Provice from Customer table string query = @"SELECT Province From Customer GROUP BY province WITH ROLLUP"; using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = query; cmd.Connection = conn; conn.Open(); customerProvince = new ProvinceCollection(); //read data using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { string provinceName = null; if (!reader.IsDBNull(0)) { provinceName = reader["Province"] as string; } else { provinceName = "ALL"; } customerProvince.Add(new Province(provinceName)); provinceName = null; } } return(customerProvince); } } }
public void LoadData() { if (ProvinceCollection != null) { ProvinceCollection.Add(new Province { ProvinceId = 1, ProvinceName = "ALBERTA", Parks = new List <Park> { new Park { ParkId = 1, ParkName = "Banff National Park", diff = 3 }, new Park { ParkId = 2, ParkName = "Jasper National Park", diff = 6 }, new Park { ParkId = 3, ParkName = "Waterton Lakes National Park", diff = 10 } }, SliderCollection = new List <Slidercontrol1> { new Slidercontrol1 { SliderId1 = 1, SliderName1 = 1 }, new Slidercontrol1 { SliderId1 = 2, SliderName1 = 2 }, new Slidercontrol1 { SliderId1 = 3, SliderName1 = 3 } } }); ProvinceCollection.Add(new Province { ProvinceId = 2, ProvinceName = "BRITISH COLUMBIA", Parks = new List <Park> { new Park { ParkId = 4, ParkName = "Glacier National Park" }, new Park { ParkId = 5, ParkName = "Kootenay National Park" }, new Park { ParkId = 6, ParkName = "Yoho National Park" } } }); ProvinceCollection.Add(new Province { ProvinceId = 3, ProvinceName = "MANITOBA", Parks = new List <Park> { new Park { ParkId = 7, ParkName = "Nopiming" }, new Park { ParkId = 77, ParkName = "Riding Mountain" }, new Park { ParkId = 546, ParkName = "Wapusk National Park" } } }); ProvinceCollection.Add(new Province { ProvinceId = 4, ProvinceName = "NEW BRUNSWICK", Parks = new List <Park> { new Park { ParkId = 7324, ParkName = "Fundy" }, new Park { ParkId = 77234234, ParkName = "Mount Carleton" }, new Park { ParkId = 542342346, ParkName = "Parlee Beach" } } }); ProvinceCollection.Add(new Province { ProvinceId = 5, ProvinceName = "NEWFOUNDLAND and LABRADOR", Parks = new List <Park> { new Park { ParkId = 7324324, ParkName = "Gros Morne" }, new Park { ParkId = 231, ParkName = "Terra Nova" }, new Park { ParkId = 23123, ParkName = "Western Brook" } } }); ProvinceCollection.Add(new Province { ProvinceId = 6, ProvinceName = "NOVA SCOTIA", Parks = new List <Park> { new Park { ParkId = 4535, ParkName = "Cape Breton" }, new Park { ParkId = 4543543, ParkName = "Kejimkujik" }, new Park { ParkId = 234234, ParkName = "Sable Island" } } }); ProvinceCollection.Add(new Province { ProvinceId = 7, ProvinceName = "ONTARIO", Parks = new List <Park> { new Park { ParkId = 756856, ParkName = "Bruce Peninsula" }, new Park { ParkId = 456, ParkName = "Point Pelee" }, new Park { ParkId = 56, ParkName = "Sandbanks" } } }); ProvinceCollection.Add(new Province { ProvinceId = 8, ProvinceName = "PRINCE EDWARD ISLAND", Parks = new List <Park> { new Park { ParkId = 345435, ParkName = "Cabot Beach" }, new Park { ParkId = 345435, ParkName = "Northumberland" }, new Park { ParkId = 7868, ParkName = "Union Corner" } } }); ProvinceCollection.Add(new Province { ProvinceId = 9, ProvinceName = "QUEBEC", Parks = new List <Park> { new Park { ParkId = 435345, ParkName = "Hautes-Gorges" }, new Park { ParkId = 4534543, ParkName = "Jacques Cartier" }, new Park { ParkId = 435, ParkName = "Gaspesie" } } }); ProvinceCollection.Add(new Province { ProvinceId = 10, ProvinceName = "SASCATCHEWAN", Parks = new List <Park> { new Park { ParkId = 345, ParkName = "Grasslands" }, new Park { ParkId = 34543543, ParkName = "Meadow Lake" }, new Park { ParkId = 34534, ParkName = "Prince Albert" } } }); ProvinceCollection.Add(new Province { ProvinceId = 11, ProvinceName = "NORTHWEST TERRITORIES", Parks = new List <Park> { new Park { ParkId = 456456, ParkName = "Nahanni" }, new Park { ParkId = 56, ParkName = "Grand Teton" }, new Park { ParkId = 456456765, ParkName = "Olympic" } } }); ProvinceCollection.Add(new Province { ProvinceId = 12, ProvinceName = "NUNAVUT", Parks = new List <Park> { new Park { ParkId = 123213, ParkName = "Auyuittuq" }, new Park { ParkId = 324324, ParkName = "Quttinirpaaq" }, new Park { ParkId = 3434, ParkName = "Ukkusiksalik " } } }); ProvinceCollection.Add(new Province { ProvinceId = 13, ProvinceName = "YUKON", Parks = new List <Park> { new Park { ParkId = 1234214, ParkName = "Ivvavik " }, new Park { ParkId = 34343, ParkName = "Kluane" }, new Park { ParkId = 34342, ParkName = "Vuntut" } } }); } }
public void ProvinceCollectionUniqueIds() { ProvinceCollection pc = new ProvinceCollection(); pc.Add(new SaveProvince(1)); Assert.Throws<ArgumentException>(() => pc.Add(new SaveProvince(1))); }
public void ProvinceCollectionEnsureIncrementalAdd() { ProvinceCollection col = new ProvinceCollection(); col.Add(new Province(1)); Assert.Throws<ApplicationException>(() => col.Add(new Province(3))); }
/// <summary> /// Maps changes made in the <see cref="FixedRateShipMethodDisplay"/> to the <see cref="IFixedRateShippingGatewayMethod"/> /// </summary> /// <param name="fixedRateShipMethodDisplay">The <see cref="FixedRateShipMethodDisplay"/> to map</param> /// <param name="destination">The <see cref="IFixedRateShippingGatewayMethod"/> to have changes mapped to</param> /// <returns>The updated <see cref="IFixedRateShippingGatewayMethod"/></returns> /// <remarks> /// /// Note: after calling this mapping, the changes are still not persisted to the database as the .Save() method is not called. /// /// * For testing you will have to use the static .Save(IGatewayProviderService ..., as MerchelloContext.Current will likely be null /// /// </remarks> internal static IFixedRateShippingGatewayMethod ToFixedRateShipMethod(this FixedRateShipMethodDisplay fixedRateShipMethodDisplay, IFixedRateShippingGatewayMethod destination) { // RUSTY HELP: Cannot assign to these properties. How should I do this mapping? // Shipmethod destination.ShipMethod.Name = fixedRateShipMethodDisplay.ShipMethod.Name; if (destination.ShipMethod.Provinces.Any() && fixedRateShipMethodDisplay.ShipMethod.Provinces.Any()) { var provinceCollection = new ProvinceCollection<IShipProvince>(); foreach (var province in fixedRateShipMethodDisplay.ShipMethod.Provinces) { provinceCollection.Add( new ShipProvince(province.Code, province.Name) { AllowShipping = province.AllowShipping, RateAdjustment = province.RateAdjustment, RateAdjustmentType = province.RateAdjustmentType } ); } destination.ShipMethod.Provinces = provinceCollection; } // Rate table var existingRows = fixedRateShipMethodDisplay.RateTable.Rows.Where(x => !x.Key.Equals(Guid.Empty)).ToArray(); foreach (var mapRow in existingRows) { var row = destination.RateTable.Rows.FirstOrDefault(x => x.Key == mapRow.Key); if (row != null) { row.Rate = mapRow.Rate; } } // remove existing rows that previously existed but were deleted in the UI var removers = destination.RateTable.Rows.Where( row => !row.Key.Equals(Guid.Empty) && existingRows.All(x => x.Key != row.Key && !x.Key.Equals(Guid.Empty))); foreach (var remove in removers) { destination.RateTable.DeleteRow(remove); } // add any new rows foreach (var newRow in fixedRateShipMethodDisplay.RateTable.Rows.Where(x => x.Key == Guid.Empty)) { destination.RateTable.AddRow(newRow.RangeLow, newRow.RangeHigh, newRow.Rate); } return destination; }