示例#1
0
        public async Task AddCommentToThem_ShouldThrow_IfThemNotExist()
        {
            var themsRepoBuilder = new ThemsRepositoryBuilder();
            var themsRepo        = themsRepoBuilder
                                   .WithAll()
                                   .Build();

            var themCommentRepoBuilder = new ThemCommentsRepositoryBuilder();
            var themCommentsRepo       = themCommentRepoBuilder
                                         .WithAll()
                                         .Build();

            var sut = new ThemService(themsRepo, null, themCommentsRepo, Mapper);

            var model = new CreateThemViewModel
            {
                Description = "TraLaLA"
            };

            var user = new GoUser {
                Id = "7"
            };

            var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await sut.AddCommentToThem("5", "New themComment", user));

            Assert.Equal("Theme not exist!", ex.Message);

            themCommentRepoBuilder.ThemCommentsRepoMock.Verify(r => r.AddAsync(It.IsAny <ThemComment>()), Times.Never);
            themCommentRepoBuilder.ThemCommentsRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never);
        }
示例#2
0
        public async Task AddCommentToThem_ShouldAddNewThemComment_Correctly()
        {
            var themsRepoBuilder = new ThemsRepositoryBuilder();
            var themsRepo        = themsRepoBuilder
                                   .WithAll()
                                   .Build();

            var themCommentRepoBuilder = new ThemCommentsRepositoryBuilder();
            var themCommentsRepo       = themCommentRepoBuilder
                                         .WithAll()
                                         .Build();

            var sut = new ThemService(themsRepo, null, themCommentsRepo, Mapper);

            var model = new CreateThemViewModel
            {
                Description = "TraLaLA"
            };

            var user = new GoUser {
                Id = "7"
            };

            await sut.AddCommentToThem("3", "New themComment", user);

            themCommentRepoBuilder.ThemCommentsRepoMock.Verify(r => r.AddAsync(It.IsAny <ThemComment>()), Times.Once);
            themCommentRepoBuilder.ThemCommentsRepoMock.Verify(r => r.SaveChangesAsync(), Times.Once);
        }