本文整理汇总了C#中AllReady.Areas.Admin.Controllers.TaskController.Edit方法的典型用法代码示例。如果您正苦于以下问题:C# TaskController.Edit方法的具体用法?C# TaskController.Edit怎么用?C# TaskController.Edit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AllReady.Areas.Admin.Controllers.TaskController
的用法示例。
在下文中一共展示了TaskController.Edit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditGetReturnsHttpNotFoundResultWhenTaskIsNull
public async Task EditGetReturnsHttpNotFoundResultWhenTaskIsNull()
{
var sut = new TaskController(Mock.Of<IMediator>(), Mock.Of<ITaskSummaryModelValidator>());
var result = await sut.Edit(It.IsAny<int>());
Assert.IsType<HttpNotFoundResult>(result);
}
示例2: EditGetReturnsHttpUnauthorizedResultWhenUserIsNotOrgAdmin
public async Task EditGetReturnsHttpUnauthorizedResultWhenUserIsNotOrgAdmin()
{
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EditTaskQueryAsync>())).ReturnsAsync(new TaskSummaryModel());
var sut = new TaskController(mediator.Object, Mock.Of<ITaskSummaryModelValidator>());
sut.SetDefaultHttpContext();
var result = await sut.Edit(It.IsAny<int>());
Assert.IsType<HttpUnauthorizedResult>(result);
}
示例3: EditPostRedirectsToCorrectAction_WhenUpdatingTask
public async Task EditPostRedirectsToCorrectAction_WhenUpdatingTask()
{
const int organizationId = 1;
var model = new EditViewModel { Id = 1, OrganizationId = organizationId };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EditTaskCommandAsync>())).ReturnsAsync(1);
var validator = new Mock<ITaskEditViewModelValidator>();
validator.Setup(x => x.Validate(It.IsAny<EditViewModel>())).Returns(new List<KeyValuePair<string, string>>());
var sut = new TaskController(mediator.Object, validator.Object);
sut.MakeUserAnOrgAdmin(organizationId.ToString());
var result = await sut.Edit(model) as RedirectToActionResult;
var routeValues = new Dictionary<string, object> { ["id"] = model.Id };
Assert.Equal(result.ControllerName, "Task");
Assert.Equal(result.ActionName, nameof(TaskController.Details));
Assert.Equal(result.RouteValues, routeValues);
}
示例4: EditGetSendsEditTaskQueryAsyncWithCorrectTaskId
public async Task EditGetSendsEditTaskQueryAsyncWithCorrectTaskId()
{
const int taskId = 1;
var mediator = new Mock<IMediator>();
var sut = new TaskController(mediator.Object, Mock.Of<ITaskSummaryModelValidator>());
await sut.Edit(taskId);
mediator.Verify(x => x.SendAsync(It.Is<EditTaskQueryAsync>(y => y.TaskId == taskId)), Times.Once);
}
示例5: EditPostSendsEditTaskCommandAsyncWhenModelStateIsValidAndUserIsOrganizationAdmin
public async Task EditPostSendsEditTaskCommandAsyncWhenModelStateIsValidAndUserIsOrganizationAdmin()
{
const int organizationId = 1;
var taskSummaryModel = new TaskSummaryModel { OrganizationId = organizationId };
var startDateTime = DateTimeOffset.Now.AddDays(-1);
var endDateTime = DateTimeOffset.Now.AddDays(1);
var model = new TaskSummaryModel { StartDateTime = startDateTime, EndDateTime = endDateTime, OrganizationId = organizationId };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event
{
Campaign = new Campaign { TimeZoneId = "Eastern Standard Time" },
StartDateTime = startDateTime.AddDays(-1),
EndDateTime = endDateTime.AddDays(1)
});
mediator.Setup(x => x.SendAsync(It.IsAny<TaskQueryAsync>())).ReturnsAsync(taskSummaryModel);
var validator = new Mock<ITaskSummaryModelValidator>();
validator.Setup(x => x.Validate(It.IsAny<TaskSummaryModel>())).Returns(new List<KeyValuePair<string, string>>());
var sut = new TaskController(mediator.Object, validator.Object);
MakeUserOrganizationAdminUser(sut, organizationId.ToString());
await sut.Edit(model);
mediator.Verify(x => x.SendAsync(It.Is<EditTaskCommandAsync>(y => y.Task == model)));
}
示例6: EditPostReturnsCorrectViewAndViewModelWhenEndDateTimeIsLessThanStartDateTimeAndModelStateIsInvalid
public async Task EditPostReturnsCorrectViewAndViewModelWhenEndDateTimeIsLessThanStartDateTimeAndModelStateIsInvalid()
{
var model = new TaskEditModel { EndDateTime = DateTimeOffset.Now.AddDays(-1), StartDateTime = DateTimeOffset.Now.AddDays(1) };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event { Campaign = new Campaign { TimeZoneId = "Eastern Standard Time" } });
var sut = new TaskController(mediator.Object);
var result = await sut.Edit(model) as ViewResult;
var modelResult = result.ViewData.Model as TaskEditModel;
Assert.IsType<ViewResult>(result);
Assert.Equal(modelResult, model);
}
示例7: EditPostAddsCorrectModelStateErrorWhenValidatorReturnsError
public async Task EditPostAddsCorrectModelStateErrorWhenValidatorReturnsError()
{
const string errorKey = "ErrorKey";
const string errorValue = "ErrorValue";
var validator = new Mock<ITaskEditViewModelValidator>();
validator.Setup(x => x.Validate(It.IsAny<EditViewModel>()))
.Returns(new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>(errorKey, errorValue) });
var sut = new TaskController(null, validator.Object);
await sut.Edit(new EditViewModel());
var modelStateErrorCollection = sut.ModelState.GetErrorMessagesByKey(errorKey);
Assert.Equal(modelStateErrorCollection.Single().ErrorMessage, errorValue);
}
示例8: EditPostReturnsCorrectViewAndViewModelWhenValidatorReturnsError
public async Task EditPostReturnsCorrectViewAndViewModelWhenValidatorReturnsError()
{
var model = new TaskSummaryModel { EndDateTime = DateTimeOffset.Now.AddDays(-1), StartDateTime = DateTimeOffset.Now.AddDays(1) };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event { Campaign = new Campaign { TimeZoneId = "Eastern Standard Time" } });
var validator = new Mock<ITaskSummaryModelValidator>();
validator.Setup(x => x.Validate(It.IsAny<TaskSummaryModel>())).Returns(new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>(nameof(TaskSummaryModel.EndDateTime), "Ending time cannot be earlier than the starting time") });
var sut = new TaskController(mediator.Object, validator.Object);
var result = await sut.Edit(model) as ViewResult;
var modelResult = result.ViewData.Model as TaskSummaryModel;
Assert.IsType<ViewResult>(result);
Assert.Equal(modelResult, model);
}
示例9: EditGetReturnsCorrectViewModelAndView
public async Task EditGetReturnsCorrectViewModelAndView()
{
const int organizationId = 1;
var editViewModel = new EditViewModel { OrganizationId = organizationId };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EditTaskQueryAsync>())).ReturnsAsync(editViewModel);
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>());
var sut = new TaskController(mediator.Object, null) { Url = urlHelper.Object };
sut.MakeUserAnOrgAdmin(organizationId.ToString());
var result = await sut.Edit(It.IsAny<int>()) as ViewResult;
var modelResult = result.ViewData.Model as EditViewModel;
Assert.IsType<ViewResult>(result);
Assert.IsType<EditViewModel>(modelResult);
Assert.Equal(modelResult, editViewModel);
}
示例10: EditPostInvokesValidateOnTaskSummaryModelValidatorWithCorrectParameters
public async Task EditPostInvokesValidateOnTaskSummaryModelValidatorWithCorrectParameters()
{
var model = new EditViewModel { EndDateTime = DateTimeOffset.Now.AddDays(-1), StartDateTime = DateTimeOffset.Now.AddDays(1), EventId = 1 };
var validator = new Mock<ITaskEditViewModelValidator>();
validator.Setup(x => x.Validate(model)).Returns(new List<KeyValuePair<string, string>>()).Verifiable();
var sut = new TaskController(null, validator.Object);
sut.AddModelStateError();
await sut.Edit(model);
validator.Verify();
}
示例11: EditGetPopulatesCorrectTitleOnViewBag
public async Task EditGetPopulatesCorrectTitleOnViewBag()
{
var model = new EditViewModel { EventId = 1, OrganizationId = 1 };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EditTaskQueryAsync>())).ReturnsAsync(model);
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>());
var sut = new TaskController(mediator.Object, null) { Url = urlHelper.Object };
sut.MakeUserAnOrgAdmin(model.OrganizationId.ToString());
await sut.Edit(It.IsAny<int>());
Assert.Equal(sut.ViewBag.Title, "Edit Task");
}
示例12: EditGetAssignsCancelUrlToModel
public async Task EditGetAssignsCancelUrlToModel()
{
const string cancelUrl = "url";
var model = new EditViewModel { EventId = 1, OrganizationId = 1 };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EditTaskQueryAsync>())).ReturnsAsync(model);
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(cancelUrl);
var sut = new TaskController(mediator.Object, null) { Url = urlHelper.Object };
sut.MakeUserAnOrgAdmin(model.OrganizationId.ToString());
var result = await sut.Edit(It.IsAny<int>()) as ViewResult;
var modelResult = result.Model as EditViewModel;
Assert.Equal(modelResult.CancelUrl, cancelUrl);
}
示例13: EditGetSendsEditTaskQueryAsyncWithCorrectTaskId
public async Task EditGetSendsEditTaskQueryAsyncWithCorrectTaskId()
{
const int taskId = 1;
const int organizationId = 1;
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EditTaskQueryAsync>())).ReturnsAsync(new EditViewModel { OrganizationId = organizationId });
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>());
var sut = new TaskController(mediator.Object, null) { Url = urlHelper.Object };
sut.MakeUserAnOrgAdmin(organizationId.ToString());
await sut.Edit(taskId);
mediator.Verify(x => x.SendAsync(It.Is<EditTaskQueryAsync>(y => y.TaskId == taskId)), Times.Once);
}
示例14: EditGetReturnsCorrectViewModelAndView
public async Task EditGetReturnsCorrectViewModelAndView()
{
const int organizationId = 1;
var TaskSummaryModel = new TaskSummaryModel { OrganizationId = organizationId };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EditTaskQueryAsync>())).ReturnsAsync(TaskSummaryModel);
var sut = new TaskController(mediator.Object, Mock.Of<ITaskSummaryModelValidator>());
MakeUserOrganizationAdminUser(sut, organizationId.ToString());
var result = await sut.Edit(It.IsAny<int>()) as ViewResult;
var modelResult = result.ViewData.Model as TaskSummaryModel;
Assert.IsType<ViewResult>(result);
Assert.IsType<TaskSummaryModel>(modelResult);
Assert.Equal(modelResult, TaskSummaryModel);
}
示例15: EditPostReturnsCorrectViewAndViewModelWhenValidatorReturnsError
public async Task EditPostReturnsCorrectViewAndViewModelWhenValidatorReturnsError()
{
var model = new EditViewModel();
var validator = new Mock<ITaskEditViewModelValidator>();
validator.Setup(x => x.Validate(It.IsAny<EditViewModel>()))
.Returns(new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("key", "value") });
var sut = new TaskController(Mock.Of<IMediator>(), validator.Object);
var result = await sut.Edit(model) as ViewResult;
var modelResult = result.ViewData.Model as EditViewModel;
Assert.IsType<ViewResult>(result);
Assert.Equal(modelResult, model);
}