Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void GetDetails_ShouldThrow_IfThemNotExist()
        {
            var themsRepoBuilder = new ThemsRepositoryBuilder();
            var themsRepo        = themsRepoBuilder
                                   .WithAll()
                                   .Build();

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

            var usersRepoBuilder = new GoUserRepositoryBuilder();
            var usersRepo        = usersRepoBuilder
                                   .WithAll()
                                   .Build();

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

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

            var ex = Assert.Throws <ArgumentException>(() => sut.GetDetails("7", user));

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

            themsRepoBuilder.ThemsRepoMock.Verify();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void GetDetails_ShouldReturnCorrect_ThemDetailsViewModel()
        {
            var themsRepoBuilder = new ThemsRepositoryBuilder();
            var themsRepo        = themsRepoBuilder
                                   .WithAll()
                                   .Build();

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

            var usersRepoBuilder = new GoUserRepositoryBuilder();
            var usersRepo        = usersRepoBuilder
                                   .WithAll()
                                   .Build();

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

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

            var actual = sut.GetDetails("1", user);

            var expected = new ThemDetailsViewModel
            {
                Id          = "1",
                Description = "Niki otiva na more",
                Date        = DateTime.Parse("07/02/2018"),
                AuthorId    = "7",
                Author      = "Slavqna ",
                Comments    = new List <ThemCommentViewModel>
                {
                    new ThemCommentViewModel
                    {
                        Id       = "6",
                        Content  = "Niki otiva na more",
                        ThemId   = "1",
                        Date     = DateTime.Parse("08/02/2018"),
                        AuthorId = "11",
                        Author   = "Koni "
                    },
                    new ThemCommentViewModel
                    {
                        Id       = "7",
                        Content  = "Nikiiiiiiiiiii",
                        ThemId   = "1",
                        Date     = DateTime.Parse("09/02/2018"),
                        AuthorId = "8",
                        Author   = "Niki "
                    },
                }
            };

            Assert.Equal(expected, actual, new ThemDetailsViewModelComparer());
            Assert.Equal(expected.Comments, actual.Comments, new ThemCommentViewModelComparer());

            themsRepoBuilder.ThemsRepoMock.Verify();
            themCommentRepoBuilder.ThemCommentsRepoMock.Verify();
            usersRepoBuilder.UsersRepoMock.Verify();
        }