public void ValidGetAllShouldDisplayAllComments()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetAllShouldDisplayAllComments))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var commentsService = new CommentsService(context);

                var added = new Lab2.DTOs.CommentPostDto

                {
                    Text      = "Write a Book",
                    Important = true,
                };
                var added2 = new Lab2.DTOs.CommentPostDto

                {
                    Text      = "Read a Book",
                    Important = false,
                };

                commentsService.Create(added);
                commentsService.Create(added2);

                var result = commentsService.GetAll(string.Empty);
                // Assert.AreEqual(0, result.Count());
            }
        }
        public async Task GetAllGenericShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetAllGeneric").Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Comments.Add(new Comment()
            {
                PostId = 1, User = new ApplicationUser()
            });
            dbContext.Comments.Add(new Comment()
            {
                PostId = 2, User = new ApplicationUser()
            });
            dbContext.Comments.Add(new Comment()
            {
                PostId = 3, User = new ApplicationUser()
            });
            await dbContext.SaveChangesAsync();

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

            Assert.Equal(3, service.GetAll <CommentViewModel>().Count());
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        public void GetAllShouldReturnCorrectNumberOfPages()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetAllShouldReturnCorrectNumberOfPages")
                          .Options;

            using (var context = new ExpensesDbContext(options))

            {
                var commentsService = new CommentsService(context);
                var expenseService  = new ExpenseService(context);

                expenseService.Create(new Lab2.DTOs.PostExpenseDto
                {
                    Description = "test_description",
                    Sum         = 999,
                    Location    = "test_location",
                    Date        = DateTime.Now,
                    Type        = "Food",
                    Currency    = "EUR",
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "test_comment",
                            Owner     = null
                        }
                    },
                }, null);

                var allComments = commentsService.GetAll(1, string.Empty);
                Assert.AreEqual(1, allComments.NumberOfPages);
            }
        }
        public void GetAllCommentsTest()
        {
            var comments = _commentsService.GetAll().ToList();

            Assert.AreEqual(1, comments.Count);
            Assert.AreEqual("Автор1", comments[0].Author);
            _mock.Verify(item => item.GetAll(), Times.Once());
        }
        public async Task DeleteAsyncShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteAsync").Options;
            var dbContext = new ApplicationDbContext(options);

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

            await service.AddAsync("content", new ApplicationUser(), new Post());

            Assert.True(repository.All().Any(x => x.Content == "content"));
            Assert.Single(service.GetAll());

            await service.DeleteAsync(1);

            Assert.Empty(service.GetAll());
        }
Beispiel #7
0
        public void GetAll_WithNoData_ShouldWorkCorrectly(int experienceId)
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

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

            var count = service.GetAll <CommentViewModel>(experienceId).Count();

            Assert.True(count == 0, "Create method does not work correctly");
        }
        public async Task GetAll_WithNullData_ShouldThrowEmptyResult()
        {
            MapperInitializer.InitializeMapper();
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

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

            var result = service.GetAll <CommentEditModel>().ToList();

            Assert.Empty(result);
        }
Beispiel #9
0
        public async Task GetAllShouldReturnExceptionUsingDbContext()
        {
            AutoMapperConfig.RegisterMappings(typeof(Post).Assembly);
            var commentsRepository = new Mock <IDeletableEntityRepository <Comment> >();
            var postsRepository    = new Mock <IDeletableEntityRepository <Post> >();

            commentsRepository.Setup(r => r.All()).Returns(new List <Comment>
            {
            }.AsQueryable());
            var service = new CommentsService(commentsRepository.Object, postsRepository.Object);

            Assert.Throws <InvalidOperationException>(() => service.GetAll <CommentViewModel>(0).Count());
        }
        public void ReturnNull_WhenRepositoryMethodAll_ReturnsNull()
        {
            //Arrange
            var comments = new Mock <IEfGenericRepository <Comment> >();

            comments.Setup(x => x.All()).Returns(() => null);
            var commentsService = new CommentsService(comments.Object);

            //Act
            var result = commentsService.GetAll();

            //Assert
            Assert.IsNull(result);
        }
        public async Task GetAll_ShouldReturnAllComments()
        {
            MapperInitializer.InitializeMapper();
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.CreateTestComments(dbContext);

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

            var result = service.GetAll <CommentEditModel>().ToList();

            Assert.Equal(5, result.Count);
        }
