コード例 #1
0
        public void _Return_Correct_Controller_RedirectToAction_AddCommentToPost(int postId, string userId, string content)
        {
            //Arrange
            var model = new AddCommentViewModel()
            {
                Content         = content,
                CommentedItemId = postId
            };

            var mockedCommentService = new Mock <ICommentService>();

            var mockedAuthProvider = new Mock <IAuthenticationProvider>();

            mockedAuthProvider.Setup(a => a.CurrentUserId).Returns(userId);

            var commentControllerSUT = new CommentController(mockedCommentService.Object, mockedAuthProvider.Object);

            commentControllerSUT.ModelState.Clear();

            //Act
            var res = commentControllerSUT.CommentPost(model) as RedirectToRouteResult;

            //Assert
            Assert.AreEqual("Post", res.RouteValues["controller"]);
        }
コード例 #2
0
ファイル: SuperController.cs プロジェクト: wxz97121/SSRD
    // Use this for initialization
    void Start()
    {
        Random.InitState(System.DateTime.Now.Second);

        commentController     = GameObject.Find("Comment").GetComponent <CommentController>();
        skillTipBarController = GameObject.Find("SkillTipArea").GetComponent <UISkillTipBarController>();
        uiBarController       = GameObject.Find("BarArea").GetComponent <UIBarController>();

        playerBattleInfo = playerBattleUIPos.GetComponentInChildren <UIBattleInfo>();
        enemyBattleInfo  = enemyBattleUIPos.GetComponentInChildren <UIBattleInfo>();

        FinishedStorySteps = new List <string>();

        InputSequenceController.Instance.ResetAvailable();



        UIWindowController.Instance.mainMenu.Open();



        SoundController.Instance.FMODmusic.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);

        //此处有个坑,FMODInstance必须创建完成才能获取channelgroup

        state = GameState.Wait;
    }
コード例 #3
0
        public void SetUp()
        {
            _commentServiceMock = new Mock <ICommentService>();
            _gameServiceMock    = new Mock <IGameService>();

            _commentController = new CommentController(_commentServiceMock.Object, _gameServiceMock.Object);
        }
コード例 #4
0
        public void _Call_CommentService_AddCommentToPost(int postId, string userId, string content)
        {
            //Arrange
            var model = new AddCommentViewModel()
            {
                Content         = content,
                CommentedItemId = postId
            };

            var mockedCommentService = new Mock <ICommentService>();

            var mockedAuthProvider = new Mock <IAuthenticationProvider>();

            mockedAuthProvider.Setup(a => a.CurrentUserId).Returns(userId);

            var commentControllerSUT = new CommentController(mockedCommentService.Object, mockedAuthProvider.Object);

            commentControllerSUT.ModelState.Clear();

            //Act
            var res = commentControllerSUT.CommentPost(model) as ActionResult;

            //Assert
            mockedCommentService.Verify(s => s.AddCommentToPost(model.Content, model.CommentedItemId, userId));
        }
コード例 #5
0
        public void Cannot_Save_Invalid_Comment()
        {
            // Организация - создание имитированного хранилища
            Mock <ICommentRepository> mock     = new Mock <ICommentRepository>();
            Mock <ILikeRepository>    mockLike = new Mock <ILikeRepository>();

            // Организация - создание контроллера
            CommentController target = new CommentController(mock.Object, mockLike.Object);

            // Организация - создание комментария
            Comment comment = new Comment {
                Id = 1, CreateDate = DateTime.Now, Username = "******", Text = "Test Text", PostId = 1
            };

            // Организация - добавление ошибки в состояние модели
            target.ModelState.AddModelError("error", "error");

            // Действие - сохраняем комментарий
            ActionResult result = target.Save(comment);

            // Утверждение - проверка того, что к хранилищу не производится обращение
            mock.Verify(m => m.Save(It.IsAny <Comment>()), Times.Never());

            // Утверждение - проверка типа результата метода
            Assert.IsNotNull(((PartialViewResult)result).Model);
            Assert.IsInstanceOfType(result, typeof(PartialViewResult));
        }
