Esempio n. 1
0
        public async Task Should_ReturnAllDailyMeals()
        {
            IMapper mapper = new Mapper(
                new MapperConfiguration(
                    cfg => cfg.CreateMap <DailyMeal, DailyMealBasicDto>()));

            var mockSet = new Mock <DbSet <DailyMeal> >();

            mockSet = MockDbProvider <DailyMeal> .ProvideMockDb(DataProvider.DataDailyMeal, mockSet);

            var mockCtx = new Mock <DataContext>(options);

            mockCtx.SetupGet(ctx => ctx.DailyMeals).Returns(mockSet.Object);


            var repository = new Mock <DailyMealRepository>(mockCtx.Object);


            var controller = new DailyMealController(repository.Object, mapper, _calc);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext
            {
                User = new ClaimsPrincipal(MockDbProvider <DailyMeal> .identity)
            };


            var result = await controller.GetDailyMeals() as ObjectResult;

            var value = result.Value as List <DailyMealBasicDto>;

            Assert.NotNull(result);
            Assert.Equal(2, value.Count);
        }
Esempio n. 2
0
        public async Task Can_GetAll()
        {
            var mockSet = new Mock <DbSet <DailyMeal> >();

            mockSet = MockDbProvider <DailyMeal> .ProvideMockDb(DataProvider.DataDailyMeal, mockSet);

            var mockCtx = new Mock <DataContext>(options);

            mockCtx.SetupGet(ctx => ctx.DailyMeals).Returns(mockSet.Object);

            //var dailyMeals = await mockCtx.Object.DailyMeals.ToListAsync();
            var repository = new DailyMealRepository(mockCtx.Object);
            var dailyMeals = await repository.GetDailyMealsAsync();

            Assert.NotNull(dailyMeals);
            Assert.Equal(4, dailyMeals.Count());
            Assert.Equal("title1", dailyMeals.ToList()[0].Title);
            Assert.Equal("title2", dailyMeals.ToList()[1].Title);
            Assert.Equal("title3", dailyMeals.ToList()[2].Title);
        }