Đây là những gì tôi đã làm, xin vui lòng cho tôi biết những gì bạn nghĩ
[Test]
public void Should_be_able_to_route_to_gettables_action_in_databaseschemaexplorercontroller()
{
const string url = "~/DatabaseSchemaExplorer/Tables/DatabaseType/Provider/DataSource/DatabaseName";
_httpContextMock.Expect(c => c.Request.AppRelativeCurrentExecutionFilePath).Return(url);
var routeData = _routes.GetRouteData(_httpContextMock);
Assert.IsNotNull(routeData, "Should have found the route");
Assert.AreEqual("DatabaseSchemaExplorer", routeData.Values["Controller"]);
Assert.AreEqual("Tables", routeData.Values["action"]);
Assert.AreEqual("DatabaseType", routeData.Values["databaseType"]);
Assert.AreEqual("Provider", routeData.Values["provider"]);
Assert.AreEqual("DataSource", routeData.Values["dataSource"]);
Assert.AreEqual("DatabaseName", routeData.Values["databaseName"]);
}
Có thể hữu ích? http://stackoverflow.com/questions/10446174/httpclient-with-asp-net-webapi-in-unit-testing-scenario –
và điều này: http://www.peterprovost.org/blog/2012/06/16/unit-testing-asp-dot-net-web-api/ –
Bạn có thể thử sử dụng gói NuGet MvcRouteUnitTester (hoạt động khá dễ dàng) http://nuget.org/packages/MvcRouteUnitTester – Styxxy