public void DeleteWrongId()
        {
            GetReady();
            var response = controller.Delete(99).ExecuteAsync(CancellationToken.None).Result;

            Assert.IsFalse(response.IsSuccessStatusCode);
        }
示例#2
0
        public void DeleteById()
        {
            GetReady("antonio");
            var actRes   = controller.Delete(1);
            var response = actRes.ExecuteAsync(CancellationToken.None).Result;

            Assert.IsTrue(response.IsSuccessStatusCode);
        }
示例#3
0
        public async Task DeleteGetActionWithId2_ReturnsModelFromService()
        {
            // Arrange

            // Act
            var result = await validController.Delete(entity.Id) as ViewResult;

            // Assert
            Assert.Equal(entity, result.Model);
        }
示例#4
0
        public async Task DeleteItem()
        {
            await _controller.Post(new ItemResponse { Id = 1 });

            var response = await _controller.Delete(0);

            Assert.IsInstanceOf <NotFoundResult>(response);

            response = await _controller.Delete(1);

            Assert.IsInstanceOf <NoContentResult>(response);
        }
        public void DeleteItem_FromDeleteByLabel_WhenLabelExists()
        {
            //Arrange
            var actionLabel = "DeleteMe!";

            var itemToDelete = new Items
            {
                Label      = actionLabel,
                Expiration = DateTime.Now.AddDays(1),
                ItemType   = 1
            };
            var data = new List <Items>
            {
                itemToDelete,
                new Items {
                    Label = "Don't Delete Me!", Expiration = DateTime.Now.AddYears(1), ItemType = 1
                }
            }.AsQueryable();

            var loggerFactory   = new LoggerFactory();
            var mockContext     = SetUpContext(data);
            var itemsController = new ItemsController(mockContext, new ItemMonitor(mockContext, new TimerFactory(), loggerFactory), loggerFactory);

            //Action
            var result = itemsController.Delete(actionLabel);

            //Assert
            Assert.Equal(1, mockContext.Items.Count());
            Assert.NotEqual(actionLabel, mockContext.Items.First().Label);
        }
        public void ReturnAViewResult_OfOK_FromDeleteByLabel_WhenLabelExists()
        {
            //Arrange
            var actionLabel = "DeleteMe!";

            var itemToDelete = new Items
            {
                Label      = actionLabel,
                Expiration = DateTime.Now.AddDays(1),
                ItemType   = 1
            };
            var data = new List <Items>
            {
                itemToDelete,
                new Items {
                    Label = "Don't Delete Me!", Expiration = DateTime.Now.AddYears(1), ItemType = 1
                }
            }.AsQueryable();

            var stExpectedConsoleOut = "Item " + itemToDelete.Label + " removed from inventory at ";

            var loggerFactory   = new TestLoggerFactory();
            var mockContext     = SetUpContext(data);
            var itemsController = new ItemsController(mockContext, new ItemMonitor(mockContext, new TimerFactory(), loggerFactory), loggerFactory);

            //Action
            var result = itemsController.Delete(actionLabel);

            //Assert
            Assert.IsType <OkResult>(result);
            Assert.Contains(stExpectedConsoleOut, loggerFactory.Logger.Message);
        }
        public void ReturnAViewResult_OfNotFound_FromDeleteByLabel_WhenLabelDoesntExists()
        {
            //Arrange
            var actionLabel = "DeleteMe!";

            var itemToDelete = new Items
            {
                Label      = actionLabel,
                Expiration = DateTime.Now.AddYears(1),
                ItemType   = 1
            };
            var data = new List <Items>
            {
                itemToDelete,
                new Items {
                    Label = "Don't Delete Me!", Expiration = DateTime.Now.AddYears(1), ItemType = 1
                }
            }.AsQueryable();

            var loggerFactory   = new LoggerFactory();
            var mockContext     = SetUpContext(data);
            var itemsController = new ItemsController(mockContext, new ItemMonitor(mockContext, new TimerFactory(), loggerFactory), loggerFactory);

            //Action
            var result = itemsController.Delete("NonexistentLabel");

            //Assert
            //verify result of Not Found
            Assert.IsType <NotFoundResult>(result);
            //verify that item was not deleted from database
            Assert.Equal(2, mockContext.Items.Count());
        }
