示例#1
0
        public void DeleteReplyByIdShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteReplyById_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);


            var reply = new Reply
            {
                Id = "replyId1",
            };

            dbContext.Replies.Add(reply);
            dbContext.SaveChanges();

            var result = commentsService.DeleteReply(reply.Id);

            //  Assert.Empty(dbContext.Replies);
            Assert.True(result);
        }
示例#2
0
        public void GetCommentsByRoadIdShouldNotReturnCommentsWhenInvalidRoadIsGiven()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetCommentsByRoadId_Comments_Roads_Db")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);

            var road = new Road
            {
                Id       = "Road1",
                RoadName = "Lorem",
                Comments = new List <Comment>
                {
                    new Comment
                    {
                        Content = "comment1"
                    },
                    new Comment
                    {
                        Content = "comment2"
                    }
                }
            };

            dbContext.Roads.Add(road);
            dbContext.SaveChanges();

            var comments = commentsService.GetCommentsByRoadId("road12");

            Assert.Null(comments);
        }
示例#3
0
        public void IsUserCreatorOfPhotoCommentShouldReturnFalse()
        {
            var comments = new List <Comment>();

            var mockCommentRepo = new Mock <IDeletableEntityRepository <Comment> >();

            mockCommentRepo.Setup(x => x.All()).Returns(comments.AsQueryable());
            mockCommentRepo.Setup(x => x.AddAsync(It.IsAny <Comment>())).Callback((Comment comm) => comments.Add(comm));

            var service = new CommentsService(mockCommentRepo.Object, null, null);

            var comment = new Comment
            {
                Id       = "1",
                UserId   = "1",
                SentById = "1",
                PhotoId  = "1",
                Content  = "Are you crazy?",
                PostId   = "1",
            };

            comments.Add(comment);
            var result = service.IsUserCreatorOfPhotoComment("1", "2");

            Assert.Equal(false, result);
        }
示例#4
0
        public void AddCommentToRoadShouldAddCommentToTheGivenRoad()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddCommentToRoad_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);


            var user = new User
            {
                UserName = "******",
                Roads    = new List <Road>
                {
                    new Road
                    {
                        Id       = "RoadId1",
                        RoadName = "Lorem",
                    }
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var result = commentsService.AddCommentToRoad("RoadId1", user, 4, "none");

            Assert.Single(dbContext.Comments);
            Assert.True(result);
        }
示例#5
0
        public async Task EditPhotoCommentShouldWorkCorrectly()
        {
            var comments = new List <Comment>();
            var appUsers = new List <ApplicationUser>();

            var mockCommentRepo = new Mock <IDeletableEntityRepository <Comment> >();

            mockCommentRepo.Setup(x => x.All()).Returns(comments.AsQueryable());
            mockCommentRepo.Setup(x => x.AddAsync(It.IsAny <Comment>())).Callback((Comment comm) => comments.Add(comm));

            var mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >();

            mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable());
            mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU));

            var service = new CommentsService(mockCommentRepo.Object, null, mockAppUser.Object);

            var commentToChangeContent = new Comment
            {
                Id       = "1",
                UserId   = "1",
                SentById = "1",
                Content  = "Are you crazy?",
            };

            comments.Add(commentToChangeContent);
            await service.EditPhotoComment("1", "newContent", "1");

            var expectedOutput = "newContent";

            Assert.Equal(expectedOutput, commentToChangeContent.Content);
        }
示例#6
0
        public void GetPostIdByCommentIdShouldWorkCorrectly()
        {
            var comments = new List <Comment>();

            var mockCommentRepo = new Mock <IDeletableEntityRepository <Comment> >();

            mockCommentRepo.Setup(x => x.All()).Returns(comments.AsQueryable());
            mockCommentRepo.Setup(x => x.AddAsync(It.IsAny <Comment>())).Callback((Comment comm) => comments.Add(comm));

            var service = new CommentsService(mockCommentRepo.Object, null, null);

            var comment = new Comment
            {
                Id       = "1",
                UserId   = "1",
                SentById = "1",
                PhotoId  = "1",
                Content  = "Are you crazy?",
                PostId   = "1",
            };

            comments.Add(comment);
            var postId = service.GetPostIdByCommentId("1");

            Assert.Equal(comment.PostId, postId);
        }
