public async Task GetBar_Throws_When_IdIsNull() { //Arrange var options = Utils.GetOptions(nameof(GetBar_Throws_When_IdIsNull)); var bar = new Bar { Id = Guid.Parse("cda3e6b5-c77c-4682-a7ff-73987919a059"), Name = "Cosmos", Address = "Sofia", Rating = 2, }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.GetBar(null)); } }
public async Task ThrowCorrectMagicExeption_WhenBarDoesNotExist() { var options = TestUtils.GetOptions(nameof(ThrowCorrectMagicExeption_WhenBarDoesNotExist)); 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 = "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 ex = await Assert.ThrowsExceptionAsync <MagicException>( async() => await sut.GetBar("4") ); Assert.AreEqual("Bar cannot be null!", ex.Message); } }
public async Task GetBar_Returns_Correct_When_Params_Are_Valid() { //Arrange var options = Utils.GetOptions(nameof(GetBar_Returns_Correct_When_Params_Are_Valid)); var bar = new Bar { Id = Guid.Parse("cda3e6b5-c77c-4682-a7ff-73987919a059"), Name = "Cosmos", Address = "Sofia", Rating = 2, Country = new Country { Name = "Bulgaria" } }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext); var result = await sut.GetBar(bar.Id); Assert.AreEqual(bar.Name, result.Name); Assert.AreEqual(bar.Address, result.Address); Assert.AreEqual(bar.Rating, result.Rating); Assert.IsInstanceOfType(result, typeof(BarDTO)); } }
public async Task Return_BarCtxModel_WithCorrectAttributes_WhenValidIdPassed() { var options = TestUtils.GetOptions(nameof(Return_BarCtxModel_WithCorrectAttributes_WhenValidIdPassed)); 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.GetBar("3"); Assert.AreEqual("Target", result.Name); Assert.AreEqual("3", result.Id); Assert.AreEqual("abv.bg", result.Website); Assert.AreEqual("Snimka", result.Image); Assert.IsInstanceOfType(result, typeof(Bar)); } }