コード例 #6
0
        public void Init()
        {
            commentServiceMock = new Mock <ICommentService>();
            mapperMock         = new Mock <IMapper>();

            commentController = new CommentController(commentServiceMock.Object, mapperMock.Object);
        }
コード例 #7
0
        public void CommentController_Index_Post_ShouldReturnCommentWithInstanceOfDateTimeSet()
        {
            // Arrange
            var data = new Mock <IUowData>();
            var commentsRepository = new Mock <IRepository <Comment> >();

            data.Setup(d => d.Comments).Returns(commentsRepository.Object);

            var claim = new Claim("test", "qwe-123");

            var identity = new Mock <ClaimsIdentity>();

            identity.Setup(i => i.FindFirst(It.IsAny <string>())).Returns(claim);

            var principal = new Mock <IPrincipal>();

            principal.Setup(p => p.Identity).Returns(identity.Object);

            var context = new Mock <ControllerContext>();

            context.Setup(c => c.HttpContext.User).Returns(principal.Object);

            CommentController controller = new CommentController(data.Object)
            {
                ControllerContext = context.Object
            };

            Comment comment = new Comment();

            // Act
            ViewResult result = controller.Index(comment, 1, 1, "threadTitle") as ViewResult;

            // Assert
            commentsRepository.Verify(d => d.Add(It.Is <Comment>(c => c.Published.GetType() == typeof(DateTime))));
        }
コード例 #8
0
        public void ListByTagReturnsListOfComments()
        {
            FakePostService postService = new FakePostService();
            FakeTagService  tagService  = new FakeTagService();

            postService.AllComments.Add(new ParentAndChild <PostBase, Comment>()
            {
                Parent = new Post(), Child = new Comment()
            });
            postService.AllComments.Add(new ParentAndChild <PostBase, Comment>()
            {
                Parent = new Post(), Child = new Comment()
            });

            tagService.StoredTags.Add("test", new Tag());

            CommentController controller = new CommentController(postService, tagService, null)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteModelList <ParentAndChild <PostBase, Comment> > result = controller.ListByTag(new Tag()
            {
                Name = "test"
            });

            Assert.Equal(2, result.List.Count);
            Assert.Same(postService.AllComments[0], result.List[0]);
            Assert.Same(postService.AllComments[1], result.List[1]);
        }
コード例 #9
0
        public void CommentController_Index_Post_ShouldSetUserIdCorrect(string userId)
        {
            // Arrange
            var data = new Mock <IUowData>();
            var commentsRepository = new Mock <IRepository <Comment> >();

            data.Setup(d => d.Comments).Returns(commentsRepository.Object);

            var claim = new Claim("test", userId);

            var identity = new Mock <ClaimsIdentity>();

            identity.Setup(i => i.FindFirst(It.IsAny <string>())).Returns(claim);

            var principal = new Mock <IPrincipal>();

            principal.Setup(p => p.Identity).Returns(identity.Object);

            var context = new Mock <ControllerContext>();

            context.Setup(c => c.HttpContext.User).Returns(principal.Object);

            CommentController controller = new CommentController(data.Object)
            {
                ControllerContext = context.Object
            };

            Comment comment = new Comment();

            // Act
            ViewResult result = controller.Index(comment, 1, 1, "threadTitle") as ViewResult;

            // Assert
            commentsRepository.Verify(d => d.Add(It.Is <Comment>(c => c.UserId == userId)));
        }
