Beispiel #1
0
 public void DeleteConfirmed_WhenIdIsLargerThanZero_RemoveIsCalled()
 {
     // Act
     controller.DeleteConfirmed(1);
     // Assert against the mock object
     fakeCustomerRepository.Verify(x => x.Remove(It.IsAny <int>()));
 }
Beispiel #2
0
        public async Task DeletePOST_Returns_CustomerInfoForDeleting()
        {
            int id       = 4;
            var customer = GetCustomers().FirstOrDefault(p => p.Id == id);

            //Arrange
            mock.Setup(repo => repo.DeleteAsync(customer.Id)).Throws(new Exception());
            controller = new CustomersController(mock.Object);

            //Act
            var result = await controller.DeleteConfirmed(customer.Id);

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result);
        }
        public async Task DeleteConfirmedWhenFoundUserNotNull()
        {
            // ARRANGE
            var dummyUsers = new List <ApplicationUser>
            {
                new ApplicationUser
                {
                    UserName   = "******",
                    Email      = "*****@*****.**",
                    ProvinceId = 1
                }
            }.AsQueryable();

            _userSet = MockingHelper.Create(dummyUsers);

            // Set the mocked db sets in the mocked db context
            _db.Setup(c => c.Users).Returns(_userSet.Object);

            // This value will get returned from UserManager
            ApplicationUser user  = dummyUsers.ToList()[0];
            var             email = user.Email;

            // Manipulate the method in and UserManager so that it cannot find the user
            _userManager.Setup(x => x.FindByEmailAsync(email)).Returns(Task.FromResult(user));

            _db.Setup(x => x.SaveChanges()).Returns(3);

            // ACT
            var result = await _controller.DeleteConfirmed(user);

            // ASSERT
            Assert.AreEqual(typeof(RedirectToRouteResult), result.GetType());
            _userManager.Verify(x => x.FindByEmailAsync(It.IsAny <string>()), Times.Once);
            _userManager.Verify(x => x.DeleteAsync(It.IsAny <ApplicationUser>()), Times.Once);
            _db.Verify(x => x.SaveChanges(), Times.Once);
        }
Beispiel #4
0
        public async Task DeleteConfirmedRedirectsToIndex()
        {
            // arrange
            var mockRepo = new Mock <ICustomerRepository>();

            mockRepo.Setup(x => x.DeleteAsync(1));

            var controller = new CustomersController(mockRepo.Object);

            // act
            IActionResult result = await controller.DeleteConfirmed(1);

            // assert that the result is a ViewResult
            var viewResult = Assert.IsAssignableFrom <RedirectToActionResult>(result);

            // ...that the model of the view is a CustomersViewModel
            Assert.Equal("Index", viewResult.ActionName);
        }
Beispiel #5
0
        public async Task DeletePOST_Returns_RedirectToActionResult()
        {
            int id       = 4;
            var customer = GetCustomers().FirstOrDefault(p => p.Id == id);

            //Arrange
            mock.Setup(repo => repo.DeleteAsync(customer.Id));
            controller = new CustomersController(mock.Object);

            //Act
            var result = await controller.DeleteConfirmed(customer.Id);

            //Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
            mock.Verify(r => r.DeleteAsync(customer.Id));
        }
Beispiel #6
0
        public async Task CustomersReturnsDeleteDeletes()
        {
            //Arrange
            DashbordCustomer customers = new DashbordCustomer()
            {
                CompanyName = "test"
            };
            await _customersControllerUnderTest.Create(customers);

            var customer = db.Customers.Where(c => c.CompanyName == customers.CompanyName).FirstOrDefault();
            int expected = db.Customers.Count() - 1;

            //Act
            await _customersControllerUnderTest.DeleteConfirmed(customer.CustomerID);

            int actual = db.Customers.Count();

            //Assert
            Assert.AreEqual(expected, actual);
        }