Exemplo n.º 1
0
        public void ShouldDisplayOnlyDraftNewsCreatedByCurrentUserWhenListingDraftNews()
        {
            string userName = "******";

            UsingSession((session) =>
            {
                var repository = new Repository(session);
                var post = new Post { Id = 1, Title = "Post 1", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1), IsDraft = true, Creator = userName };
                repository.Create(post);
                post = new Post { Id = 2, Title = "Post 2", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1), IsDraft = true, Creator = userName };
                repository.Create(post);
                post = new Post { Id = 3, Title = "Post 3", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1), IsDraft = true, Creator = "anotherUser" };
                repository.Create(post);
                var controller = new PostsController(repository);
            });

            UsingSession((session) =>
            {
                WaitForTheLastWrite<Post>(session);

                var httpContextStub = new Mock<HttpContextBase>
                {
                    DefaultValue = DefaultValue.Mock
                };
                var user = Mock.Get(httpContextStub.Object.User);
                user.Setup(u => u.Identity.Name).Returns(userName);

                var controller = new PostsController(new Repository(session));
                controller.ControllerContext = new ControllerContext(httpContextStub.Object, new RouteData(), controller);
                var result = (ViewResult)controller.News(excludeDraft: false);
                var pages = (PagedList.IPagedList<IBasePostInformation>)result.Model;

                Assert.AreEqual(2, pages.Count);
            });
        }
Exemplo n.º 2
0
        public void PostsGetWithPageAndPageSizeShouldReturnOkResult()
        {
            var controller = new PostsController(this.postsService);

            var result = controller.Get(1, 10);

            var okResult = result as OkNegotiatedContentResult<List<PostDetailsResponseModel>>;

            Assert.IsNotNull(okResult);
        }
Exemplo n.º 3
0
        public void List_FirstPage_IsDisplayed()
        {
            //Arrange
            var postRepository = new MockPostService().Service;
            var postCategoryRepository = new MockPostCategoryDataService().DataService;
            var controller = new PostsController( postRepository, null, null, null, null, null, null, null, null );

            //Act
            var result = controller.Index( string.Empty, null, null, null, null );

            // Assert
            Assert.IsNotNull(result);
        }
        public void Init()
        {
            _ctrl = new PostsController(new FakePostRepository());

            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/be/api");
            var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "posts" } });

            _ctrl.ControllerContext = new HttpControllerContext(config, routeData, request);
            _ctrl.Request = request;
            _ctrl.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
        }
        public void PostsCheckReturnPosts_Test()
        {
            var paginationModel = new PaginationModel {
                Skip = 1, Take = 2
            };
            var mock = new Mock <IPostService>();

            mock.Setup(repo => repo.GetPosts(paginationModel.Take, paginationModel.Skip)).Returns(GetTestPosts());

            var postsController = new PostsController(mock.Object);

            var result = postsController.GetPosts(paginationModel);

            Assert.Equal(2, result.Result.Count);
        }
Exemplo n.º 6
0
        public async Task GetAsync_WhenCalled_ReturnsOkObjectResult(
            [Frozen] Mock <IPostService> _postService,
            [Frozen] Mock <PaginationQuery> paginationQuery)
        {
            //Arrange
            _mapper.Setup(x => x.Map <ReadPostDto>(It.IsAny <Post>()));
            var Sut = new PostsController(_postService.Object, _mapper.Object);

            //Act
            var actual = await Sut.GetAsync(paginationQuery.Object);

            //Assert
            Assert.NotNull(actual);
            Assert.IsType <OkObjectResult>(actual);
        }