コード例 #10
0
        public void CommentController_Index_Post_ShouldRedirectToCorrectActionName()
        {
            // Arrange
            var data = new Mock <IUowData>();
            var commentsRepository = new Mock <IRepository <Comment> >();

            data.Setup(d => d.Comments).Returns(commentsRepository.Object);

            var claim = new Claim("test", "qwe-123");

            var identity = new Mock <ClaimsIdentity>();

            identity.Setup(i => i.FindFirst(It.IsAny <string>())).Returns(claim);

            var principal = new Mock <IPrincipal>();

            principal.Setup(p => p.Identity).Returns(identity.Object);

            var context = new Mock <ControllerContext>();

            context.Setup(c => c.HttpContext.User).Returns(principal.Object);

            CommentController controller = new CommentController(data.Object)
            {
                ControllerContext = context.Object
            };

            Comment comment = new Comment();

            // Act
            RedirectToRouteResult result = controller.Index(comment, 1, 1, "threadTitle") as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
コード例 #11
0
 public CommentControllerTests(ScrumToolDBFixture p_ScrumToolDBFixture)
 {
     m_ScrumToolDBFixture = p_ScrumToolDBFixture;
     m_ParentTaskID       = m_ScrumToolDBFixture.FirstTaskID;
     m_ScrumToolDBContext = m_ScrumToolDBFixture.ScrumToolDB;
     m_CommentController  = new CommentController(m_ScrumToolDBContext);
 }
コード例 #12
0
        public void CanSaveComment_withParentComment()
        {
            var controller = new CommentController(
                _userRepository.Object,
                _postRepository.Object,
                _commentRepository.Object,
                _commentLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.SaveComment(new CommentForm {
                PostId    = 1,
                Content   = "testContent",
                CommentId = 1
            }) as ObjectResult;

            _commentRepository.Verify(c => c.SaveComment(It.IsAny <Comment>()), Times.Once);
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);

            var comment = result.Value as ItemViewData <Comment>;

            Assert.IsType <ItemViewData <Comment> >(comment);
            Assert.Equal("test1", comment.Item.User.UserName);
            Assert.Equal(1, comment.Item.Post.Id);
            Assert.Equal("testContent", comment.Item.Content);
            Assert.NotNull(comment.Item.ParentComment);
        }
コード例 #13
0
        public async Task <VMs.Ticket> ConvertVMTicket(Data.Ticket ticket)
        {
            try
            {
                VMs.User           u;
                List <VMs.Comment> c;
                using (var user = new UserController(context))
                {
                    u = await user.GetUserData(ticket.UserId);
                }
                using (var com = new CommentController(context))
                {
                    c = await com.GetCommentData(ticket.Id);
                }
                VMs.Ticket result = new VMs.Ticket
                {
                    Id          = ticket.Id,
                    ClosingDate = ticket.ClosingDate,
                    Code        = ticket.Code,
                    Description = ticket.Description,
                    OpeningDate = ticket.OpeningDate,
                    Priority    = ticket.Priority.ToString(),
                    Status      = ticket.Status.ToString(),
                    Type        = ticket.Type.ToString(),
                    Owner       = u,
                    Comments    = c
                };

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #14
0
        public async Task Call_CommentServiceWithCorrectParams_OnPost()
        {
            // Arrange
            string commentText = "Very interesting. Would love to see it!";

            string title = "Avengers EndGame";

            string userName = "******";

            var commentServiceMock = new Mock <ICommentService>();

            var model = new CommentViewModel();


            commentServiceMock.Setup(asm => asm.AddComment(commentText, title, userName))
            .ReturnsAsync(model);

            var createModel = new CreateCommentViewModel()
            {
                Text  = commentText,
                Title = title,
                User  = userName
            };

            var sut = new CommentController(commentServiceMock.Object);

            // Act
            var result = await sut.AddComment(createModel);

            // Assert
            commentServiceMock.Verify(x => x.AddComment(commentText, title, userName), Times.Once);
        }
コード例 #15
0
        public void TestGetCommentByPostIsAuthenticated()
        {
            var claims = new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "abc"),
                new Claim(ClaimTypes.Role, "member"),
                new Claim("user_id", "5d15941f197c3400015db0aa")
            }, "authenticationType");
            List <Comment> listComment = new List <Comment>();

            listComment.Add(cmt);
            listComment.Add(cmtSecond);
            IEnumerable <Comment> comments = listComment;
            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal(claims));
            mockCommentService.Setup(x => x.GetCommentByPost(It.IsAny <string>(), It.IsAny <string>())).Returns(comments);
            var _commenController = new CommentController(mockCommentService.Object, mockAuthorService.Object);

            _commenController.ControllerContext.HttpContext = contextMock.Object;
            var            getCommentByPost = _commenController.GetCommentByPost("5d15941f197c3400015db0aa");
            OkObjectResult okObjectResult   = getCommentByPost as OkObjectResult;
            List <Comment> listComments     = (List <Comment>)okObjectResult.Value;
            Comment        commentActual    = listComments.FirstOrDefault();

            Assert.AreEqual(commentActual, cmt);
        }
