public async Task GetAllRecipes_WithInitialData_ShouldReturnCorrectResult() { string errorMessagePrefix = "RecipesService Method GetAllRecipes() does not work properly."; var context = MyLifeStyleInmemoryFactory.InitializeContext(); await SeedData(context); this.recipsService = new RecipesService(context); IEnumerable <AllRecipesViewModel> actualResultsEnumerable = await this.recipsService.GetAllRecipes <AllRecipesViewModel>(); List <AllRecipesViewModel> actualResults = actualResultsEnumerable.ToList(); List <AllRecipesViewModel> expectedResults = context.Recipes.OrderByDescending(x => x.Publication.CreatedOn).To <AllRecipesViewModel>().ToList(); for (int i = 0; i < expectedResults.Count; i++) { var expectedEntry = expectedResults[i]; var actualEntry = actualResults[i]; Assert.True(expectedEntry.PublicationTitle == actualEntry.PublicationTitle, errorMessagePrefix + " " + "Title is not returned properly"); Assert.True(expectedEntry.DishType == actualEntry.DishType, errorMessagePrefix + " " + "DishType is not returned properly"); Assert.True(expectedEntry.DietType == actualEntry.DietType, errorMessagePrefix + " " + "DietType is not returned properly"); Assert.True(expectedEntry.Summary == actualEntry.Summary, errorMessagePrefix + " " + "Summary is not returned properly"); } }
public async Task GetAllArticles_WithInitialData_ShouldReturnCorrectResult() { string errorMessagePrefix = "ArticlesService Method GetAllArticles() does not work properly."; var context = MyLifeStyleInmemoryFactory.InitializeContext(); await SeedData(context); this.articlesService = new ArticlesService(context); IEnumerable <ArticleServiceModel> actualResultsEnumerable = await this.articlesService.GetAllArticles <ArticleServiceModel>(); List <ArticleServiceModel> actualResults = actualResultsEnumerable.ToList(); List <ArticleServiceModel> expectedResults = context.Articles.OrderByDescending(x => x.Publication.CreatedOn).To <ArticleServiceModel>().ToList(); for (int i = 0; i < expectedResults.Count; i++) { var expectedEntry = expectedResults[i]; var actualEntry = actualResults[i]; Assert.True(expectedEntry.PublicationTitle == actualEntry.PublicationTitle, errorMessagePrefix + " " + "Title is not returned properly"); Assert.True(expectedEntry.Description == actualEntry.Description, errorMessagePrefix + " " + "Description is not returned properly"); Assert.True(expectedEntry.CategoryId == actualEntry.CategoryId, errorMessagePrefix + " " + "CategoryId is not returned properly"); Assert.True(expectedEntry.UserId == actualEntry.UserId, errorMessagePrefix + " " + "UserId is not returned properly"); } }
public async Task Delete_WithGivenNonExistenId_ShouldThrowArgumentNullException() { var context = MyLifeStyleInmemoryFactory.InitializeContext(); await SeedData(context); this.articlesService = new ArticlesService(context); await Assert.ThrowsAsync <ArgumentNullException>(() => this.articlesService.Delete("Non-Existent")); }
public async Task GetAllArticles_WithZeroData_ShouldReturnEmptyResult() { string errorMessagePrefix = "ArticlesService Method GetAllArticles() does not work properly."; var context = MyLifeStyleInmemoryFactory.InitializeContext(); this.articlesService = new ArticlesService(context); IEnumerable <ArticleServiceModel> actualResultsEnumerable = await this.articlesService.GetAllArticles <ArticleServiceModel>(); List <ArticleServiceModel> actualResults = actualResultsEnumerable.ToList(); Assert.True(actualResults.Count == 0, errorMessagePrefix); }
public async Task Delete_WithCorrectData_ShouldDeleteFromContext() { string errorMessagePrefix = "ArticlesService Method Delete() does not work properly."; var context = MyLifeStyleInmemoryFactory.InitializeContext(); await SeedData(context); this.articlesService = new ArticlesService(context); Article articleFromDb = context.Articles.Where(a => a.Description == "MyLifeStyle is a social media for sharing of information and ideas").FirstOrDefault(); string idToDelete = articleFromDb.Id; await this.articlesService.Delete(idToDelete); int expectedCount = 1; int actualCount = context.Articles.Count(); Assert.True(expectedCount == actualCount, errorMessagePrefix); }
public async Task Create_WithCorrectData_ShouldSuccesfullyCreate() { string errorMessagePrefix = "ArticlesService Method CreateArticle() does not work properly."; var context = MyLifeStyleInmemoryFactory.InitializeContext(); await SeedData(context); this.articlesService = new ArticlesService(context); ArticleServiceModel articleServiceModel = new ArticleServiceModel() { PublicationTitle = "Books Exchange", Description = "Users can add readed book to list of books for second hand exchange", CategoryId = "category_1", UserId = "Mimi_1", }; bool actualResult = await this.articlesService.CreateArticle(articleServiceModel); Assert.True(actualResult, errorMessagePrefix); }
public async Task Create_WithCorrectData_ShouldSuccesfullyCreate() { string errorMessagePrefix = "RecipesService Method CreateRecipe() does not work properly."; var context = MyLifeStyleInmemoryFactory.InitializeContext(); await SeedData(context); this.recipsService = new RecipesService(context); RecipeCreateInputModel recipeCreateInputModel = new RecipeCreateInputModel() { PublicationTitle = "One Desert", Ingredients = "Med i orehi", Description = "Razburkvame vsichko", DishType = DishType.Desserts, DietType = DietType.Raw, PublicationUserId = "Mimi_1", }; bool actualResult = await this.recipsService.CreateRecipe(recipeCreateInputModel); Assert.True(actualResult, errorMessagePrefix); }