示例#7
0
        public async Task CreateCommentShouldWorkCorrectlyAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Comment>(dbContext);

            var service = new CommentsService(repository);

            var comment = new Comment
            {
                ArticleId = 1,
                UserId    = "1",
                Content   = "test",
                ParentId  = null,
            };

            await service.CreateAsync(comment.ArticleId, comment.UserId, comment.Content, comment.ParentId);

            dbContext.SaveChanges();

            var count = repository.All().CountAsync();

            Assert.Equal(1, count.Result);
        }
        public void ReturnExpectedCollectionSorted()
        {
            //Arrange
            var service = new CommentsService
                              (this.commentRepositoryMock.Object,
                              this.tripRepositoryMock.Object,
                              this.usersServiceMock.Object,
                              this.identifierProviderMock.Object,
                              this.unitOfWorkMock.Object);

            var expectedCollection = new List <Comment>();
            var mockComment        = new Mock <Comment>();

            for (int i = 10; i > 0; i--)
            {
                mockComment.Setup(c => c.Author.UserName).Returns(i + "username");
                expectedCollection.Add(mockComment.Object);
            }
            this.commentRepositoryMock.Setup(x => x.AdminAll()).Returns(expectedCollection.AsQueryable);

            expectedCollection.Sort(delegate(Comment x, Comment y)
            {
                return(x.Author.UserName.CompareTo(y.Author.UserName));
            });

            //Act
            var commentsCollection = service.GetAllAdmin().ToList();

            //Assert
            Assert.AreEqual(expectedCollection, commentsCollection);
        }
示例#9
0
        public async Task GetCommentByIdShouldReturnComment()
        {
            // Arrange
            var db = this.GetDatabase();

            var comment = new Comment
            {
                Id      = "slihdbflisdbnfawef",
                MovieId = "lihsbdfjsndfsf",
                UserId  = "s;lkdf;sldfkg"
            };

            db.AddRange(comment);

            await db.SaveChangesAsync();

            var commentsService = new CommentsService(db);

            // Act
            var result = commentsService.GetCommentById(comment.Id);

            // Assert
            result
            .Should()
            .Be(comment);
        }
示例#10
0
        public JsonResult GetNewNews(string parameters)
        {
            List <Comment> allComments    = new List <Comment>();
            List <Comment> actualComments = new List <Comment>();

            if (UserService.user != null)
            {
                int newCountComments = CommentsService.GetCountComments(NewService.currentStateNews.newsId);
                if (countComments < newCountComments)
                {
                    using (SampleContext context = new SampleContext())
                    {
                        allComments = context.comments.Where(x => x.newId == NewService.currentStateNews.newsId).ToList();
                    }
                    int i = newCountComments - countComments;
                    for (; i != 0; --i)
                    {
                        actualComments.Add(allComments[allComments.Count - i]);
                    }
                    countComments = newCountComments;
                }
            }

            return(Json(actualComments, JsonRequestBehavior.AllowGet));
        }
示例#11
0
        public async Task DeleteShouldDeleteComment()
        {
            // Arrange
            var db = this.GetDatabase();

            var comment = new Comment()
            {
                Title = "asdfgw56y345h",
                Text  = "dfgsdfgsdfgf"
            };


            db.AddRange(comment);

            await db.SaveChangesAsync();

            var commentsService = new CommentsService(db);

            // Act
            var result = await commentsService.Delete(comment);

            // Assert
            result.Succeeded
            .Should()
            .Be(true);

            db.Comments
            .Should()
            .BeEmpty();
        }
示例#12
0
        public async Task UpdateShouldUpdateComment()
        {
            // Arrange
            var db = this.GetDatabase();

            var comment = new Comment()
            {
                Title = "asdfgw56y345h",
                Text  = "dfgsdfgsdfgf"
            };

            var model = new CommentBindingModel()
            {
                Title = "I Like this movie",
                Text  = "Its a great movie"
            };

            db.AddRange(comment);

            await db.SaveChangesAsync();

            var commentsService = new CommentsService(db);

            // Act
            var result = await commentsService.Update(comment, model);

            // Assert
            result.Succeeded
            .Should()
            .Be(true);

            db.Comments
            .Should()
            .Match(r => r.Any(c => c.Title == model.Title && c.Text == model.Text));
        }
