public void Test_ActionsWithArgumentMatchers_InvokingCallbacks()
        {
            // Arrange
            var cart      = Substitute.For <ICart>();
            var events    = Substitute.For <IEvents>();
            var processor = Substitute.For <IOrderProcessor>();

            cart.OrderId = 3;
            // 设置 processor 当处理订单ID为3时,调用回调函数,参数为true
            processor.ProcessOrder(3, Arg.Invoke(true));

            // Act
            var command = new OrderPlacedCommand(processor, events);

            command.Execute(cart);

            // Assert
            events.Received().RaiseOrderProcessed(3);
        }
示例#2
0
        public void OrderPlacedCommand_Execute_InvokeCallbackWhenArgsMatched()
        {
            //Arrange
            var cart      = Substitute.For <ICart>();
            var events    = Substitute.For <IEvents>();
            var processor = Substitute.For <IOrderProcessor>();

            cart.OrderId = 3;
            //设置processor:当ID=3时,调用回调函数,参数为true
            processor.ProcessOrder(3, Arg.Invoke(true));
            //Arg.InvokeDelegate()

            //Act
            var command = new OrderPlacedCommand(processor, events);

            command.Execute(cart);

            //Assert
            events.Received().RaiseOrderProcessed(3);
        }