Exemple #1
0
        public void NSubstituteNote20()
        {
            //arrange
            var service = Substitute.For <IService>();
            var total   = Substitute.For <ITotal>();
            var send    = Substitute.For <ISend>();
            var sut     = new MyDemo(service, total, send);

            //act
            sut.Do();
            //assert
            Received.InOrder(() =>
            {
                service.GetCount();
                total.GetTotal();
                send.Send();
            });

            //若順序不對 會是錯誤訊息是

            /*
             * Expected to receive these calls in order:
             *
             *  IService.GetCount()
             *  ITotal.GetTotal()
             *  ISend.Send()
             *
             * Actually received matching calls in this order:
             *
             *  ISend.Send()
             *  IService.GetCount()
             *  ITotal.GetTotal()
             */
        }
Exemple #2
0
        public void NSubstituteNote26()
        {
            //arrange
            var func = Substitute.For <Func <string, bool> >();
            var sut  = new MyDemo(null, null);

            //act
            sut.DoB(func, true);
            //assert
            func.ReceivedWithAnyArgs().Invoke(Arg.Any <string>());
        }
Exemple #3
0
        public void NSubstituteNote18()
        {
            //arrange
            var service  = Substitute.For <IService>();
            var sut      = new MyDemo(service);
            var expected = "bosso";

            //act
            sut.Start();
            //assert
            Assert.AreEqual(expected, sut.Call.Method.Name);
        }
Exemple #4
0
        public void NSubstituteNote28()
        {
            //arrange
            var func = Substitute.For <Func <string, bool> >();

            func.Invoke(Arg.Any <string>()).Returns(false);
            var action = Substitute.For <Action <int> >();
            var sut    = new MyDemo(null, null);

            //act
            sut.DoC(func, action);
            //assert
            action.DidNotReceiveWithAnyArgs().Invoke(Arg.Any <int>());
        }
Exemple #5
0
        public void NSubstituteNote24()
        {
            //arrange
            var myAction = Substitute.For <Action <int, int> >();
            var myFunc   = Substitute.For <Func <int, bool> >();

            var sut = new MyDemo(myAction, myFunc);

            //act
            sut.DoA(1, 2, 3, false);
            //assert

            myFunc.DidNotReceiveWithAnyArgs().Invoke(Arg.Any <int>());
            myAction.DidNotReceiveWithAnyArgs().Invoke(Arg.Any <int>(), Arg.Any <int>());
        }
Exemple #6
0
        public void NSubstituteNote19()
        {
            //arrange
            var service   = Substitute.For <IService>();
            var sut       = new MyDemo(service);
            var funcCount = 0;

            service.GetFunc().Returns((x) => funcCount++);
            var expected = 2;

            //act
            sut.ExecFunc();
            //assert
            Assert.AreEqual(expected, funcCount);
        }
Exemple #7
0
        public void NSubstituteNote21()
        {
            //arrange
            var service = Substitute.For <IService>();

            service.GetCount()
            .ReturnsForAnyArgs(Task.FromResult(66));
            var sut = new MyDemo(service);

            var expected = 66;
            //act
            var actual = sut.Do().Result;

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void NSubstituteNote9()
        {
            //arrange
            //NSubstitute會產生一個ICalculator 假的實體出來
            ICalculator calculator = Substitute.For <ICalculator>();

            var myDemo = new MyDemo(calculator);

            //act
            myDemo.Action1(true);

            //assert
            calculator.Received(1).Clear(7);
            calculator.DidNotReceive().Clear(1);
            calculator.Received(1).Clear(Arg.Any <int>());
            calculator.ReceivedWithAnyArgs(1).Clear(default(int));
        }