Ejemplo n.º 1
0
        public void Remove_NotExistingIdPassed_ReturnsBadRequestResult()
        {
            var notExistingId = 45;
            var badResponse   = _controller.Delete(notExistingId);

            Assert.IsType <BadRequestResult>(badResponse);
        }
        public void Delete_WhenIdIsLargerThanZero_RemoveIsCalled()
        {
            // Act
            controller.Delete(1);

            // Assert against the mock object
            fakeCustomerRepository.Verify(x => x.Remove(It.IsAny <int>()));
        }
Ejemplo n.º 3
0
        public void DeleteById()
        {
            GetReady();
            var actRes   = controller.Delete(2);
            var response = actRes.ExecuteAsync(CancellationToken.None).Result;

            Assert.IsTrue(response.IsSuccessStatusCode);
        }
Ejemplo n.º 4
0
        public void Delete_WhenRoomIdIsValid_ReturnViewRoom()
        {
            // Act
            var result     = controller.Delete(2) as ViewResult;
            var customer   = result.Model as Customer;
            var customerId = customer.Id;

            // Assert Verify
            Assert.InRange <int>(customerId, 1, 2);
        }
Ejemplo n.º 5
0
        public void Delete_NotExistingGuidPassed_ReturnsNotFoundResponse()
        {
            // Arrange
            var notExistingGuid = Guid.NewGuid();

            // Act
            var badResponse = _customerController.Delete(notExistingGuid);

            // Assert
            Assert.IsType <NotFoundResult>(badResponse);
        }
Ejemplo n.º 6
0
        public async Task Delete_Returns_NotFound_WhenIdIsInvalid()
        {
            // Arrange
            var customerToUpdate = CustomerFixture.Customers().First();

            mockCustomerService.Setup(service => service.Get(It.IsAny <int>())).Returns(Task.FromResult <Customer>(null));

            // Act
            var result = await controller.Delete(100);

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }
Ejemplo n.º 7
0
        public async Task DeleteWhenEmailNull()
        {
            // ARRANGE
            string email = null;

            // ACT
            var result = await _controller.Delete(email) as HttpStatusCodeResult;

            // ASSERT
            Assert.AreEqual((int)HttpStatusCode.BadRequest, result.StatusCode);

            // verify that the method was not called
            _userManager.Verify(x => x.FindByEmailAsync(It.IsAny <string>()), Times.Never);
        }
Ejemplo n.º 8
0
        public void DeleteRemovesCustomer()
        {
            var context         = new Mock <IApplicationDbContext>();
            var deletedCustomer = new Customer {
                Id = 4, Name = "Test", isSubscribedToNewsletter = true, MembershipType = new MembershipType(), MembershipTypeId = 2, Birthdate = DateTime.Parse("10/30/2001")
            };
            var mockedDbMemberships = new Mock <DbSet <MembershipType> >();
            var mockedDbCustomers   = new Mock <DbSet <Customer> >();
            var membershipTypeData  = TestMembershipTypeList();

            mockedDbMemberships.As <IQueryable <MembershipType> >().Setup(m => m.Provider).Returns(membershipTypeData.Provider);
            mockedDbMemberships.As <IQueryable <MembershipType> >().Setup(m => m.Expression).Returns(membershipTypeData.Expression);
            mockedDbMemberships.As <IQueryable <MembershipType> >().Setup(m => m.ElementType).Returns(membershipTypeData.ElementType);
            mockedDbMemberships.As <IQueryable <MembershipType> >().Setup(m => m.GetEnumerator()).Returns(membershipTypeData.GetEnumerator());
            context.Setup(m => m.MembershipTypes).Returns(mockedDbMemberships.Object);
            var customerData = TestCustomerList();

            mockedDbCustomers.As <IQueryable <Customer> >().Setup(m => m.Provider).Returns(customerData.Provider);
            mockedDbCustomers.As <IQueryable <Customer> >().Setup(m => m.Expression).Returns(customerData.Expression);
            mockedDbCustomers.As <IQueryable <Customer> >().Setup(m => m.ElementType).Returns(customerData.ElementType);
            mockedDbCustomers.As <IQueryable <Customer> >().Setup(m => m.GetEnumerator()).Returns(customerData.GetEnumerator());
            context.Setup(m => m.Customers).Returns(mockedDbCustomers.Object);
            var controller = new CustomersController(context.Object);

            var result = controller.Delete(deletedCustomer.Id);

            Assert.AreEqual(result.GetType(), typeof(RedirectToRouteResult));
            var SingleMethodResult = mockedDbCustomers.Object.Single(c => c.Id == deletedCustomer.Id);

            Assert.AreEqual(SingleMethodResult.Name, deletedCustomer.Name);
            context.Verify(c => c.Customers.Remove(It.IsAny <Customer>()), Times.Once);
            context.Verify(c => c.SaveChanges(), Times.Once());
        }