Exemplo n.º 7
0
        public async Task DeleteAsync_PostId_DeleteSuccessReturnsNoContent(
            [Frozen] Mock <IPostService> _postService)
        {
            //Arrange
            int id  = 1;
            var Sut = new PostsController(_postService.Object, _mapper.Object);

            //Act
            var actual = await Sut.DeleteAsync(id);

            //Assert
            _postService.Verify(x => x.RemovePost(It.IsAny <Post>()));
            Assert.NotNull(actual);
            Assert.IsType <NoContentResult>(actual);
        }
        public async Task PostsCheckReturnPostsNull_Test()
        {
            var paginationModel = new PaginationModel {
                Skip = 1, Take = 2
            };
            var mock = new Mock <IPostService>();

            mock.Setup(repo => repo.GetPosts(paginationModel.Take, paginationModel.Skip)).Returns(async() => { return(null); });

            var postsController = new PostsController(mock.Object);

            Exception ex = await Assert.ThrowsAsync <Exception>(() => postsController.GetPosts(paginationModel));

            Assert.Equal("No posts.", ex.Message);
        }
Exemplo n.º 9
0
        public async Task Delete_IdLessThanOneShouldReturnBadRequest()
        {
            // Arrange
            PostsController controller = new PostsController();

            // Act
            var actionResult = await controller.Delete(0);

            var contentResult = actionResult as BadRequestErrorMessageResult;

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(contentResult);
            Assert.AreEqual("invalid id", contentResult.Message);
        }
Exemplo n.º 10
0
        public async Task Put_NullBodyShouldReturnBadRequest()
        {
            // Arrange
            PostsController controller = new PostsController();

            // Act
            var actionResult = await controller.Put(1, null);

            var contentResult = actionResult as BadRequestErrorMessageResult;

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(contentResult);
            Assert.AreEqual("post body required", contentResult.Message);
        }
Exemplo n.º 11
0
        public void Init()
        {
            _ctrl = new PostsController(new FakePostRepository());

            var config    = new HttpConfiguration();
            var request   = new HttpRequestMessage(HttpMethod.Post, "http://localhost/be/api");
            var route     = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary {
                { "controller", "posts" }
            });

            _ctrl.ControllerContext = new HttpControllerContext(config, routeData, request);
            _ctrl.Request           = request;
            _ctrl.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
        }
        public void PostsController_AddPost_ReturnsOk()
        {
            // Arrange
            _postsController = new PostsController(_mockPostService.Object);
            Post post = new Post {
                Author = "hanna", Content = "test"
            };

            // Act
            IHttpActionResult result = _postsController.AddPost(post);

            // Assert
            _mockPostService.Verify(x => x.Create(It.IsAny <Post>()), Times.Once);
            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Exemplo n.º 13
0
        public void GetPages_First_ReturnFivePosts()
        {
            //arrange
            var blogRepositoryMock = CreateRepositoryMock(10);
            var controller         = new PostsController(blogRepositoryMock.Object);

            //act
            var result = controller.Page(1) as ViewResult;

            //assert
            var model = result.ViewData.Model as BlogPosts;

            Assert.That(model.CurrentPage, Is.EqualTo(1));
            Assert.That(model.Content.Count, Is.EqualTo(5));
        }
Exemplo n.º 14
0
        public void GetNews_GetLatestNews_ReturnPosts()
        {
            // Arrange
            postServiceMock.Setup(service => service.GetPosts("user2", 1))
            .Returns(Mapper.Map <IEnumerable <PostDTO> >(unitOfWork.PostManager.Get(p => p.Author.UserName == "user2")));
            postServiceMock.Setup(service => service.GetPaginationData(1, "")).Returns("Pagination data");
            postServiceMock.Setup(service => service.PageInfo).Returns(new PageInfo());
            var controller = new PostsController(postServiceMock.Object);

            // Act
            var result = controller.GetNews(1);

            //Assert
            Assert.IsNotNull(result);
        }
Exemplo n.º 15
0
            public async Task WhenCreatePostGetsCalled()
            {
                Setup();

                _createPostRequest = new Fixture().Create <CreatePostRequest>();

                AuthService.Setup(service => service.AuthorizeSelf(It.IsAny <string>(), It.IsAny <Guid>()))
                .Returns(true);
                AuthService.Setup(service => service.AuthorizeFriend(It.IsAny <string>(), It.IsAny <Guid>()))
                .ReturnsAsync(true);
                PostsService.Setup(service => service.CreatePost(It.IsAny <Post>()))
                .Callback <Post>(post => _usedPost = post);

                _result = await PostsController.CreatePost(_createPostRequest);
            }
        public async void DeletePost_ReturnsNoContentResult_WhenThePostHasBeenRemoved()
        {
            //Arrange
            _mockPostService.Setup(Service => Service.DeletePostAsync(It.IsAny <Guid>()))
            .Verifiable();

            var controller = new PostsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object);
            //Act
            var result = await controller.DeletePost(ConstIds.ExamplePostId);

            //Act
            var noContentResult = Assert.IsType <NoContentResult>(result);

            _mockPostService.Verify();
        }
