当前位置: 首页>>代码示例>>C#>>正文


C# Builder.Do方法代码示例

本文整理汇总了C#中Builder.Do方法的典型用法代码示例。如果您正苦于以下问题:C# Builder.Do方法的具体用法?C# Builder.Do怎么用?C# Builder.Do使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Builder的用法示例。


在下文中一共展示了Builder.Do方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetVerifyWithSequenceOfActionsTestCases

        public IEnumerable<TestCaseData> GetVerifyWithSequenceOfActionsTestCases()
        {
            var builder = new Builder<ILogWriter>();

            yield return builder.Do(lw => lw.Write(42))
                .Do(lw => lw.Write(42))
                .Expects(lw => lw.Write(42), Times.Exactly(2));
        }
开发者ID:SergeyTeplyakov,项目名称:VerificationFakes,代码行数:8,代码来源:MockActionsParametrizedTests.cs

示例2: GetVerifyWithOneFuncTestCases

        public static IEnumerable<TestCaseData> GetVerifyWithOneFuncTestCases()
        {
            var builder = new Builder<ILogWriter>();
            // Test cases for ILogWriter.WriteR(int)
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(42));
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(42));
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(It.IsAny<int>()));
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(It.IsInRange(41, 43)));

            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(It.IsInRange(44, 46)),
                                                        Times.Never());

            // Failure cases
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(21))
                .Throws(typeof(VerificationException));
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(It.IsInRange(43, 44)))
                .Throws(typeof(VerificationException));
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(42), Times.Never())
                .Throws(typeof(VerificationException));
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(42), Times.AtLeast(2))
                .Throws(typeof(VerificationException));
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(42), Times.Exactly(2))
                .Throws(typeof(VerificationException));
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.ToString().Length)
                .Throws(typeof(InvalidOperationException));

            // Test cases for ILogWriter.WriteR(string)
            yield return builder.Do(lw => lw.WriteR("foo")).Expects(lw => lw.WriteR("foo"));
            yield return builder.Do(lw => lw.WriteR("foo")).Expects(lw => lw.WriteR(It.IsAny<string>()));

            // Test cases for ILogWriter.WriteR(int, string)
            yield return builder.Do(lw => lw.WriteR(42, "Foo")).Expects(lw => lw.WriteR(42, "Foo"));
            yield return builder.Do(lw => lw.WriteR(42, "Foo"))
                .Expects(lw => lw.WriteR(It.IsAny<int>(), It.IsAny<string>()));
            yield return builder.Do(lw => lw.WriteR(42, "Foo"))
                .Expects(lw => lw.WriteR(It.IsInRange(1, 43), It.IsAny<string>()));

            // Tests cases with predicate-base verification
            yield return builder.Do(lw => lw.WriteR(42)).Expects(lw => lw.WriteR(It.Is<int>(n => n == 42)));
            yield return builder.Do(lw => lw.WriteR("Foooo"))
                .Expects(lw => lw.WriteR(It.Is<string>(s => s.ToLower().StartsWith("foo"))));
        }
开发者ID:SergeyTeplyakov,项目名称:VerificationFakes,代码行数:42,代码来源:MockFuncsParametrizedTests.cs


注:本文中的Builder.Do方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。