public void PlanetAreaControllerTestsSetup()
        {
            var automapperConfig = new AutoMapperConfig();
            automapperConfig.Execute(typeof(CommentsController).Assembly);

            var commentsServiceMock = new Mock<ICommentsService>();
            commentsServiceMock
                .Setup(x => x.GetPagesCount(tutorialId))
                .Returns(pages);

            commentsServiceMock
                .Setup(x => x.GetByPage(tutorialId, page))
                .Returns(new List<Comment>()
                {
                    new Comment
                    {
                        Content = content,
                        Tutorial = new Tutorial { Title = "" },
                        Author = new User()
                    },
                    new Comment
                    {
                        Content = content,
                        Tutorial = new Tutorial { Title = "" },                      
                        Author = new User()
                    }
                }.AsQueryable());

            commentsController = new CommentsController(commentsServiceMock.Object);
        }
        public void Init()
        {
            _ctrl = new CommentsController(new FakeCommentRepository());

            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", "comments" } });

            _ctrl.ControllerContext = new HttpControllerContext(config, routeData, request);
            _ctrl.Request = request;
            _ctrl.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
        }
        public void CommentShouldValidateModelState()
        {
            var controller = new CommentsController(TestObjectFactory.GetCommentsService());
            controller.Configuration = new System.Web.Http.HttpConfiguration();

            var model = TestObjectFactory.GetInvalidModel();

            controller.Validate(model);

            var result = controller.Post(model);

            Assert.IsFalse(controller.ModelState.IsValid);
        }
        public void CommentShouldReturnBadRequestWithInvalidModel()
        {
            var controller = new CommentsController(TestObjectFactory.GetCommentsService());
            controller.Configuration = new System.Web.Http.HttpConfiguration();

            var model = TestObjectFactory.GetInvalidModel();

            controller.Validate(model);

            var result = controller.Post(model);

            Assert.AreEqual(typeof (InvalidModelStateResult), result.GetType());
        }
 public CommentsControllerTests()
 {
     _commentsController = new CommentsController(_articleRepositoryMock.Object, _commentRepositoryMock.Object);
 }
Пример #6
0
 public void CommentController_should_throw_ArgumentNullException_if_input_service_is_null()
 {
     // Act & Assert
     Assert.Throws <ArgumentNullException>(() => _commentController = new CommentsController(null));
 }
Пример #7
0
        public void Initialize()
        {
            _commentService = new Mock <ICommentService>();

            _commentController = new CommentsController(_commentService.Object);
        }
 public static CommentsController GetCommentsController(IRepository<Comment> comments, IRepository<Photo> photos, bool validUser = true)
 {
     var controller = new CommentsController(comments, photos);
     SetUser(controller, validUser);
     return controller;
 }
Пример #9
0
 public CommentsControllerTests()
 {
     serviceMock = new Mock <ICommentsService>();
     loggerMock  = new Mock <ILoggingService>();
     controller  = new CommentsController(serviceMock.Object, loggerMock.Object);
 }