• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Controllers.TaskApiController类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



TaskApiController类属于AllReady.Controllers命名空间,在下文中一共展示了TaskApiController类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: UnregisterTaskReturnsCorrectStatus

        public async Task UnregisterTaskReturnsCorrectStatus()
        {
            const string status = "status";

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<TaskUnenrollCommand>())).ReturnsAsync(new TaskUnenrollResult { Status = status });

            var sut = new TaskApiController(mediator.Object, null);
            sut.SetDefaultHttpContext();

            var jsonResult = await sut.UnregisterTask(It.IsAny<int>());
            var result = jsonResult.GetValueForProperty<string>("Status");

            Assert.IsType<JsonResult>(jsonResult);
            Assert.IsType<string>(result);
            Assert.Equal(result, status);
        }
开发者ID:codethug,项目名称:allReady,代码行数:17,代码来源:TaskApiControllerTests.cs


示例6: UnregisterTaskSendsTaskUnenrollCommandAsyncWithCorrectTaskIdAndUserId

        public async Task UnregisterTaskSendsTaskUnenrollCommandAsyncWithCorrectTaskIdAndUserId()
        {
            const string userId = "1";
            const int taskId = 1;

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<TaskUnenrollCommand>())).ReturnsAsync(new TaskUnenrollResult());

            var sut = new TaskApiController(mediator.Object, null);
            sut.SetFakeUser(userId);

            await sut.UnregisterTask(taskId);

            mediator.Verify(x => x.SendAsync(It.Is<TaskUnenrollCommand>(y => y.TaskId == taskId && y.UserId == userId)));
        }
开发者ID:codethug,项目名称:allReady,代码行数:15,代码来源:TaskApiControllerTests.cs


示例7: PutHasHttpPutAttributeWithCorrectTemplate

 public void PutHasHttpPutAttributeWithCorrectTemplate()
 {
     var sut = new TaskApiController(null, null);
     var attribute = sut.GetAttributesOn(x => x.Put(It.IsAny<int>(), It.IsAny<TaskViewModel>())).OfType<HttpPutAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "{id}");
 }
开发者ID:codethug,项目名称:allReady,代码行数:7,代码来源:TaskApiControllerTests.cs


示例8: ControllerHasProducesAtttributeWithTheCorrectContentType

 public void ControllerHasProducesAtttributeWithTheCorrectContentType()
 {
     var sut = new TaskApiController(null, null);
     var attribute = sut.GetAttributes().OfType<ProducesAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.ContentTypes.Select(x => x.MediaType).First(), "application/json");
 }
开发者ID:codethug,项目名称:allReady,代码行数:7,代码来源:TaskApiControllerTests.cs


示例9: DeleteReturnsHttpUnauthorizedResultWhenAUserDoesNotHavePermissionToEditTheTaskOrTheTaskIsNotEditable

        public async Task DeleteReturnsHttpUnauthorizedResultWhenAUserDoesNotHavePermissionToEditTheTaskOrTheTaskIsNotEditable()
        {
            var mediator = new Mock<IMediator>();
            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(false);

            var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object);
            var result = await sut.Delete(It.IsAny<int>());

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


示例10: ChangeStatusReturnsCorrectStatus

        public async Task ChangeStatusReturnsCorrectStatus()
        {
            const string status = "status";

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<TaskStatusChangeCommandAsync>())).Returns(() => Task.FromResult(new TaskChangeResult { Status = status }));

            var sut = new TaskApiController(mediator.Object, null);
            sut.SetDefaultHttpContext();

            var jsonResult = await sut.ChangeStatus(new TaskChangeModel());
            var result = jsonResult.GetValueForProperty<string>("Status");

            Assert.IsType<JsonResult>(jsonResult);
            Assert.IsType<string>(result);
            Assert.Equal(result, status);
        }
开发者ID:codethug,项目名称:allReady,代码行数:17,代码来源:TaskApiControllerTests.cs


示例11: UnregisterTaskHasHttpDeleteAttributeWithCorrectTemplate

 public void UnregisterTaskHasHttpDeleteAttributeWithCorrectTemplate()
 {
     var sut = new TaskApiController(null, null);
     var attribute = sut.GetAttributesOn(x => x.UnregisterTask(It.IsAny<int>())).OfType<HttpDeleteAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "{id}/signup");
 }
开发者ID:codethug,项目名称:allReady,代码行数:7,代码来源:TaskApiControllerTests.cs


示例12: Register_ReturnsCorrectJson_WhenApiResult_IsSuccess

        public async Task Register_ReturnsCorrectJson_WhenApiResult_IsSuccess()
        {
            const string taskSignUpResultStatus = TaskSignupResult.SUCCESS;
            var model = new EventSignupViewModel();
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(y => y.TaskSignupModel == model)))
                .Returns(Task.FromResult(new TaskSignupResult
                {
                    Status = taskSignUpResultStatus,
                    Task = new AllReadyTask { Id = 1, Name = "Task" }
                }));

            var sut = new TaskApiController(mediator.Object, null);

            var jsonResult = await sut.RegisterTask(model) as JsonResult;

            var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess");
            var taskModel = jsonResult.GetValueForProperty<TaskViewModel>("task");

            Assert.True(successStatus);
            Assert.NotNull(taskModel);
        }
