本文整理汇总了C#中TestableController类的典型用法代码示例。如果您正苦于以下问题:C# TestableController类的具体用法?C# TestableController怎么用?C# TestableController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestableController类属于命名空间,在下文中一共展示了TestableController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Raven_session_is_not_opened_before_on_action_executing
public void Raven_session_is_not_opened_before_on_action_executing()
{
var store = new TestableStore();
var controller = new TestableController(store);
Assert.Null(controller.Session);
}
示例2: If_no_exception_occurred_then_changes_are_saved
public void If_no_exception_occurred_then_changes_are_saved()
{
var testDocument = new Foo { Id = "foos/123", Title = "foo" };
var store = new TestableStore();
var controller = new TestableController(store);
StartActionExecuting(controller);
using (var session = controller.Session)
{
session.Store(testDocument);
session.SaveChanges();
var doc = session.Load<Foo>(testDocument.Id);
doc.Title = "bar";
FinishActionExecuted(controller);
}
using (var session = store.OpenSession())
{
var doc = session.Load<Foo>(testDocument.Id);
Assert.Equal("bar", doc.Title);
}
}
示例3: Redirect_WithParameter_NullOrEmptyUrl_Throws
public void Redirect_WithParameter_NullOrEmptyUrl_Throws(string url)
{
// Arrange
var controller = new TestableController();
// Act & Assert
ExceptionAssert.ThrowsArgumentNullOrEmpty(
() => controller.Redirect(url: url), "url");
}
示例4: RedirectPermanent_WithParameterUrl_SetsRedirectResultPermanentAndSameUrl
public void RedirectPermanent_WithParameterUrl_SetsRedirectResultPermanentAndSameUrl()
{
// Arrange
var controller = new TestableController();
var url = "/test/url";
// Act
var result = controller.RedirectPermanent(url);
// Assert
Assert.IsType<RedirectResult>(result);
Assert.True(result.Permanent);
Assert.Same(url, result.Url);
}
示例5: Controller_View_WithoutParameter_SetsResultNullViewNameAndNullViewDataModelAndSameTempData
public void Controller_View_WithoutParameter_SetsResultNullViewNameAndNullViewDataModelAndSameTempData()
{
// Arrange
var controller = new TestableController()
{
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
TempData = new TempDataDictionary(new DefaultHttpContext(), Mock.Of<ITempDataProvider>()),
};
// Act
var actualViewResult = controller.View();
// Assert
Assert.IsType<ViewResult>(actualViewResult);
Assert.Null(actualViewResult.ViewName);
Assert.Same(controller.ViewData, actualViewResult.ViewData);
Assert.Same(controller.TempData, actualViewResult.TempData);
Assert.Null(actualViewResult.ViewData.Model);
}
示例6: SettingViewData_AlsoUpdatesViewBag
public void SettingViewData_AlsoUpdatesViewBag()
{
// Arrange
var metadataProvider = TestModelMetadataProvider.CreateDefaultProvider();
var controller = new TestableController();
var originalViewData = controller.ViewData = new ViewDataDictionary<object>(metadataProvider);
var replacementViewData = new ViewDataDictionary<object>(metadataProvider);
// Act
controller.ViewBag.Hello = "goodbye";
controller.ViewData = replacementViewData;
controller.ViewBag.Another = "property";
// Assert
Assert.NotSame(originalViewData, controller.ViewData);
Assert.Same(replacementViewData, controller.ViewData);
Assert.Null(controller.ViewBag.Hello);
Assert.Equal("property", controller.ViewBag.Another);
Assert.Equal("property", controller.ViewData["Another"]);
}
示例7: Controller_Content_WithParameterContentString_SetsResultContent
public void Controller_Content_WithParameterContentString_SetsResultContent()
{
// Arrange
var controller = new TestableController();
// Act
var actualContentResult = controller.Content("TestContent");
// Assert
Assert.IsType<ContentResult>(actualContentResult);
Assert.Equal("TestContent", actualContentResult.Content);
Assert.Null(actualContentResult.ContentType);
}
示例8: BadRequest_SetsStatusCodeAndValue_ModelState
public void BadRequest_SetsStatusCodeAndValue_ModelState()
{
// Arrange
var controller = new TestableController();
// Act
var result = controller.HttpBadRequest(new ModelStateDictionary());
// Assert
Assert.IsType<BadRequestObjectResult>(result);
Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
var errors = Assert.IsType<SerializableError>(result.Value);
Assert.Equal(0, errors.Count);
}
示例9: BadRequest_IDisposableObject_RegistersForDispose
public void BadRequest_IDisposableObject_RegistersForDispose()
{
// Arrange
var mockHttpContext = new Mock<DefaultHttpContext>();
mockHttpContext.Setup(x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()));
var controller = new TestableController()
{
ActionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor())
};
var input = new DisposableObject();
// Act
var result = controller.HttpBadRequest(input);
// Assert
Assert.IsType<BadRequestObjectResult>(result);
Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
Assert.Same(input, result.Value);
mockHttpContext.Verify(
x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()),
Times.Once());
}
示例10: CreatedAtAction_WithActionControllerAndNullRouteValue_SetsSameValue
public void CreatedAtAction_WithActionControllerAndNullRouteValue_SetsSameValue(
string controllerName)
{
// Arrange
var controller = new TestableController();
// Act
var result = controller.CreatedAtAction("SampleAction", controllerName, null, null);
// Assert
Assert.IsType<CreatedAtActionResult>(result);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal("SampleAction", result.ActionName);
Assert.Equal(controllerName, result.ControllerName);
}
示例11: ViewDataModelSetter_DoesNotThrow
public void ViewDataModelSetter_DoesNotThrow(object model, Type expectedType)
{
// Arrange
var activator = new ViewDataDictionaryControllerPropertyActivator(new EmptyModelMetadataProvider());
var actionContext = new ActionContext(
new DefaultHttpContext(),
new RouteData(),
new ControllerActionDescriptor());
var controllerContext = new ControllerContext(actionContext);
var controller = new TestableController();
activator.Activate(controllerContext, controller);
// Guard
Assert.NotNull(controller.ViewData);
// Act (does not throw)
controller.ViewData.Model = model;
// Assert
Assert.NotNull(controller.ViewData.ModelMetadata);
Assert.Equal(expectedType, controller.ViewData.ModelMetadata.ModelType);
}
示例12: Controller_Json_WithParameterValue_SetsResultData
public void Controller_Json_WithParameterValue_SetsResultData()
{
// Arrange
var controller = new TestableController();
var data = new object();
// Act
var actualJsonResult = controller.Json(data);
// Assert
Assert.IsType<JsonResult>(actualJsonResult);
Assert.Same(data, actualJsonResult.Value);
}
示例13: HttpNotFound_SetsStatusCode
public void HttpNotFound_SetsStatusCode()
{
// Arrange
var controller = new TestableController();
// Act
var result = controller.HttpNotFound();
// Assert
Assert.IsType<HttpNotFoundResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
}
示例14: File_WithStreamAndFileDownloadName
public void File_WithStreamAndFileDownloadName()
{
// Arrange
var mockHttpContext = new Mock<DefaultHttpContext>();
mockHttpContext.Setup(x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()));
var controller = new TestableController()
{
ActionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor())
};
var fileStream = Stream.Null;
// Act
var result = controller.File(fileStream, "application/pdf", "someDownloadName");
// Assert
Assert.NotNull(result);
Assert.Same(fileStream, result.FileStream);
Assert.Equal("application/pdf", result.ContentType.ToString());
Assert.Equal("someDownloadName", result.FileDownloadName);
mockHttpContext.Verify(
x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()),
Times.Once());
}
示例15: File_WithPathAndFileDownloadName
public void File_WithPathAndFileDownloadName()
{
// Arrange
var controller = new TestableController();
var path = Path.GetFullPath("somepath");
// Act
var result = controller.File(path, "application/pdf", "someDownloadName");
// Assert
Assert.NotNull(result);
Assert.Equal(path, result.FileName);
Assert.Equal("application/pdf", result.ContentType.ToString());
Assert.Equal("someDownloadName", result.FileDownloadName);
}