Exemple #1
0
        public void Details_ReturnsAView_WithInventoryAndOrders()
        {
            // Arrange
            int id = 1;
            var mockLocationRepo = new Mock <ILocationRepository>();

            mockLocationRepo.Setup(repo => repo.GetWithInventory(id))
            .Returns(LocationWithInventory());
            var mockOrderRepository = new Mock <IOrderRepository>();

            mockOrderRepository.Setup(repo => repo.GetByLocationId(id))
            .Returns(ListOfTwoOrders());
            var controller = new LocationsController(mockLocationRepo.Object, mockOrderRepository.Object, null);

            // Act
            var result = controller.Details(id);

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

            Assert.Equal("Walmart", model.Name);
            var inventory = Assert.IsAssignableFrom <IEnumerable <InventoryViewModel> >(model.Inventory);

            Assert.Equal(2, inventory.Count());
            var orders = Assert.IsAssignableFrom <IEnumerable <OrderViewModel> >(model.Orders);

            Assert.Equal(2, orders.Count());
        }
        public void Details()
        {
            var controller = new LocationsController();

            var result = controller.Details(2);

            Assert.IsNotNull(result);
        }
Exemple #3
0
        public void TestLocationDetailView()
        {
            // Arrange
            var location            = GetLocation();
            var mockLocationService = new Mock <ILocationService>();
            var mockPostCodeService = new Mock <IPostCodeService>();

            mockLocationService.Setup(r => r.GetById(3)).Returns(location);
            var controller = new LocationsController(mockLocationService.Object, mockPostCodeService.Object);

            // Act
            var result = controller.Details(3);

            // Assert
            var locationTypeEx = LocationTypeEx.LocationTypes.First(lte => lte.LocationType == (int)location.Type);

            Assert.AreEqual(location.Name, ((LocationsDetailsViewModel)((ViewResult)result).Model).Name);
            Assert.AreEqual(locationTypeEx, ((LocationsDetailsViewModel)((ViewResult)result).Model).LocationType);
        }