示例#13
0
        public async Task GetCommentByIdJsonShouldReturnCommentJson()
        {
            // Arrange
            var db = this.GetDatabase();

            var comment = new Comment
            {
                Id      = "slihdbflisdbnfawef",
                MovieId = "lihsbdfjsndfsf",
                UserId  = "s;lkdf;sldfkg"
            };

            var json = JsonConvert.SerializeObject(comment);

            db.AddRange(comment);

            await db.SaveChangesAsync();

            var commentsService = new CommentsService(db);

            // Act
            var result = commentsService.GetCommentByIdJson(comment.Id);

            // Assert
            result
            .Should()
            .Equals(json);
        }
 public CommentsServiceTestWrapper(Mock <ICommentsRepository> mockCommentRepository,
                                   Mock <IPostsRepository> mockPostRepository, Guid postWithNoCommentsId)
 {
     this.postWithNoCommentsId = postWithNoCommentsId;
     postRepository            = mockPostRepository.Object;
     CommentsService           = new CommentsService(mockCommentRepository.Object, postRepository);
 }
示例#15
0
        public async Task IsInSamePostReturnTrueAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Comment>(dbContext);

            var service = new CommentsService(repository);

            var comment = new Comment
            {
                ArticleId = 1,
                UserId    = "1",
                Content   = "test",
                ParentId  = null,
            };
            var commentWithParent = new Comment
            {
                ArticleId = 1,
                UserId    = "1",
                Content   = "test",
                ParentId  = 1,
            };

            await service.CreateAsync(comment.ArticleId, comment.UserId, comment.Content, comment.ParentId);

            var result = service.IsInPostId((int)commentWithParent.ParentId, commentWithParent.ArticleId);

            dbContext.SaveChanges();

            Assert.True(result);
        }
示例#16
0
        public async Task AddComment_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <Comment>(context);
            var service    = new CommentsService(repository);

            var userId       = context.Users.First().Id;
            var experienceId = context.Experiences.First().Id;

            var expectedId = 2;
            var comment    = new CommentViewModel()
            {
                Id           = expectedId,
                Content      = "Test comment",
                UserId       = userId,
                ExperienceId = experienceId,
            };

            var commentId = await service.AddComment(comment);

            Assert.True(commentId == expectedId, "Add method does not work correctly");
        }
示例#17
0
        public void GetAllShouldReturnCorrectNumberOfPages()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPages))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var commentService = new CommentsService(context);
                var expenseService = new ExpenseService(context);
                var addedExpense   = expenseService.Create(new Lab2.DTOs.PostExpenseDto
                {
                    Description = "fdsfsd",
                    Date        = new DateTime(),
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "asd",
                            Owner     = null
                        }
                    },
                    Currency = "large",
                    Sum      = 5,
                    Type     = "food",
                    Location = "aaa"
                }, null);

                var allComments = commentService.GetAll(1, string.Empty);
                Assert.AreEqual(1, allComments.NumberOfPages);
            }
        }
示例#18
0
        public async Task DeletePhotoCommentShouldNotDelete()
        {
            var comments = new List <Comment>();
            var appUsers = new List <ApplicationUser>();

            var mockCommentRepo = new Mock <IDeletableEntityRepository <Comment> >();

            mockCommentRepo.Setup(x => x.All()).Returns(comments.AsQueryable());
            mockCommentRepo.Setup(x => x.AddAsync(It.IsAny <Comment>())).Callback((Comment comm) => comments.Add(comm));

            var mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >();

            mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable());
            mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU));

            var service = new CommentsService(mockCommentRepo.Object, null, mockAppUser.Object);

            var commentToDelete = new Comment
            {
                Id       = "1",
                UserId   = "1",
                SentById = "1",
            };

            comments.Add(commentToDelete);
            Task result = service.DeletePhotoCommentAsync("2", "1");

            Assert.True(!result.IsCompletedSuccessfully);
        }
示例#19
0
        public async System.Threading.Tasks.Task testCategoriesGetAsync()
        {
            var comments = new List<Comments>
            {
                new Comments() { Id = "test1" },
                new Comments() { Id = "test2" },
            };

            var fakeRepositoryMock = new Mock<ICommentsRepository>();
            fakeRepositoryMock.Setup(x => x.GetAll()).ReturnsAsync(comments);


            var commentsService = new CommentsService(fakeRepositoryMock.Object);

            var resltComments = await commentsService.GetComments();

            Xunit.Assert.Collection(resltComments, comments =>
            {
                Xunit.Assert.Equal("test1", comments.Id);
            },
            comments =>
            {
                Xunit.Assert.Equal("test2", comments.Id);
            });
        }