コード例 #16
0
        public void LikePostCommentTest()
        {
            int id = 2;

            HttpContext.Current = AbstractHttpContext.FakeHttpContext(
                new Dictionary <string, object> {
                { "UserExpandedState", 5 },
                { "MaxId", 1000 }
            },
                "http://localhost:55024/api/v1/");

            var comment = db.CommentPosts.Find(id);

            CommentController commentController = new CommentController()
            {
                GetUserId = () => "14a66224-b316-407a-a1bc-507ea56fa8eb"
            };
            JsonResult result = commentController.LikePostComment(id) as JsonResult;
            IDictionary <string, object> wrapper = (IDictionary <string, object>) new System.Web.Routing.RouteValueDictionary(result.Data);

            int?cc = wrapper["amount"] as int?;

            if (cc > comment.Likes)
            {
                Assert.AreEqual(comment.Likes + 1, cc);
            }
            else
            {
                Assert.AreEqual(comment.Likes - 1, cc);
            }
        }
コード例 #17
0
        public void ShouldGetAllForEntry()
        {
            List <UserComment> mockedComments = new List <UserComment>();

            for (int i = 0; i < 10; i++)
            {
                mockedComments.Add(new UserComment()
                {
                    Text          = "comment " + i,
                    UserProfileId = Hdid,
                });
            }

            RequestResult <IEnumerable <UserComment> > expectedResult = new RequestResult <IEnumerable <UserComment> >()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                ResourcePayload = mockedComments,
            };

            Mock <IHttpContextAccessor> httpContextAccessorMock = CreateValidHttpContext(Token, UserId, Hdid);
            Mock <ICommentService>      commentServiceMock      = new Mock <ICommentService>();

            commentServiceMock.Setup(s => s.GetEntryComments(It.IsAny <string>(), It.IsAny <string>())).Returns(expectedResult);

            CommentController service = new CommentController(commentServiceMock.Object, httpContextAccessorMock.Object);
            var actualResult          = service.GetAllForEntry(Hdid, "parentEntryIdMock");
            RequestResult <IEnumerable <UserComment> > actualRequestResult = (RequestResult <IEnumerable <UserComment> >)((JsonResult)actualResult).Value;

            Assert.Equal(Common.Constants.ResultType.Success, actualRequestResult.ResultStatus);
        }
コード例 #18
0
        public void Can_Save_Valid_Comment()
        {
            // Организация - создание имитированного хранилища
            Mock <ICommentRepository> mock     = new Mock <ICommentRepository>();
            Mock <ILikeRepository>    mockLike = new Mock <ILikeRepository>();
            var context = new Mock <HttpContextBase>();
            var request = new Mock <HttpRequestBase>();

            request.Setup(r => r.UrlReferrer).Returns(new Uri("http://test.com"));
            context.Setup(c => c.Request).Returns(request.Object);

            // Организация - создание контроллера
            CommentController target = new CommentController(mock.Object, mockLike.Object);

            target.ControllerContext = new ControllerContext(context.Object, new System.Web.Routing.RouteData(), target);

            // Организация - создание комментария
            Comment comment = new Comment {
                Id = 1, CreateDate = DateTime.Now, Username = "******", Text = "Test Text", PostId = 1
            };

            // Действие - сохраняем комментарий
            ActionResult result = target.Save(comment);

            // Утверждение - проверка того, что к хранилищу производится обращение
            mock.Verify(m => m.Save(comment));

            // Утверждение - проверка типа результата метода
            Assert.IsNull(((PartialViewResult)result).Model);
            Assert.IsInstanceOfType(result, typeof(PartialViewResult));
        }