Beispiel #12
0
        public void GetAll_ShouldReturnCorrectNumberOfComments()
        {
            Mapper.Initialize(x => x.AddProfile <MapperConfiguration>());
            var repo     = new Mock <IRepository <Comment> >();
            var comments = GetTestData().AsQueryable();

            repo.Setup(r => r.All()).Returns(comments);
            var service = new CommentsService(repo.Object);

            //do
            var result = service.GetAll();

            //assert
            Assert.Equal(2, result.Count());
        }
        public async Task LikeShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddAsync").Options;
            var dbContext = new ApplicationDbContext(options);

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

            await service.AddAsync("content", new ApplicationUser(), new Post());

            await service.Like(1, new ApplicationUser());

            Assert.Equal(1, service.GetAll().FirstOrDefault(x => x.Content == "content").UserLikes.Count);
        }
        public void ReturnCorrectInstance()
        {
            //Arrange
            var comments           = new Mock <IEfGenericRepository <Comment> >();
            var commentsCollection = DataHelper.GetComments();

            comments.Setup(x => x.All()).Returns(commentsCollection);
            var commentsService = new CommentsService(comments.Object);

            //Act
            var result = commentsService.GetAll();

            //Assert
            Assert.IsInstanceOf <IQueryable <Comment> >(result);
        }
        public void InvokeRepositoryMethosAllOnce()
        {
            //Arrange
            var comments           = new Mock <IEfGenericRepository <Comment> >();
            var commentsCollection = DataHelper.GetComments();

            comments.Setup(x => x.All()).Returns(commentsCollection);
            var commentsService = new CommentsService(comments.Object);

            //Act
            var result = commentsService.GetAll();

            //Assert
            comments.Verify(x => x.All(), Times.Once);
        }
Beispiel #16
0
        public async Task GetAll_ShouldReturnCorrectCountAsync()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

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

            var experience = context.Experiences.FirstOrDefault();

            var count = service.GetAll <CommentViewModel>(experience.Id).Count();

            Assert.True(count == 1, "Create method does not work correctly");
        }
Beispiel #17
0
        public async Task GetAllShouldReturnAllCommentsUsingDbContext()
        {
            AutoMapperConfig.RegisterMappings(typeof(CommentViewModel).Assembly);
            AutoMapperConfig.RegisterMappings(typeof(IndexCommentViewModel).Assembly);

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var commentsRepository = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options));
            var postsRepository    = new EfDeletableEntityRepository <Post>(new ApplicationDbContext(options.Options));

            var testComment = new Comment
            {
                Id = 1,
            };

            var testPost = new Post
            {
                Id = 10,
            };

            var expectedComment = new IndexCommentViewModel
            {
                Id      = 1,
                Content = "content",
                PostId  = testPost.Id,
                UserId  = "userId",
            };

            var comments = new List <IndexCommentViewModel>();

            comments.Add(expectedComment);

            var expectedComments = new CommentViewModel
            {
                Comments = comments,
                PostId   = testPost.Id,
            };

            commentsRepository.AddAsync(testComment).GetAwaiter().GetResult();
            postsRepository.AddAsync(testPost).GetAwaiter().GetResult();
            commentsRepository.SaveChangesAsync().GetAwaiter().GetResult();
            postsRepository.SaveChangesAsync().GetAwaiter().GetResult();

            var categoriesService = new CommentsService(commentsRepository, postsRepository);
            var categories        = categoriesService.GetAll <CommentViewModel>(1);

            Assert.Single(categories);
        }
        public void ReturnCorrectModel()
        {
            //Arrange
            var comments           = new Mock <IEfGenericRepository <Comment> >();
            var commentsCollection = DataHelper.GetComments();

            comments.Setup(x => x.All()).Returns(commentsCollection);
            var commentsService = new CommentsService(comments.Object);

            //Act
            var result = commentsService.GetAll();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result, commentsCollection);
        }