Exemplo n.º 17
0
        public async Task PostAsync_CreatePostDto_ReturnsCreateAnimalDto(
            [Frozen] Mock <IPostService> _postService,
            [Frozen] Mock <CreatePostDto> postDto)
        {
            //Arrange
            _mapper.Setup(x => x.Map <CreatePostDto>(It.IsAny <Post>()));
            var Sut = new PostsController(_postService.Object, _mapper.Object);

            //Act
            var actual = await Sut.PostAsync(postDto.Object);

            //Assert
            _postService.Verify(x => x.CreatePost(It.IsAny <Post>()));
            Assert.NotNull(actual);
            Assert.IsType <CreatedResult>(actual);
        }
Exemplo n.º 18
0
        public async Task GetAsync_PostId_ReturnsOkObjectResult(
            [Frozen] Mock <IPostService> _postService)
        {
            //Arrange
            int id = 2;

            _mapper.Setup(x => x.Map <ReadPostDto>(It.IsAny <Post>()));
            var Sut = new PostsController(_postService.Object, _mapper.Object);

            //Act
            var actual = await Sut.GetAsync(id);

            //Assert
            Assert.NotNull(actual);
            Assert.IsType <OkObjectResult>(actual);
        }
        public void GetAllPosts_ReturnAllPosts()
        {
            // Arrange
            var mockManager = new Mock <IPostManager>();

            mockManager.Setup(manager => manager.GetPosts()).Returns(GetTestPosts());

            var testPostController = new PostsController(mockManager.Object);

            // Act
            var posts = testPostController.GetPosts();

            //Assert
            Assert.IsNotNull(posts);
            Assert.AreEqual(2, posts.ToList().Count);
        }
Exemplo n.º 20
0
        public void List_Number_Of_Items_Displayed_On_Page_Equals_DefaultPageSize()
        {
            //Arrange
            var postRepository = new MockPostService().Service;
            var postCategoryRepository = new MockPostCategoryDataService().DataService;
            var locationService = new MockLocationService().Service;
            var controller = new PostsController( postRepository, locationService, null, null, null, null, null, null, null );

            //Act
            var result = controller.Index( string.Empty, null, null, null, null );
            var model = ((ViewResult)result).ViewData.Model as DefaultViewModel<Post>;
            
            // Assert
            Assert.IsNotNull( model.PagedList );
            //Assert.AreEqual( 15, model.PagedList.Count, "Wrong number of posts" );
        }
Exemplo n.º 21
0
        public void GetPost_Test_01()
        {
            // Arrange
            PostsController controller = new PostsController();

            // Act
            Task <IHttpActionResult> task = controller.GetPost(ChannelName, 3);

            task.Wait();
            TelegramPost result =
                (task.Result as System.Web.Http.Results.OkNegotiatedContentResult <TelegramPost>)?.Content;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Id);
        }
        public void IndexShouldReturnProperView()
        {
            // Arrange
            var mockPostsService = new Mock <IPostsService>();

            mockPostsService.Setup(mm => mm.GetAll()).Returns(this.GetAll <Post>());

            var controller = new PostsController(mockPostsService.Object);

            // Act
            var result = controller.Index();

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <PostsAdminPanel>(viewResult.ViewData.Model);
        }
        public void GetPostById_ReturnCorrectPost()
        {
            // Arrange
            var mockManager = new Mock <IPostManager>();

            mockManager.Setup(x => x.GetPostById(It.IsAny <Guid>()))
            .Returns <Guid>(id => GetTestPostById(id));

            var testPostController = new PostsController(mockManager.Object);

            // Act
            var post = testPostController.GetPostById(TestPost1.Id);

            //Assert
            TestPost1.AssertAreEqual(post);
        }
