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 CantAddLicence() { 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(); Licence licence = new Licence() { inventory_number = "xxxx", name = "Windows XP", last_modified_date = DateTime.Now }; transaction.AddLicence(licence); } }
public void AddLicence(Licence licence) { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { try { context.Context.Licences.AddObject(licence); context.SaveChanges(); } catch (UpdateException) { throw new FaultException(string.Format( "Nie udało się dodać licencji. Popraw dane i spróbuj ponownie")); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }
public void EditLicence(Licence licence) { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { try { Licence originalLicence = context.Context.Licences.FirstOrDefault(l => l.id_number == licence.id_number); context.Context.Licences.ApplyCurrentValues(licence); context.SaveChanges(); } catch (UpdateException) { throw new FaultException(string.Format( "Nie udało się edytować licencji. Popraw dane i spróbuj ponownie")); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }
public void DeleteLicence(Licence licence) { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { try { context.Context.Licences.Attach(licence); context.Context.Licences.DeleteObject(licence); context.SaveChanges(); } catch (UpdateException) { throw new FaultException(string.Format( "Nie udało się usunąć licencji. Prawdopodobnie nie istnieje")); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }