Пример #1
0
        public void GetClosestFoodTruck_Returns_Single_FoodTruck()
        {
            // Arrange
            Mock <ILogger <FoodTrucksController> > loggerMock = new Mock <ILogger <FoodTrucksController> >();
            FoodTrucksController controller = new FoodTrucksController(loggerMock.Object, foodTruckProvider);

            // Act
            var result = controller.GetClosestFoodTruck(37.76, -122.41);

            // Assert
            Assert.IsInstanceOf <JsonResult>(result);
            JsonResult jsonResult = result as JsonResult;

            Assert.IsInstanceOf <Core.Models.FoodTruck>(jsonResult.Value);
            Core.Models.FoodTruck ft = jsonResult.Value as Core.Models.FoodTruck;

            Assert.AreEqual(1181513, ft.LocationId);
        }
Пример #2
0
        public void WhenTagParameterPassedToAPI_SearchIsDoneByTag()
        {
            // Arrange
            var mockLogger = GetMockLogger <FoodTrucksController>();
            var searchTag  = "Tacos";

            var mockService = new Mock <IFoodTruckService>();

            mockService.Setup(r => r.GetAllFoodTrucks())
            .Returns(foodTruckList);
            FoodTrucksController controller = new FoodTrucksController(mockLogger.Object, mapper, mockService.Object);

            // Act
            var response = controller.Get(searchTag);

            // Assert
            mockService.Verify(r => r.GetAllFoodTrucks(), Times.Never());
            mockService.Verify(r => r.GetFoodTrucksByTag(searchTag), Times.Once());
        }
Пример #3
0
        public void WhenNoParametersPassedToAPI_WeCallMethodToGetAllFoodTrucks()
        {
            // Arrange
            var mockLogger = GetMockLogger <FoodTrucksController>();


            var mockService = new Mock <IFoodTruckService>();

            mockService.Setup(r => r.GetAllFoodTrucks())
            .Returns(foodTruckList);
            FoodTrucksController controller = new FoodTrucksController(mockLogger.Object, mapper, mockService.Object);

            // Act
            var response = controller.Get();

            // Assert
            mockService.Verify(r => r.GetAllFoodTrucks(), Times.Once());
            mockService.Verify(r => r.GetFoodTrucksByTag(It.IsAny <String>()), Times.Never());
        }
Пример #4
0
        public void GetClosestFoodTrucks_Returns_Collection_of_FoodTrucks()
        {
            // Arrange
            Mock <ILogger <FoodTrucksController> > loggerMock = new Mock <ILogger <FoodTrucksController> >();
            FoodTrucksController controller = new FoodTrucksController(loggerMock.Object, foodTruckProvider);

            // Act
            var result = controller.GetClosestFoodTrucks(37.76, -122.41, 100);

            // Assert
            Assert.IsInstanceOf <JsonResult>(result);
            JsonResult jsonResult = result as JsonResult;

            Assert.IsInstanceOf <List <Core.Models.FoodTruck> >(jsonResult.Value);
            var foodTrucks = jsonResult.Value as List <Core.Models.FoodTruck>;

            CollectionAssert.IsNotEmpty(foodTrucks);
            CollectionAssert.AllItemsAreInstancesOfType(foodTrucks, typeof(Core.Models.FoodTruck));
        }