Exemplo n.º 1
0
        public async Task OnPostAsync_Should_ReturnRedirectToPageResult()
        {
            var loggerMock   = new Mock <ILogger <AddPostModel> >();
            var mediaterMock = new Mock <IMediator>();

            mediaterMock.Setup(m => m.Send(It.IsAny <IRequest <Result <Post> > >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Result <Post> .Success(new Post()));

            var httpContext = new DefaultHttpContext();

            httpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "*****@*****.**") }));
            var pageContext = GetPageContext(httpContext);

            var pageModel = new AddPostModel(mediaterMock.Object, loggerMock.Object)
            {
                PageContext = pageContext.Item1,
                TempData    = GetTempDataDictionary(httpContext),
                Url         = new UrlHelper(pageContext.Item2),
                Post        = new AddPostCommand
                {
                    Categories  = "category",
                    Title       = "title",
                    Content     = "content",
                    Description = "description"
                }
            };

            var result = await pageModel.OnPostAsync(default);
Exemplo n.º 2
0
        public async Task OnGet_Should_SetEmptyAddPostCommand()
        {
            var loggerMock   = new Mock <ILogger <AddPostModel> >();
            var mediaterMock = new Mock <IMediator>();
            var httpContext  = new DefaultHttpContext();
            var pageContext  = GetPageContext(httpContext);

            var pageModel = new AddPostModel(mediaterMock.Object, loggerMock.Object)
            {
                PageContext = pageContext.Item1,
                TempData    = GetTempDataDictionary(httpContext),
                Url         = new UrlHelper(pageContext.Item2)
            };

            var result = pageModel.OnGet();

            result.Should().BeOfType <PageResult>();
            pageModel.Post.Should().NotBeNull();
        }