示例#8
0
        public void Delete_RemovesAnItem()
        {
            var expectedItemCode = "Arduino";
            var expectedBasket   = new Basket(Guid.NewGuid());

            basketsRepositoryMock.Setup(x => x.GetBasket(expectedBasket.Id))
            .Returns(expectedBasket);
            basketsRepositoryMock.Setup(x => x.GetItem(expectedBasket.Id, expectedItemCode))
            .Returns(new Item {
                code = expectedItemCode
            });

            sut.Delete(expectedBasket.Id, expectedItemCode);

            basketsRepositoryMock.Verify(x => x.RemoveItemFromBasket(expectedBasket.Id, expectedItemCode));
        }
        public void Delete()
        {
            var controller = new ItemsController();
            var result     = controller.Delete("Star Trek");

            Assert.IsInstanceOfType(result, typeof(Microsoft.AspNetCore.Mvc.OkResult));
        }
示例#10
0
        public async Task Delete_ReturnsNoContent_WhenItemDeleted()
        {
            var controller = new ItemsController(_context);

            var result = await controller.Delete(2);

            Assert.IsType <NoContentResult>(result);
        }
示例#11
0
        public async Task Delete_ReturnsNotFound_WhenIsIsInvalid()
        {
            var controller = new ItemsController(_context);

            var result = await controller.Delete(99);

            Assert.IsType <NotFoundResult>(result);
        }
示例#12
0
        public async Task DeleteItemReturnsNotFoundWhenIdDoesNotExist()
        {
            var context    = GetInMemoryContext();
            var controller = new ItemsController(context);
            var result     = await controller.Delete(1);

            Assert.IsInstanceOf <NotFoundObjectResult>(result);
        }
示例#13
0
        public void DeleteTest()
        {
            mockItems.RemoveAt(0);

            controller.Delete(1);
            var result = controller.Get() as List <Item>;

            Assert.AreEqual(mockItems.Count, result.Count);
        }
示例#14
0
        public async Task DeleteItemReturnsOkWhenIdExists()
        {
            var context    = GetInMemoryContext(true);
            var controller = new ItemsController(context);
            var first      = context.Items.First();
            var result     = await controller.Delete(first.ID);

            Assert.IsInstanceOf <OkObjectResult>(result);
        }
示例#15
0
        public void TestDeleteMethod()
        {
            List <Item> beforeIlist = new List <Item>(cntr.Get());

            cntr.Delete(2);
            List <Item> afterIlist = new List <Item>(cntr.Get());

            Assert.AreEqual(beforeIlist.Count - 1, afterIlist.Count);
        }
示例#16
0
        public async Task Should_delete_an_item()
        {
            //Act
            var result = await _itemsController.Delete(_itemId);

            //Assert
            await _itemService.Received(1).Delete(_itemId);

            result.Should().BeOfType <NoContentResult>();
        }
示例#17
0
        public void Get_ViewResult_Delete_Test()
        {
            //Arrange
            ItemsController controller = new ItemsController();

            //Act
            var result = controller.Delete(0);

            //Assert
            Assert.IsType <ViewResult>(result);
        }
示例#18
0
        public async Task Delete_Item_Via_Controller()
        {
            await WithinTestContext(async (ctx) =>
            {
                var controller = new ItemsController(ctx.ItemsRepository);
                var itemInDb   = await controller.Post(new MyItem {
                    Description = "Test1"
                });
                await controller.Delete(itemInDb.Id);

                var itemsInDb = await controller.Get();
                itemsInDb.Should().HaveCount(0);
            });
        }
示例#19
0
            public void Should_remove_an_item()
            {
                // Arrange
                var       controller = new ItemsController();
                const int itemId     = 7;

                controller.Put(itemId, new Item());

                // Act
                controller.Delete(itemId);

                // Assert
                var result = controller.Get(itemId).Result as StatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(404, result.StatusCode);
            }
