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 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 GetFixedAssetsByContractor()
        {
            Contractor contractor = new Contractor() { id = 16, name = "Firma1" };

            Mock<IFixedAssetRepository> mock = new Mock<IFixedAssetRepository>();
            mock.Setup(a => a.FixedAssets).Returns(new FixedAsset[]
            {
                new FixedAsset { id = 1, inventory_number = "002/4/11111", id_contractor = contractor.id },
                new FixedAsset { id = 2, inventory_number = "002/4/22222", id_contractor = 15 },
                new FixedAsset { id = 3, inventory_number = "002/4/33333", id_contractor = contractor.id },
                new FixedAsset { id = 4, inventory_number = "002/4/44444", id_contractor = 12 },
                new FixedAsset { id = 5, inventory_number = "002/4/55555", id_contractor = contractor.id },
                new FixedAsset { id = 6, inventory_number = "002/4/66666", id_contractor = 18 }
            }.AsQueryable());
            FixedAssetController ctrl = new FixedAssetController(mock.Object);
            object[] temp = ctrl.GetFixedAssetsByContractor(contractor.id);
            Assert.AreEqual(temp.Length, 3);
            Assert.AreEqual(((FixedAsset)temp[2]).id, 5);

            temp = ctrl.GetFixedAssetsByContractor(12);
            Assert.AreEqual(temp.Length, 1);
            Assert.AreEqual(((FixedAsset)temp[0]).id, 4);

            temp = ctrl.GetFixedAssetsByContractor(28);
            Assert.AreEqual(temp.Length, 0);
        }
        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);
            }
        }
     private void FixupContractor(Contractor previousValue, bool skipKeys = false)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.FixedAssets.Contains(this))
         {
             previousValue.FixedAssets.Remove(this);
         }
 
         if (Contractor != null)
         {
             if (!Contractor.FixedAssets.Contains(this))
             {
                 Contractor.FixedAssets.Add(this);
             }
 
             id_contractor = Contractor.id;
         }
         else if (!skipKeys)
         {
             id_contractor = null;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Contractor")
                 && (ChangeTracker.OriginalValues["Contractor"] == Contractor))
             {
                 ChangeTracker.OriginalValues.Remove("Contractor");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Contractor", previousValue);
             }
             if (Contractor != null && !Contractor.ChangeTracker.ChangeTrackingEnabled)
             {
                 Contractor.StartTracking();
             }
         }
     }