public void Delete_MealNotFound_ReturnsNotFound() { var sut = new MealsController(_mealService.Object, _dtoConverter); var response = sut.Delete(2); Assert.IsType <NotFoundObjectResult>(response); }
public MealsControllerTest() { mockMealDataModel = new Mock <IMealDataModel>(); var mealDataModel = mockMealDataModel.Object; controller = new MealsController(mealDataModel, new NullLogger <MealsController>()); }
public void DetailsByIdShouldReturnCorrectViewAndModel() { var mealsServiceMock = new Mock <IMealsService>(); const string mealName = "Салата Цезар"; mealsServiceMock.Setup(x => x.GetById(It.IsAny <int>())) .Returns(new Meal() { Name = mealName, Category = new MealCategory() { Name = "Салати" } }); var controller = new MealsController(mealsServiceMock.Object, null); controller.WithCallTo(x => x.Details(123123)) .ShouldRenderView("Details") .WithModel <MealDetailsViewModel>( viewModel => { Assert.AreEqual(mealName, viewModel.Name); } ) .AndNoModelErrors(); }
public void Delete_MealFound_ReturnsOk() { _mealService.Setup(m => m.TryDeleteMeal(1)).Returns(true); var sut = new MealsController(_mealService.Object, _dtoConverter); var response = sut.Delete(1); Assert.IsType <NoContentResult>(response); }
public void GetAll_NoMealsExist_ReturnsEmptyCollection() { var sut = new MealsController(new Mock <IMealApplicationService>().Object, _dtoConverter); var response = sut.Get(count: 10, offset: 0); Assert.Empty(response.Value.Items); }
public void GetSingle_MealNotFound_ReturnsNotFoundResult() { var sut = new MealsController(_mealService.Object, _dtoConverter); var response = sut.Get(id: 2, peopleToFeed: null); Assert.IsType <NotFoundObjectResult>(response.Result); }
public void GetSingle_MealFound_ReturnsResult() { var sut = new MealsController(_mealService.Object, _dtoConverter); var response = sut.Get(id: 1, peopleToFeed: null); Assert.IsType <DTO.Response.Meal>(response.Value); Assert.NotNull(response.Value); }
public void ApiGetMeals() { var acc = Mock.Of <IMealService>(a => a.GetMeals() == _manyMeals); var uow = Mock.Of <IUnitOfWork>(u => u.MealService == acc); MealsController controller = new MealsController(uow); var meals = controller.GetMeals(); Assert.IsTrue(meals.EqualValues(_manyMeals)); }
public void ApiGetMealById() { long id = 7; var acc = Mock.Of <IMealService>(a => a.GetMeal(id) == _sampleMeal1); var uow = Mock.Of <IUnitOfWork>(u => u.MealService == acc); MealsController controller = new MealsController(uow); var response = controller.GetMeal(id); var result = response as OkNegotiatedContentResult <MealDto>; var meal = result.Content; Assert.IsTrue(meal.EqualValues(_sampleMeal1)); }
public MealsControllerTest() { _mockService = new MockMealService(); _controller = GetMealsController(_mockService, true); _controllerWithNoRole = GetMealsController(_mockService, false); _testFood = new Food { Id = 1, Name = "Test Food" }; _testMealFoodViewModel = new MealFoodViewModel { Food = _testFood, MealId = 1, SesshinId = 1 }; }
public void DetailsByIdShouldTReturnNotFound() { var mealsServiceMock = new Mock <IMealsService>(); Meal meal = null; mealsServiceMock.Setup(x => x.GetById(0)) .Returns(meal); var controller = new MealsController(mealsServiceMock.Object, null); controller.WithCallTo(x => x.Details(0)) .ShouldGiveHttpStatus(HttpStatusCode.NotFound); }
public void GetAll_MealsExist_CountAndActualNumberOfItemsMatch() { var numMeals = 1; var mealService = new Mock <IMealApplicationService>(); mealService.Setup(m => m.GetMeals(It.IsAny <int>(), It.IsAny <int>(), out numMeals)).Returns(new List <Meal> { _meal }); var sut = new MealsController(mealService.Object, _dtoConverter); var response = sut.Get(count: 10, offset: 0); Assert.Equal(response.Value.Count, response.Value.Items.Count()); }
public void GetAll_MealsExist_ReturnsNonEmptyCollection() { var numMeals = 1; var mealService = new Mock <IMealApplicationService>(); mealService.Setup(m => m.GetMeals(It.IsAny <int>(), It.IsAny <int>(), out numMeals)).Returns(new List <Meal> { _meal }); var sut = new MealsController(mealService.Object, _dtoConverter); var response = sut.Get(count: 10, offset: 0); Assert.NotEmpty(response.Value.Items); }
public void GetAllMeals_FromService_ReturnsAllMeals() { var meals = MealsTestData(); var mockDataService = new Mock <IDataService>(); mockDataService.Setup(x => x.GetMeals()) .Returns(meals); var controller = new MealsController(mockDataService.Object); var result = controller.GetMeals(); Assert.Equal(meals, result); }
private MealsController GetMealsController(MockMealService mockService, bool addRole) { var authService = MockAuthorizationService.BuildAuthorizationService(services => { services.AddScoped <IMealService>(sp => mockService.Object); services.AddScoped <IAuthorizationHandler, AdminAuthorizationHandler>(); }); var controller = new MealsController(mockService.Object, authService); if (addRole) { MockAuthorizationService.SetupUserWithRole(controller, Constants.UserAdministratorsRole); } return(controller); }
public void ApiPostMeal() { var meal = _sampleMeal1; var mock = new Mock <IMealService>(); mock.Setup(acc => acc.CreateMeal(meal)) .Returns(meal); var uowMock = new Mock <IUnitOfWork>(); uowMock.Setup(u => u.MealService) .Returns(mock.Object); var con = new MealsController(uowMock.Object); con.User = new ClaimsPrincipal( new GenericPrincipal(new GenericIdentity(""), null)); var response = con.PostMeal(meal); var result = response as CreatedAtRouteNegotiatedContentResult <MealDto>; var resultMeal = result.Content; Assert.IsTrue(resultMeal.EqualValues(meal)); mock.Verify(acc => acc.CreateMeal(meal)); uowMock.Verify(u => u.Save()); }