Ejemplo n.º 9
0
        public void DeleteCustomersSuccessViewRenders()
        {
            var cust_id = Guid.NewGuid();
            var cust    = new Customer
            {
                customer_id     = cust_id,
                name            = "Test2",
                billing_address = " 123 Cherry Oak Street",
                billing_city    = "Hilliard",
                billing_state   = "OH",
                billing_zip     = "43221",
                isActive        = true
            };

            var mockCust = new Mock <DbSet <Customer> >();

            mockCust.Setup(m => m.Find(cust_id)).Returns(cust);

            var mockContext = new Mock <StoreDbContext>();

            mockContext.Setup(m => m.Customers).Returns(mockCust.Object);

            var controller = new CustomersController(mockContext.Object);
            var result     = controller.Delete(cust_id);

            Assert.IsAssignableFrom(typeof(ViewResult), result);
        }
Ejemplo n.º 10
0
        public void DeleteCustomerByWrongId(int id)
        {
            var controller = new CustomersController(context);
            var response   = controller.Delete(id) as StatusCodeResult;

            Assert.AreEqual(404, response.StatusCode);
        }
        public void DeleteCustomerSuccess()
        {
            Address add = new Address
            {
                City    = "Sarajevo",
                Name    = "Bosmal",
                ZipCode = "71000"
            };

            Customer c = new Customer();

            c = new Customer()
            {
                Name           = "Mistral Technologies new",
                Image          = null,
                Monogram       = null,
                Contact        = "Sulejman Catibusic",
                Email          = "*****@*****.**",
                Phone          = "+38761200333",
                StatusCustomer = StatusCustomer.Client,
                Address        = add
            };

            UnitOfWork unit = new UnitOfWork();

            unit.Customer.Insert(c);
            unit.Save();

            var controller = new CustomersController();
            var response   = controller.Delete(c.Id);
            var result     = (OkResult)response;

            Assert.IsNotNull(result);
        }
Ejemplo n.º 12
0
        public void ControllerDeleteCustomerWithValidID()
        {
            var controller = new CustomersController();
            var response   = controller.Delete(2);
            var result     = (OkResult)response;

            Assert.IsNotNull(result);
        }
Ejemplo n.º 13
0
        public void ControllerDeleteCustomerWithInvalidID()
        {
            var controller = new CustomersController();

            var response = controller.Delete(1337);
            var result   = (NotFoundResult)response;

            Assert.IsNotNull(result);
        }
Ejemplo n.º 14
0
        public async Task DeleteCustomer()
        {
            var controller = new CustomersController(unit.Context);
            int id         = 2;//Try to delete the customer with id

            var response = await controller.Delete(id) as StatusCodeResult;

            Assert.AreEqual(204, response.StatusCode);
        }
Ejemplo n.º 15
0
        public async Task DeleteCustomerWithWrongId()
        {
            var controller = new CustomersController(unit.Context);
            int id         = 40;//Try to delete the customer with id (doesn't exist)

            var response = await controller.Delete(id) as StatusCodeResult;

            Assert.AreEqual(404, response.StatusCode);
        }
Ejemplo n.º 16
0
        public void CustomerControllerDelete()
        {
            var controller = new CustomersController();

            var response = controller.Delete(1);
            var result   = (OkResult)response;

            Assert.IsNotNull(result);
        }
Ejemplo n.º 17
0
        public async Task DeleteCustomerValidTest()
        {
            var result = await _customersController.Delete(CustomerMotherObject.ValidCustomer().PublicId);

            var contentResult = (NoContentResult)result;

            Assert.IsType <NoContentResult>(contentResult);
            Assert.Equal(204, contentResult.StatusCode);
        }
        public void SetUp()
        {
            _id = 1;
            _customersRepository = new Mock <ICustomersRepository>();
            _customersRepository.Setup(mock => mock.Delete(It.IsAny <int>())).Returns(false);

            var subject = new CustomersController(_customersRepository.Object);

            _result = subject.Delete(_id) as NotFoundResult;
        }
