Пример #1
0
        public async Task DeleteItem_ReturnUnauthorizedResult_WhenUserIsNotTheItemSeller()
        {
            // Arrange
            var sellerId = 1;
            var item     = GetTestItems().FirstOrDefault(i => i.SellerId == sellerId);

            // setup GetItemById to return null
            _mockItemService.Setup(service => service.GetItemById(It.IsAny <int>()))
            .ReturnsAsync(item);
            var controller       = new ItemsController(_mockItemService.Object, _mapper);
            var unauthorizedUser = new ClaimsPrincipal(new ClaimsIdentity(
                                                           new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "2")
            }
                                                           , "TestAuthentication"));

            SetupHttpContextUser(controller, unauthorizedUser);

            // Act
            var actionResult = await controller.DeleteItem(item.Id);

            // Assert
            Assert.IsType <UnauthorizedResult>(actionResult);
        }
Пример #2
0
        public async void DeleteItem_ReturnsBadRequest()
        {
            // Act
            var badResponse = await controller.DeleteItem(100);

            // Assert
            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
        public async Task DeleteItem_WithUnexistingItem_ReturnsNotFound()
        {
            // Arrange
            itemRepositoryStub.Setup(repo => repo.GetItemAsync(It.IsAny <Guid>()))
            .ReturnsAsync((Item)null);
            var controller = new ItemsController(itemRepositoryStub.Object);

            // Act
            var result = await controller.DeleteItem(Guid.NewGuid());

            // Assert
            result.Should().BeOfType <NotFoundResult>();
        }
Пример #4
0
        public void Delete_Employee()
        {
            using (var context = GetContextWithData())
            using (var controller = new ItemsController(context))
            {
                var item = context.Items.First();

                var result = controller.DeleteItem(item.Id);

                var del = context.Items.FirstOrDefault(i => i.Id == item.Id);
                Assert.False(del != null);
            }
        }
Пример #5
0
        public async Task DeleteItemTest_NotFound()
        {
            var       mockService = new Mock <IItemService>();
            var       itemDto     = GetItemDto();
            const int id          = 1;

            mockService.Setup(service => service.DeleteAsync(id))
            .ReturnsAsync(null as ItemDto);
            var controller = new ItemsController(mockService.Object);

            var result = await controller.DeleteItem(id);

            Assert.IsInstanceOfType(result.Result, typeof(NotFoundResult));
        }
        public async Task DeleteItem_WithExistingItem_ReturnsNoContent()
        {
            // Arrange
            var item = CreateRandomItem();

            itemRepositoryStub.Setup(repo => repo.GetItemAsync(It.IsAny <Guid>()))
            .ReturnsAsync(item);
            var controller = new ItemsController(itemRepositoryStub.Object);

            // Act
            var result = await controller.DeleteItem(item.Id);

            // Assert
            result.Should().BeOfType <NoContentResult>();
        }
Пример #7
0
        public void DeleteItem_ReturnsNoContent_ForSuccessfulDelete()
        {
            // Arrange
            int testId = 5;
            var mock   = new Mock <IItemRepository>();

            mock.Setup(repo => repo.GetItemById(It.IsAny <int>())).Returns(new Item());
            var controller = new ItemsController(itemRepository: mock.Object, cartService: null, mapper: null);

            // Act
            var result = controller.DeleteItem(testId);

            // Assert
            Assert.IsType <NoContentResult>(result);
        }
        public void DeleteItem_IsOk()
        {
            //arrange
            var item = new Item {
                Id = 1, PriceListId = 999, Title = "ItemToRemove"
            };

            _context.Items.Add(item);

            //act
            _controller.DeleteItem(item.Id);

            //assert
            Assert.AreEqual(false, _context.Items.Any());
        }
        public async Task Cannot_delete_Item_when_it_not_exist()
        {
            const string ITEMID = "IT00001";

            using (var context = new ProcurementDbContext(ContextOptions))
            {
                ItemsController itemsController = new ItemsController(context);

                var result = await itemsController.DeleteItem(ITEMID);

                var viewResult = Assert.IsType <ActionResult <Item> >(result);
                Assert.IsNotType <Item>(viewResult.Value);
                var response = Assert.IsType <NotFoundResult>(viewResult.Result);
                Assert.Equal(404, response.StatusCode);
            }
        }
        public async Task Can_delete_Item_by_ItemId()
        {
            const string ITEMID = "IT001";

            using (var context = new ProcurementDbContext(ContextOptions))
            {
                ItemsController itemsController = new ItemsController(context);

                var result = await itemsController.DeleteItem(ITEMID);

                var viewResult = Assert.IsType <ActionResult <Item> >(result);
                var model      = Assert.IsType <Item>(viewResult.Value);

                Assert.Equal(ITEMID, model.ItemId);
            }
        }
Пример #11
0
        public void Can_remove_item_and_all_associated_tags()
        {
            using (var context = new ItemsContext(this.ContextOptions))
            {
                var controller = new ItemsController(context);

                var item = controller.DeleteItem("ItemThree").Value;

                Assert.Equal("ItemThree", item.Name);
            }

            using (var context = new ItemsContext(this.ContextOptions))
            {
                Assert.False(context.Items.Any(e => e.Name == "ItemThree"));
                Assert.False(context.Tags.Any(e => e.Label.StartsWith("Tag3")));
            }
        }
Пример #12
0
        public async Task DeleteItem_ReturnNoContentResult_WhenDeleteItemIsSuccess()
        {
            // Arrange
            var itemId = 1;
            var item   = GetTestItems().FirstOrDefault(i => i.Id == itemId);

            // setup GetItemById to return null
            _mockItemService.Setup(service => service.GetItemById(It.IsAny <int>()))
            .ReturnsAsync(item);
            var controller = new ItemsController(_mockItemService.Object, _mapper);

            SetupHttpContextUser(controller, _user);

            // Act
            var actionResult = await controller.DeleteItem(itemId);

            // Assert
            Assert.IsType <NoContentResult>(actionResult);
        }
Пример #13
0
        public void DeleteItemSuccessRemovedFromDb()
        {
            var id       = new Guid();
            var del_item = new Item {
                item_id = id, name = "Test Delete", price = 20.00M, quantity = 10
            };

            var mockItem = new Mock <DbSet <Item> >();

            mockItem.Setup(m => m.Find(id)).Returns(del_item);

            var mockContext = new Mock <StoreDbContext>();

            mockContext.Setup(m => m.Items).Returns(mockItem.Object);

            var controller = new ItemsController(mockContext.Object);
            var result     = controller.DeleteItem(id);


            mockContext.Verify(x => x.SaveChanges());
            Assert.IsAssignableFrom(typeof(RedirectToRouteResult), result);
        }