public void Save(Models.ConsumableUsage model) { if (model.IsNew) { base.CreatePostRequest(model); } else { base.CreatePutRequest(model.Id, model); } }
public void Can_SaveNewConsumable() { var consumable = new Consumable { Id = Guid.NewGuid(), Name = "Zat 1", Type = (byte)ConsumableType.Feed, Unit = "liter", UnitPrice = 10000 }; var house = new HenHouse { Id = Guid.NewGuid(), Name = "House 1", Depreciation = 100, Active = true, PurchaseCost = 100000 }; using (var conn = factory.OpenDbConnection()) { conn.InsertParam(house); conn.InsertParam(consumable); } var usage = new Models.ConsumableUsage { Total = 10000, Date = DateTime.Today, Details = new List <ConsumableUsageDetail> { new ConsumableUsageDetail { ConsumableId = consumable.Id, Count = 10, HouseId = house.Id, SubTotal = 10000, UnitPrice = 100000 } } }; service.Save(usage); using (var conn = factory.OpenDbConnection()) { var usageData = conn.FirstOrDefault <Models.Data.ConsumableUsage>(c => c.Date == usage.Date); var details = conn.Where <Models.Data.ConsumableUsageDetail>(new { UsageId = usageData.Id }); Compare(usageData, details, usage); } }
public void Can_SaveNewConsumable() { var consumable = new Consumable { Id = Guid.NewGuid(), Name = "Zat 1", Type = (byte) ConsumableType.Feed, Unit = "liter", UnitPrice = 10000 }; var house = new HenHouse { Id = Guid.NewGuid(), Name = "House 1", Depreciation = 100, Active = true, PurchaseCost = 100000 }; using (var conn = factory.OpenDbConnection()) { conn.InsertParam(house); conn.InsertParam(consumable); } var usage = new Models.ConsumableUsage { Total = 10000, Date = DateTime.Today, Details = new List<ConsumableUsageDetail> { new ConsumableUsageDetail { ConsumableId = consumable.Id, Count = 10, HouseId = house.Id, SubTotal = 10000, UnitPrice = 100000 } } }; service.Save(usage); using (var conn = factory.OpenDbConnection()) { var usageData = conn.FirstOrDefault<Models.Data.ConsumableUsage>(c => c.Date == usage.Date); var details = conn.Where<Models.Data.ConsumableUsageDetail>(new {UsageId = usageData.Id}); Compare(usageData, details, usage); } }
void Compare(Models.Data.ConsumableUsage data, IList <Models.Data.ConsumableUsageDetail> details, Models.ConsumableUsage model) { Assert.Equal(data.Id, model.Id); Assert.Equal(data.Total, model.Total); Assert.Equal(data.Date, model.Date); if (details != null) { foreach (var detail in details) { var detailModel = model.Details.FirstOrDefault( d => d.ConsumableId == detail.ConsumableId && d.HouseId == detail.HouseId); Assert.Equal(detail.ConsumableId, detailModel.ConsumableId); Assert.Equal(detail.Count, detailModel.Count); Assert.Equal(detail.HouseId, detailModel.HouseId); Assert.Equal(detail.SubTotal, detailModel.SubTotal); Assert.Equal(detail.UnitPrice, detailModel.UnitPrice); } } }