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


C# Moq.Mock.Expect方法代碼示例

本文整理匯總了C#中Moq.Moq.Mock.Expect方法的典型用法代碼示例。如果您正苦於以下問題:C# Moq.Mock.Expect方法的具體用法?C# Moq.Mock.Expect怎麽用?C# Moq.Mock.Expect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Moq.Moq.Mock的用法示例。


在下文中一共展示了Moq.Mock.Expect方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ClientSideValidationRules_Helper_Passes_ActiveRuleProvider_Output_To_Formatter

        public void ClientSideValidationRules_Helper_Passes_ActiveRuleProvider_Output_To_Formatter()
        {
            // Arrange
            var html = new HtmlHelperMocks<object>().HtmlHelper;
            var arbitraryType = typeof (DateTime);
            var ruleProvider = new Moq.Mock<IRulesProvider>();
            var rules = new RuleSet(new[] { "someProperty" }.ToLookup(x => x, x => (Rule)new RequiredRule()));
            ruleProvider.Expect(x => x.GetRulesFromType(arbitraryType)).Returns(rules);
            ActiveRuleProviders.Providers.Clear();
            ActiveRuleProviders.Providers.Add(ruleProvider.Object);

            // Capture params passed to mockFormatter
            var mockFormatter = new Moq.Mock<IValidationConfigFormatter>(MockBehavior.Strict);
            RuleSet passedRules = null;
            Action<RuleSet> callback = x =>
            {
                passedRules = x;
            };
            mockFormatter.Expect(x => x.FormatRules(It.IsAny<RuleSet>()))
                .Callback(callback)
                .Returns("ok");
            ValidationInfo.Formatter = mockFormatter.Object;

            // Act
            var result = html.ClientSideValidationRules(arbitraryType);

            // Assert
            Assert.Equal("ok", result.ToString());
            Assert.Equal(1, passedRules.Keys.Count());
            Assert.Same(rules["someProperty"].Single(), passedRules["someProperty"].First());
        }
開發者ID:chakrit,項目名稱:xVal-mirror,代碼行數:31,代碼來源:HtmlHelpersTests.cs

示例2: StepDefinitions

 public StepDefinitions()
 {
     var mock = new Moq.Mock<IUserAuthentication>();
     mock.Expect(x => x.IsValidLogin("admin", "password")).Returns(true);
     //mock.Expect(x => x.IsValidLogin(It.IsAny<string>(), It.IsAny<string>())).Returns(false);
     _auth = mock.Object;
 }
開發者ID:JorgeMCSilva,項目名稱:NetPonto,代碼行數:7,代碼來源:UserAuthentication.cs

示例3: ClientSideValidationRules_Helper_Passes_Ruleset_Name_To_Formatter

        public void ClientSideValidationRules_Helper_Passes_Ruleset_Name_To_Formatter()
        {
            // Arrange
            var arbitraryType = typeof(DateTime);
            var html = new HtmlHelperMocks<object>().HtmlHelper;
            var mockFormatter = new Moq.Mock<IValidationConfigFormatter>(MockBehavior.Strict);
            mockFormatter.Expect(x => x.FormatRules(It.IsAny<RuleSet>()))
                .Returns("ok");
            ValidationInfo.Formatter = mockFormatter.Object;

            // Act
            var result = html.ClientSideValidationRules(arbitraryType);

            // Assert
            Assert.Equal("ok", result.ToString());
        }
開發者ID:chakrit,項目名稱:xVal-mirror,代碼行數:16,代碼來源:HtmlHelpersTests.cs

