示例#1
0
            public void noUserAuthorShouldNotReturnAnything()
            {
                WishListVieModel Actual = Sut.PopulateWishListViewModel("Empty");

                Assert.Empty(Actual.WantWishes.GetWishList);
                Assert.Empty(Actual.readWishes.GetWishList);
                Assert.Empty(Actual.NeedWishes.GetWishList);
                Assert.Empty(Actual.WearWishes.GetWishList);
            }
示例#2
0
            public void ShouldReturnPopulatedWishViewModel()
            {
                WishListVieModel Actual = Sut.PopulateWishListViewModel("valid");

                Assert.Equal(4, Actual.NeedWishes.GetWishList.Count);
                Assert.Equal(4, Actual.WantWishes.GetWishList.Count);
                Assert.Equal(4, Actual.WearWishes.GetWishList.Count);
                Assert.Equal(4, Actual.readWishes.GetWishList.Count);
            }
        public void WishListVieModelShouldBe5WishesEachCat()
        {
            ViewResult       Result = (ViewResult)Sut.WishList();
            WishListVieModel Actual = (WishListVieModel)Result.ViewData.Model;

            Assert.Equal(5, Actual.NeedWishes.GetWishList.Count);
            Assert.Equal(5, Actual.WantWishes.GetWishList.Count);
            Assert.Equal(5, Actual.WearWishes.GetWishList.Count);
            Assert.Equal(5, Actual.readWishes.GetWishList.Count);
        }
示例#4
0
        /// <summary>
        /// Creates WishList ViewModel
        /// </summary>
        /// <param name="need"></param>
        /// <param name="want"></param>
        /// <param name="read"></param>
        /// <param name="wear"></param>
        /// <returns></returns>
        public WishListVieModel NewWishListViewModel(List <Wish> need, List <Wish> want, List <Wish> read, List <Wish> wear)
        {
            WishListVieModel Result = new WishListVieModel();

            Result.NeedWishes = NewWishList(need);
            Result.WantWishes = NewWishList(want);
            Result.readWishes = NewWishList(read);
            Result.WearWishes = NewWishList(wear);

            return(Result);
        }
示例#5
0
        public WishListViewModelTest()
        {
            Sut = new WishListVieModel();

            var wishListMock = Mock.Of <WishList>();

            Sut.NeedWishes = wishListMock;
            Sut.WantWishes = wishListMock;
            Sut.readWishes = wishListMock;
            Sut.WearWishes = wishListMock;
        }
示例#6
0
        public IActionResult WishList(string msg = null)
        {
            ViewBag.msg = msg;
            WishListVieModel model = WishListFactory.PopulateWishListViewModel(UserManager.GetUserId(User));

            ValidateViewModel(model.WantWishes.GetWishList);
            ValidateViewModel(model.NeedWishes.GetWishList);
            ValidateViewModel(model.readWishes.GetWishList);
            ValidateViewModel(model.WearWishes.GetWishList);

            return(View(model));
        }
示例#7
0
        /// <summary>
        /// Populates wishList with currentUsers wishes from Database
        /// </summary>
        /// <param name="CurrentUserId"></param>
        /// <returns></returns>
        public virtual WishListVieModel PopulateWishListViewModel(string CurrentUserId)
        {
            WishListVieModel Result = new WishListVieModel();

            List <Wish> need = EntityQuery(CategoriesEnum.Need, CurrentUserId);
            List <Wish> want = EntityQuery(CategoriesEnum.Want, CurrentUserId);
            List <Wish> wear = EntityQuery(CategoriesEnum.Wear, CurrentUserId);
            List <Wish> read = EntityQuery(CategoriesEnum.Read, CurrentUserId);

            Result.NeedWishes = NewWishList(need);
            Result.WantWishes = NewWishList(want);
            Result.WearWishes = NewWishList(wear);
            Result.readWishes = NewWishList(read);

            return(Result);
        }
示例#8
0
        public RedirectToActionResult Save(WishListVieModel model)
        {
            WishListVieModel OldValues = WishListFactory.PopulateWishListViewModel(UserManager.GetUserId(User));

            foreach (Wish wish in OldValues.WantWishes.GetWishList)
            {
                dbContext.Remove(wish);
            }
            foreach (Wish wish in OldValues.NeedWishes.GetWishList)
            {
                dbContext.Remove(wish);
            }
            foreach (Wish wish in OldValues.readWishes.GetWishList)
            {
                dbContext.Remove(wish);
            }
            foreach (Wish wish in OldValues.WearWishes.GetWishList)
            {
                dbContext.Remove(wish);
            }
            dbContext.SaveChanges();

            AddToContext(model.WantWishes.GetWishList, CategoriesEnum.Want);
            AddToContext(model.NeedWishes.GetWishList, CategoriesEnum.Need);
            AddToContext(model.WearWishes.GetWishList, CategoriesEnum.Wear);
            AddToContext(model.readWishes.GetWishList, CategoriesEnum.Read);

            int    save = dbContext.SaveChanges();
            string msg  = null;

            if (save > 0)
            {
                msg = "Changes Saved";
            }

            return(RedirectToAction("WishList", new { msg }));
        }