Exemplo n.º 24
0
        public async void Get_Not_Exists()
        {
            PostsControllerMockFacade mock = new PostsControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiPostsResponseModel>(null));
            PostsController controller = new PostsController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Exemplo n.º 25
0
        public async void Index_IfCallAction_ReturnNotNull()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <BlogDbContext>()
                          .UseInMemoryDatabase(databaseName: "SomeDatabase")
                          .Options;
            var context         = new BlogDbContext(options);
            var mockUserManager = new FakeUserManager();
            var unit            = new UnitOfWork(context);
            var controller      = new PostsController(mockUserManager, unit);
            // Act
            var result = await controller.Index() as ViewResult;

            // Assert
            Assert.NotNull(result);
        }
Exemplo n.º 26
0
        public async Task Browse_Defaults()
        {
            var postsRepository = new Mock <IPostsRepository>(MockBehavior.Strict);

            postsRepository
            .Setup(mock => mock.BrowsePostsAsync(PostSortBy.Created, PostSortDirection.Down, PostedSince.Forever, 0, 16, null, null, null, It.Is <DateTimeOffset>(d => d <= DateTimeOffset.UtcNow)))
            .ReturnsAsync(new[]
            {
                new Post
                {
                    Id      = Guid.Parse("9495ee61-37ac-43cf-8ee0-dbcd18510914"),
                    Title   = "My Scene",
                    Version = 4,
                    Author  = new User {
                        Username = "******"
                    },
                    Tags = new[]
                    {
                        new PostTag {
                            Tag = new Tag {
                                Id = Guid.Parse("c2fa02b7-b107-4261-8306-9465178f2949"), Name = "artsy"
                            }
                        }
                    }
                }
            });
            var cache      = SetupCaching("posts:browse:(Created;Down;Default;0;16)");
            var controller = new PostsController(postsRepository.Object, cache.Object);

            var result = await controller.BrowseAsync();

            result.ShouldDeepEqual(new[]
            {
                new PostViewModel
                {
                    Id      = "9495ee61-37ac-43cf-8ee0-dbcd18510914",
                    Title   = "My Scene",
                    Version = 4,
                    Author  = new UserViewModel {
                        Username = "******"
                    },
                    Tags = new[] { new TagViewModel {
                                       Name = "artsy"
                                   } }
                }
            });
        }
Exemplo n.º 27
0
        public async void PartiallyUpdatePost_ReturnsBadRequestResult_WhenThePostHasNotBeenUpdated()
        {
            //Arrange
            _mockPostService.Setup(Service => Service.TryUpdatePostAsync(It.IsAny <Guid>(), It.IsAny <JsonPatchDocument <PostToUpdateDto> >()))
            .ReturnsAsync(false)
            .Verifiable();

            var controller = new PostsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object);

            //Act
            var result = await controller.PartiallyUpdatePost(ConstIds.ExamplePostId, GetJsonPatchDocument());

            //Assert
            var noContentResult = Assert.IsType <BadRequestResult>(result);

            _mockPostService.Verify();
        }
Exemplo n.º 28
0
        public void List_Presents_Correct_Page_Of_Posts()
        {
            //Arrange
            var postRepository = new MockPostService().Service;
            var postCategoryRepository = new MockPostCategoryDataService().DataService;
            var controller = new PostsController( postRepository, null, null, null, null, null, null, null, null );
            //controller.PageSize = 3;

            //Act
            var result = controller.Index( string.Empty, null, null, null, null );
            var model = ((ViewResult)result).ViewData.Model as DefaultViewModel<Post>;

            //Assert
            Assert.IsNotNull( model.PagedList );
            Assert.AreEqual( "Wanted: Socks", model.PagedList.ElementAt<Post>( 0 ).Title );
            Assert.AreEqual( "Offered: Linen", model.PagedList.ElementAt<Post>( 1 ).Title );
        }
