public void Setup()
 {
     // Arrange, arguably cleaner/tidier to do this in the test(s) that uses these, but I like to use my setup, plus it saves repetition which is good
     command    = Substitute.For <ICommand>();
     something  = new SomethingThatNeedsACommand(command);
     repeater   = new CommandRepeater(command, 3);
     calculator = Substitute.For <ICalculator>();
     dictionary = Substitute.For <IDictionary <string, int> >();
     watcher    = new CommandWatcher(command);
     runner     = new OnceOffCommandRunner(command);
 }
 public void TearDown()
 {
     // break it, break it down
     command    = null;
     something  = null;
     repeater   = null;
     calculator = null;
     dictionary = null;
     watcher    = null;
     runner     = null;
 }
Exemplo n.º 3
0
        public void Test_ClearReceivedCalls_ForgetPreviousCalls()
        {
            var command = Substitute.For <ICommand>();
            var runner  = new OnceOffCommandRunner(command);

            // 第一次运行
            runner.Run();
            command.Received().Execute();

            // 忘记前面对command的调用
            command.ClearReceivedCalls();

            // 第二次运行
            runner.Run();
            command.DidNotReceive().Execute();
        }
Exemplo n.º 4
0
        public void ICommand_Execute_ClearReceiveCallToForgetPrecall()
        {
            var command = Substitute.For <ICommand>();
            var runner  = new OnceOffCommandRunner(command);

            //first run
            runner.Run();
            command.Received().Execute();

            //forget pre-call on command
            command.ClearReceivedCalls();
            //ClearReceivedCalls()不会清理通过Returns()为替代实例设定的返回值。如果需要这样做,可通过再次调用Returns()来替换之前指定的值得方式来进行



            //second run
            runner.Run();
            command.DidNotReceive().Execute();
        }
Exemplo n.º 5
0
        public void Test_ClearReceivedCalls_ForgetPreviousCalls()
        {
            //清理以收到的呼叫
            var command = Substitute.For <ICommand>();
            var runner  = new OnceOffCommandRunner(command);

            // 第一次运行
            runner.Run();
            command.Received().Execute();

            // 忘记前面对command的调用
            command.ClearReceivedCalls();

            // 第二次运行
            runner.Run();
            command.DidNotReceive().Execute();


            /*
             * 執行過ClearReceivedCalls就會把實體給null,執行此段可以嘗試用偵錯去看實體,
             * 會發現建構子傳入的ICommand實體已經不存在
             */
        }