コード例 #19
0
        private async void SecurityRejectButton_Clicked(object sender, EventArgs e)
        {
            CommentsStack.IsVisible = true;


            if (string.IsNullOrEmpty(CommentsEditor.Text) || string.IsNullOrWhiteSpace(CommentsEditor.Text))
            {
                await DisplayAlert("Comments Required", "Please enter a brief description of your reason for rejecting this application.", "OK");
            }
            else
            {
                bool confirm = await DisplayAlert("Confirm", "Are you sure you want to reject this application?", "Yes", "No");

                if (confirm)
                {
                    Comment comment = new Comment
                    {
                        applicationid = applicationid,
                        commenter     = "NA",
                        comment_by    = "SECURITY",
                        comment_time  = DateTime.UtcNow,
                        comment       = CommentsEditor.Text
                    };

                    //SEND COMMENTS TO API and Update app_status to REJECTED
                    CommentController.AddComment(comment);

                    Models.Application app = ApplicationController.GetApplication(int.Parse(applicationid));
                }
            }
        }
コード例 #20
0
        public void GetCommentsByGameId_InputIsValid_GetByIdForRepositoryIsCalledAndJsonResultIsCorrect()
        {
            // Arrange
            var mock = new Mock <ICommentRepository>();
            //context
            int gameId = 44;
            List <CommentDataModel> expectedCommentList = new List <CommentDataModel>()
            {
                new CommentDataModel()
                {
                    Body = "first comment", Id = 1, GameId = gameId, ParentCommentId = 102, Name = "testN"
                },
                new CommentDataModel()
                {
                    Body = "second comment", Id = 2, GameId = gameId, ParentCommentId = null, Name = "testN"
                },
                new CommentDataModel()
                {
                    Body = "my own comment", Id = 3, GameId = gameId, ParentCommentId = 102, Name = "testN"
                }
            };

            mock.Setup(m => m.GetCommentsByGameId(gameId)).Returns(expectedCommentList);
            var controller = new CommentController(mock.Object);

            // Act
            var result = controller.GetCommentsByGameId(gameId) as JsonResult;

            // Assert
            Assert.IsNotNull(result);
            mock.Verify(a => a.GetCommentsByGameId(gameId), Times.Once);
            Assert.AreEqual(expectedCommentList, result.Data);
        }
コード例 #21
0
        private async Task <VMs.Ticket> ConvertVMTicket(Data.Ticket ticket)
        {
            VMs.Ticket result = new VMs.Ticket();

            try
            {
                result.Id          = ticket.Id;
                result.Code        = ticket.Code;
                result.Description = ticket.Description;
                result.OpeningDate = ticket.OpeningDate;
                result.ClosingDate = ticket.ClosingDate;
                result.Priority    = ticket.Priority.ToString();
                result.Status      = ticket.Status.ToString();
                result.Type        = ticket.Type.ToString();

                using (var user = new UserController(context))
                {
                    result.Owner = await user.GetUserData(ticket.UserId);
                }

                using (var comment = new CommentController(context))
                {
                    result.Comments = await comment.GetCommentData(ticket.Id);
                }

                return(result);
            }
            catch (Exception ex) { throw ex; }
        }
コード例 #22
0
 public CommentControllerTests(ScrumToolDBFixture p_ScrumToolDBFixture)
 {
     m_ScrumToolDBFixture = p_ScrumToolDBFixture;
      m_ParentTaskID = m_ScrumToolDBFixture.FirstTaskID;
      m_ScrumToolDBContext = m_ScrumToolDBFixture.ScrumToolDB;
      m_CommentController = new CommentController(m_ScrumToolDBContext);
 }
