本文整理汇总了C#中System.Web.Mvc.ViewResult.Should方法的典型用法代码示例。如果您正苦于以下问题:C# ViewResult.Should方法的具体用法?C# ViewResult.Should怎么用?C# ViewResult.Should使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.ViewResult
的用法示例。
在下文中一共展示了ViewResult.Should方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeRedirect_GivenNotRedirect_ShouldFail
public void BeRedirect_GivenNotRedirect_ShouldFail()
{
ActionResult result = new ViewResult();
Action a = () => result.Should().BeRedirectResult();
a.ShouldThrow<Exception>()
.WithMessage("Expected ActionResult to be \"RedirectResult\", but found \"ViewResult\"");
}
示例2: BeEmpty_GivenNotEmpty_ShouldPass
public void BeEmpty_GivenNotEmpty_ShouldPass()
{
ActionResult result = new ViewResult();
Action a = () => result.Should().BeEmptyResult();
a.ShouldThrow<Exception>()
.WithMessage("Expected ActionResult to be \"EmptyResult\", but found \"ViewResult\"");
}
示例3: WithMasterName_GivenExpectedValue_ShouldPass
public void WithMasterName_GivenExpectedValue_ShouldPass()
{
ActionResult result = new ViewResult
{
MasterName = "master",
};
result.Should().BeViewResult().WithMasterName("master");
}
示例4: WithTempData_GivenExpectedValue_ShouldPass
public void WithTempData_GivenExpectedValue_ShouldPass()
{
ActionResult result = new ViewResult
{
TempData = new TempDataDictionary { { "key1", "value1" } }
};
result.Should().BeViewResult().WithTempData("key1", "value1");
}
示例5: WithViewName_GivenExpectedValue_ShouldPass
public void WithViewName_GivenExpectedValue_ShouldPass()
{
ActionResult result = new ViewResult
{
ViewName = "index",
};
result.Should().BeViewResult().WithViewName("index");
}
示例6: WithViewName_GivenUnexpectedValue_ShouldFail
public void WithViewName_GivenUnexpectedValue_ShouldFail()
{
var actualViewName = "index";
var expectedViewName = "xyz";
var failureMessage = FailureMessageHelper.Format(FailureMessages.ViewResultBase_ViewName, expectedViewName, actualViewName);
ActionResult result = new ViewResult
{
ViewName = actualViewName,
};
Action action = () => result.Should().BeViewResult().WithViewName(expectedViewName);
action.ShouldThrow<Exception>()
.WithMessage(failureMessage);
}
示例7: WithDefaultViewName_GivenUnexpectedValue_ShouldFail
public void WithDefaultViewName_GivenUnexpectedValue_ShouldFail()
{
string viewName = "index";
string failureMessage = FailureMessageHelper.Format(FailureMessages.ViewResultBase_WithDefaultViewName, viewName);
ActionResult result = new ViewResult
{
ViewName = viewName
};
Action action = () => result.Should().BeViewResult().WithDefaultViewName();
action.ShouldThrow<Exception>()
.WithMessage(failureMessage);
}
示例8: WithDefaultViewName_GivenExpectedValue_ShouldPass
public void WithDefaultViewName_GivenExpectedValue_ShouldPass()
{
ActionResult result = new ViewResult
{
ViewName = String.Empty
};
result.Should().BeViewResult().WithDefaultViewName();
}
示例9: ModelAs_Null_ShouldFail
public void ModelAs_Null_ShouldFail()
{
ActionResult result = new ViewResult();
string failureMessage = FailureMessageHelper.Format(FailureMessages.ViewResultBase_NullModel, typeof(Object).Name);
Action a = () => result.Should().BeViewResult().ModelAs<Object>();
a.ShouldThrow<Exception>()
.WithMessage(failureMessage);
}
示例10: ModelAs_GivenWrongType_ShouldFail
public void ModelAs_GivenWrongType_ShouldFail()
{
#if NETCOREAPP1_0
var result = new TestController().ViewSimpleModel();
#else
ActionResult result = new ViewResult
{
ViewData = new ViewDataDictionary("hello")
};
#endif
Action a = () => result.Should().BeViewResult().ModelAs<int>().Should().Be(2);
a.ShouldThrow<Exception>();
}
示例11: ModelAs_GivenUnexpectedValue_ShouldFail
public void ModelAs_GivenUnexpectedValue_ShouldFail()
{
#if NETCOREAPP1_0
var result = new TestController().ViewSimpleModel();
#else
ActionResult result = new ViewResult
{
ViewData = new ViewDataDictionary("hello")
};
#endif
Action a = () => result.Should().BeViewResult().ModelAs<string>().Should().Be("xyx");
a.ShouldThrow<Exception>();
}
示例12: ModelAs_GivenUnexpectedValue_ShouldFail
public void ModelAs_GivenUnexpectedValue_ShouldFail()
{
ActionResult result = new ViewResult
{
ViewData = new ViewDataDictionary("hello")
};
Action a = () => result.Should().BeViewResult().ModelAs<string>().Should().Be("xyx");
a.ShouldThrow<Exception>();
}
示例13: WithTempData_GivenTwoExpectedValues_ShouldPass
public void WithTempData_GivenTwoExpectedValues_ShouldPass()
{
#if NETCOREAPP1_0
var result = new TestController().ViewWithTwoTempData();
#else
ActionResult result = new ViewResult
{
TempData = new TempDataDictionary
{
{ "key1", "value1" },
{ "key2", "value2" },
}
};
#endif
result.Should().BeViewResult()
.WithTempData("key1", "value1")
.WithTempData("key2", "value2");
}
示例14: WithViewData_GivenUnexpectedKey_ShouldFail
public void WithViewData_GivenUnexpectedKey_ShouldFail()
{
var actualKey = "key1";
var expectedKey = "xyz";
#if NETCOREAPP1_0
var result = new TestController().ViewWithTwoViewData();
#else
ActionResult result = new ViewResult
{
ViewData = new ViewDataDictionary { { actualKey, "value1" } }
};
#endif
var failureMessage = FailureMessageHelper.Format(FailureMessages.ViewResultBase_ViewData_ContainsKey, expectedKey, actualKey);
Action a = () => result.Should().BeViewResult().WithViewData(expectedKey, "value1");
a.ShouldThrow<Exception>()
.WithMessage(failureMessage);
}
示例15: WithViewData_GivenUnexpectedValue_ShouldFail
public void WithViewData_GivenUnexpectedValue_ShouldFail()
{
var key = "key1";
var actualValue = "value1";
var expectedValue = "abc";
var failureMessage = FailureMessageHelper.Format(FailureMessages.ViewResultBase_ViewData_HaveValue, key, expectedValue, actualValue);
#if NETCOREAPP1_0
var result = new TestController().ViewWithOneViewData();
#else
ActionResult result = new ViewResult
{
ViewData = new ViewDataDictionary { { key, actualValue } }
};
#endif
Action a = () => result.Should().BeViewResult().WithViewData(key, expectedValue);
a.ShouldThrow<Exception>()
.WithMessage(failureMessage);
}