public void Index_AnonymousUser_PrivateWishlist_Throws404Exception()
        {
            Member member = new Member
            {
                UserAccount = new User
                {
                    UserName = "******"
                },
                WishListVisibility = WishListVisibility.Private
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable());
            memberDbSetStub.Setup(db => db.Find(member.UserId)).Returns(member);
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(false);

            WishlistController controller = new WishlistController(dbStub.Object, idGetter: null)
            {
                ControllerContext = context.Object
            };

            Assert.That(async () => await controller.Index(member.UserAccount.UserName), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404));
        }
Exemplo n.º 2
0
        protected void productList_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            var wishlistID = e.CommandArgument;
            WishlistController wishlistControl = new WishlistController();

            if (e.CommandName == "Delete")
            {
                wishlistControl.DeleteWishlist(wishlistID.ToString());

                DataBindToPage(customer_id.InnerText);
            }
            else if (e.CommandName == "InsertData")
            {
                Wishlist obj_wishlist = new Wishlist();
                obj_wishlist = wishlistControl.GetWishlistByID(wishlistID.ToString());
                //Add to Cart
                CartController obj_cart_control = new CartController();
                CartInfo       obj_cart         = new CartInfo();
                obj_cart.ProductID  = obj_wishlist.ProductID;
                obj_cart.CustomerID = obj_wishlist.CustomerID;
                obj_cart.Quantity   = Convert.ToInt32("1");
                obj_cart_control.InsertCart(obj_cart);
                //Delete Wishlist
                wishlistControl.DeleteWishlist(wishlistID.ToString());

                DataBindToPage(customer_id.InnerText);
            }
        }
Exemplo n.º 3
0
        public void TestInitialize()
        {
            var serviceCollection = new ServiceCollection()
                                    .AddLogging();

            serviceCollection.Add(new ServiceDescriptor(typeof(DatabaseContext),
                                                        UnitTestDatabaseContext.Get()));
            serviceCollection.Add(new ServiceDescriptor(typeof(DaoManager),
                                                        DaoManager.Get(UnitTestDatabaseContext.Get())));
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var factory         = serviceProvider.GetService <ILoggerFactory>();
            var logger          = factory.CreateLogger <WishlistController>();

            Controller = new WishlistController(logger)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext {
                        RequestServices = serviceProvider
                    }
                }
            };
            var identity = new ClaimsIdentity();

            identity.AddClaim(new Claim(ClaimTypes.Sid, "5"));
            identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
            Controller.ControllerContext.HttpContext.User = new ClaimsPrincipal(identity);
        }
        public static string InsertWishlist(string product_id)
        {
            string result     = "";
            string customerID = "";

            if (HttpContext.Current.Request.Cookies["CustomerID"] != null)
            {
                customerID = HttpContext.Current.Request.Cookies["CustomerID"].Value;
                if (customerID.Length <= 0)
                {
                    result = "Fail";
                }
                else
                {
                    WishlistController obj_wishlist_control = new WishlistController();
                    Wishlist           obj_wishlist         = new Wishlist();
                    obj_wishlist.ProductID  = product_id;
                    obj_wishlist.CustomerID = customerID;
                    obj_wishlist.AddedDate  = DateTime.Now;
                    result = obj_wishlist_control.InsertWishlist(obj_wishlist);
                }
            }
            else
            {
                result = "Fail";
            }

            return(result);
        }
Exemplo n.º 5
0
        public async Task GetWishlistAsync_shouldReturnBadRequest_WhenCustomerIdNotProvided()
        {
            //Arrange
            int id = 0;

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.GetWishlistAsync(id);

            //Assert
            Assert.Equal((int)HttpStatusCode.BadRequest, (result.Result as ObjectResult).StatusCode);
        }
