コード例 #1
0
        public async Task OnPostAsync_Should_ReturnSuccess()
        {
            var loggerMock   = new Mock <ILogger <UpdatePostModel> >();
            var mediaterMock = new Mock <IMediator>();

            mediaterMock.Setup(m => m.Send(It.IsAny <UpdatePostCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Result <Post> .Success(new Post {
                Id = _guid
            }));

            var httpContext = new DefaultHttpContext();
            var pageContext = GetPageContext(httpContext);

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

            var result = await pageModel.OnPostAsync(default);
コード例 #2
0
        public async Task OnGetAsync_Should_SetUpdatePostCommand()
        {
            var loggerMock   = new Mock <ILogger <UpdatePostModel> >();
            var mediaterMock = new Mock <IMediator>();

            mediaterMock.Setup(m => m.Send(It.IsAny <GetPostByIdQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Result <Post> .Success(new Post {
                Id = _guid
            }));

            var httpContext = new DefaultHttpContext();
            var pageContext = GetPageContext(httpContext);

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

            var result = await pageModel.OnGetAsync(_guid, default);

            result.Should().BeOfType <PageResult>();
            pageModel.Post.Id.Should().Be(_guid);
        }