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 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 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 DeleteSubgroup(Subgroup subgroup)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.Subgroups.Attach(subgroup);
             context.Context.Subgroups.DeleteObject(subgroup);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się usunąć podgrupy. Prawdopodobnie nie istnieje"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
 public void EditSubgroup(Subgroup subgroup)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.Subgroups.Attach(subgroup);
             context.Context.ObjectStateManager.ChangeObjectState(subgroup, System.Data.EntityState.Modified);
             context.Context.Subgroups.ApplyChanges(subgroup);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się edytować podgrupy. Popraw dane i spróbuj ponownie"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
        public void GetFixedAssetsBySubgroupId()
        {
            Subgroup podrodzaj = new Subgroup { id = 1, name = "Środki wysokiej wartości", short_name = "N491" };

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

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

            temp = ctrl.GetFixedAssetsBySubgroupId(6);
            Assert.AreEqual(temp.Length, 1);

            temp = ctrl.GetFixedAssetsBySubgroupId(8);
            Assert.AreEqual(temp.Length, 0);
        }
Ejemplo n.º 7
0
     private void FixupSubgroup(Subgroup previousValue, bool skipKeys = false)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.FixedAssets.Contains(this))
         {
             previousValue.FixedAssets.Remove(this);
         }
 
         if (Subgroup != null)
         {
             if (!Subgroup.FixedAssets.Contains(this))
             {
                 Subgroup.FixedAssets.Add(this);
             }
 
             id_subgroup = Subgroup.id;
         }
         else if (!skipKeys)
         {
             id_subgroup = null;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Subgroup")
                 && (ChangeTracker.OriginalValues["Subgroup"] == Subgroup))
             {
                 ChangeTracker.OriginalValues.Remove("Subgroup");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Subgroup", previousValue);
             }
             if (Subgroup != null && !Subgroup.ChangeTracker.ChangeTrackingEnabled)
             {
                 Subgroup.StartTracking();
             }
         }
     }