示例4: ClientSideValidationRules_Can_Take_Explicit_RuleSet_And_Passes_It_To_Formatter

        public void ClientSideValidationRules_Can_Take_Explicit_RuleSet_And_Passes_It_To_Formatter()
        {
            // Arrange
            var html = new HtmlHelperMocks<object>().HtmlHelper;
            var rules = new RuleSet(new[] { "someProperty" }.ToLookup(x => x, x => (Rule)new RequiredRule()));

            // Capture params passed to mockFormatter
            var mockFormatter = new Moq.Mock<IValidationConfigFormatter>(MockBehavior.Strict);
            mockFormatter.Expect(x => x.FormatRules(rules)).Returns("ok");

            ValidationInfo.Formatter = mockFormatter.Object;

            // Act
            var result = html.ClientSideValidationRules(rules);

            // Assert
            Assert.Equal("ok", result.ToString());
        }
開發者ID:chakrit,項目名稱:xVal-mirror,代碼行數:18,代碼來源:HtmlHelpersTests.cs

示例5: ClientSideValidation_Can_Suppress_Script_Tags

        public void ClientSideValidation_Can_Suppress_Script_Tags()
        {
            // Arrange
            var html = new HtmlHelperMocks<object>().HtmlHelper;

            // Capture params passed to mockFormatter
            var mockFormatter = new Moq.Mock<IValidationConfigFormatter>(MockBehavior.Strict);
            mockFormatter.Expect(x => x.FormatRules(RuleSet.Empty)).Returns("{rulesWouldGoHere}");

            ValidationInfo.Formatter = mockFormatter.Object;

            // Act
            var result = html.ClientSideValidation("my.prefix", RuleSet.Empty);
            result.SuppressScriptTags();
            var formattedAsString = result.ToString();

            // Assert
            Assert.Equal(@"xVal.AttachValidator(""my.prefix"", {rulesWouldGoHere}, {})", formattedAsString);
        }
開發者ID:chakrit,項目名稱:xVal-mirror,代碼行數:19,代碼來源:HtmlHelpersTests.cs

示例6: ClientSideValidation_Wraps_Output_From_Rule_Formatter

        public void ClientSideValidation_Wraps_Output_From_Rule_Formatter()
        {
            // Arrange
            var html = new HtmlHelperMocks<object>().HtmlHelper;

            // Capture params passed to mockFormatter
            var mockFormatter = new Moq.Mock<IValidationConfigFormatter>(MockBehavior.Strict);
            mockFormatter.Expect(x => x.FormatRules(RuleSet.Empty)).Returns("{rulesWouldGoHere}");

            ValidationInfo.Formatter = mockFormatter.Object;

            // Act
            var result = html.ClientSideValidation("my.prefix", RuleSet.Empty);
            var formattedAsString = result.ToString();

            // Assert
            Assert.Equal(@"<script type=""text/javascript"">xVal.AttachValidator(""my.prefix"", {rulesWouldGoHere}, {})</script>", formattedAsString);
        }
開發者ID:chakrit,項目名稱:xVal-mirror,代碼行數:18,代碼來源:HtmlHelpersTests.cs

示例7: ClientSideValidation_Includes_ValidationSummaryConfig

        public void ClientSideValidation_Includes_ValidationSummaryConfig()
        {
            // Arrange
            var html = new HtmlHelperMocks<object>().HtmlHelper;

            // Mock away the formatter so it doesn't affect this test
            var mockFormatter = new Moq.Mock<IValidationConfigFormatter>();
            mockFormatter.Expect(x => x.FormatRules(It.IsAny<RuleSet>())).Returns("rules");
            ValidationInfo.Formatter = mockFormatter.Object;

            // Act
            var result = html.ClientSideValidation("my.prefix", RuleSet.Empty);
            result.SuppressScriptTags().UseValidationSummary("testElementId", "Here's the validation summary message");
            var formattedAsString = result.ToString();

            // Assert
            Assert.Equal(@"xVal.AttachValidator(""my.prefix"", rules, {""ValidationSummary"":{""ElementID"":""testElementId"",""HeaderMessage"":""Here\u0027s the validation summary message""}})", formattedAsString);
        }
開發者ID:chakrit,項目名稱:xVal-mirror,代碼行數:18,代碼來源:HtmlHelpersTests.cs


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