コード例 #23
0
        public async void Patch_No_Errors()
        {
            CommentControllerMockFacade mock = new CommentControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiCommentServerResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(true);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiCommentServerRequestModel>()))
            .Callback <int, ApiCommentServerRequestModel>(
                (id, model) => model.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"))
                )
            .Returns(Task.FromResult <UpdateResponse <ApiCommentServerResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCommentServerResponseModel>(new ApiCommentServerResponseModel()));
            CommentController controller = new CommentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiCommentServerModelMapper());

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

            var patch = new JsonPatchDocument <ApiCommentServerRequestModel>();

            patch.Replace(x => x.CreationDate, DateTime.Parse("1/1/1987 12:00:00 AM"));

            IActionResult response = await controller.Patch(default(int), patch);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            mock.ServiceMock.Verify(x => x.Update(It.IsAny <int>(), It.IsAny <ApiCommentServerRequestModel>()));
        }
コード例 #24
0
        public void ListSetsHomePageContainer()
        {
            FakePostService postService = new FakePostService();

            postService.AllComments.Add(new ParentAndChild <PostBase, Comment>()
            {
                Parent = new Post(), Child = new Comment()
            });
            postService.AllComments.Add(new ParentAndChild <PostBase, Comment>()
            {
                Parent = new Post(), Child = new Comment()
            });

            CommentController controller = new CommentController(postService, null, null)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteModelList <ParentAndChild <PostBase, Comment> > result = controller.List();

            Assert.IsType <HomePageContainer>(result.Container);
        }
コード例 #25
0
        public void Setup()
        {
            var client = new MongoClient(Constants.MongoDbConnectionUri());

            _userRepository    = new UsersRepository(client);
            _commentRepository = new CommentsRepository(client);
            _movieRepository   = new MoviesRepository(client);
            _opinionatedUser   = new User
            {
                Name     = "Inigo Montoya",
                Email    = "*****@*****.**",
                Password = "******"
            };
            _anotherUser = new User
            {
                Name     = "Vizzini",
                Email    = "*****@*****.**",
                Password = "******"
            };
            _movieId = "573a1398f29313caabcea974";
            var jwt = new JwtAuthentication
            {
                SecurityKey   = "ouNtF8Xds1jE55/d+iVZ99u0f2U6lQ+AHdiPFwjVW3o=",
                ValidAudience = "https://localhost:5000/",
                ValidIssuer   = "https://localhost:5000/"
            };
            var appSettingsOptions = Options.Create(jwt);

            _userController    = new UserController(_userRepository, _commentRepository, appSettingsOptions);
            _commentController = new CommentController(_commentRepository, _userRepository, appSettingsOptions);
        }
コード例 #26
0
        public async void BulkInsert_No_Errors()
        {
            CommentControllerMockFacade mock = new CommentControllerMockFacade();

            var mockResponse = ValidationResponseFactory <ApiCommentServerResponseModel> .CreateResponse(null as ApiCommentServerResponseModel);

            mockResponse.SetRecord(new ApiCommentServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCommentServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCommentServerResponseModel> >(mockResponse));
            CommentController controller = new CommentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

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

            var records = new List <ApiCommentServerRequestModel>();

            records.Add(new ApiCommentServerRequestModel());
            IActionResult response = await controller.BulkInsert(records);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var result = (response as OkObjectResult).Value as CreateResponse <List <ApiCommentServerResponseModel> >;

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCommentServerRequestModel>()));
        }
コード例 #27
0
        public void ListByTagReturnsListOfComments()
        {
            FakeCommentService commentService = new FakeCommentService();
            FakePostService    postService    = new FakePostService();
            FakeTagService     tagService     = new FakeTagService();

            commentService.AllComments.Add(new Comment());
            commentService.AllComments.Add(new Comment());

            tagService.StoredTags.Add("test", new Tag());

            CommentController controller = new CommentController(postService, commentService, tagService, null)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteViewModelItems <Comment> result = controller.ListByTag(new Tag()
            {
                Name = "test"
            });

            Assert.Equal(2, result.Items.Count());
            Assert.Same(commentService.AllComments[0], result.Items.ElementAt(0));
            Assert.Same(commentService.AllComments[1], result.Items.ElementAt(1));
        }
