Ejemplo n.º 1
0
        public async Task Create_ReturnsCreated()
        {
            var classUnderTest = new LunchController(_lunchService.Object, _mapper);
            var lunch          = GetSampleLunch();

            var lunchDto = new InputLunchDto
            {
                Date   = lunch.Date,
                MealId = lunch.MealId
            };

            _lunchService.Setup(a => a.CreateAsync(
                                    It.Is <Lunch>(l => l.MealId == lunchDto.MealId && l.Date == lunchDto.Date)))
            .ReturnsAsync(lunch);

            var result = await classUnderTest.Create(lunchDto);

            var createdResponse = Assert.IsType <CreatedAtActionResult>(result);
            var resultLunch     = Assert.IsType <LunchDto>(createdResponse.Value);

            Assert.Equal(lunch.MealId, resultLunch.Meal.Id);
            Assert.Equal(lunch.Date, resultLunch.Date);

            _lunchService.Verify(a => a.CreateAsync(
                                     It.Is <Lunch>(l => l.MealId == lunchDto.MealId && l.Date == lunchDto.Date)), Times.Once);
        }
Ejemplo n.º 2
0
        public async Task Create_ReturnsBadRequest_WhenInputIsNull()
        {
            var classUnderTest = new LunchController(_lunchService.Object, _mapper);

            var result = await classUnderTest.Create(null);

            Assert.IsType <BadRequestResult>(result);
            _lunchService.Verify(a => a.CreateAsync(It.IsAny <Lunch>()), Times.Never);
        }