示例#20
0
        public async Task EditPhotoCommentShouldReturnFalse()
        {
            var comments = new List <Comment>();
            var appUsers = new List <ApplicationUser>();

            var mockCommentRepo = new Mock <IDeletableEntityRepository <Comment> >();

            mockCommentRepo.Setup(x => x.All()).Returns(comments.AsQueryable());
            mockCommentRepo.Setup(x => x.AddAsync(It.IsAny <Comment>())).Callback((Comment comm) => comments.Add(comm));

            var mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >();

            mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable());
            mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU));

            var service = new CommentsService(mockCommentRepo.Object, null, mockAppUser.Object);

            var commentToChangeContent = new Comment
            {
                Id       = "1",
                UserId   = "1",
                SentById = "1",
                Content  = "Are you crazy?",
            };

            comments.Add(commentToChangeContent);
            Task result = service.EditPhotoComment("1", "newContent", "2");

            Assert.False(result.IsFaulted);
        }
        public void DeleteShouldDeleteAGivenComment()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldDeleteAGivenComment))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var commentsService = new CommentsService(context);
                var toAdd           = new CommentPostDTO()

                {
                    Important = true,
                    Text      = "A nice task...",
                };


                var actual               = commentsService.Create(toAdd, null);
                var afterDelete          = commentsService.Delete(actual.Id);
                int numberOfCommentsInDb = context.Comments.CountAsync().Result;
                var resultComment        = context.Comments.Find(actual.Id);


                Assert.IsNotNull(afterDelete);
                Assert.IsNull(resultComment);
                Assert.AreEqual(0, numberOfCommentsInDb);
            }
        }
示例#22
0
        public async Task CreatePhotoCommentAsyncShouldWorkCorrectly()
        {
            var comments = new List <Comment>();
            var photos   = new List <Photo>();
            var appUsers = new List <ApplicationUser>();

            var mockCommentRepo = new Mock <IDeletableEntityRepository <Comment> >();

            mockCommentRepo.Setup(x => x.All()).Returns(comments.AsQueryable());
            mockCommentRepo.Setup(x => x.AddAsync(It.IsAny <Comment>())).Callback((Comment comm) => comments.Add(comm));

            var mockPhoto = new Mock <IDeletableEntityRepository <Photo> >();

            mockPhoto.Setup(x => x.All()).Returns(photos.AsQueryable());
            mockPhoto.Setup(x => x.AddAsync(It.IsAny <Photo>())).Callback((Photo ph) => photos.Add(ph));

            var mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >();

            mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable());
            mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU));

            var service = new CommentsService(mockCommentRepo.Object, mockPhoto.Object, mockAppUser.Object);

            await service.CreatePhotoCommentAsync("1", "1", "Are you crazy?", "1");

            var expectedResult = 1;

            Assert.Equal(expectedResult, comments.Count());
        }
        public void GetByIdShouldReturnCommentWithCorrectId()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnCommentWithCorrectId))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var commentsService = new CommentsService(context);
                var toAdd           = new CommentPostDTO()

                {
                    Important = true,
                    Text      = "A nice task...",
                };


                var current  = commentsService.Create(toAdd, null);
                var expected = commentsService.GetById(current.Id);



                Assert.IsNotNull(expected);
                Assert.AreEqual(expected.Text, current.Text);
                Assert.AreEqual(expected.Id, current.Id);
            }
        }
示例#24
0
        public async Task GetByUserIdShouldReturnCount2()
        {
            var comments = new List <Comment>();

            var mockCommentRepo = new Mock <IDeletableEntityRepository <Comment> >();

            mockCommentRepo.Setup(x => x.All()).Returns(comments.AsQueryable());
            mockCommentRepo.Setup(x => x.AddAsync(It.IsAny <Comment>())).Callback((Comment comm) => comments.Add(comm));

            var service = new CommentsService(mockCommentRepo.Object, null, null);

            var comment = new Comment
            {
                Id      = "1",
                PhotoId = "1",
                Content = "Test",
            };
            var secondComment = new Comment
            {
                Id      = "2",
                PhotoId = "1",
                Content = "Another test",
            };

            comments.Add(comment);
            comments.Add(secondComment);
            var countOfCommentsByUser = service.GetByUserId <CommentViewModel>("1");

            var expectedResult = 2;

            Assert.Equal(expectedResult, countOfCommentsByUser.Count());
        }
        public void UpsertShouldModifyTheGivenComment()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldModifyTheGivenComment))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var commentsService = new CommentsService(context);
                var toAdd           = new CommentPostDTO()

                {
                    Important = true,
                    Text      = "A nice task...",
                };

                var added = commentsService.Create(toAdd, null);
                context.Entry(added).State = EntityState.Detached;

                var update = new Comment()
                {
                    Important = false,
                    Text      = "A nice task...",
                };


                var updateResult = commentsService.Upsert(added.Id, update);
                Assert.NotNull(updateResult);
                Assert.False(updateResult.Important);
                Assert.AreEqual(added.Text, updateResult.Text);
            }
        }