Exemplo n.º 29
0
        public void Like(int idPost)
        {
            PostsController post  = new PostsController();
            Notification    notif = new Notification();

            notif.idPost   = idPost;
            notif.userName = Context.User.Identity.GetUserName();

            var currentUserId = Context.User.Identity.GetUserId();

            post.CreateLike(idPost, currentUserId);

            Clients.Client(Context.ConnectionId).isLike(idPost);
            Clients.Group("online").Like(idPost);
            Clients.Group("online", Context.ConnectionId).updateNotification(notif);
            //Clients.All.Like(idPost);
        }
Exemplo n.º 30
0
        public async Task Post_InvalidModelShouldReturnBadRequest()
        {
            // Arrange
            PostsController controller = new PostsController();

            controller.ModelState.AddModelError("userId", "required");

            // Act
            var actionResult = await controller.Post(new Post());

            var contentResult = actionResult as InvalidModelStateResult;

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(contentResult);
            Assert.AreEqual(1, contentResult.ModelState.Keys.Count);
        }
        public void GetPostsByCategory_ReturnCorrectPosts()
        {
            // Arrange
            var mockManager = new Mock <IPostManager>();

            mockManager.Setup(x => x.GetPostsByCategory(It.IsAny <Guid>()))
            .Returns <Guid>(id => GetTestPostsByCategory(id));

            var testPostController = new PostsController(mockManager.Object);

            // Act
            var posts = testPostController.GetPostsByCategory(TestCategory.Id).ToList();

            //Assert
            Assert.AreEqual(1, posts.Count);
            TestPost1.AssertContains(posts);
        }
Exemplo n.º 32
0
        public async Task Post_FailureToSaveShouldReturnInternalServerError()
        {
            // Arrange
            Mock <IPostsService> mockService = new Mock <IPostsService>();

            mockService.Setup(ur => ur.UpdatePostAsync(1, null)).Returns <Task <Post> >(null);
            PostsController controller = new PostsController(mockService.Object);

            // Act
            var actionResult = await controller.Post(new Post());

            var contentResult = actionResult as InternalServerErrorResult;

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(contentResult);
        }
        public async void DeletePost_ReturnsInternalServerErrorResult_WhenExceptionThrownInService()
        {
            //Arrange
            _mockPostService.Setup(Service => Service.DeletePostAsync(It.IsAny <Guid>()))
            .Throws(new ArgumentNullException(nameof(Guid)))
            .Verifiable();

            var controller = new PostsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object);
            //Act
            var result = await controller.DeletePost(ConstIds.ExamplePostId);

            //Assert
            var internalServerErrorResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal(StatusCodes.Status500InternalServerError, internalServerErrorResult.StatusCode);
            _mockPostService.Verify();
        }
Exemplo n.º 34
0
 public void Setup()
 {
     _unitOfWork  = new Mock <IUnitOfWork>();
     _mapper      = new Mock <IMapper>();
     _fileHandler = new Mock <IFileHandler>();
     _env         = new Mock <IWebHostEnvironment>();
     _controller  = new PostsController(_unitOfWork.Object, _mapper.Object, _fileHandler.Object, _env.Object)
     {
         ControllerContext = new ControllerContext()
         {
             HttpContext = new DefaultHttpContext()
             {
                 User = new ClaimsPrincipal()
             }
         }
     };
 }
Exemplo n.º 35
0
        public PostsControllerTests()
        {
            TestsHelper.InitializeAutoMapper();
            _uow                = Substitute.For <IUnitOfWork>();
            _postRepository     = Substitute.For <IRepository <Post> >();
            _categoryRepository = Substitute.For <IRepository <Category> >();
            _categoryRepository.GetAll().Returns(TestsHelper.GetInMemoryCagegories().AsQueryable());
            _postRepository.GetAll().Returns(TestsHelper.GetInMemoryPosts().AsQueryable());

            editPost = TestsHelper.GetInMemoryPosts().FirstOrDefault(p => p.Id == 6);
            _postRepository.Get(Arg.Any <Expression <Func <Post, bool> > >()).ReturnsForAnyArgs(editPost);

            _uow.Repository <Post>().Returns(_postRepository);
            _uow.Repository <Category>().Returns(_categoryRepository);

            _postsController = new PostsController(_uow);
        }
