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 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 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 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 AddDevice(EF_ZMTdbEntities.Device device)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.Devices.AddObject(device);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się dodać urządzenia. Popraw dane i spróbuj ponownie"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
 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 AddContractor(EF_ZMTdbEntities.Contractor contractor)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.Contractors.AddObject(contractor);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się dodać kontrahenta. Popraw dane i spróbuj ponownie"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
        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 AddSubgroup(Subgroup subgroup)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.Subgroups.AddObject(subgroup);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się dodać podgrupy. 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 EditDevice(EF_ZMTdbEntities.Device device)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             Device originalDevice = context.Context.Devices.Single(p => p.id == device.id);
             context.Context.Devices.ApplyCurrentValues(device);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się edytować urządzenia. Popraw dane i spróbuj ponownie"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
 public void DeleteDevice(EF_ZMTdbEntities.Device device)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.Devices.Attach(device);
             context.Context.Devices.DeleteObject(device);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się usunąć urządzenia. Prawdopodobnie nie istnieje"));
         }
         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 EditContractor(EF_ZMTdbEntities.Contractor contractor)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             Contractor originalContractor = context.Context.Contractors.FirstOrDefault(c => c.id == contractor.id);
             context.Context.Contractors.ApplyCurrentValues(contractor);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało sie edytować kontrahenta. Popraw dane i spróbuj ponownie"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
 public void DeleteContractor(EF_ZMTdbEntities.Contractor contractor)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.Contractors.Attach(contractor);
             context.Context.Contractors.DeleteObject(contractor);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się usunąć kontrahenta. Prawdopodobnie kontrahent nie istnieje"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }