public void CanEditFixedAsset() { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { context.Context.ExecuteStoreCommand("DELETE FROM FixedAsset"); FixedAssetService transaction = new FixedAssetService(); FixedAsset asset = new FixedAsset() { inventory_number = "222222", cassation = false, date_of_activation = DateTime.Now, MPK = "AAAAAA" }; transaction.AddFixedAsset(asset); asset = context.Context.FixedAssets.FirstOrDefault(x => x.inventory_number == "222222"); asset.MPK = "BBBBB"; asset.inventory_number = "333333"; transaction.EditFixedAsset(asset); asset = context.Context.FixedAssets.FirstOrDefault(x => x.inventory_number == "333333"); Assert.IsNotNull(asset); Assert.AreEqual(context.Context.FixedAssets.Count(), 1); } }
public void CanAddDevice() { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { context.Context.ExecuteStoreCommand("DELETE FROM Device"); context.Context.ExecuteStoreCommand("DELETE FROM PeripheralDevice"); context.Context.ExecuteStoreCommand("DELETE FROM FixedAsset"); Assert.AreEqual(context.Context.Devices.Count(), 0); Assert.AreEqual(context.Context.PeripheralDevices.Count(), 0); Assert.AreEqual(context.Context.FixedAssets.Count(), 0); FixedAssetService transaction = new FixedAssetService(); FixedAsset asset = new FixedAsset() { inventory_number = "222222", cassation = false, date_of_activation = DateTime.Now }; PeripheralDevice pd = new PeripheralDevice() { name = "Kamera" }; Device device = new Device() { model = "x400", producer = "Sony", PeripheralDevice = pd, FixedAsset = asset }; transaction.AddDevice(device); Assert.AreEqual(context.Context.Devices.Count(), 1); Assert.AreEqual(context.Context.PeripheralDevices.Count(), 1); Assert.AreEqual(context.Context.FixedAssets.Count(), 1); } }
public void CanAddLicence() { using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { context.Context.ExecuteStoreCommand("DELETE FROM Licence"); context.Context.ExecuteStoreCommand("DELETE FROM MembershipUser"); context.Context.ExecuteStoreCommand("DELETE FROM Kind"); context.Context.ExecuteStoreCommand("DELETE FROM FixedAsset"); FixedAssetService transaction = new FixedAssetService(); FixedAsset asset = new FixedAsset() { id = 2222, inventory_number = "aaaa", date_of_activation = DateTime.Now, cassation = false }; MembershipUser user = new MembershipUser() { login = "******", email = "*****@*****.**", creation_date = DateTime.Now, is_online = false, name = "Jan", surname = "Kowalski", is_active = true, last_login_date = DateTime.Now, password = "******" }; Kind kind = new Kind() { name = "Oprogramowanie" }; Licence licence = new Licence() { inventory_number = "xxxx", name = "Windows XP", created_by = user.login, MembershipUser = user, FixedAsset = asset, Kind = kind, last_modified_login = user.login, last_modified_date = DateTime.Now }; transaction.AddLicence(licence); Assert.AreEqual(context.Context.Licences.Count(), 1); licence = context.Context.Licences.FirstOrDefault(x => x.inventory_number == "xxxx"); Assert.IsNotNull(licence); Assert.AreEqual(licence.name, "Windows XP"); } }
public void CantAddFixedAsset() { using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { context.Context.ExecuteStoreCommand("DELETE FROM FixedAsset"); FixedAssetService transaction = new FixedAssetService(); FixedAsset asset = new FixedAsset() { cassation = false, date_of_activation = DateTime.Now }; transaction.AddFixedAsset(asset); } }
public void CanEditDevice() { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { context.Context.ExecuteStoreCommand("DELETE FROM Device"); context.Context.ExecuteStoreCommand("DELETE FROM PeripheralDevice"); context.Context.ExecuteStoreCommand("DELETE FROM FixedAsset"); Assert.AreEqual(context.Context.Devices.Count(), 0); Assert.AreEqual(context.Context.PeripheralDevices.Count(), 0); Assert.AreEqual(context.Context.FixedAssets.Count(), 0); FixedAssetService transaction = new FixedAssetService(); FixedAsset asset = new FixedAsset() { inventory_number = "222222", cassation = false, date_of_activation = DateTime.Now }; PeripheralDevice pd = new PeripheralDevice() { name = "Kamera" }; Device device = new Device() { model = "x400", producer = "Sony", PeripheralDevice = pd, FixedAsset = asset }; transaction.AddDevice(device); Assert.AreEqual(context.Context.Devices.Count(), 1); Assert.AreEqual(context.Context.PeripheralDevices.Count(), 1); Assert.AreEqual(context.Context.FixedAssets.Count(), 1); pd = new PeripheralDevice() { name = "Aparat" }; context.Context.PeripheralDevices.AddObject(pd); context.SaveChanges(); Assert.AreEqual(context.Context.PeripheralDevices.Count(), 2); device = context.Context.Devices.FirstOrDefault(x => x.model == "x400"); Assert.IsNotNull(device); device.PeripheralDevice = pd; device.model = "x500"; transaction.EditDevice(device); device = context.Context.Devices.FirstOrDefault(x => x.model == "x500"); Assert.IsNotNull(device); Assert.AreEqual(device.model, "x500"); Assert.AreEqual(device.PeripheralDevice.name, "Aparat"); Assert.AreEqual(context.Context.Devices.Count(), 1); } }
public void AddFixedAsset(FixedAsset fixedAsset) { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { try { context.Context.FixedAssets.AddObject(fixedAsset); context.SaveChanges(); } catch (UpdateException) { throw new FaultException(string.Format( "Nie udało się dodać środka trwałego. Popraw dane i spróbuj ponownie")); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }
public void EditFixedAsset(FixedAsset fixedAsset) { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { try { FixedAsset originalFixedAsset = context.Context.FixedAssets.FirstOrDefault(f => f.id == fixedAsset.id); context.Context.FixedAssets.ApplyCurrentValues(fixedAsset); context.SaveChanges(); } catch (UpdateException) { throw new FaultException(string.Format( "Nie udało się edytować środka trwałego. Popraw dane i spróbuj ponownie")); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }
public void DeleteFixedAsset(FixedAsset fixedAsset) { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { try { context.Context.FixedAssets.Attach(fixedAsset); context.Context.FixedAssets.DeleteObject(fixedAsset); context.SaveChanges(); } catch (UpdateException) { throw new FaultException(string.Format( "Nie udało się usunąć środka trwałego. Prawdopodobnie nie istnieje")); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }
public void CantEditNotExistingFixedAsset() { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { context.Context.ExecuteStoreCommand("DELETE FROM FixedAsset"); FixedAssetService transaction = new FixedAssetService(); FixedAsset asset = new FixedAsset() { inventory_number = "222222", cassation = false, date_of_activation = DateTime.Now, MPK = "AAAAAA" }; transaction.EditFixedAsset(asset); } }
private void FixupFixedAsset(FixedAsset previousValue) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.Licences.Contains(this)) { previousValue.Licences.Remove(this); } if (FixedAsset != null) { if (!FixedAsset.Licences.Contains(this)) { FixedAsset.Licences.Add(this); } assign_fixed_asset = FixedAsset.id; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("FixedAsset") && (ChangeTracker.OriginalValues["FixedAsset"] == FixedAsset)) { ChangeTracker.OriginalValues.Remove("FixedAsset"); } else { ChangeTracker.RecordOriginalValue("FixedAsset", previousValue); } if (FixedAsset != null && !FixedAsset.ChangeTracker.ChangeTrackingEnabled) { FixedAsset.StartTracking(); } } }