示例#1
0
        public void GetCountOfPhotosCommentsShouldWorkCorrectly()
        {
            var comments = new List <Comment>();
            var photos   = new List <Photo>();

            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 service = new AdminsService(null, mockCommentRepo.Object, mockPhoto.Object, null, null);

            var photo = new Photo
            {
                Id        = "1",
                ImagePath = "/images/photos",
            };
            var comment = new Comment
            {
                Id        = "1",
                ImagePath = "/images/photos",
                PhotoId   = "1",
                UserId    = "1",
                SentById  = "1",
            };
            var secondComment = new Comment
            {
                Id        = "2",
                ImagePath = "/images/photos",
                PhotoId   = "1",
                UserId    = "1",
                SentById  = "1",
            };

            photos.Add(photo);
            comments.Add(comment);
            comments.Add(secondComment);

            var result         = service.GetCountOfPhotosComments();
            var expectedResult = 2;

            Assert.Equal(expectedResult, result);
        }