Пример #1
0
        public void DBDistrictTest_Persist_Delete()
        {
            DBDistrict   db       = new DBDistrict();
            const string dName    = "Norway";
            var          district = new District()
            {
                Name = dName, PrimarySalesperson = new Salesperson()
                {
                    Id = 2
                }
            };

            var countOld = db.GetAll().Count();

            db.Persist(district);
            var countNew = db.GetAll().Count();

            Assert.AreNotEqual(countOld, countNew);

            district = db.GetAll().ToList().SingleOrDefault(x => x.Name.Equals(dName));

            db.Delete(district.Id);
            countNew = db.GetAll().Count();

            Assert.AreEqual(countOld, countNew);
        }
 // POST api/<controller>
 public District Post([FromBody] District value)
 {
     if (value != null)
     {
         var faulted = new District();
         try
         {
             db.Persist(value);
             return(new District()
             {
                 IsFaulted = false
             });
         }
         catch (DataLayerArgumentException e)
         {
             faulted.IsFaulted = true;
             faulted.DataLayerArgumentException = e.Message;
         }
         catch (DataLayerException e)
         {
             faulted.IsFaulted          = true;
             faulted.DataLayerException = e.Message;
         }
         return(faulted);
     }
     return(null);
 }