示例#26
0
        public void AddReplyToCommentShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddReplyToComment_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);

            var user = new User
            {
                UserName = "******"
            };
            var comment = new Comment
            {
                Content = "comment1",
                Id      = "commentId1",
                Replies = new List <Reply>(),
                User    = user
            };

            dbContext.Users.Add(user);
            dbContext.Comments.Add(comment);
            dbContext.SaveChanges();
            var result = commentsService.AddReplyToComment("commentId1", "reply1", user);

            Assert.True(result);
            Assert.Equal(1, comment.Replies.Count);
        }
示例#27
0
        public ActionResult GetComments(int lawId)
        {
            CommentsService   service = new CommentsService();
            CommentsListModel model   = service.GetCommentsForLaw(lawId, User.Identity.GetUserId(), Infrastructure.CommentOrder.Chronological);

            return(PartialView("_LawComments", model));
        }
示例#28
0
        public void GetCommentsByRoadIdShouldReturnAllCommentsOfGivenRoad()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetCommentsByRoadId_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);

            var road = new Road
            {
                Id       = "Road1",
                RoadName = "Lorem",
                Comments = new List <Comment>
                {
                    new Comment
                    {
                        Content = "comment1"
                    },
                    new Comment
                    {
                        Content = "comment2"
                    }
                }
            };

            dbContext.Roads.Add(road);
            dbContext.SaveChanges();

            var comments = commentsService.GetCommentsByRoadId(road.Id);

            Assert.Equal(2, comments.Count);
        }
        public async Task<ActionResult<long>> CreateProject([FromBody] ProjectSettings projectSettings)
        {
            var projectId = await ProjectService.CreateProject(projectSettings);
            if (projectSettings.FromTemplateId.HasValue)
            {
                var templateId = projectSettings.FromTemplateId.Value;
                await CommentsService.CreateComment(new Comment{Content = $"TemplateId:{templateId}", ProjectId = projectId});
                var templateItems = await ItemService.GetItemsInProject(templateId);
                var sections = await SectionService.GetSectionsAsync(templateId);
                var firstSection = sections.First();
                var firstSectionItems = templateItems.Where(x => x.SectionId == firstSection.Id)
                    .ToList();

                firstSectionItems.ForEach(x =>
                    {
                        x.SectionId = null;
                        x.ProjectId = projectId;
                        x.DueDateTime = x.Due?.Datetime;
                        x.DueDate = x.Due?.Datetime == null ? x.Due?.Date : null;
                        x.UniqueId = $"{projectId}{x.Id}".GetHashCode().ToString();
                    });
                await ItemService.PostItems(firstSectionItems);
            }

            return CreatedAtAction(nameof(Get), projectId, new {projectId});
        }
示例#30
0
        public void MakeComment_OnSeedLaw_CommentMade()
        {
            var commmentText = "Test comment";
            var law          = Helpers.GetTestLaw();
            var user         = Helpers.CreateNewUser();

            JavnaRasprava.WEB.DomainModels.ApplicationDbContext context = null;
            try
            {
                context = JavnaRasprava.WEB.DomainModels.ApplicationDbContext.Create();

                new CommentsService().MakeComment(law.LawID, user.Id, commmentText);

                var response = new CommentsService().GetCommentsForLaw(law.LawID, user.Id, CommentOrder.Chronological);
                var comment  = response.Comments.Where(x => x.Comment.ApplicationUserID == user.Id && x.Comment.Text == commmentText).FirstOrDefault();

                Assert.IsNotNull(comment, "Comment not made");
                Assert.AreEqual(0, comment.VotesDown, "New Comment, no votes down yet");
                Assert.AreEqual(0, comment.VotesUp, "New Comment, no votes up yet");
                Assert.AreEqual(false, comment.UserVoted, "New Comment, no votes yet");
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }

                Helpers.DeleteUser(user);
            }
        }
 public CommentsController(CommentsService commentsService)
 {
     _commentsService = commentsService;
 }