示例#20
0
        public async Task Delete_ShouldReturnNoContent()
        {
            var expectedGuid = Guid.NewGuid();

            var mediatr = new Mock <IMediator>();

            mediatr
            .Setup(m => m.Send(It.IsAny <IRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

            var itemsController = new ItemsController(mediatr.Object);

            var actionResults = await itemsController.Delete(Guid.NewGuid(), Guid.NewGuid());

            var noContentResult = actionResults as NoContentResult;

            Assert.NotNull(noContentResult);
        }
        public void Mock_PostResultViewDelete_ViewResult()
        {
            //Arrange
            Item testItem = new Item();

            testItem.ItemId      = 2;
            testItem.Name        = "Girl Scout Cookies";
            testItem.Cost        = 5;
            testItem.Description = "dank gummi";

            DbSetup();
            ItemsController controller = new ItemsController(mock.Object);

            //Act
            var resultView = controller.Delete(testItem.ItemId) as ViewResult;

            //Assert
            Assert.IsInstanceOfType(resultView, typeof(ViewResult));
        }
示例#22
0
        public void WhenDelete_WithAnUnknownId_Returns_404()
        {
            var itemId = 1000;
            // Arrange
            IEnumerable <BudgetItem> fakeArtists = GetFakeItems();

            // setup
            _itemRepository.Setup(x => x.GetItem(itemId)).Returns(fakeArtists.FirstOrDefault(p => p.Id == itemId));

            var controller = new ItemsController(_itemRepository.Object);

            // Act

            IHttpActionResult actionResult = controller.Delete(itemId);

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.IsInstanceOf(typeof(NotFoundResult), actionResult, "It should return 404");
        }
示例#23
0
        public void WhenDelete_WithValidId_Returns_Ok()
        {
            var itemId = 2;
            // Arrange
            IEnumerable <BudgetItem> fakeItems = GetFakeItems();
            var numberOfItemsBeforeDelete      = fakeItems.Count();

            // setup
            _itemRepository.Setup(x => x.GetItem(itemId)).Returns(fakeItems.FirstOrDefault(p => p.Id == itemId));

            var controller = new ItemsController(_itemRepository.Object);

            // Act

            IHttpActionResult actionResult = controller.Delete(itemId);

            // Assert
            Assert.IsInstanceOf(typeof(OkNegotiatedContentResult <BudgetItem>), actionResult);
        }
示例#24
0
        public async Task ItemsController_DeleteItem_ItemDoesntExist()
        {
            // Arrange
            int id   = 2;
            var item = new ItemModel()
            {
                Id = 1, ItemName = "name"
            };
            var mockRepo        = new Mock <IItemsBLL>();
            var httpServiceMock = new Mock <IHttpServices>();

            mockRepo.Setup(x => x.GetItemById(It.IsAny <int>()))
            .ReturnsAsync(null as ItemModel);
            var controller = new ItemsController(mockRepo.Object, httpServiceMock.Object);

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

            // Assert
            Assert.Equal(404, ((StatusCodeResult)result).StatusCode);
        }
示例#25
0
        public async Task Get_Delete_Item_ReturnsActionResult()
        {
            //Arrange
            var  mock = new Mock <IItemsRepository>();
            Item item = new Item {
                ID = 1, UserID = "john123", Title = "New Title"
            };

            mock.Setup(x => x.GetItem(It.IsAny <int>())).ReturnsAsync(item);
            var controller = new ItemsController(mock.Object);

            //Act
            ActionResult result = await controller.Delete(item.ID);

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsType <Item>(viewResult.ViewData.Model);

            Assert.Equal(item.ID, model.ID);
            Assert.Equal(item.UserID, model.UserID);
            Assert.Equal(item.Title, model.Title);
        }
示例#26
0
        public async Task Delete_ReturnsViewResultWithItem()
        {
            var item = new Item()
            {
                Id = 1
            };
            // Arrange
            var mockRepo = new Mock <IInvoicesRepository>();

            mockRepo.Setup(repo => repo.GetItemAsync(item.Id))
            .ReturnsAsync(item);
            var controller = new ItemsController(mockRepo.Object);

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

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <Item>(viewResult.ViewData.Model);

            Assert.Equal(item.Id, model.Id);
        }
示例#27
0
        public async void DeleteReturnsBoolAndDeleteItemIfItExist(string id)
        {
            // Arrange
            var items = await GetTestItems();

            var mock          = new Mock <IItemsRepository>();
            var returnedValue = items.Find(x => x.Id == id) != null
                ? true : false;

            mock.Setup(repo => repo.Delete(id)).Returns(Task.FromResult(returnedValue));
            var controller = new ItemsController(mock.Object);

            // Act
            var actual = await controller.Delete(id);

            var result = actual?.Value;

            // Assert
            Assert.IsType <JsonResult>(actual);
            Assert.IsType <Boolean>(result);
            Assert.Equal(returnedValue, result);
        }
示例#28
0
        public async Task ItemsController_DeleteItem_ConcurrencyItemNotFound()
        {
            // Arrange
            int id   = 2;
            var item = new ItemModel()
            {
                Id = 1, ItemName = "name"
            };
            var mockRepo        = new Mock <IItemsBLL>();
            var httpServiceMock = new Mock <IHttpServices>();

            mockRepo.Setup(x => x.GetItemById(It.IsAny <int>()))
            .ReturnsAsync(item);
            mockRepo.Setup(x => x.DeleteItem(It.IsAny <ItemModel>()))
            .ThrowsAsync(new Exception());
            var controller = new ItemsController(mockRepo.Object, httpServiceMock.Object);

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

            // Assert
            Assert.Equal(204, ((StatusCodeResult)result).StatusCode);
        }
示例#29
0
 public void DeleteTest()
 {
     cmd.Delete(6);
     Assert.AreEqual(5, cmd.Get().Count());
 }
示例#30
0
        public void TestItemController()
        {
            // Clear list for testing
            ItemsController.Items = new List <Item>();

            // Post a couple of pre determined items
            foreach (var item in _items)
            {
                _itemsController.Post(item);
            }

            // Get all items
            var getAllItems = _itemsController.Get().ToList();

            // Check if the Posted list and the list we got with Get are equal.
            for (int i = 0; i < getAllItems.Count; i++)
            {
                Assert.AreEqual(_items[i], getAllItems[i]);
            }

            // Create item and Post it
            Item postItem = new Item(9010, "Bread", "Low", 33);

            _itemsController.Post(postItem);

            // Add item to pre determined list for later use
            _items.Add(postItem);

            // Get item just posted
            Item getItem = _itemsController.Get(9010);

            //Check if they are equal
            Assert.AreEqual(postItem, getItem);

            // Get all with name "Bread"
            var getByName = _itemsController.GetByName("Bread").ToList();
            // Find all with name "Bread" in pre determined list
            var getByNameList = _items.FindAll(i => i.Name == "Bread");

            // Compare the two lists
            for (int i = 0; i < getByName.Count; i++)
            {
                Assert.AreEqual(getByNameList[i], getByName[i]);
            }

            // Get all with quality "low" (The method uses .lower so it will get all with "low" but AreEqual can't compare "low" and "Low")
            var getByQuality = _itemsController.GetByQuality("low").ToList();
            // Find all with quality "low" in pre determined list
            var getByQualityList = _items.FindAll(i => i.Quality.ToLower() == "low");

            for (int i = 0; i < getByQuality.Count; i++)
            {
                Assert.AreEqual(getByQualityList[i], getByQuality[i]);
            }

            // Get all where value is atleast 50
            var getFilterLow = _itemsController.GetWithFilter(new FilterItem(50, 0)).ToList();
            // You know it by now...
            var getFilterLowList = _items.FindAll(i => i.Quantity > 50);

            // Get all where value is at maximum 50
            var getFilterHigh = _itemsController.GetWithFilter(new FilterItem(0, 50)).ToList();
            // You know it by now...
            var getFilterHighList = _items.FindAll(i => i.Quantity < 50);

            // Get all between 30 and 120
            var getFilterBoth = _itemsController.GetWithFilter(new FilterItem(30, 120)).ToList();
            // You know it by now...
            var getFilterBothList = _items.FindAll(i => i.Quantity > 30 && i.Quantity < 120);

            // Compare all three variants
            for (int i = 0; i < getFilterLow.Count; i++)
            {
                Assert.AreEqual(getFilterLowList[i], getFilterLow[i]);
            }
            for (int i = 0; i < getFilterHigh.Count; i++)
            {
                Assert.AreEqual(getFilterHighList[i], getFilterHigh[i]);
            }
            for (int i = 0; i < getFilterBoth.Count; i++)
            {
                Assert.AreEqual(getFilterBothList[i], getFilterBoth[i]);
            }

            // Create Item to Put and Put it
            Item putItem = new Item(9010, "Cheese", "Low", 33);

            _itemsController.Put(9010, putItem);

            // Get item just put
            Item getPutItem = _itemsController.Get(9010);

            // double float precision problem when comparing to objects containing double/float etc.
            Assert.AreEqual(JsonConvert.SerializeObject(putItem), JsonConvert.SerializeObject(getPutItem));

            _itemsController.Delete(9010);

            Item itemDeleted = _itemsController.Get(9010);

            Assert.IsNull(itemDeleted);
        }