コード例 #1
0
        public async Task Update_User()
        {
            UserManagerMock.Setup(m => m.FindByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(new IdentityUser());

            UserManagerMock.Setup(m => m.UpdateAsync(It.IsAny <IdentityUser>()))
            .ReturnsAsync(IdentityResult.Success);

            UserValidatorMock.Setup(m => m.ValidateAsync(UserManagerMock.Object, It.IsAny <IdentityUser>()))
            .ReturnsAsync(IdentityResult.Success);

            UnitOfWorkMock.Setup(um => um.Customers.UpdateItem(It.IsAny <Customer>())).Verifiable();
            UnitOfWorkMock.Setup(um => um.SaveChanges()).Verifiable();
            var target = new UserController(UserManagerMock.Object, null, null, UserValidatorMock.Object,
                                            UnitOfWorkMock.Object, null);

            var resultAction = await target.Create(new UserInfoViewModel()
            {
                Customer = new Customer(),
                Email    = "*****@*****.**",
                Password = "******",
                IsAdmin  = false
            }) as RedirectToActionResult;

            Assert.NotNull(resultAction);
            UnitOfWorkMock.Verify(e => e.SaveChanges());
            UnitOfWorkMock.Verify(e => e.Customers.UpdateItem(It.IsAny <Customer>()));
        }
コード例 #2
0
        public void Make_InValid_Order()
        {
            var cart   = new SessionCart();
            var target = new CartController(UnitOfWorkMock.Object, cart, UserManagerMock.Object);

            var result = target.MakeOrder("returnUrl") as RedirectResult;

            Assert.Equal("returnUrl", result.Url);
            UnitOfWorkMock.Verify(m => m.SaveChanges(), Times.Never);
        }
コード例 #3
0
        public void Delete_Non_Existence_Product()
        {
            UnitOfWorkMock.Setup(m => m.Products.GetItem(It.IsAny <Guid>())).Returns(value: null);
            UnitOfWorkMock.Setup(m => m.Products.DeleteItem(It.IsAny <Product>())).Verifiable();

            var target = new ProductController(UnitOfWorkMock.Object, Cart);

            target.Delete(It.IsAny <Guid>());

            UnitOfWorkMock.Verify(v => v.Products.DeleteItem(It.IsAny <Product>()), Times.Never);
        }
コード例 #4
0
        public void Invalid_Delete_Order()
        {
            UnitOfWorkMock.Setup(m => m.Orders.GetItem(It.IsAny <Guid>())).Returns(new Order()
            {
                StatusID = 2
            });
            var target = new OrderController(UnitOfWorkMock.Object, UserManagerMock.Object);

            var result = target.Delete(It.IsAny <Guid>(), It.IsAny <Statuses>()) as ViewResult;

            Assert.NotNull(result);
            UnitOfWorkMock.Verify(uow => uow.Orders.DeleteItem(It.IsAny <Order>()), Times.Never);
        }
コード例 #5
0
        public void Create_Valid_Product()
        {
            UnitOfWorkMock.Setup(m => m.Products.GetAllItems()).Returns(new List <Product>());
            UnitOfWorkMock.Setup(m => m.SaveChanges()).Verifiable();
            UnitOfWorkMock.Setup(m => m.Products.AddItem(It.IsAny <Product>())).Verifiable();

            var target = new ProductController(UnitOfWorkMock.Object, Cart);
            var result = (target.Create(new Product())) as RedirectToActionResult;

            Assert.NotNull(result);
            UnitOfWorkMock.Verify(v => v.SaveChanges());
            UnitOfWorkMock.Verify(v => v.Products.AddItem(It.IsAny <Product>()));
        }
コード例 #6
0
        public void Valid_Delete_Order()
        {
            UnitOfWorkMock.Setup(m => m.Orders.GetItem(It.IsAny <Guid>())).Returns(new Order()
            {
                StatusID = 3
            });
            UnitOfWorkMock.Setup(m => m.Orders.DeleteItem(It.IsAny <Order>())).Verifiable();
            var target = new OrderController(UnitOfWorkMock.Object, UserManagerMock.Object);

            var result = target.Delete(It.IsAny <Guid>(), It.IsAny <Statuses>()) as RedirectToActionResult;

            Assert.NotNull(result);
            UnitOfWorkMock.Verify(uow => uow.Orders.DeleteItem(It.IsAny <Order>()));
        }
コード例 #7
0
        public void Delete_Real_Product()
        {
            Product testProduct = new Product()
            {
                ID = Guid.Parse("BFF5192C-14F0-4FD7-BCB9-B1EE32737301")
            };

            UnitOfWorkMock.Setup(m => m.Products.GetItem(It.IsAny <Guid>())).Returns(testProduct);
            UnitOfWorkMock.Setup(m => m.Products.DeleteItem(It.IsAny <Product>())).Verifiable();

            var target = new ProductController(UnitOfWorkMock.Object, Cart);

            target.Delete(testProduct.ID);

            UnitOfWorkMock.Verify(v => v.Products.DeleteItem(It.IsAny <Product>()), Times.Once);
        }
コード例 #8
0
        public void Make_Valid_Order()
        {
            var cart = new SessionCart();

            cart.AddItem(new Product(), 3);

            UnitOfWorkMock.Setup(m => m.Orders.GetAllItems()).Returns(Enumerable.Empty <Order>());
            UnitOfWorkMock.Setup(m => m.Orders.AddItem(It.IsAny <Order>())).Verifiable();
            UnitOfWorkMock.Setup(m => m.SaveChanges()).Verifiable();
            UserManagerMock.Setup(m => m.GetUserId(It.IsAny <ClaimsPrincipal>())).Returns(Guid.NewGuid().ToString());
            var target = new CartController(UnitOfWorkMock.Object, cart, UserManagerMock.Object);

            var result = target.MakeOrder("returnUrl") as RedirectResult;

            UnitOfWorkMock.Verify(m => m.SaveChanges());
            UnitOfWorkMock.Verify(m => m.Orders.AddItem(It.IsAny <Order>()));
            Assert.Equal("returnUrl", result.Url);
        }
コード例 #9
0
        public void Update_Product()
        {
            Product testProduct = new Product()
            {
                Name = "Name1", ID = Guid.Parse("AD65CE6B-10C5-463E-B0E8-61B08A2BE7A8")
            };

            UnitOfWorkMock.Setup(m => m.Products.GetAllItems()).Returns(new List <Product>()
            {
                testProduct
            });
            UnitOfWorkMock.Setup(m => m.SaveChanges()).Verifiable();
            UnitOfWorkMock.Setup(m => m.Products.UpdateItem(It.IsAny <Product>())).Verifiable();

            var target = new ProductController(UnitOfWorkMock.Object, Cart);
            var result = (target.Create(testProduct)) as RedirectToActionResult;

            Assert.NotNull(result);
            UnitOfWorkMock.Verify(v => v.SaveChanges());
            UnitOfWorkMock.Verify(v => v.Products.UpdateItem(It.IsAny <Product>()));
        }