开发者ID:codethug,项目名称:allReady,代码行数:22,代码来源:TaskApiControllerTests.cs


示例13: RegisterTaskSendsTaskSignupCommandWithCorrectTaskSignupModel

        public async Task RegisterTaskSendsTaskSignupCommandWithCorrectTaskSignupModel()
        {
            var model = new EventSignupViewModel();
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(y => y.TaskSignupModel == model))).Returns(Task.FromResult(new TaskSignupResult()));

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

            mediator.Verify(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(command => command.TaskSignupModel.Equals(model))));
        }
开发者ID:codethug,项目名称:allReady,代码行数:11,代码来源:TaskApiControllerTests.cs


示例14: RegisterTaskReturnsJsonWhenThereIsModelStateError

        public async Task RegisterTaskReturnsJsonWhenThereIsModelStateError()
        {
            const string modelStateErrorMessage = "modelStateErrorMessage";

            var sut = new TaskApiController(null, null);
            sut.AddModelStateErrorWithErrorMessage(modelStateErrorMessage);

            var jsonResult = await sut.RegisterTask(new EventSignupViewModel()) as JsonResult;
            var result = jsonResult.GetValueForProperty<List<string>>("errors");

            Assert.IsType<JsonResult>(jsonResult);
            Assert.IsType<List<string>>(result);
            Assert.Equal(result.First(), modelStateErrorMessage);
        }
开发者ID:codethug,项目名称:allReady,代码行数:14,代码来源:TaskApiControllerTests.cs


示例15: RegisterTaskReturnsHttpBadRequestWhenModelIsNull

        public async Task RegisterTaskReturnsHttpBadRequestWhenModelIsNull()
        {
            var sut = new TaskApiController(null, null);
            var result = await sut.RegisterTask(null);

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


示例16: DeleteSendsTaskByTaskIdQueryWithCorrectTaskId

        public async Task DeleteSendsTaskByTaskIdQueryWithCorrectTaskId()
        {
            const int taskId = 1;

            var mediator = new Mock<IMediator>();
            var sut = new TaskApiController(mediator.Object, null);
            await sut.Delete(taskId);

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


示例17: DeleteSendsDeleteTaskCommandAsyncWithCorrectTaskId

        public async Task DeleteSendsDeleteTaskCommandAsyncWithCorrectTaskId()
        {
            var allReadyTask = new AllReadyTask { Id = 1 };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<TaskByTaskIdQuery>())).Returns(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);
            await sut.Delete(It.IsAny<int>());

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


示例18: UnregisterTaskReturnsTaskViewModelWhenResultTaskIsNotNull

        public async Task UnregisterTaskReturnsTaskViewModelWhenResultTaskIsNotNull()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<TaskUnenrollCommand>())).ReturnsAsync(new TaskUnenrollResult { Task = new AllReadyTask() });

            var sut = new TaskApiController(mediator.Object, null);
            sut.SetDefaultHttpContext();
            
            var jsonResult = await sut.UnregisterTask(It.IsAny<int>());
            var result = jsonResult.GetValueForProperty<TaskViewModel>("Task");

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


示例19: UnregisterTaskHasAuthorizeAttrbiute

 public void UnregisterTaskHasAuthorizeAttrbiute()
 {
     var sut = new TaskApiController(null, null);
     var attribute = sut.GetAttributesOn(x => x.UnregisterTask(It.IsAny<int>())).OfType<AuthorizeAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
 }
开发者ID:codethug,项目名称:allReady,代码行数:6,代码来源:TaskApiControllerTests.cs


示例20: Register_ReturnsCorrectJson_WhenTaskIsClosed

        public async Task Register_ReturnsCorrectJson_WhenTaskIsClosed()
        {
            const string taskSignUpResultStatus = TaskSignupResult.FAILURE_CLOSEDTASK;

            var model = new EventSignupViewModel();
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(y => y.TaskSignupModel == model)))
                .Returns(Task.FromResult(new TaskSignupResult
                {
                    Status = taskSignUpResultStatus
                }));

            var sut = new TaskApiController(mediator.Object, null);

            var jsonResult = await sut.RegisterTask(model) as JsonResult;

            var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess");
            var errors = jsonResult.GetValueForProperty<string[]>("errors");

            Assert.False(successStatus);
            Assert.NotNull(errors);
            Assert.Equal(1, errors.Count());
            Assert.Equal(TaskApiController.FAILED_SIGNUP_TASK_CLOSED, errors[0]);
        }
开发者ID:codethug,项目名称:allReady,代码行数:24,代码来源:TaskApiControllerTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Models.AllReadyTask类代码示例发布时间:2022-05-24
下一篇:
C# Controllers.EventApiController类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap