public void CanAddContractor()
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         FixedAssetService transaction = new FixedAssetService();
         context.Context.ExecuteStoreCommand("DELETE FROM Contractor");
         int count = context.Context.Contractors.Count();
         Assert.AreEqual(count, 0);
         
         Contractor contractor = new Contractor()
         {
             name = "ABC",
             city = "Kraków",
             nip = 555123213,
             postal_code = "31-987",
             street = "Królewska",
             country = "Polska"
         };
         transaction.AddContractor(contractor);
         count = context.Context.Contractors.Count();
         Assert.AreEqual(count, 1);
         Contractor temp = context.Context.Contractors.FirstOrDefault(x => x.name == "ABC");
         Assert.IsNotNull(temp);
         Assert.AreEqual(temp.nip, 555123213);
     }
 }
        public void CantEditMembershipUser()
        {
            using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
            {
                context.Context.ExecuteStoreCommand("DELETE FROM MembershipUser");
                FixedAssetService transaction = new FixedAssetService();
                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 = "******"
                };

                transaction.AddMembershipUser(user);
                Assert.AreEqual(context.Context.MembershipUsers.Count(), 1);
                user = context.Context.MembershipUsers.FirstOrDefault(x => x.login == "user123");
                user.email = "*****@*****.**";
                transaction.EditMembershipUser(user);
                user = context.Context.MembershipUsers.FirstOrDefault(x => x.email == "*****@*****.**");
                Assert.IsNull(user);
                Assert.AreEqual(context.Context.MembershipUsers.Count(), 1);
            }
        }
        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 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 CantAddContractorWithoutData()
 {
     using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         context.Context.ExecuteStoreCommand("DELETE FROM Contractor");
         FixedAssetService transaction = new FixedAssetService();
         Contractor contractor = new Contractor() { name = "ABC", city = "Kraków"};
         transaction.AddContractor(contractor);
     }
 }
 public void CantAddDeviceWithoutData()
 {
     using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         context.Context.ExecuteStoreCommand("DELETE FROM Device");
         FixedAssetService transaction = new FixedAssetService();
         Device device = new Device() { model = "x400", producer = "Sony" };
         transaction.AddDevice(device);
     }
 }
 public void CantEditMembershipRole()
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         context.Context.ExecuteStoreCommand("DELETE FROM MembershipRole");
         FixedAssetService transaction = new FixedAssetService();
         MembershipRole role = new MembershipRole() { name = "Admins" };
         transaction.EditMembershipRole(role);
     }
 }
 public void CantEditSubgroup()
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         FixedAssetService transaction = new FixedAssetService();
         context.Context.ExecuteStoreCommand("DELETE FROM Subgroup");
         Subgroup subgroup = new Subgroup() { name = "Środki wysokiej wartości", short_name = "N491" };
         Assert.AreEqual(context.Context.Subgroups.Count(), 0);
         transaction.EditSubgroup(subgroup);
     }
 }
        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 CanAddMembershipRole()
 {
     using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         context.Context.ExecuteStoreCommand("DELETE FROM MembershipRole");
         FixedAssetService transaction = new FixedAssetService();
         MembershipRole role = new MembershipRole() {  name = "Admins" };
         transaction.AddMembershipRole(role);
         Assert.AreEqual(context.Context.MembershipRoles.Count(), 1);
         role = context.Context.MembershipRoles.FirstOrDefault(x => x.name == "Admins");
         Assert.IsNotNull(role);
     }
 }
 public void CanAddKind()
 {
     using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         context.Context.ExecuteStoreCommand("DELETE FROM Kind");
         FixedAssetService transaction = new FixedAssetService();
         Kind kind = new Kind() { name = "N491" };
         transaction.AddKind(kind);
         Assert.AreEqual(context.Context.Kinds.Count(), 1);
         kind = context.Context.Kinds.FirstOrDefault(x => x.name == "N491");
         Assert.IsNotNull(kind);
     }
 }
 public void CantAddPeripheralDevice()
 {
     using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         FixedAssetService transaction = new FixedAssetService();
         context.Context.ExecuteStoreCommand("DELETE FROM PeripheralDevice");
         PeripheralDevice device = new PeripheralDevice() { name = "printer" };
         transaction.AddPeripheralDevice(device);
         Assert.AreEqual(context.Context.PeripheralDevices.Count(), 1);
         device = context.Context.PeripheralDevices.FirstOrDefault(x => x.name == "printer");
         Assert.IsNotNull(device);
     }
 }
 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 CanAddSubgroup()
 {
     using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         FixedAssetService transaction = new FixedAssetService();
         context.Context.ExecuteStoreCommand("DELETE FROM Subgroup");
         Subgroup subgroup = new Subgroup() { name = "Środki wysokiej wartości", short_name = "N491" };
         transaction.AddSubgroup(subgroup);
         Assert.AreEqual(context.Context.Subgroups.Count(), 1);
         subgroup = context.Context.Subgroups.FirstOrDefault(x => x.short_name == "N491");
         Assert.IsNotNull(subgroup);
         Assert.AreEqual(subgroup.name, "Środki wysokiej wartości");
     }
 }
        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 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 CantAddMembershipUser()
        {
            using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
            {
                context.Context.ExecuteStoreCommand("DELETE FROM MembershipUser");
                FixedAssetService transaction = new FixedAssetService();
                MembershipUser user = new MembershipUser()
                {
                    login = "******",
                    name = "Jan",
                    surname = "Kowalski",
                    
                };

                transaction.AddMembershipUser(user);
                Assert.AreEqual(context.Context.MembershipUsers.Count(), 1);
                user = context.Context.MembershipUsers.FirstOrDefault(x => x.login == "user123");
                Assert.IsNotNull(user);
            }
        }
        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 CantEditNotExistingContractor()
        {
            using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
            {
                FixedAssetService transaction = new FixedAssetService();
                context.Context.ExecuteStoreCommand("DELETE FROM Contractor");
                int count = context.Context.Contractors.Count();
                Assert.AreEqual(count, 0);

                Contractor contractor = new Contractor()
                {
                    name = "ABC",
                    city = "Kraków",
                    nip = 555123213,
                    postal_code = "31-987",
                    street = "Królewska",
                    country = "Polska"
                };
                transaction.AddContractor(contractor);

                Contractor contractor2 = new Contractor()
                {
                    name = "XXX",
                    city = "Warszawa",
                    nip = 6666666,
                    postal_code = "22-987",
                    street = "Wrocławska",
                    country = "Polska"
                };
                transaction.EditContractor(contractor2);
                count = context.Context.Contractors.Count();
                Assert.AreEqual(count, 1);
            }
        }
 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);
     }
 }
        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);
            }
        }