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 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 AddKind(Kind kind)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.Kinds.AddObject(kind);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się dodać rodzaju. Popraw dane i spróbuj ponownie"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
 public void DeleteKind(Kind kind)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.Kinds.Attach(kind);
             context.Context.Kinds.DeleteObject(kind);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się usunąć rodzaju. Prawdopodobnie nie istnieje"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
        public void EditKind(Kind kind)
        {
            using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
            {
                try
                {
                    Kind originalKind = context.Context.Kinds.FirstOrDefault(k => k.id == kind.id);
                    context.Context.Kinds.ApplyCurrentValues(kind);
                    context.SaveChanges();

                }
                catch (UpdateException)
                {
                    throw new FaultException(string.Format(
                    "Nie udało się edytować rodzaju. Popraw dane i spróbuj ponownie"));
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
            }
        }
     private void FixupKind(Kind previousValue)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.Licences.Contains(this))
         {
             previousValue.Licences.Remove(this);
         }
 
         if (Kind != null)
         {
             if (!Kind.Licences.Contains(this))
             {
                 Kind.Licences.Add(this);
             }
 
             id_kind = Kind.id;
         }
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Kind")
                 && (ChangeTracker.OriginalValues["Kind"] == Kind))
             {
                 ChangeTracker.OriginalValues.Remove("Kind");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Kind", previousValue);
             }
             if (Kind != null && !Kind.ChangeTracker.ChangeTrackingEnabled)
             {
                 Kind.StartTracking();
             }
         }
     }
        public void GetFixedAssetsByKindId()
        {
            Kind rodzaj = new Kind { id = 1, name = "Zestawy komputerowe" };

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

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

            temp = ctrl.GetFixedAssetsByKindId(2);
            Assert.AreEqual(temp.Length, 1);

            temp = ctrl.GetFixedAssetsByKindId(8);
            Assert.AreEqual(temp.Length, 0);
        }