public async Task ReturnCorectTypeOfInstance() { //Arrange var options = TestUtilities.GetOptions(nameof(ReturnCorectTypeOfInstance)); var mapperMock = new Mock <IDtoMapper <Bar, BarDto> >(); var searchMapperMock = new Mock <IDtoMapper <Bar, SearchBarDto> >(); var cocktailMapperMock = new Mock <IDtoMapper <Cocktail, CocktailDto> >(); var guid = Guid.NewGuid(); var entityDto = new BarDto { Id = guid, Name = "testBar", Info = "testInfo", Address = "testAddress", ImagePath = "testImagePath", Phone = "111-333-666" }; var bar = new Bar { Id = guid, Name = "testBar", Info = "testInfo", Address = "testAddress", ImagePath = "testImagePath", Phone = "111-333-666" }; var cocktail = new Cocktail { Id = Guid.NewGuid(), Name = "testCocktail", Info = "testCocktailInfo", }; var list = new List <string>() { "testCocktail" }; using (var arrangeContext = new CWContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new CWContext(options)) { //Act & Assert var sut = new BarService(assertContext, mapperMock.Object, searchMapperMock.Object, cocktailMapperMock.Object); var result = await sut.AddCocktailsAsync(entityDto, list); Assert.IsInstanceOfType(result, typeof(BarDto)); } }
public async Task ThrowWhen_NobarFound() { //Arrange var options = TestUtilities.GetOptions(nameof(ThrowWhen_NobarFound)); var mapperMock = new Mock <IDtoMapper <Bar, BarDto> >(); var searchMapperMock = new Mock <IDtoMapper <Bar, SearchBarDto> >(); var cocktailMapperMock = new Mock <IDtoMapper <Cocktail, CocktailDto> >(); var guid = Guid.NewGuid(); var entityDto = new BarDto { Id = Guid.NewGuid(), Name = "testBar", Info = "testInfo", Address = "testAddress", ImagePath = "testImagePath", Phone = "111-333-666" }; var bar = new Bar { Id = guid, Name = "testBar", Info = "testInfo", Address = "testAddress", ImagePath = "testImagePath", Phone = "111-333-666" }; var cocktail = new Cocktail { Id = Guid.NewGuid(), Name = "testCocktail", Info = "testCocktailInfo", }; var list = new List <string>() { "testCocktail" }; using (var arrangeContext = new CWContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new CWContext(options)) { //Act & Assert var sut = new BarService(assertContext, mapperMock.Object, searchMapperMock.Object, cocktailMapperMock.Object); await Assert.ThrowsExceptionAsync <BusinessLogicException>(() => sut.AddCocktailsAsync(entityDto, list)); } }
public async Task CreateBarCocktailWithCorrectDataa() { //Arrange var options = TestUtilities.GetOptions(nameof(CreateBarCocktailWithCorrectDataa)); var mapperMock = new Mock <IDtoMapper <Bar, BarDto> >(); var searchMapperMock = new Mock <IDtoMapper <Bar, SearchBarDto> >(); var cocktailMapperMock = new Mock <IDtoMapper <Cocktail, CocktailDto> >(); var barGuid = Guid.NewGuid(); var cocktailGuid = Guid.NewGuid(); var entityDto = new BarDto { Id = barGuid, Name = "testBar", Info = "testInfo", Address = "testAddress", ImagePath = "testImagePath", Phone = "111-333-666" }; var bar = new Bar { Id = barGuid, Name = "testBar", Info = "testInfo", Address = "testAddress", ImagePath = "testImagePath", Phone = "111-333-666" }; var cocktail = new Cocktail { Id = cocktailGuid, Name = "testCocktail", Info = "testCocktailInfo", }; var list = new List <string>() { "testCocktail" }; using (var arrangeContext = new CWContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new CWContext(options)) { //Act & Assert var sut = new BarService(assertContext, mapperMock.Object, searchMapperMock.Object, cocktailMapperMock.Object); var result = await sut.AddCocktailsAsync(entityDto, list); var barCocktail = await assertContext.BarCocktails.FirstAsync(); Assert.AreEqual(bar.Id, barCocktail.BarId); Assert.AreEqual(cocktail.Id, barCocktail.CocktailId); } }