public void CantAddPersonWithoutSection()
 {
     using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         FixedAssetService transaction = new FixedAssetService();
         Person person = new Person() { id = 1, name = "Damian", surname = "Kowalski" };
         transaction.AddPerson(person);
     }
 }
        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 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 GetFixedAssetsByCreator()
        {
            Person creator = new Person() { id = 15, name = "Jan", surname = "Kowalski" };

            Mock<IFixedAssetRepository> mock = new Mock<IFixedAssetRepository>();
            mock.Setup(a => a.FixedAssets).Returns(new FixedAsset[]
            {
                new FixedAsset { id = 1, inventory_number = "002/4/11111", created_by = creator.id },
                new FixedAsset { id = 2, inventory_number = "002/4/22222", created_by = creator.id },
                new FixedAsset { id = 3, inventory_number = "002/4/33333", created_by = 2 },
                new FixedAsset { id = 4, inventory_number = "002/4/44444", created_by = creator.id },
                new FixedAsset { id = 5, inventory_number = "002/4/55555", created_by = 9 },
                new FixedAsset { id = 6, inventory_number = "002/4/66666", created_by = creator.id }
            }.AsQueryable());

            FixedAssetController ctrl = new FixedAssetController(mock.Object);
            object[] temp = ctrl.GetFixedAssetsByCreator(creator.id);
            Assert.AreEqual(temp.Length, 4);
            Assert.AreEqual(((FixedAsset)temp[2]).inventory_number, "002/4/44444");

            temp = ctrl.GetFixedAssetsByCreator(9);
            Assert.AreEqual(temp.Length, 1);

            temp = ctrl.GetFixedAssetsByCreator(7);
            Assert.AreEqual(temp.Length, 0);
        }
        public void GetFixedAssetsByLastModifiedId()
        {
            Person person = new Person() { id = 15, name = "Jan", surname = "Kowalski" };

            Mock<IFixedAssetRepository> mock = new Mock<IFixedAssetRepository>();
            mock.Setup(a => a.FixedAssets).Returns(new FixedAsset[]
            {
                new FixedAsset { id = 1, inventory_number = "002/4/11111", last_modifed_login = 15 },
                new FixedAsset { id = 2, inventory_number = "002/4/22222", last_modifed_login = 1 },
                new FixedAsset { id = 3, inventory_number = "002/4/33333", last_modifed_login = 2 },
                new FixedAsset { id = 4, inventory_number = "002/4/44444", last_modifed_login = 5 },
                new FixedAsset { id = 5, inventory_number = "002/4/55555", last_modifed_login = 15 },
                new FixedAsset { id = 6, inventory_number = "002/4/66666", last_modifed_login = 15 }
            }.AsQueryable());

            FixedAssetController ctrl = new FixedAssetController(mock.Object);
            object[] temp = ctrl.GetFixedAssetsByLastModifiedId(person.id);
            Assert.AreEqual(temp.Length, 3);
            Assert.AreEqual(((FixedAsset)temp[2]).inventory_number, "002/4/66666");

            temp = ctrl.GetFixedAssetsByLastModifiedId(2);
            Assert.AreEqual(temp.Length, 1);
            Assert.AreEqual(((FixedAsset)temp[0]).inventory_number, "002/4/33333");

            temp = ctrl.GetFixedAssetsByLastModifiedId(24);
            Assert.AreEqual(temp.Length, 0);
        }
Пример #6
0
        public void GetLicencesByLastModifiedPersonId()
        {
            Person person = new Person { id = 5, name = "Jan", surname = "Kowalski" };

            Mock<ILicenceRepository> mock = new Mock<ILicenceRepository>();
            mock.Setup(a => a.Licences).Returns(new Licence[]
            {
                new Licence { id_number = 1, inventory_number = "aaaa", last_modified_id = person.id },
                new Licence { id_number = 2, inventory_number = "bbbb", last_modified_id = 4 },
                new Licence { id_number = 3, inventory_number = "cccc", last_modified_id = person.id },
                new Licence { id_number = 4, inventory_number = "dddd", last_modified_id = 2 },
                new Licence { id_number = 5, inventory_number = "eeee", last_modified_id = person.id }
            }.AsQueryable());

            LicenceController ctrl = new LicenceController(mock.Object);
            Object[] temp = ctrl.GetLicencesByLastModifiedPersonId(person.id);
            Assert.AreEqual(temp.Length, 3);
            Assert.AreEqual(((Licence)temp[2]).inventory_number, "eeee");

            temp = ctrl.GetLicencesByLastModifiedPersonId(2);
            Assert.AreEqual(temp.Length, 1);
            Assert.AreEqual(((Licence)temp[0]).inventory_number, "dddd");

            temp = ctrl.GetLicencesByLastModifiedPersonId(52);
            Assert.AreEqual(temp.Length, 0);
        }
Пример #7
0
        public void GetLicencesByCreatorOrLastModifiedPersonID()
        {
            Person person = new Person { id = 4, name = "Jan", surname = "Kowalski" };
            Mock<ILicenceRepository> mock = new Mock<ILicenceRepository>();
            mock.Setup(a => a.Licences).Returns(new Licence[]
            {
                new Licence { id_number = 1, inventory_number = "aaaa", created_by = person.id, last_modified_id = 9 },
                new Licence { id_number = 2, inventory_number = "bbbb", created_by = 2, last_modified_id = 2},
                new Licence { id_number = 3, inventory_number = "cccc", created_by = 3, last_modified_id = 9},
                new Licence { id_number = 4, inventory_number = "dddd", created_by = person.id, last_modified_id = 9},
                new Licence { id_number = 5, inventory_number = "eeee", created_by = 1, last_modified_id = 12}
            }.AsQueryable());

            LicenceController ctrl = new LicenceController(mock.Object);
            object[] temp = ctrl.GetLicenceByCreator(person.id);
            Assert.AreEqual(temp.Length, 2);
            Assert.AreEqual(((Licence)temp[1]).inventory_number, "dddd");

            temp = ctrl.GetLicenceByCreator(22);
            Assert.AreEqual(temp.Length, 0);

            temp = ctrl.GetLicencesByLastModifiedPersonId(9);
            Assert.AreEqual(temp.Length, 3);
            Assert.AreEqual(((Licence)temp[1]).inventory_number, "cccc");

            temp = ctrl.GetLicencesByLastModifiedPersonId(33);
            Assert.AreEqual(temp.Length, 0);
        }
Пример #8
0
     private void FixupPerson(Person previousValue, bool skipKeys = false)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.FixedAssets.Contains(this))
         {
             previousValue.FixedAssets.Remove(this);
         }
 
         if (Person != null)
         {
             if (!Person.FixedAssets.Contains(this))
             {
                 Person.FixedAssets.Add(this);
             }
 
             id_person = Person.id;
         }
         else if (!skipKeys)
         {
             id_person = null;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Person")
                 && (ChangeTracker.OriginalValues["Person"] == Person))
             {
                 ChangeTracker.OriginalValues.Remove("Person");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Person", previousValue);
             }
             if (Person != null && !Person.ChangeTracker.ChangeTrackingEnabled)
             {
                 Person.StartTracking();
             }
         }
     }