Ejemplo n.º 19
0
        public void Delete_CheckCountAfterDelete_ReturnCount()
        {
            var controller = new CustomersController(_context);
            var count      = _context.Customers.CountAsync().Result;

            controller.Delete(1);
            var result = controller.Get(sort: "asc").CountAsync();

            Assert.Equal(count - 1, result.Result);
        }
Ejemplo n.º 20
0
        public void DeleteCustomer_Success()
        {
            // Arrange
            CustomersController controller = new CustomersController();
            // Act
            ViewResult result = controller.Delete(1) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Ejemplo n.º 21
0
        public async Task DeleteCustomer(int customerId)
        {
            customerService.Setup(x => x.DeleteCustomer(customerId)).Returns(Task.FromResult(true));

            var controller = new CustomersController(customerService.Object, _mapper);
            //act
            IHttpActionResult httpActionResult = await controller.Delete(customerId);

            Assert.IsNotNull(httpActionResult);
            Assert.IsInstanceOfType(httpActionResult, typeof(OkResult));
        }
Ejemplo n.º 22
0
        public void PreventDeletionOfCustomerWithIdGreaterThanOrEqualTo100()
        {
            //  arrange
            var controller = new CustomersController();

            //  act
            var result = controller.Delete(123) as NotFoundResult;


            Assert.NotNull(result);
        }
Ejemplo n.º 23
0
        public void DeleteTest()
        {
            // Arrange
            CustomersController controller = new CustomersController(new CustomerManager(new TestCustomerRepository()));

            // Act
            ViewResult result = controller.Delete(1) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Ejemplo n.º 24
0
        public void SuccessfullyDeleteCustomerWithIdLessThan100()
        {
            //  arrange
            var controller = new CustomersController();

            //  act
            var result = controller.Delete(98) as OkObjectResult;


            Assert.NotNull(result);
        }
        public async void CustomerController_DeleteCustomer_ReturnBadRequestResult()
        {
            //Arrange
            var controller = new CustomersController(customersDAL);
            int?postId     = null;

            //Act
            var data = await controller.Delete(postId);

            //Assert
            Assert.IsType <BadRequestResult>(data);
        }
Ejemplo n.º 26
0
        public void DeleteCustomerReturnsInternalServerErrorStatusCode()
        {
            ICustomerRepository repository = mockCustomerRepository.Object;

            CustomersController controller = new CustomersController(repository);

            controller.Request = new HttpRequestMessage();
            HttpResponseMessage response = controller.Request.CreateResponse(HttpStatusCode.InternalServerError);

            var result = controller.Delete("1");

            Assert.AreEqual(response.StatusCode, result.StatusCode);
        }
        public async void CustomerController_DeleteCustomer_ReturnNotFoundResult()
        {
            //Arrange
            var controller = new CustomersController(customersDAL);

            // Our test database is seeded with seedRowsCount datarows. Choose an invalid value.
            var customerBadID = seedRowsCount + 10;

            //Act
            var data = await controller.Delete(customerBadID);

            //Assert
            Assert.IsType <NotFoundObjectResult>(data);
        }
        public async Task Customer_Delete_NotFound()
        {
            //ARRANGE
            var mockRepository = new Mock <IRepository>();

            mockRepository.Setup(r => r.FindCustomer(1)).ReturnsAsync(GetTestSessions()[0]);
            // make a using my mock
            var controller = new CustomersController(mockRepository.Object);
            // ACT
            var result = await controller.Delete(1);

            //Assert should be a 404
            var viewResult = Assert.IsType <ViewResult>(result);
        }
Ejemplo n.º 29
0
        public async Task Delete_Returns_CustomerInfoForDeleting()
        {
            int id       = 4;
            var customer = GetCustomers().FirstOrDefault(p => p.Id == id);

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

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

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result);
        }
Ejemplo n.º 30
0
        public async Task Delete_Returns_WhenCustomerIsNotFound()
        {
            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.Delete(customer.Id);

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