public async void CreateAsync_ReturnsCreatedLunch()
        {
            var lunchId = Guid.NewGuid();

            using (var context = new MSLunchesContext(GetDbOptions("CreateAsync_ReturnsCreatedLunch")))
            {
                context.Lunches.Add(GetLunch(lunchId));
                context.SaveChanges();
            }

            var       lunch  = GetUserLunch(lunchId: lunchId);
            UserLunch result = null;

            using (var context = new MSLunchesContext(GetDbOptions("CreateAsync_ReturnsCreatedLunch")))
            {
                var classUnderTest = new UserLunchService(context);
                result = await classUnderTest.CreateAsync(lunch);
            }

            Assert.NotNull(result);
            Assert.NotEqual(Guid.Empty, result.Id);
            Assert.NotEqual(default(DateTime), result.CreatedOn);
            Assert.Equal(lunch.Approved, result.Approved);
            Assert.Equal(lunch.LunchId, result.LunchId);
            Assert.Equal(lunch.UserId, result.UserId);
        }
        public async Task GetAsync_ReturnsMeals()
        {
            var meal1 = GetADefaultMeal(Guid.NewGuid());
            var meal2 = GetADefaultMeal(Guid.NewGuid());

            var dbOptions = GetDbOptions("GetAsync_ReturnsMeals");

            using (var context = new MSLunchesContext(dbOptions))
            {
                context.MealTypes.Add(GetSampleMealType());
                context.Meals.Add(meal1);
                context.Meals.Add(meal2);
                context.SaveChanges();
            }

            IEnumerable <Meal> result = null;

            using (var context = new MSLunchesContext(dbOptions))
            {
                var classUnderTest = new MealService(context);
                result = await classUnderTest.GetAsync();
            }

            Assert.NotNull(result);
            Assert.Contains(result, meal => Equals(meal, meal1));
            Assert.Contains(result, meal => Equals(meal, meal2));
        }
        public async Task GetById_RetunsAMealType()
        {
            var mealType = GetSampleMealType(1);

            using (var context = new MSLunchesContext(GetDbOptions("GetById_RetunsAMealType")))
            {
                context.MealTypes.Add(mealType);
                context.SaveChanges();
            }

            MealType result;

            using (var context = new MSLunchesContext(GetDbOptions("GetById_RetunsAMealType")))
            {
                var classUnderTest = new MealTypeService(context);
                result = await classUnderTest.GetByIdAsync(mealType.Id);
            }

            Assert.Equal(mealType.Id, result.Id);
        }
Пример #4
0
        public async Task GetByIdAsync_ReturnsNull_WhenIdNotExist()
        {
            var dbOptions = GetDbOptions("GetByIdAsync_ReturnsLunch_WhenIdExist");

            using (var context = new MSLunchesContext(dbOptions))
            {
                context.Lunches.Add(GetADefaultLunch());
                context.SaveChanges();
            }

            Lunch result = null;

            using (var context = new MSLunchesContext(dbOptions))
            {
                var classUnderTest = new LunchService(context);
                result = await classUnderTest.GetByIdAsync(Guid.NewGuid());
            }

            Assert.Null(result);
        }
        public async Task GetByIdAsync_ReturnsLunch_WhenIdExist()
        {
            var userLunch = GetUserLunch(Guid.NewGuid());

            var dbOptions = GetDbOptions("GetByIdAsync_ReturnsLunch_WhenIdExist");

            using (var context = new MSLunchesContext(dbOptions))
            {
                context.UserLunches.Add(userLunch);
                context.SaveChanges();
            }

            UserLunch result = null;

            using (var context = new MSLunchesContext(dbOptions))
            {
                var classUnderTest = new UserLunchService(context);
                result = await classUnderTest.GetByIdAsync(userLunch.Id);
            }

            Assert.NotNull(result);
            Assert.True(Equals(userLunch, result));
        }
        public async Task GetByIdAsync_ReturnsMeal_WhenIdExist()
        {
            var meal = GetADefaultMeal(Guid.NewGuid());

            var dbOptions = GetDbOptions("GetByIdAsync_ReturnsMeal_WhenIdExist");

            using (var context = new MSLunchesContext(dbOptions))
            {
                context.Meals.Add(meal);
                context.SaveChanges();
            }

            Meal result = null;

            using (var context = new MSLunchesContext(dbOptions))
            {
                var classUnderTest = new MealService(context);
                result = await classUnderTest.GetByIdAsync(meal.Id);
            }

            Assert.NotNull(result);
            Assert.True(Equals(meal, result));
        }
        public async Task Get_ReturnsAListOfMealTypes()
        {
            var mealType1 = GetSampleMealType(1);
            var mealType2 = GetSampleMealType(2);

            using (var context = new MSLunchesContext(GetDbOptions("Get_ReturnsAListOfMealTypes")))
            {
                context.MealTypes.Add(mealType1);
                context.MealTypes.Add(mealType2);
                context.Meals.Add(GetSampleMeal(1));
                context.SaveChanges();
            }

            IEnumerable <MealType> result;

            using (var context = new MSLunchesContext(GetDbOptions("Get_ReturnsAListOfMealTypes")))
            {
                var classUnderTest = new MealTypeService(context);
                result = await classUnderTest.GetAsync();
            }

            Assert.Contains(result, a => a.Id == mealType1.Id);
            Assert.Contains(result, a => a.Id == mealType2.Id);
        }