public async Task AddImageToPostShouldWork() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "AddImageToPostShouldWork").Options; var dbContext = new ApplicationDbContext(options); var postsRepo = new EfDeletableEntityRepository <Post>(dbContext); var makesRepo = new EfDeletableEntityRepository <Make>(dbContext); var makesService = new MakesService(makesRepo); var postsService = new PostsService(postsRepo, makesService); var post = new Post() { Id = 1, Name = "random name", Price = 53222, Currency = Currency.LV, Mileage = 25123, Color = new Color(), EngineType = EngineType.Disel, Horsepower = 255, TransmissionType = TransmissionType.Automatic, ManufactureDate = DateTime.Now, Category = new Category(), City = new City(), User = new ApplicationUser(), PhoneNumber = "0897456321", Description = "random descr", Eurostandard = Eurostandard.Five, Condition = Condition.New, VehicleCategory = new VehicleCategory(), }; var image = new Image() { Url = "random", }; await dbContext.Images.AddAsync(image); await dbContext.Posts.AddAsync(post); await dbContext.SaveChangesAsync(); var postImage = new PostImage() { Image = image, ImageId = image.Id, Post = post, PostId = post.Id, }; await postsService.AddImageToPost(1, postImage); Assert.Single(post.Images); }