本文整理汇总了C#中AllReady.Areas.Admin.Controllers.ItineraryController.Edit方法的典型用法代码示例。如果您正苦于以下问题:C# ItineraryController.Edit方法的具体用法?C# ItineraryController.Edit怎么用?C# ItineraryController.Edit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AllReady.Areas.Admin.Controllers.ItineraryController
的用法示例。
在下文中一共展示了ItineraryController.Edit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditPost_ReturnsRedirect_AfterCommandIsSent
public async Task EditPost_ReturnsRedirect_AfterCommandIsSent()
{
var model = new ItineraryEditViewModel
{
Id = 1,
EventId = 1,
Name = "Test",
Date = new DateTime(2016, 06, 01)
};
var mediator = new Mock<IMediator>();
var itinerarySummaryModel = new ItinerarySummaryViewModel
{
Id = 1,
Name = "Itinerary",
OrganizationId = 1,
EventSummary = new EventSummaryViewModel
{
StartDateTime = new DateTimeOffset(new DateTime(2016, 01, 01)),
EndDateTime = new DateTimeOffset(new DateTime(2016, 12, 31))
}
};
mediator.Setup(x => x.SendAsync(It.IsAny<ItinerarySummaryQuery>())).ReturnsAsync(itinerarySummaryModel);
mediator.Setup(x => x.SendAsync(It.IsAny<EditItineraryCommand>())).ReturnsAsync(0);
var mockValidator = new Mock<IItineraryEditModelValidator>();
mockValidator.Setup(mock => mock.Validate(It.IsAny<ItineraryEditViewModel>(), It.IsAny<EventSummaryViewModel>())).Returns(new List<KeyValuePair<string, string>>());
var sut = new ItineraryController(mediator.Object, mockValidator.Object);
sut.SetClaims(new List<Claim>
{
new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()),
new Claim(AllReady.Security.ClaimTypes.Organization, "1")
});
var result = await sut.Edit(model);
var redirectResult = Assert.IsType<RedirectToActionResult>(result);
redirectResult.ActionName.ShouldBe("Details");
var id = redirectResult.RouteValues["id"];
id.ShouldNotBeNull();
id.ShouldBe(model.Id);
}
示例2: EditPost_ReturnsViewWithModel_WhenValidatonFails
public async Task EditPost_ReturnsViewWithModel_WhenValidatonFails()
{
var model = new ItineraryEditViewModel
{
EventId = 1,
Name = "Test",
Date = new DateTime(2016, 06, 01)
};
var mediator = new Mock<IMediator>();
var itinerarySummaryModel = new ItinerarySummaryViewModel
{
Id = 1,
Name = "Itinerary",
OrganizationId = 1,
EventSummary = new EventSummaryViewModel
{
StartDateTime = new DateTimeOffset(new DateTime(2016, 01, 01)),
EndDateTime = new DateTimeOffset(new DateTime(2016, 12, 31))
}
};
mediator.Setup(x => x.SendAsync(It.IsAny<ItinerarySummaryQuery>())).ReturnsAsync(itinerarySummaryModel);
var validatorError = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("key", "value")
};
var mockValidator = new Mock<IItineraryEditModelValidator>();
mockValidator.Setup(mock => mock.Validate(It.IsAny<ItineraryEditViewModel>(), It.IsAny<EventSummaryViewModel>())).Returns(validatorError);
var sut = new ItineraryController(mediator.Object, mockValidator.Object);
sut.SetClaims(new List<Claim>
{
new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()),
new Claim(AllReady.Security.ClaimTypes.Organization, "1")
});
var result = await sut.Edit(model);
var viewResult = Assert.IsType<ViewResult>(result);
var resultViewModel = viewResult.ViewData.Model;
Assert.IsType<ItineraryEditViewModel>(resultViewModel);
Assert.Equal(resultViewModel, model);
}
示例3: EditPost_SendsEditItineraryCommand_WithCorrectItineraryEditModel
public async Task EditPost_SendsEditItineraryCommand_WithCorrectItineraryEditModel()
{
var model = new ItineraryEditViewModel
{
EventId = 1,
Name = "Test",
Date = new DateTime(2016, 06, 01)
};
var mediator = new Mock<IMediator>();
var itinerarySummaryModel = new ItinerarySummaryViewModel
{
Id = 1,
Name = "Itinerary",
OrganizationId = 1,
EventSummary = new EventSummaryViewModel
{
StartDateTime = new DateTimeOffset(new DateTime(2016, 01, 01)),
EndDateTime = new DateTimeOffset(new DateTime(2016, 12, 31))
}
};
mediator.Setup(x => x.SendAsync(It.IsAny<ItinerarySummaryQuery>())).ReturnsAsync(itinerarySummaryModel);
mediator.Setup(x => x.SendAsync(It.IsAny<EditItineraryCommand>())).ReturnsAsync(0).Verifiable();
var mockValidator = new Mock<IItineraryEditModelValidator>();
mockValidator.Setup(mock => mock.Validate(It.IsAny<ItineraryEditViewModel>(), It.IsAny<EventSummaryViewModel>())).Returns(new List<KeyValuePair<string, string>>());
var sut = new ItineraryController(mediator.Object, mockValidator.Object);
sut.SetClaims(new List<Claim>
{
new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()),
new Claim(AllReady.Security.ClaimTypes.Organization, "1")
});
await sut.Edit(model);
mediator.Verify(x => x.SendAsync(It.Is<EditItineraryCommand>(y => y.Itinerary == model)), Times.Once);
}
示例4: EditPost_ReturnsHttpUnauthorizedResult_WhenUserIsNotOrgAdminForEventOrg
public async Task EditPost_ReturnsHttpUnauthorizedResult_WhenUserIsNotOrgAdminForEventOrg()
{
const int orgId = 1;
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<ItinerarySummaryQuery>())).ReturnsAsync(new ItinerarySummaryViewModel { OrganizationId = orgId });
var sut = new ItineraryController(mediator.Object, MockSuccessValidation().Object);
sut.MakeUserNotAnOrgAdmin();
Assert.IsType<UnauthorizedResult>(await sut.Edit(new ItineraryEditViewModel { Id = 50 }));
}
示例5: EditPost_ReturnsBadResult_WhenEditItineraryQuery_ReturnsNull
public async Task EditPost_ReturnsBadResult_WhenEditItineraryQuery_ReturnsNull()
{
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<ItinerarySummaryQuery>())).ReturnsAsync(null);
var sut = new ItineraryController(mediator.Object, Mock.Of<IItineraryEditModelValidator>());
Assert.IsType<BadRequestResult>(await sut.Edit(new ItineraryEditViewModel { Id = 50 }));
}
示例6: EditPost_SendsItinerarySummaryQuery_WithCorrectId
public async Task EditPost_SendsItinerarySummaryQuery_WithCorrectId()
{
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<ItinerarySummaryQuery>())).ReturnsAsync(null).Verifiable();
var sut = new ItineraryController(mediator.Object, Mock.Of<IItineraryEditModelValidator>());
await sut.Edit(new ItineraryEditViewModel { Id = 50 });
mediator.Verify(x => x.SendAsync(It.Is<ItinerarySummaryQuery>(y => y.ItineraryId == 50)), Times.Once);
}
示例7: EditPost_ReturnsHttpBadRequestWhenModelIsNull
public async Task EditPost_ReturnsHttpBadRequestWhenModelIsNull()
{
var sut = new ItineraryController(Mock.Of<IMediator>(), MockSuccessValidation().Object);
Assert.IsType<BadRequestResult>(await sut.Edit(null));
}
示例8: EditGet_ReturnsViewResult_WhenUserIsSiteAdmin
public async Task EditGet_ReturnsViewResult_WhenUserIsSiteAdmin()
{
const int orgId = 1;
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EditItineraryQuery>())).ReturnsAsync(new ItineraryEditViewModel { OrganizationId = orgId, Id = 100, Name = "Test"});
var sut = new ItineraryController(mediator.Object, MockSuccessValidation().Object);
sut.SetClaims(new List<Claim>
{
new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()),
new Claim(AllReady.Security.ClaimTypes.Organization, "0")
});
// Assert
var viewResult = Assert.IsType<ViewResult>(await sut.Edit(1));
var model = viewResult.Model as ItineraryEditViewModel;
model.ShouldNotBeNull();
model.Name.ShouldBe("Test");
}