當前位置: 首頁>>代碼示例>>C#>>正文


C# ViewResult.Should方法代碼示例

本文整理匯總了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\"");
 }
開發者ID:jrnail23,項目名稱:FluentAssertions.MVC,代碼行數:7,代碼來源:ActionResultAssertions_Tests.cs

示例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\"");
 }
開發者ID:jrnail23,項目名稱:FluentAssertions.MVC,代碼行數:7,代碼來源:ActionResultAssertions_Tests.cs

示例3: WithMasterName_GivenExpectedValue_ShouldPass

        public void WithMasterName_GivenExpectedValue_ShouldPass()
        {
            ActionResult result = new ViewResult
            {
                MasterName = "master",
            };

            result.Should().BeViewResult().WithMasterName("master");
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:9,代碼來源:ViewResultAssertions_Tests.cs

示例4: WithTempData_GivenExpectedValue_ShouldPass

        public void WithTempData_GivenExpectedValue_ShouldPass()
        {
            ActionResult result = new ViewResult
            {
                TempData = new TempDataDictionary { { "key1", "value1" } }
            };

            result.Should().BeViewResult().WithTempData("key1", "value1");
        }
開發者ID:rikrak,項目名稱:FluentAssertions.MVC,代碼行數:9,代碼來源:ViewResultAssertions_Tests.cs

示例5: WithViewName_GivenExpectedValue_ShouldPass

        public void WithViewName_GivenExpectedValue_ShouldPass()
        {
            ActionResult result = new ViewResult
            {
                ViewName = "index",
            };

            result.Should().BeViewResult().WithViewName("index");
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:9,代碼來源:ViewResultAssertions_Tests.cs

示例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);
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:15,代碼來源:ViewResultAssertions_Tests.cs

示例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);
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:15,代碼來源:ViewResultAssertions_Tests.cs

示例8: WithDefaultViewName_GivenExpectedValue_ShouldPass

        public void WithDefaultViewName_GivenExpectedValue_ShouldPass()
        {
            ActionResult result = new ViewResult
            {
                ViewName = String.Empty
            };

            result.Should().BeViewResult().WithDefaultViewName();
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:9,代碼來源:ViewResultAssertions_Tests.cs

示例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);
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:10,代碼來源:ViewResultAssertions_Tests.cs

示例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>();
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:14,代碼來源:ViewResultAssertions_Tests.cs

示例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>();
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:14,代碼來源:ViewResultAssertions_Tests.cs

示例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>();
        }
開發者ID:rikrak,項目名稱:FluentAssertions.MVC,代碼行數:10,代碼來源:ViewResultAssertions_Tests.cs

示例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");
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:19,代碼來源:ViewResultAssertions_Tests.cs

示例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);
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:20,代碼來源:ViewResultAssertions_Tests.cs

示例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);
        }
開發者ID:kevinkuszyk,項目名稱:FluentAssertions.MVC,代碼行數:21,代碼來源:ViewResultAssertions_Tests.cs


注:本文中的System.Web.Mvc.ViewResult.Should方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。