public void InsertSpaceShipCargoTest() { SpaceShipCargoDAO target = new SpaceShipCargoDAO(); SpaceShipCargo spaceShipCargo = new SpaceShipCargo(); spaceShipCargo.CargoId = cargo1.CargoId; spaceShipCargo.CargoCount = 3; spaceShipCargo.SpaceShipId = ship.SpaceShipId; bool insert = target.InsertSpaceShipCargo(spaceShipCargo); Assert.IsTrue(insert); }
public void GetSpaceShipCargoBySpaceShipId() { SpaceShipCargoDAO target = new SpaceShipCargoDAO(); SpaceShipCargo spaceShipCargo = new SpaceShipCargo(); spaceShipCargo.CargoId = cargo1.CargoId; spaceShipCargo.CargoCount = 3; spaceShipCargo.SpaceShipId = ship.SpaceShipId; bool insert = target.InsertSpaceShipCargo(spaceShipCargo); spaceShipCargo.CargoId = cargo2.CargoId; target.InsertSpaceShipCargo(spaceShipCargo); List <SpaceShipCargo> cargos = target.GetSpaceShipCargoBySpaceShipId(ship.SpaceShipId); Assert.IsTrue(cargos.Count == 2); }
public bool UpdateCargoCountById(SpaceShipCargo spaceShipCargo) { using (var contextDB = CreateContext()) { try { var spaceShipCargoTab = contextDB.SpaceShipsCargos.FirstOrDefault(x => x.SpaceShipId.Equals(spaceShipCargo.SpaceShipId) && x.CargoId.Equals(spaceShipCargo.CargoId)); spaceShipCargoTab.CargoCount += spaceShipCargo.CargoCount; // save context to database contextDB.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool InsertSpaceShipCargo(SpaceShipCargo spaceShipCargo) { using (var contextDB = CreateContext()) { try { // add space ship to context contextDB.SpaceShipsCargos.Add(spaceShipCargo); // save context to database contextDB.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public void RemoveSpaceShipCargoByIdTest() { SpaceShipCargoDAO target = new SpaceShipCargoDAO(); SpaceShipCargo spaceShipCargo = new SpaceShipCargo(); spaceShipCargo.CargoId = cargo1.CargoId; spaceShipCargo.CargoCount = 3; spaceShipCargo.SpaceShipId = ship.SpaceShipId; bool insert = target.InsertSpaceShipCargo(spaceShipCargo); bool actual = target.RemoveSpaceShipCargoById(ship.SpaceShipId, cargo1.CargoId); Assert.IsTrue(actual); SpaceShipCargoDAO cargo = new SpaceShipCargoDAO(); List <SpaceShipCargo> cargos = cargo.GetSpaceShipCargoBySpaceShipId(ship.SpaceShipId); Assert.IsTrue(cargos != null); }