示例#1
0
        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);
        }
示例#2
0
        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);
        }