예제 #1
0
        public JsonNetResult CreatePageWidget(PageWidgetModel model)
        {
            PageWidget widget = Mapper.Map <PageWidget>(model);

            _pageWidgetRepository.Insert(widget);
            Mapper.Map(widget, model);

            return(new JsonNetResult(model));
        }
예제 #2
0
        public static void Test(IKeyedRepository <TKey, TEntity> repo, List <string> protectedPropertyNames, TEntity seed)
        {
            // Get the inital count
            int countBefore = repo.All().Count();

            // Look for the seed.Id item in the DB; if found, refresh up to 5 times then error.
            int loopCount = 0;

            while (true)
            {
                var item = repo.FindBy(seed.Id);
                if (item == null)
                {
                    break;
                }
                if (loopCount > 4)
                {
                    Assert.Fail("Can't find a unique new key for: " + repo.GetType().Name);
                    return;
                }
                seed = Random <TEntity> .UpdateSpecifiedProperties(seed, new List <string> {
                    "Id"
                });

                loopCount += 1;
            }


            // add
            repo.Insert(seed);
            int countAfter = repo.All().Count();

            Assert.IsTrue(countBefore + 1 == countAfter);


            // read
            TEntity entity2 = repo.FindBy(seed.Id);

            //Assert.IsTrue(seed.Equals(entity2));
            Assert.IsTrue(Comparison.PublicInstancePropertiesEqual(seed, entity2, protectedPropertyNames));

            // update
            protectedPropertyNames.Add("Id");             // Make sure Id is now in the list.
            seed = Random <TEntity> .Update(seed, protectedPropertyNames);

            repo.Update(seed);
            TEntity entity3 = repo.FindBy(seed.Id);

            Assert.IsFalse(Comparison.PublicInstancePropertiesEqual(entity2, seed, protectedPropertyNames));
            Assert.IsTrue(Comparison.PublicInstancePropertiesEqual(entity3, seed, protectedPropertyNames));

            // delete
            repo.Delete(seed.Id);
            countAfter = repo.All().Count();
            Assert.IsTrue(countAfter == countBefore);
        }