Esempio n. 1
0
        public void GetAllItems_ShouldReturnAllItems()
        {
            //Arrange
            var testItems  = GetTestItems();
            var controller = new ItemsController(testItems);

            //Act
            var result = controller.GetAllItems() as List <Item>;

            //Assert
            Assert.AreEqual(testItems.Count, result.Count);
        }
Esempio n. 2
0
        public void EmptyWarehouseReturnsNoItems()
        {
            var c = new ItemsController(new Repository(new List <Item>()));

            c.Request       = new HttpRequestMessage();
            c.Configuration = new HttpConfiguration();

            IHttpActionResult actionResult = c.GetAllItems();
            var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <Item> >;

            Assert.AreEqual(0, contentResult.Content.Count());
        }
Esempio n. 3
0
        public async Task GetAllItems_ReturnNotFoundResult_WhenItemsAreNotFound()
        {
            //Arrange
            // setup GetAllWithUser method to return null
            _mockItemService.Setup(service => service.GetAllWithUser())
            .ReturnsAsync((IEnumerable <Item>)null);
            // inject mocked IItemService and _mapper in controller
            var controller = new ItemsController(_mockItemService.Object, _mapper);

            //Act
            var actionResult = await controller.GetAllItems();

            //Assert
            Assert.IsType <NotFoundResult>(actionResult);
        }
Esempio n. 4
0
        public void WarehouseReturnsPagedResults()
        {
            var items    = TestData.CreateLargeTestDataSet();
            var cntItems = items.Count();
            var c        = new ItemsController(new Repository(items));

            setupItemsController(c);

            IHttpActionResult actionResult = c.GetAllItems();

            var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <Item> >;
            var resultItems   = contentResult.Content;

            Assert.AreEqual(10, resultItems.Count());
            Assert.IsTrue(resultItems.All(
                              s => items.Take(10).First(
                                  t => s.Name == t.Name &&
                                  s.Description == t.Description &&
                                  s.Price == t.Price) != null));
        }
Esempio n. 5
0
        public async Task GetAllItems_ReturnWithAListOfItemResources_WhenSuccess()
        {
            //Arrange
            var expectedObject = GetTestItemResources();

            // setup GetAllWithUser method to return test items
            _mockItemService.Setup(service => service.GetAllWithUser())
            .ReturnsAsync(GetTestItems());
            // inject mocked IItemService and _mapper in controller
            var controller = new ItemsController(_mockItemService.Object, _mapper);

            //Act
            var actionResult = await controller.GetAllItems() as OkObjectResult;

            var resultObject = GetObjectResultContent <IEnumerable <ItemResource> >(actionResult);

            //Assert
            Assert.IsType <OkObjectResult>(actionResult);
            Assert.Equal(serializeObject(expectedObject), serializeObject(resultObject));
        }