public async Task GetBars_Return_Only_ExistingEntities() { //Arrange var options = Utils.GetOptions(nameof(GetBars_Return_Only_ExistingEntities)); var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan", IsDeleted = true, Country = new Country { Id = Guid.NewGuid(), Name = "USA" } }; var bar2 = new Bar { Id = Guid.NewGuid(), Name = "The Cocktail Bar", Address = "Sofia", Country = new Country { Id = Guid.NewGuid(), Name = "Bulgaria" } }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.AddRangeAsync(bar, bar2); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext); var result = await sut.GetAllBars(); Assert.AreEqual(1, result.Count); } }
public async Task GetBars_Returns_Correct_Instance() { //Arrange var options = Utils.GetOptions(nameof(GetBars_Returns_Correct_Instance)); var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan", Country = new Country { Id = Guid.NewGuid(), Name = "Bulgaria", } }; var bar2 = new Bar { Id = Guid.NewGuid(), Name = "The Cocktail Bar", Country = new Country { Id = Guid.NewGuid(), Name = "Bulgaria", } }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.AddRangeAsync(bar, bar2); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext); var result = await sut.GetAllBars(); Assert.IsInstanceOfType(result, typeof(ICollection <BarDTO>)); } }
public async Task Return_PaginatedListWithBarDtos_WhenValidValuesPassed() { var options = TestUtils.GetOptions(nameof(Return_PaginatedListWithBarDtos_WhenValidValuesPassed)); var fileService = new Mock <IFileUploadService>(); using (var arrangeContext = new CMContext(options)) { //1 arrangeContext.Cocktails.Add(new Cocktail { Id = "1", Name = "cocktail" }); arrangeContext.Bars.Add( new Bar { Id = "1", Name = "BashBar", Address = new Address { Id = "1", BarId = "1", Country = new Country { Id = "1", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "1", CocktailId = "1" } } }); //2 arrangeContext.Bars.Add( new Bar { Id = "2", Name = "BashBar2", Address = new Address { Id = "2", BarId = "2", Country = new Country { Id = "2", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "2", CocktailId = "1" } } }); //3 arrangeContext.Bars.Add( new Bar { Id = "3", Name = "Target", Image = "Snimka", Website = "abv.bg", Address = new Address { Id = "3", BarId = "3", Country = new Country { Id = "3", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "3", CocktailId = "1" } } , BarRating = 3 }); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext, fileService.Object); var result = await sut.GetAllBars(null, null); Assert.IsInstanceOfType(result, typeof(PaginatedList <BarDTO>)); } }
public async Task Return_OnlyTheBarsWichIsNotDeleted() { var options = TestUtils.GetOptions (nameof(Return_OnlyTheBarsWichIsNotDeleted)); var fileService = new Mock <IFileUploadService>(); using (var arrangeContext = new CMContext(options)) { //1 arrangeContext.Cocktails.Add(new Cocktail { Id = "1", Name = "cocktail" }); arrangeContext.Bars.Add( new Bar { Id = "1", Name = "BashBar", Address = new Address { Id = "1", BarId = "1", Country = new Country { Id = "1", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "1", CocktailId = "1" } }, BarRating = 1, DateDeleted = DateTime.Now }); //2 arrangeContext.Bars.Add( new Bar { Id = "2", Name = "BashBar2", Address = new Address { Id = "2", BarId = "2", Country = new Country { Id = "2", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "2", CocktailId = "1" } }, BarRating = 2, DateDeleted = DateTime.Now }); //3 arrangeContext.Bars.Add( new Bar { Id = "3", Name = "Target", Image = "Snimka", Website = "abv.bg", Address = new Address { Id = "3", BarId = "3", Country = new Country { Id = "3", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "3", CocktailId = "1" } } , BarRating = 3 }); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext, fileService.Object); var result = await sut.GetAllBars(null, null); Assert.AreEqual("Target", result[0].Name); } }
public async Task Return_TheRestOfTheBars_IfThereAreNoTwoBarsLeft() { var options = TestUtils.GetOptions (nameof(Return_TheRestOfTheBars_IfThereAreNoTwoBarsLeft)); var fileService = new Mock <IFileUploadService>(); using (var arrangeContext = new CMContext(options)) { //1 arrangeContext.Cocktails.Add(new Cocktail { Id = "1", Name = "cocktail" }); arrangeContext.Bars.Add( new Bar { Id = "1", Name = "BashBar", Address = new Address { Id = "1", BarId = "1", Country = new Country { Id = "1", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "1", CocktailId = "1" } }, BarRating = 1 }); arrangeContext.Bars.Add( new Bar { Id = "4", Name = "Target", Image = "Snimka", Website = "abv.bg", Address = new Address { Id = "4", BarId = "4", Country = new Country { Id = "3", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "4", CocktailId = "4" } } , BarRating = 3 }); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext, fileService.Object); var result = await sut.GetAllBars(null, null); Assert.AreEqual(2, result.Count()); } }
public async Task Return_SortedPaginatedListByRatingDes_IfPassedSortCriteria_IsRating_asc() { var options = TestUtils.GetOptions (nameof(Return_SortedPaginatedListByRatingDes_IfPassedSortCriteria_IsRating_asc)); var fileService = new Mock <IFileUploadService>(); using (var arrangeContext = new CMContext(options)) { //1 arrangeContext.Cocktails.Add(new Cocktail { Id = "1", Name = "cocktail" }); arrangeContext.Bars.Add( new Bar { Id = "1", Name = "BashBar", Address = new Address { Id = "1", BarId = "1", Country = new Country { Id = "1", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "1", CocktailId = "1" } }, BarRating = 1 }); //2 arrangeContext.Bars.Add( new Bar { Id = "2", Name = "BashBar2", Address = new Address { Id = "2", BarId = "2", Country = new Country { Id = "2", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "2", CocktailId = "1" } }, BarRating = 2 }); //3 arrangeContext.Bars.Add( new Bar { Id = "3", Name = "Target", Image = "Snimka", Website = "abv.bg", Address = new Address { Id = "3", BarId = "3", Country = new Country { Id = "3", Name = "Bulgaria" } }, BarCocktails = new List <BarCocktail> { new BarCocktail { BarId = "3", CocktailId = "1" } } , BarRating = 3 }); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext, fileService.Object); var result = await sut.GetAllBars(null, "rating_asc"); Assert.AreEqual(3, result[0].Rating); Assert.AreEqual(2, result[1].Rating); } }