Exemplo n.º 6
0
        public void DataBindToPage(string customerID)
        {
            WishlistController wishlistController = new WishlistController();
            DataTable          dt_Wishlist        = new DataTable();

            dt_Wishlist = wishlistController.GetAllWishlistByCustomer(customerID);

            //Bind to List View
            productList.DataSource = dt_Wishlist;
            productList.DataBind();

            customer_id.InnerText = customerID;
        }
Exemplo n.º 7
0
        public async Task Delete_shouldReturnBadRequest_WhenProductIdIsNotProvided()
        {
            //Arrange
            int    customerId = 1;
            string productId  = "";

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.DeleteAsync(customerId, productId);

            //Assert
            Assert.Equal((int)HttpStatusCode.BadRequest, (result as ObjectResult).StatusCode);
        }
Exemplo n.º 8
0
        public async Task GetWishlistAsync_shouldReturnNotFound_WhenItIsNotPossibleToGet()
        {
            //Arrange
            int id = 1;
            List <WishListProduct> notFound = null;

            _wishlistService.GetCustomerWishlistAsync(id).Returns(notFound);

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.GetWishlistAsync(id);

            //Assert
            Assert.Equal((int)HttpStatusCode.NotFound, (result.Result as StatusCodeResult).StatusCode);
        }
Exemplo n.º 9
0
        public async Task Delete_shouldReturnNotFound_WhenItIsNotPossibleToAddProduct()
        {
            //Arrange
            int    customerId = 1;
            string productId  = "1";

            _wishlistService.RemoveProductFromCustomerrWishlistAsync(customerId, productId).Returns(false);

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.DeleteAsync(customerId, productId);

            //Assert
            Assert.Equal((int)HttpStatusCode.NotFound, (result as StatusCodeResult).StatusCode);
        }
Exemplo n.º 10
0
        public async Task Post_shouldReturnCreated_WhenItIsPossibleToAddProduct()
        {
            //Arrange
            int             customerId      = 1;
            string          productId       = "1";
            WishListProduct existingProduct = new WishListProduct();

            _wishlistService.AddProductToCustomerrWishlistAsync(customerId, productId).Returns(existingProduct);

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.PostAsync(customerId, productId);

            //Assert
            Assert.Equal((int)HttpStatusCode.Created, (result.Result as ObjectResult).StatusCode);
        }
Exemplo n.º 11
0
        public async Task Post_shouldReturnNotFound_WhenItIsNotPossibleToAddProduct()
        {
            //Arrange
            int             customerId = 1;
            string          productId  = "1";
            WishListProduct notFound   = null;

            _wishlistService.AddProductToCustomerrWishlistAsync(customerId, productId).Returns(notFound);

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.PostAsync(customerId, productId);

            //Assert
            Assert.Equal((int)HttpStatusCode.NotFound, (result.Result as StatusCodeResult).StatusCode);
        }
Exemplo n.º 12
0
        public async Task GetWishlistAsync_shouldReturnOk_WhenItIsPossibleToGet()
        {
            //Arrange
            int id = 1;
            List <WishListProduct> existingList = new List <WishListProduct>()
            {
                new WishListProduct()
            };

            _wishlistService.GetCustomerWishlistAsync(id).Returns(existingList);

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.GetWishlistAsync(id);

            //Assert
            Assert.Equal((int)HttpStatusCode.OK, (result.Result as ObjectResult).StatusCode);
        }
