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); }
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); }