コード例 #28
0
        public void ListByTagSetsTagAsContainer()
        {
            FakeCommentService commentService = new FakeCommentService();
            FakePostService    postService    = new FakePostService();
            FakeTagService     tagService     = new FakeTagService();

            commentService.AllComments.Add(new Comment());
            commentService.AllComments.Add(new Comment());

            tagService.StoredTags.Add("test", new Tag());

            CommentController controller = new CommentController(postService, commentService, tagService, null)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteViewModelItems <Comment> result = controller.ListByTag(new Tag()
            {
                Name = "test"
            });

            Assert.Same(tagService.StoredTags["test"], result.Container);
        }
コード例 #29
0
        public void ListByPostReturnsListOfComments()
        {
            FakeCommentService commentService = new FakeCommentService();
            FakePostService    postService    = new FakePostService();
            FakeAreaService    areaService    = new FakeAreaService();

            commentService.AllComments.Add(new Comment());
            commentService.AllComments.Add(new Comment());

            postService.AddedPosts.Add(new Post()
            {
                Slug = "test"
            });

            areaService.StoredAreas.Add("test", new Area());

            CommentController controller = new CommentController(postService, commentService, null, areaService)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteViewModelItems <Comment> result = controller.ListByPost(0, 50, new PostAddress("test", "test"), null);

            Assert.Equal(2, result.Items.Count());
            Assert.Same(commentService.AllComments[0], result.Items.ElementAt(0));
            Assert.Same(commentService.AllComments[1], result.Items.ElementAt(1));
            Assert.Same(postService.AddedPosts[0], result.Items.ElementAt(0).Parent);
            Assert.Same(postService.AddedPosts[0], result.Items.ElementAt(1).Parent);
        }
コード例 #30
0
        public void ListByPostSetsPostAsContainer()
        {
            FakeCommentService commentService = new FakeCommentService();
            FakePostService    postService    = new FakePostService();
            FakeAreaService    areaService    = new FakeAreaService();

            commentService.AllComments.Add(new Comment());
            commentService.AllComments.Add(new Comment());

            postService.AddedPosts.Add(new Post()
            {
                Slug = "test"
            });

            areaService.StoredAreas.Add("test", new Area());

            CommentController controller = new CommentController(postService, commentService, null, areaService)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteViewModelItems <Comment> result = controller.ListByPost(0, 50, new PostAddress("test", "test"), null);

            Assert.Same(postService.AddedPosts[0], result.Container);
        }
コード例 #31
0
        public void ListByAreaSetsAreaAsContainer()
        {
            FakeCommentService commentService = new FakeCommentService();
            FakePostService    postService    = new FakePostService();
            FakeAreaService    areaService    = new FakeAreaService();

            commentService.AllComments.Add(new Comment());
            commentService.AllComments.Add(new Comment());

            areaService.StoredAreas.Add("test", new Area());

            CommentController controller = new CommentController(postService, commentService, null, areaService)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteViewModelItems <Comment> result = controller.ListByArea(new Area()
            {
                Name = "test"
            });

            Assert.Same(areaService.StoredAreas["test"], result.Container);
        }
コード例 #32
0
 public static IController<CommentDto> GetCommentController()
 {
     if(CommentController == null)
     {
         CommentController = new CommentController();
     }
     return CommentController;
 }
コード例 #33
0
        public void SetUp()
        {
            _postDomain = new Mock<IPostService>();
            _controller = new CommentController(_postDomain.Object, null);
            var headers = new FormCollection {{"Referer", ExpectedRefererUrl}};
            MockRequest.Setup(r => r.Headers).Returns(headers);

            SetControllerContext(_controller);
        }
コード例 #34
0
        public void IndexReturnsViewResult()
        {
            var commentRepository = new Mock<ICommentRepository>();
            var postRepository = new Mock<IPostRepository>();

            var controller = new CommentController(commentRepository.Object, postRepository.Object);

            var result = controller.Index();

            Assert.That(result, Is.AssignableFrom<ViewResult>());
        }
コード例 #35
0
 public static ISearch<CommentDto> GetCommentSearh()
 {
     if(CommentSearch == null)
     {
         CommentSearch = new CommentController();
     }
     return CommentSearch;
 }