Exemplo n.º 13
0
        public async Task GetWishlistAsync_shouldReturnVlidBody_WhenItIsPossibleToGet()
        {
            //Arrange
            int id              = 1;
            var productId       = "1bf0f365-fbdd-4e21-9786-da459d78dd1f";
            var url             = "http://images.luizalabs.com/123.png";
            var wishlistProduct = new WishListProduct()
            {
                Id        = 1,
                ProductId = productId,
                Image     = url,
                Price     = "30.00",
                Title     = "Product123"
            };
            List <WishListProduct> existingList = new List <WishListProduct>()
            {
                wishlistProduct
            };

            _wishlistService.GetCustomerWishlistAsync(id).Returns(existingList);

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.GetWishlistAsync(id);

            //Assert
            Assert.Equal((int)HttpStatusCode.OK, (result.Result as ObjectResult).StatusCode);

            var json = JsonConvert.SerializeObject((result.Result as ObjectResult).Value);

            var expected = "[" +
                           "{" +
                           $"\"productId\":\"{productId}\"," +
                           "\"price\":\"30.00\"," +
                           $"\"image\":\"{url}\"," +
                           "\"title\":\"Product123\"" +
                           "}" +
                           "]";

            Assert.Equal(expected, json, ignoreCase: true, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
        }
Exemplo n.º 14
0
 public WishlistControllerTests() : base()
 {
     _controller = new WishlistController(_wishlistService);
 }
        public void Index_WishlistOwnerFound_Private_Throws404Exception()
        {
            Member wishlistOwner = new Member
            {
                UserAccount = new User
                {
                    UserName = "******"
                },
                UserId = Id,
                WishListVisibility = WishListVisibility.Private
            };

            Member currentMember = new Member
            {
                UserId = UserId
            };

            List<Member> members = new List<Member>
            {
                wishlistOwner,
                currentMember
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(members.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(currentMember.UserId)).ReturnsAsync(currentMember);
            memberDbSetStub.Setup(db => db.FindAsync(wishlistOwner.UserId)).ReturnsAsync(wishlistOwner);
            memberDbSetStub.SetupForInclude();
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(currentMember.UserId);

            WishlistController controller = new WishlistController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            Assert.That(async () => await controller.Index(wishlistOwner.UserAccount.UserName), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404));
        }
        public async void Index_WishlistOwnerFound_FriendsOnly_NotFriends_Throws404Exception()
        {
            Member wishlistOwner = new Member
            {
                UserAccount = new User
                {
                    UserName = "******"
                },
                UserId = Id,
                WishListVisibility = WishListVisibility.FriendsOnly,
                RequestedFriendships = new List<Friendship>(),
                ReceivedFriendships = new List<Friendship>(),
            };

            Member currentMember = new Member
            {
                UserId = UserId
            };

            List<Member> members = new List<Member>
            {
                wishlistOwner,
                currentMember
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(members.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(currentMember.UserId)).ReturnsAsync(currentMember);
            memberDbSetStub.Setup(db => db.FindAsync(wishlistOwner.UserId)).ReturnsAsync(wishlistOwner);
            memberDbSetStub.SetupForInclude();
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(currentMember.UserId);

            WishlistController controller = new WishlistController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            var result = await controller.Index(wishlistOwner.UserAccount.UserName) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["controller"], Is.EqualTo("FriendList"));
            Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));
        }
        public void RenderPhysicalGameProduct_CurrentUserIsMember()
        {
            Guid gameProductId = new Guid("976ACE77-D87C-4EBE-83A0-46F911F6490E");
            PhysicalGameProduct gameProduct = new PhysicalGameProduct()
            {
                Id = gameProductId
            };

            Member wishlistOwner = new Member
            {
                UserId = Id,
                WishListVisibility = WishListVisibility.FriendsOnly,
                RequestedFriendships = new List<Friendship>(),
                ReceivedFriendships = new List<Friendship>(),
                UserAccount = new DataModels.Models.Identity.User()
                {
                    UserName = "******"
                }
            };

            Member currentMember = new Member
            {
                UserId = UserId,
                Wishlist = new List<Product>
                {
                    gameProduct
                },
                Cart = new Cart
                {
                    Items = new List<CartItem>
                    {
                        new CartItem
                        {
                            Product = gameProduct,
                            ProductId = gameProduct.Id,
                            IsNew = true,
                            MemberId = UserId,
                            Quantity = 1
                        },
                        new CartItem
                        {
                            Product = gameProduct,
                            ProductId = gameProduct.Id,
                            IsNew = false,
                            MemberId = UserId,
                            Quantity = 1
                        }
                    }
                }
            };

            List<Member> members = new List<Member>
            {
                wishlistOwner,
                currentMember
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(members.AsQueryable());
            memberDbSetStub.Setup(db => db.Find(currentMember.UserId)).Returns(currentMember);
            memberDbSetStub.Setup(db => db.Find(wishlistOwner.UserId)).Returns(wishlistOwner);
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(currentMember.UserId);

            WishlistController controller = new WishlistController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            var result = controller.RenderPhysicalGameProduct(gameProduct, wishlistOwner.UserId) as PartialViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<WishlistPhysicalGameProductViewModel>());

            var model = (WishlistPhysicalGameProductViewModel)result.Model;

            Assert.That(model.GameProduct.Id, Is.EqualTo(gameProduct.Id));
            Assert.That(model.NewIsInCart);
            Assert.That(model.UsedIsInCart);
            Assert.That(model.ProductIsOnWishlist);
            Assert.That(!model.MemberIsCurrentUser);
        }
        public void Remove_IdNotInDb_Throws404Exception()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Product>> productDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Product>().AsQueryable());

            dbStub.Setup(db => db.Products).Returns(productDbSetStub.Object);

            WishlistController controller = new WishlistController(dbStub.Object, idGetter: null);

            Assert.That(async () => await controller.Remove(Id), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404));
        }
        public async void Remove_IdInDb_RedirectsToIndex(bool itemAlreadyInWishlist)
        {
            Guid gameProductId = new Guid("976ACE77-D87C-4EBE-83A0-46F911F6490E");
            PhysicalGameProduct gameProduct = new PhysicalGameProduct()
            {
                Game = new Game()
                {
                    Name = "TestGame"
                },
                SKUNameSuffix = "TestGameProductName",
                Id = gameProductId
            };

            Member currentMember = new Member
            {
                UserId = UserId,
                Wishlist = new List<Product>()
            };

            if (itemAlreadyInWishlist)
            {
                currentMember.Wishlist.Add(gameProduct);
            }

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Product>> productDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Product>().AsQueryable());
            productDbSetStub.Setup(db => db.FindAsync(gameProduct.Id)).ReturnsAsync(gameProduct);
            dbStub.Setup(db => db.Products).Returns(productDbSetStub.Object);

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { currentMember }.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(currentMember.UserId)).ReturnsAsync(currentMember);
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(currentMember.UserId);

            WishlistController controller = new WishlistController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            var result = await controller.Remove(gameProduct.Id) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));
            Assert.That(currentMember.Wishlist.Contains(gameProduct), Is.False);
        }
        public async void Index_AnonymousUser_PublicWishlist_ReturnsMatchingModel()
        {
            Member member = new Member
            {
                UserAccount = new User
                {
                    UserName = "******"
                },
                UserId = UserId,
                WishListVisibility = WishListVisibility.Public,
                Wishlist = new List<Product>()
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(member.UserId)).ReturnsAsync(member);
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(false);

            WishlistController controller = new WishlistController(dbStub.Object, idGetter: null)
            {
                ControllerContext = context.Object
            };

            var result = await controller.Index(member.UserAccount.UserName) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<Member>());

            var model = (Member)result.Model;

            Assert.That(model.Wishlist, Is.EqualTo(member.Wishlist));
        }
Exemplo n.º 21
0
 public frmWishlist(User user)
 {
     _controller = new WishlistController(this, user);
     InitializeComponent();
 }
        public async void Index_CurrentMemberWishlist_ReturnsMatchingModel()
        {
            Member member = new Member
            {
                UserId = UserId,
                UserAccount = new User
                {
                    UserName = "******"
                }
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(member.UserId)).ReturnsAsync(member);
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(member.UserId);

            WishlistController controller = new WishlistController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            var result = await controller.Index(null) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<Member>());

            var model = (Member)result.Model;

            Assert.That(model.UserId, Is.EqualTo(UserId));
        }