public async Task GetAllShouldGetTwo() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); await context.Users.AddAsync(new ApplicationUser() { Id = "1" }); var repository = new EfDeletableEntityRepository <CommentOnPost>(context); var service = new CommentService(repository); var model = new AddCommentInputModel() { Description = "test", PostId = "1", UserId = "1", }; var secondModel = new AddCommentInputModel() { Description = "test2", PostId = "1", UserId = "1", }; await service.AddCommentToPostAsync(model); await service.AddCommentToPostAsync(secondModel); var actual = await service.GetAllAsync <CommentViewModel>("1"); Assert.Equal(2, actual.Count()); }
public async Task GetAllAsyncShouldReturnCollection() { //Arange var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; //Act var db = new ApplicationDbContext(options); var config = new MapperConfiguration(cfg => { cfg.AddProfile <ApplicationProfile>(); }); var mapper = new Mapper(config); var commentService = new CommentService(db, mapper); var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**", PasswordHash = "abcdefg1" }; var post = new Post { ImageUrl = "https://media.istockphoto.com/vectors/set-of-round-minus-and-plus-sign-icons-buttons-flat-negative-and-on-vector-id1189799128?b=1&k=6&m=1189799128&s=612x612&w=0&h=Dh3OKJ30k2hJj8948AU4MpNHfDL6Au3YrtcKD_UpMK8=", Title = "Some Post", Description = "Some Description", CreatedOn = DateTime.UtcNow }; await db.Users.AddAsync(user); await db.Posts.AddAsync(post); await db.SaveChangesAsync(); await commentService.AddCommentAsync(user.Id, "Niko", "Hello!"); var postModel = await db.Posts.FirstOrDefaultAsync(); await commentService.AddCommentToPostAsync(user.Id, "Niksan", "Hi", post.Id); var models = commentService.GetAllAsync(); //assert Assert.True(models != null); }