コード例 #1
0
        public void Index_ReturnsNewDish_WhenNotDishId([Frozen] IMealService mealService)
        {
            //Arrange

            var mealMock       = Mock.Get(mealService);
            var dishController = new DishController(mealMock.Object);

            //Act

            var sut = dishController.Index(null);

            //Assert

            sut.Should().BeAssignableTo <IActionResult>().And.BeOfType <ViewResult>()
            .Which.Model.Should().NotBeNull().And.BeOfType <Dish>();


            mealMock.Verify();
        }
コード例 #2
0
        public async Task Returns_correct_dishes()
        {
            //Arrange
            var mockLogger            = new Mock <ILogger <DishController> >();
            var mockIngredientService = new IngredientService(_context);
            var mockDishService       = new DishService(_context);


            var controller = new DishController(_context, mockLogger.Object, mockIngredientService, mockDishService);

            //Act
            var result = await controller.Index();

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

            Assert.Equal(3, model.Count());
        }
コード例 #3
0
        public void Index_ReturnsExistingDish_WhenPassExistingDishId([Frozen] IMealService mealService, [Frozen] Dish dish)
        {
            //Arrange

            var mealMock = Mock.Get(mealService);

            mealMock.Setup(m => m.GetDish(dish.Id)).Returns(dish).Verifiable();
            var dishController = new DishController(mealMock.Object);

            //Act

            var sut = dishController.Index(dish.Id);

            //Assert

            sut.Should().BeAssignableTo <IActionResult>().And.BeOfType <ViewResult>()
            .Which.Model.Should().NotBeNull().And.BeOfType <Dish>()
            .Which.Should().BeSameAs(dish);

            mealMock.Verify();
        }