public void GetShoppingListItem_ParametersMatchExpectedValues() { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeShoppingListItem = new FakeShoppingListItem { }.Generate(); //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.ShoppingListItems.AddRange(fakeShoppingListItem); context.SaveChanges(); var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions)); //Assert var ShoppingListItemById = context.ShoppingListItems.FirstOrDefault(i => i.ShoppingListItemId == fakeShoppingListItem.ShoppingListItemId); ShoppingListItemById.Should().BeEquivalentTo(fakeShoppingListItem); ShoppingListItemById.ShoppingListItemId.Should().Be(fakeShoppingListItem.ShoppingListItemId); ShoppingListItemById.Name.Should().Be(fakeShoppingListItem.Name); ShoppingListItemById.Category.Should().Be(fakeShoppingListItem.Category); ShoppingListItemById.Unit.Should().Be(fakeShoppingListItem.Unit); } }
public void GetRecipe_ParametersMatchExpectedValues() { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeRecipe = new FakeRecipe { }.Generate(); //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.Recipes.AddRange(fakeRecipe); context.SaveChanges(); var service = new RecipeRepository(context, new SieveProcessor(sieveOptions)); //Assert var recipeById = context.Recipes.FirstOrDefault(r => r.RecipeId == fakeRecipe.RecipeId); recipeById.Should().BeEquivalentTo(fakeRecipe); recipeById.RecipeId.Should().Be(fakeRecipe.RecipeId); recipeById.Title.Should().Be(fakeRecipe.Title); recipeById.Directions.Should().Be(fakeRecipe.Directions); } }
public void AddIngredient_NewRecordAddedWithProperValues() { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"IngredientDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeIngredient = new FakeIngredient { }.Generate(); //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { var service = new IngredientRepository(context, new SieveProcessor(sieveOptions)); service.AddIngredient(fakeIngredient); context.SaveChanges(); } //Assert using (var context = new CarbonKitchenDbContext(dbOptions)) { context.Ingredients.Count().Should().Be(1); var ingredientById = context.Ingredients.FirstOrDefault(i => i.IngredientId == fakeIngredient.IngredientId); ingredientById.Should().BeEquivalentTo(fakeIngredient); ingredientById.IngredientId.Should().Be(fakeIngredient.IngredientId); ingredientById.Name.Should().Be(fakeIngredient.Name); ingredientById.Unit.Should().Be(fakeIngredient.Unit); ingredientById.Amount.Should().Be(fakeIngredient.Amount); } }
public ShoppingListItemRepository(CarbonKitchenDbContext context, SieveProcessor sieveProcessor) { _context = context ?? throw new ArgumentNullException(nameof(context)); _sieveProcessor = sieveProcessor ?? throw new ArgumentNullException(nameof(sieveProcessor)); }
public void GetShoppingListItems_FilterListWithExact(string filters) { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeShoppingListItemOne = new FakeShoppingListItem { }.Generate(); fakeShoppingListItemOne.Name = "Alpha"; fakeShoppingListItemOne.Category = "Bravo"; fakeShoppingListItemOne.ShoppingListId = 5; var fakeShoppingListItemTwo = new FakeShoppingListItem { }.Generate(); fakeShoppingListItemTwo.Name = "Charlie"; fakeShoppingListItemTwo.Category = "Delta"; fakeShoppingListItemTwo.ShoppingListId = 6; var fakeShoppingListItemThree = new FakeShoppingListItem { }.Generate(); fakeShoppingListItemThree.Name = "Echo"; fakeShoppingListItemThree.Category = "Foxtrot"; fakeShoppingListItemThree.ShoppingListId = 7; //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo, fakeShoppingListItemThree); context.SaveChanges(); var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions)); var ShoppingListItemRepo = service.GetShoppingListItems(new ShoppingListItemParametersDto { Filters = filters }); //Assert ShoppingListItemRepo.Should() .HaveCount(1); context.Database.EnsureDeleted(); } }
public void GetShoppingListItems_SearchQueryReturnsExpectedRecordCount(string queryString, int expectedCount) { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeShoppingListItemOne = new FakeShoppingListItem { }.Generate(); fakeShoppingListItemOne.Name = "Alpha"; fakeShoppingListItemOne.Category = "Bravo"; var fakeShoppingListItemTwo = new FakeShoppingListItem { }.Generate(); fakeShoppingListItemTwo.Name = "Hartsfield"; fakeShoppingListItemTwo.Category = "White"; var fakeShoppingListItemThree = new FakeShoppingListItem { }.Generate(); fakeShoppingListItemThree.Name = "Bravehart"; fakeShoppingListItemThree.Category = "Jonfav"; //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo, fakeShoppingListItemThree); context.SaveChanges(); var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions)); var ShoppingListItemRepo = service.GetShoppingListItems(new ShoppingListItemParametersDto { QueryString = queryString }); //Assert ShoppingListItemRepo.Should() .HaveCount(expectedCount); context.Database.EnsureDeleted(); } }
public void GetRecipes_FilterListWithContains(string filters, int expectedCount) { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeRecipeOne = new FakeRecipe { }.Generate(); fakeRecipeOne.Title = "Alpha"; fakeRecipeOne.Directions = "Bravo"; var fakeRecipeTwo = new FakeRecipe { }.Generate(); fakeRecipeTwo.Title = "Hartsfield"; fakeRecipeTwo.Directions = "Favaro"; var fakeRecipeThree = new FakeRecipe { }.Generate(); fakeRecipeThree.Title = "Bravehart"; fakeRecipeThree.Directions = "Jonfav"; //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree); context.SaveChanges(); var service = new RecipeRepository(context, new SieveProcessor(sieveOptions)); var recipeRepo = service.GetRecipes(new RecipeParametersDto { Filters = filters }); //Assert recipeRepo.Should() .HaveCount(expectedCount); context.Database.EnsureDeleted(); } }
public void GetShoppingListItems_ListSortedInDescOrder() { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeShoppingListItemOne = new FakeShoppingListItem { }.Generate(); fakeShoppingListItemOne.Name = "Bravo"; var fakeShoppingListItemTwo = new FakeShoppingListItem { }.Generate(); fakeShoppingListItemTwo.Name = "Alpha"; var fakeShoppingListItemThree = new FakeShoppingListItem { }.Generate(); fakeShoppingListItemThree.Name = "Charlie"; //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo, fakeShoppingListItemThree); context.SaveChanges(); var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions)); var ShoppingListItemRepo = service.GetShoppingListItems(new ShoppingListItemParametersDto { SortOrder = "-Name" }); //Assert ShoppingListItemRepo.Should() .ContainInOrder(fakeShoppingListItemThree, fakeShoppingListItemOne, fakeShoppingListItemTwo); context.Database.EnsureDeleted(); } }
public void GetRecipes_ListSortedInAscOrder() { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeRecipeOne = new FakeRecipe { }.Generate(); fakeRecipeOne.Title = "Bravo"; var fakeRecipeTwo = new FakeRecipe { }.Generate(); fakeRecipeTwo.Title = "Alpha"; var fakeRecipeThree = new FakeRecipe { }.Generate(); fakeRecipeThree.Title = "Charlie"; //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree); context.SaveChanges(); var service = new RecipeRepository(context, new SieveProcessor(sieveOptions)); var recipeRepo = service.GetRecipes(new RecipeParametersDto { SortOrder = "Title" }); //Assert recipeRepo.Should() .ContainInOrder(fakeRecipeTwo, fakeRecipeOne, fakeRecipeThree); context.Database.EnsureDeleted(); } }
public void DeleteRecipe_ReturnsProperCount() { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeRecipeOne = new FakeRecipe { }.Generate(); var fakeRecipeTwo = new FakeRecipe { }.Generate(); var fakeRecipeThree = new FakeRecipe { }.Generate(); //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree); var service = new RecipeRepository(context, new SieveProcessor(sieveOptions)); service.DeleteRecipe(fakeRecipeTwo); context.SaveChanges(); //Assert var recipeList = context.Recipes.ToList(); recipeList.Should() .NotBeEmpty() .And.HaveCount(2); recipeList.Should().ContainEquivalentOf(fakeRecipeOne); recipeList.Should().ContainEquivalentOf(fakeRecipeThree); Assert.DoesNotContain(recipeList, r => r == fakeRecipeTwo); context.Database.EnsureDeleted(); } }
public void GetShoppingListItems_ReturnExpectedPageSize() { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeShoppingListItemOne = new FakeShoppingListItem { }.Generate(); var fakeShoppingListItemTwo = new FakeShoppingListItem { }.Generate(); var fakeShoppingListItemThree = new FakeShoppingListItem { }.Generate(); //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo, fakeShoppingListItemThree); context.SaveChanges(); var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions)); var ShoppingListItemRepo = service.GetShoppingListItems(new ShoppingListItemParametersDto { PageSize = 2 }); //Assert ShoppingListItemRepo.Should() .NotBeEmpty() .And.HaveCount(2); ShoppingListItemRepo.Should().ContainEquivalentOf(fakeShoppingListItemOne); ShoppingListItemRepo.Should().ContainEquivalentOf(fakeShoppingListItemTwo); context.Database.EnsureDeleted(); } }
public void GetRecipes_CountMatchesAndContainsEvuivalentObjects() { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeRecipeOne = new FakeRecipe { }.Generate(); var fakeRecipeTwo = new FakeRecipe { }.Generate(); var fakeRecipeThree = new FakeRecipe { }.Generate(); //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree); context.SaveChanges(); var service = new RecipeRepository(context, new SieveProcessor(sieveOptions)); var recipeRepo = service.GetRecipes(new RecipeParametersDto()); //Assert recipeRepo.Should() .NotBeEmpty() .And.HaveCount(3); recipeRepo.Should().ContainEquivalentOf(fakeRecipeOne); recipeRepo.Should().ContainEquivalentOf(fakeRecipeTwo); recipeRepo.Should().ContainEquivalentOf(fakeRecipeThree); context.Database.EnsureDeleted(); } }
public void GetIngredients_ReturnExpectedPageNumberAndSize() { //Arrange var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>() .UseInMemoryDatabase(databaseName: $"IngredientDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeIngredientOne = new FakeIngredient { }.Generate(); var fakeIngredientTwo = new FakeIngredient { }.Generate(); var fakeIngredientThree = new FakeIngredient { }.Generate(); //Act using (var context = new CarbonKitchenDbContext(dbOptions)) { context.Ingredients.AddRange(fakeIngredientOne, fakeIngredientTwo, fakeIngredientThree); context.SaveChanges(); var service = new IngredientRepository(context, new SieveProcessor(sieveOptions)); var ingredientRepo = service.GetIngredients(new IngredientParametersDto { PageSize = 1, PageNumber = 2 }); //Assert ingredientRepo.Should() .NotBeEmpty() .And.HaveCount(1); ingredientRepo.Should().ContainEquivalentOf(fakeIngredientTwo); context.Database.EnsureDeleted(); } }