public async Task AddRatingAsyncShouldThrowExceptionIfUserIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var commentsService = new CommentsService(dbContext, null, usersService); var comment = new Comment { Id = CommentId, Text = CommentText, }; await dbContext.Comments.AddAsync(comment); await dbContext.SaveChangesAsync(); var exception = await Assert.ThrowsAsync <NullReferenceException>(async() => await commentsService.AddRatingAsync(comment.Id)); Assert.IsType <NullReferenceException>(exception); }
public async Task AddRatingAsyncShouldThrowExceptionIfCommentIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var commentsService = new CommentsService(dbContext, null, usersService); var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await commentsService.AddRatingAsync(CommentId)); Assert.IsType <ArgumentNullException>(exception); }