public void Test_ActionsWithArgumentMatchers_ArgActionsCallSpec()
        {
            var calculator = Substitute.For<ICalculator>();

            var numberOfCallsWhereFirstArgIsLessThan0 = 0;

            // 指定调用参数:
            // 第一个参数小于0
            // 第二个参数可以为任意的int类型值
            // 当此满足此规格时,为计数器加1。
            calculator
              .Multiply(
                Arg.Is<int>(x => x < 0),
                Arg.Do<int>(x => numberOfCallsWhereFirstArgIsLessThan0++)
              ).Returns(123);

            var results = new[] {
            calculator.Multiply(-4, 3),
            calculator.Multiply(-27, 88),
            calculator.Multiply(-7, 8),
            calculator.Multiply(123, 2) // 第一个参数大于0,所以不会被匹配
              };
            numberOfCallsWhereFirstArgIsLessThan0.ShouldBe(3);
            results.ShouldBe(new[] { 123, 123, 123, 0 });
            //Assert.AreEqual(3, numberOfCallsWhereFirstArgIsLessThan0); // 4个调用中有3个匹配上
            //CollectionAssert.AreEqual(results, new[] { 123, 123, 123, 0 }); // 最后一个未匹配
        }
示例#2
0
 public void EnumerablesOfNumerics()
 {
     DocExampleWriter.Document(() =>
     {
         var firstSet = new[] { 1.23m, 2.34m, 3.45001m };
         var secondSet = new[] { 1.4301m, 2.34m, 3.45m };
         firstSet.ShouldBe(secondSet, 0.1m);
     }, _testOutputHelper);
 }
示例#3
0
        public void Object_WithSubArray()
        {
            var result = new { hello = new [] { "hello", "world" } }.ToJson();

            result.ShouldBe("{\"hello\":[\"hello\", \"world\"]}");
        }
示例#4
0
        public void Object_WithSubObject()
        {
            var result = new { hello = new { world = "hello" } }.ToJson();

            result.ShouldBe("{\"hello\":{\"world\":\"hello\"}}");
        }
示例#5
0
        public void Object_With2Properties()
        {
            var result = new { hello = "world", world = "domination" }.ToJson();

            result.ShouldBe("{\"hello\":\"world\", \"world\":\"domination\"}");
        }
示例#6
0
        public void Object()
        {
            var result = new { hello = "world" }.ToJson();

            result.ShouldBe("{\"hello\":\"world\"}");
        }
示例#7
0
        public void Array()
        {
            var result = new [] { "hello", "world" }.ToJson();

            result.ShouldBe("[\"hello\", \"world\"]");
        }
示例#8
0
 public void ShouldBe_DecimalEnumerable_ShouldAllowTolerance()
 {
     var firstSet = new[] { 1.23m, 2.34m, 3.45001m };
     var secondSet = new[] { 1.2301m, 2.34m, 3.45m };
     firstSet.ShouldBe(secondSet, 0.01m);
 }