Exemplo n.º 36
0
        public async Task Index_ReturnsAViewResult_WithAList()
        {
            //Arrange
            createUser();
            for (int i = 0; i < 2; i++)
            {
                using (var context = new ApplicationDbContext(inMemoryDatabaseHelper.Options))
                {
                    var user           = context.Users.Single();
                    var postRepository = new PostRepository(context);
                    var post           = new Post
                    {
                        Title          = "post",
                        Content        = "post",
                        OriginalPoster = user
                    };
                    await postRepository.CreatePostAsync(post);
                }
            }


            using (var context = new ApplicationDbContext(inMemoryDatabaseHelper.Options))
            {
                // Act
                var postsController = new PostsController(context,
                                                          new Mock <IUserRepository>().Object,
                                                          //new PostRepository(context)
                                                          new Repository <Post>(context)
                                                          );
                var result = await postsController.Index();

                // Assert
                //IsTypeOf
                Assert.IsInstanceOf <ViewResult>(result);
                var viewResult = result as ViewResult;

                //IsAssignableFrom
                Assert.IsInstanceOf <IList <Post> >(viewResult.ViewData.Model);
                var model = viewResult.ViewData.Model;
                Assert.That(model, Is.InstanceOf <IList <Post> >());
                var posts = model as IList <Post>;

                Assert.AreEqual(2, posts.Count());
            }
        }
Exemplo n.º 37
0
 public void ShouldHavePostsAndBookPosts()
 {
     var posts = new List<Post> {new Post {Id = 1, Title = "Post", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1)}};
     var books = new List<Book>
         {
             new Book
                 {
                     Posts = new List<BookPost> {new BookPost {Id = 2, Title = "BookPost", Content = "A BookPost", Type = BookPost.BookPostType.News, UpdatedAt = DateTime.Now}}
                 }
         };
     var repo = new Mock<Repository>();
     repo.Setup(r => r.List<Post>()).Returns(posts);
     repo.Setup(r => r.List<Book>()).Returns(books);
     var controller = new PostsController(repo.Object);
     var result = (ViewResult)controller.News();
     var model = (PagedList.IPagedList<IBasePostInformation>) result.Model;
     Assert.AreEqual(2, model.Count);
     Assert.AreEqual(2, model[0].Model.Id);
     Assert.AreEqual(1, model[1].Model.Id);
 }
Exemplo n.º 38
0
        public void ShouldExcludeDraftPostsWhenListingAllPosts()
        {
            UsingSession((session) =>
            {
                var repository = new Repository(session);
                var post = new Post { Id = 1, Title = "Post 1", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1) } ;
                repository.Create(post);
                post = new Post { Id = 2, Title = "Post 2", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1) } ;
                repository.Create(post);
                post = new Post { Id = 3, Title = "Post 3", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1), IsDraft = true} ;
                repository.Create(post);
                var controller = new PostsController(repository);
            });

            UsingSession((session) =>
            {
                WaitForTheLastWrite<Post>(session);
                var controller = new PostsController(new Repository(session));
                var result = (ViewResult)controller.News();
                var pages = (PagedList.IPagedList<IBasePostInformation>)result.Model;

                Assert.AreEqual(2, pages.Count);
            });
        }
Exemplo n.º 39
0
        public void SetupContext()
        {
            // Организация - создание имитированного хранилища
            _mock = new Mock<IPostRepository>();

            // Организация - создание имитированного поставщика настроек
            _mockSettingsProvider = new Mock<ISettingsProvider>();
            _mockSettingsProvider.Setup(s => s.GetSettings()).Returns(_settings);

            _target = new PostsController(_mock.Object, _mockSettingsProvider.Object);
        }