public void SaveItemCommand_DoSave() { var fakeBattery = new BatteryType { name = "Test Battery" }; Assert.That(fakeBattery.IsChanged, nameof(fakeBattery.IsChanged), Is.True); Assert.That(fakeBattery.name, Is.EqualTo("Test Battery")); //Assert.That(fakeBattery.displayName, Is.EqualTo(fakeBattery.name)); var cmd = new SaveItemCommand(); Assert.NotNull(cmd, nameof(SaveItemCommand)); Assert.IsTrue(cmd.CanExecute(fakeBattery)); cmd.Execute(fakeBattery); Assert.IsFalse(cmd.CanExecute(fakeBattery)); var db = DataRepository.GetDataRepository; var fakeBatteryReplica = db.Load <BatteryType>(fakeBattery.PrimaryKey); Assert.NotNull(fakeBatteryReplica, nameof(fakeBatteryReplica)); db.Delete(fakeBattery); }
private void addOrUpdateItems(UpdateOrderViewModel model, Order order) { var itemCmd = new SaveItemCommand(_itemRepository, _itemValidator); foreach (var item in model.Items) { var entity = item.Adapt <Item>(); entity.PedidoId = order.Id; itemCmd.Execute(entity); AddNotifications(itemCmd); if (Invalid) { break; } } }
public void SaveItemCommand_DoSave_ManyToMany() { var fakeUnit = new EquipmentUnitType { name = "Test Trailer", description = "My Description", unitCode = "T" }; Assert.That(fakeUnit.IsChanged, nameof(fakeUnit.IsChanged), Is.True); Assert.That(fakeUnit.name, Is.EqualTo("Test Trailer")); Assert.That(fakeUnit.displayName, Is.EqualTo(fakeUnit.name)); var cmd = new SaveItemCommand(); Assert.NotNull(cmd, nameof(SaveItemCommand)); fakeUnit.unitCode = "T"; Assert.IsTrue(cmd.CanExecute(fakeUnit)); var fakeSite = new SiteLocation { name = "My Site", locSuffix = "My" }; Assert.That(fakeSite.IsChanged, nameof(fakeSite.IsChanged), Is.True); Assert.That(fakeSite.name, Is.EqualTo("My Site")); fakeSite.equipmentUnitTypesAvailable.Add(fakeUnit); Assert.IsTrue(cmd.CanExecute(fakeSite)); cmd.Execute(fakeSite); Assert.IsFalse(cmd.CanExecute(fakeSite)); Assert.IsFalse(cmd.CanExecute(fakeUnit)); var db = DataRepository.GetDataRepository; var fakeSiteReplica = db.Load <SiteLocation>(fakeSite.PrimaryKey); Assert.NotNull(fakeSiteReplica, nameof(fakeSiteReplica)); Assert.That(fakeSiteReplica.equipmentUnitTypesAvailable.Count, Is.GreaterThan(0)); // note that must delete site first to remove mappings otherwise will fail due to mapping fk constraints db.Delete(fakeSite); db.Delete(fakeUnit); }
private void addItems(Order order) { if (Valid) { var itemCmd = new SaveItemCommand(_itemRepository, _itemValidator); foreach (var item in order.Items) { item.PedidoId = order.Id; itemCmd.Execute(item); AddNotifications(itemCmd); if (Invalid) { break; } } } }
public void AddItemCommand() { var cmd = new SaveItemCommand(); var db = DataRepository.GetDataRepository; Assert.NotNull(db); var testInstance = db.Load <ItemInstance>(SampleItemInstance); Assert.NotNull(testInstance); Assert.IsFalse(cmd.CanExecute(testInstance)); // not an Item, can't add ItemInstance directly Assert.IsFalse(cmd.CanExecute(testInstance.item)); // because it already exists Assert.IsFalse(cmd.CanExecute(testInstance.item.itemType)); // an ItemType, reference data var item = db.Load <Item>("f69eb75a-3468-2f78-6b54-2530f95e75e0"); Assert.NotNull(item); Assert.IsFalse(cmd.CanExecute(item)); // mutate as new item so we can add it item.id = Guid.Empty; item.itemId = 99999; // way too large to be valid, ideally we'd ask for proper value Assert.IsTrue(cmd.CanExecute(item)); // add the item instances (and item is not already saved) cmd.Execute(item); var itemInstances = db.db.LoadRows <ItemInstance>("WHERE itemId=?", item.id.ToString()); Assert.That(itemInstances.Count, Is.EqualTo(13)); // cleanup, remove the item instances foreach (var itemInstance in itemInstances) { db.Delete(itemInstance); } db.Delete(item); }