当前位置: 首页>>代码示例>>C#>>正文


C# TaskApiController.Post方法代码示例

本文整理汇总了C#中AllReady.Controllers.TaskApiController.Post方法的典型用法代码示例。如果您正苦于以下问题:C# TaskApiController.Post方法的具体用法?C# TaskApiController.Post怎么用?C# TaskApiController.Post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AllReady.Controllers.TaskApiController的用法示例。


在下文中一共展示了TaskApiController.Post方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PostReturnsBadRequestObjectResultWithCorrectErrorMessageWhenEventIsNull

        public async Task PostReturnsBadRequestObjectResultWithCorrectErrorMessageWhenEventIsNull()
        {
            var determineIfATaskIsEditable = new Mock<IDetermineIfATaskIsEditable>();
            determineIfATaskIsEditable.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(true);

            var sut = new TaskApiController(Mock.Of<IMediator>(), determineIfATaskIsEditable.Object);
            var result = await sut.Post(new TaskViewModel()) as BadRequestObjectResult;

            Assert.IsType<BadRequestObjectResult>(result);
            Assert.Equal(result.StatusCode, 400);
        }
开发者ID:codethug,项目名称:allReady,代码行数:11,代码来源:TaskApiControllerTests.cs

示例2: Event

        public async Task PostReturnsHttpUnauthorizedWhenUserDoesNotHaveTheAuthorizationToEditTheTaskOrTheTaskIsNotInAnEditableState()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event());

            var determineIfATaskIsEditable = new Mock<IDetermineIfATaskIsEditable>();
            determineIfATaskIsEditable.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(false);

            var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object);
            var result = await sut.Post(new TaskViewModel { EventId = 1 });

            Assert.IsType<HttpUnauthorizedResult>(result);
        }
开发者ID:codethug,项目名称:allReady,代码行数:13,代码来源:TaskApiControllerTests.cs

示例3: PostReturnsBadRequestResultWhenTaskAlreadyExists

        public async Task PostReturnsBadRequestResultWhenTaskAlreadyExists()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event());
            mediator.Setup(x => x.Send(It.IsAny<TaskByTaskIdQuery>())).Returns(new AllReadyTask());

            var determineIfATaskIsEditable = new Mock<IDetermineIfATaskIsEditable>();
            determineIfATaskIsEditable.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(true);

            var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object);
            var result = await sut.Post(new TaskViewModel { EventId = 1 });

            Assert.IsType<BadRequestResult>(result);
        }
开发者ID:codethug,项目名称:allReady,代码行数:14,代码来源:TaskApiControllerTests.cs

示例4: PostSendsAddTaskCommandAsyncWithCorrectData

        public async Task PostSendsAddTaskCommandAsyncWithCorrectData()
        {
            var model = new TaskViewModel { EventId = 1, Id = 1 };
            var allReadyTask = new AllReadyTask();

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(new Event());
            mediator.SetupSequence(x => x.SendAsync(It.IsAny<TaskByTaskIdQuery>()))
                .ReturnsAsync(allReadyTask).ReturnsAsync(null);

            var determineIfATaskIsEditable = new Mock<IDetermineIfATaskIsEditable>();
            determineIfATaskIsEditable.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>(), null)).Returns(true);

            var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object, null);
            await sut.Post(model);

            mediator.Verify(x => x.SendAsync(It.Is<AddTaskCommand>(y => y.AllReadyTask == allReadyTask)), Times.Once);
        }
开发者ID:stevejgordon,项目名称:allReady,代码行数:18,代码来源:TaskApiControllerTests.cs

示例5: PostSendsTaskByTaskIdQueryWithCorrectTaskId

        public async Task PostSendsTaskByTaskIdQueryWithCorrectTaskId()
        {
            var model = new TaskViewModel { EventId = 1, Id = 1 };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event());
            mediator.Setup(x => x.Send(It.IsAny<TaskByTaskIdQuery>())).Returns(new AllReadyTask());

            var provider = new Mock<IDetermineIfATaskIsEditable>();
            provider.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(true);

            var sut = new TaskApiController(mediator.Object, provider.Object);
            await sut.Post(model);

            mediator.Verify(x => x.Send(It.Is<TaskByTaskIdQuery>(y => y.TaskId == model.Id)));
        }
开发者ID:codethug,项目名称:allReady,代码行数:16,代码来源:TaskApiControllerTests.cs

示例6: PostReturnsHttpStatusCodeResultOf201

        public async Task PostReturnsHttpStatusCodeResultOf201()
        {
            var model = new TaskViewModel { EventId = 1, Id = 0 };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event());

            var provider = new Mock<IDetermineIfATaskIsEditable>();
            provider.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(true);

            var sut = new TaskApiController(mediator.Object, provider.Object);
            var result = await sut.Post(model) as HttpStatusCodeResult;

            Assert.IsType<HttpStatusCodeResult>(result);
            Assert.Equal(result.StatusCode, 201);
        }
开发者ID:codethug,项目名称:allReady,代码行数:16,代码来源:TaskApiControllerTests.cs


注:本文中的AllReady.Controllers.TaskApiController.Post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。