public void GetStyleShouldReturnTheRightCategory() { var options = new DbContextOptionsBuilder <TattooShopContext>() .UseInMemoryDatabase(databaseName: "Unique_Db_Name_57821987") .Options; var dbContext = new TattooShopContext(options); dbContext.Styles.Add(new Style() { Id = "1" }); dbContext.SaveChanges(); var stylesRepository = new DbRepository <Style>(dbContext); var stylesService = new StylesService(stylesRepository); var style = stylesService.GetStyle("1"); Assert.Equal("1", style.Id); }
public void GetCategoryShouldReturnTheRightCategory() { var options = new DbContextOptionsBuilder <TattooShopContext>() .UseInMemoryDatabase(databaseName: "Unique_Db_Name_5785217") .Options; var dbContext = new TattooShopContext(options); dbContext.Categories.Add(new Category() { Id = "1" }); dbContext.SaveChanges(); var categoriesRepository = new DbRepository <Category>(dbContext); var categoriesService = new CategoriesService(categoriesRepository); var category = categoriesService.GetCategory("1"); Assert.Equal("1", category.Id); }
public async Task AddBookShouldActuallyAddBookToDatabase() { var options = new DbContextOptionsBuilder <TattooShopContext>() .UseInMemoryDatabase(databaseName: "Unique_Db_Name_5785216") .Options; var dbContext = new TattooShopContext(options); dbContext.Artists.Add(new Artist() { Id = "1" }); dbContext.Users.Add(new TattooShopUser() { Id = "2" }); dbContext.SaveChanges(); var artistsRepository = new DbRepository <Artist>(dbContext); var booksRepository = new DbRepository <Book>(dbContext); var imageService = new ImageService(dbContext); var tattoosRepository = new DbRepository <Tattoo>(dbContext); var artistsService = new ArtistsService(artistsRepository, imageService, booksRepository, tattoosRepository); var fileMock = new Mock <IFormFile>(); var content = "Hallo world from a fake file!"; var fileName = "test.pdf"; var ms = new MemoryStream(); var writer = new StreamWriter(ms); writer.Write(content); writer.Flush(); ms.Position = 0; fileMock.Setup(x => x.OpenReadStream()).Returns(ms); fileMock.Setup(x => x.FileName).Returns(fileName); fileMock.Setup(x => x.Length).Returns(ms.Length); await artistsService.AddBook(DateTime.UtcNow.AddDays(3).ToString(), "short description", fileMock.Object, "Geometric", "2", "1"); Assert.Equal(1, booksRepository.All().Count()); }
public async Task AddOrderShouldActuallyAddOrder() { var options = new DbContextOptionsBuilder <TattooShopContext>() .UseInMemoryDatabase(databaseName: "Unique_Db_Name_578521936") .Options; var dbContext = new TattooShopContext(options); dbContext.Products.Add(new Product() { Id = "1" }); dbContext.Users.Add(new TattooShopUser() { Id = "2" }); dbContext.SaveChanges(); var ordersRepository = new DbRepository <Order>(dbContext); var ordersService = new OrdersService(ordersRepository); await ordersService.AddOrder("sample address", "sample description", 3, "1", "2"); Assert.Equal(1, dbContext.Orders.Count()); }