Beispiel #19
0
        public void GetCommentsFilteredByValueShouldReturnAListOfFilteredComments()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetCommentsFilteredByValueShouldReturnAListOfFilteredComments))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var commentsService = new CommentsService(context);
                var expensesService = new ExpensesService(context);

                var expenseWithCommentToAdd = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 1 filtered",
                            Important = false
                        },
                        new Comment()
                        {
                            Text      = "A test comment 2 filtered",
                            Important = true
                        },
                        new Comment()
                        {
                            Text      = "A test comment 3",
                            Important = false
                        }
                    }
                };
                expensesService.AddExpense(expenseWithCommentToAdd);

                List <CommentGetModel> comments = commentsService.GetAll("filtered");
                int numberOfComments            = comments.Count;

                Assert.IsNotNull(comments);
                Assert.AreEqual(2, numberOfComments);
            }
        }
        public void ReturnCorrectModelWithRightProperties()
        {
            //Arrange
            var comments           = new Mock <IEfGenericRepository <Comment> >();
            var commentsCollection = DataHelper.GetComments();

            comments.Setup(x => x.All()).Returns(commentsCollection);
            var commentsService = new CommentsService(comments.Object);

            //Act
            var result = commentsService.GetAll();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result, commentsCollection);
            Assert.AreEqual(result.FirstOrDefault().Id, commentsCollection.FirstOrDefault().Id);
            Assert.AreEqual(result.FirstOrDefault().Content, commentsCollection.FirstOrDefault().Content);
            Assert.AreEqual(result.FirstOrDefault().CreationDate, commentsCollection.FirstOrDefault().CreationDate);
        }
        public void GetAllShouldReturnCorrectNumberOfPagesForComments()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForComments))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var taskService    = new TasksService(context);
                var commentService = new CommentsService(context);
                var added          = new TaskPostDTO()

                {
                    Title          = "BookingNOW",
                    Description    = "Verify booking commision",
                    DateAdded      = DateTime.Parse("2019-06-15T00:00:00"),
                    Deadline       = DateTime.Parse("2019-06-17T00:00:00"),
                    TaskImportance = "High",
                    TaskState      = "Closed",
                    DateClosed     = null,

                    Comments = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "A nice task...",
                            Owner     = null
                        }
                    },
                };

                var current = taskService.Create(added, null);

                var allComments = commentService.GetAll(string.Empty, 1);
                Assert.AreEqual(1, allComments.NumberOfPages);
            }
        }
Beispiel #22
0
        public void GetAllShouldReturnCorrectNumberOfPages()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPages))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                //some text
                var commentService = new CommentsService(context);
                var movieService   = new MoviesService(context);
                var addedMovie     = movieService.Create(new ExamenNet.ViewModels.MoviePostModel
                {
                    Title       = "film de test 1",
                    Director    = "dir1",
                    DateAdded   = new DateTime(),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "asd",
                            AddedBy   = null
                        }
                    },
                }, null);

                var allComments = commentService.GetAll(string.Empty, 1);
                Assert.AreEqual(1, allComments.NumberOfPages);
            }
        }
Beispiel #23
0
        public void GetAllShouldReturnCorrectNumberOfPagesForComments()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForComments))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var taskService    = new ExpensesService(context);
                var commentService = new CommentsService(context);
                var added          = new ExpensePostModel()

                {
                    Description = "Variable",
                    Type        = "5",
                    Location    = "Sibiu",
                    Date        = Convert.ToDateTime("2019-05-05T11:11:11"),
                    Currency    = "USD",
                    Sum         = 555.77,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "An important expense",
                            Owner     = null
                        }
                    },
                };

                var current = taskService.Create(added, null);

                var allComments = commentService.GetAll(string.Empty, 1);
                Assert.AreEqual(1, allComments.NumberOfPages);
            }
        }
