当前位置: 首页>>代码示例>>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;未经允许,请勿转载。