public void CantEditSection() { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { FixedAssetService transaction = new FixedAssetService(); context.Context.ExecuteStoreCommand("DELETE FROM Person"); context.Context.ExecuteStoreCommand("DELETE FROM Section"); Section section = new Section() { name = "IMZ1", email = "*****@*****.**" }; transaction.EditSection(section); section = context.Context.Sections.FirstOrDefault(x => x.name == "IMZ1"); Assert.IsNull(section); Assert.AreEqual(context.Context.Sections.Count(), 0); } }
public void AddSection(Section section) { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { try { context.Context.Sections.AddObject(section); context.SaveChanges(); } catch (UpdateException) { throw new FaultException(string.Format( "Nie udało się dodać sekcji. Popraw dane i spróbuj ponownie")); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }
public void CanEditPersonTransaction() { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { FixedAssetService transaction = new FixedAssetService(); context.Context.ExecuteStoreCommand("DELETE FROM Person"); context.Context.ExecuteStoreCommand("DELETE FROM Section"); Section sekcja = new Section() { name = "IMZ1" }; Person person = new Person() { id = 1, name = "Jan", surname = "Kowalski", email = "*****@*****.**", Section = sekcja }; transaction.AddPerson(person); Section sekcja1 = new Section() { name = "Sekcja IMR", short_name = "IMR5" }; transaction.AddSection(sekcja1); Section sekcja_temp = context.Context.Sections.FirstOrDefault(x => x.id == sekcja.id); Assert.AreEqual(sekcja.name, sekcja_temp.name); Assert.AreEqual(context.Context.Sections.Count(), 2); Person person_temp = context.Context.People.FirstOrDefault(x => x.id == person.id); Assert.IsNotNull(person_temp); Assert.AreEqual(person_temp.id, person_temp.id); Assert.AreEqual(person_temp.name, "Jan"); Assert.AreEqual(person_temp.surname, "Kowalski"); Assert.AreEqual(person_temp.email, "*****@*****.**"); Assert.AreEqual(context.Context.People.Count(), 1); sekcja_temp = context.Context.Sections.FirstOrDefault(x => x.short_name == "IMR5"); person_temp.email = "*****@*****.**"; person_temp.surname = "Kowalczyk"; person_temp.Section = sekcja_temp; transaction.EditPerson(person_temp); Person person_temp2 = context.Context.People.FirstOrDefault(x => x.id == person.id); Assert.AreEqual(person_temp2.surname, "Kowalczyk"); Assert.AreEqual(person_temp2.email, "*****@*****.**"); Assert.AreEqual(person_temp.Section.name, "Sekcja IMR"); Assert.AreEqual(context.Context.People.Count(), 1); Assert.AreEqual(context.Context.Sections.Count(), 2); } }
public void DeleteSection(Section section) { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { try { context.Context.Sections.Attach(section); context.Context.Sections.DeleteObject(section); context.SaveChanges(); } catch (UpdateException) { throw new FaultException(string.Format( "Nie udało się usunąć sekcji. Przepisz użytkowników do innej sekcji a następnie usuń daną sekcję.")); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }
public void CanAddPersonTransaction() { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { FixedAssetService transaction = new FixedAssetService(); context.Context.ExecuteStoreCommand("DELETE FROM Person"); context.Context.ExecuteStoreCommand("DELETE FROM Section"); Section sekcja = new Section() { name = "IMZ1" }; Person person = new Person() { id = 1, name = "Jan", surname = "Kowalski", Section = sekcja }; transaction.AddPerson(person); Section sekcja_temp = context.Context.Sections.FirstOrDefault(x => x.id == sekcja.id); Assert.AreEqual(sekcja.name, sekcja_temp.name); Assert.AreEqual(context.Context.Sections.Count(), 1); Person person_temp = context.Context.People.FirstOrDefault(x => x.id == person.id); Assert.AreEqual(person.id, person_temp.id); Assert.AreEqual(person.name, person_temp.name); Assert.AreEqual(context.Context.People.Count(), 1); } }
public void EditSection(Section section) { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { try { // Section originalSection = context.Context.Sections.FirstOrDefault(s => s.id == section.id); context.Context.Sections.Attach(section); context.Context.ObjectStateManager.ChangeObjectState(section, System.Data.EntityState.Modified); context.Context.Sections.ApplyChanges(section); context.SaveChanges(); } catch (UpdateException) { throw new FaultException(string.Format( "Nie udało się edytować sekcji. Popraw dane i spróbuj ponownie")); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }
public void GetPersonsBySection() { Section sekcja = new Section() { name = "Sekcja", id = 1 }; Mock<IPersonRepository> mock = new Mock<IPersonRepository>(); mock.Setup(a => a.Persons).Returns(new Person[] { new Person { id = 1, name = "Jan", surname = "Kowalski", email = "*****@*****.**", id_section = sekcja.id }, new Person { id = 2, name = "Kamil", surname = "Nowak" }, new Person { id = 3, name = "Paweł", surname = "Barwicki", email = "*****@*****.**" }, new Person { id = 4, name = "Michał", surname = "Jelonek", id_section = sekcja.id }, new Person { id = 5, name = "Dawid", surname = "Kowalczyk", id_section = sekcja.id }, new Person { id = 6, name = "Emil", surname = "Kopycki", id_section = sekcja.id }, new Person { id = 7, name = "Adam", surname = "Fugiel" }, new Person { id = 8, name = "Jan", surname = "Jelonek" }, new Person { id = 9, name = "Rafał", surname = "Michalski", email = "*****@*****.**" }, new Person { id = 10, name = "Paweł", surname = "Jakubowski" } }.AsQueryable()); PersonController ctrl = new PersonController(mock.Object); object[] temp = ctrl.GetPersonsBySection(sekcja.id); Assert.AreEqual(temp.Length, 4); Assert.AreEqual(((Person)temp[2]).surname, "Kowalczyk"); object[] temp2 = ctrl.GetPersonsBySection(2); Assert.AreEqual(temp2.Length, 0); }
private void FixupSection(Section previousValue) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.People.Contains(this)) { previousValue.People.Remove(this); } if (Section != null) { if (!Section.People.Contains(this)) { Section.People.Add(this); } id_section = Section.id; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("Section") && (ChangeTracker.OriginalValues["Section"] == Section)) { ChangeTracker.OriginalValues.Remove("Section"); } else { ChangeTracker.RecordOriginalValue("Section", previousValue); } if (Section != null && !Section.ChangeTracker.ChangeTrackingEnabled) { Section.StartTracking(); } } }
public void CantAddSection() { using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext()) { FixedAssetService transaction = new FixedAssetService(); context.Context.ExecuteStoreCommand("DELETE FROM Person"); context.Context.ExecuteStoreCommand("DELETE FROM Section"); Section sekcja1 = new Section() { name = "Sekcja IMR", short_name = "IMR5" }; transaction.AddSection(sekcja1); } }