Beispiel #24
0
        public async void ShowComments()
        {
            try
            {
                comments = new List <Comment>();
                comments = await CommentsService.GetAll(relatedId);

                if (comments.Count == 0)
                {
                    return;
                }
                if (comments.Count > 4)
                {
                    btnSeeAll.IsVisible = true;
                }
                else
                {
                    btnSeeAll.IsVisible = false;
                }

                viewModel.Comments = new ObservableCollection <Comment>(comments.Take(4));

                if (slComments.Children.Count > 0)
                {
                    slComments.Children.RemoveAt(0);
                }
                StringBuilder HTMLComments = new StringBuilder();
                if (Device.RuntimePlatform.ToLower() == "android")
                {
                    HTMLComments.Append("<html><body>");
                }
                else
                {
                    HTMLComments.Append("<html><head><meta name='viewport' content='width=device-width; height=device-height; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;'/></head><body>");
                }


                foreach (Comment item in viewModel.Comments)
                {
                    string body = item.CommentBody;
                    body = item.CommentBodyRendered;
                    while (body.Contains("display:none"))
                    {
                        int from = body.Substring(0, body.IndexOf("display:none")).LastIndexOf("<");
                        int to   = body.IndexOf(">", body.IndexOf("display:none;\">") + 15) + 1;
                        body = body.Substring(0, from) + body.Substring(to);
                    }
                    string commentBody = Regex.Replace(body, "<.*?>", String.Empty);
                    //string commentBody = item.CommentBody;
                    bool isCommentCut = false;
                    if (commentBody.Length > 100)
                    {
                        commentBody  = commentBody.Substring(0, 100) + "...";
                        isCommentCut = true;
                    }
                    // var photoUrl = Common.CurrentWorkspace.WorkspaceURL + item.UserCreated.PhotoUrl;


                    string userHTML = string.Empty;
                    if (!string.IsNullOrEmpty(item.UserCreated.PhotoUrl))
                    {
                        userHTML = string.Format("<img src='{0}'>", Common.CurrentWorkspace.WorkspaceURL + item.UserCreated.PhotoUrl);
                    }
                    else
                    {
                        if (item.UserCreated.AvatarHtml != String.Empty)
                        {
                            userHTML  = "<style>.user-avatar {font-family: 'Open Sans',segoe ui,verdana,helvetica;width: 60px!important;height: 60px!important;border-radius: 2px;line-height: 60px!important;font-size: 32px!important;color: #fff;text-align: center;margin: 0 !important;vertical-align: middle;overflow: hidden;cursor: pointer;display: inline-block;}</style>";
                            userHTML += item.UserCreated.AvatarHtml;
                        }
                    }



                    HTMLComments.Append(
                        CommentsHelperClass.CreateHtmlCommentsWithSeeMore(
                            item.UserCreated.Name,
                            userHTML,
                            item.CreatedDateTimeUTC != null ? (DateTime)item.CreatedDateTimeUTC : DateTime.Now,
                            commentBody, item.Id.ToString(),
                            isCommentCut)
                        );
                }

                HTMLComments.Append(CommentsHelperClass.GetHtmlCommentsWithSeeMoreStyle());
                HTMLComments.Append("</body></html>");
                var htmlString    = HTMLComments.ToString();
                var hybridWebView = new CustomControls.HybridWebView();
                hybridWebView.Uri = htmlString;
                hybridWebView.RegisterAction(data => OpenAllComments(data));
                hybridWebView.HorizontalOptions = LayoutOptions.FillAndExpand;
                hybridWebView.VerticalOptions   = LayoutOptions.FillAndExpand;
                hybridWebView.HeightRequest     = 450;
                hybridWebView.Margin            = 0;
                hybridWebView.BackgroundColor   = Color.Transparent;

                slComments.Children.Add(hybridWebView);
            }
            catch (Exception ex)
            {
                //return null;
            }
        }