Exemplo n.º 1
0
        public void CallA_CallsDependencyA()
        {
            var subject = _moq.Create <SomeClass>();

            subject.CallA();

            _moq.Of <IDepencyA>().Verify(x => x.Call(), Times.Once);
        }
Exemplo n.º 2
0
        public void DoWork_CallsRepositoryGetData()
        {
            // 1 -  First create an instance of Moqqer which will
            //      act as a container for Mocks and Objects.
            _moq = new Moqqer();

            // 2 -  Get Moqqer to create an instance of some class you want to test.
            // It will auto inject mocks in the its constructor.
            _subject = _moq.Create <SomeClass>();

            // 3 -  Call the mothod you want to test on SomeClass
            _subject.CallA(); // Calls private field IDependencyA.Call()

            // 4 -  Verify a mock that was auto injected was called.
            _moq.Of <IDepencyA>()
            .Verify(x => x.Call(), Times.Once);

            //      Alternatively use the Verify extension method
            _moq.Verify <IDepencyA>(x => x.Call())
            .Once();

            // 5 -  Test and Refactor to your hearts content
            //      without worrying about changing the constructor calls!
        }
Exemplo n.º 3
0
 public static MoqFluentVerifyBuilder <T> .IHasVerifyAction Verify <T>
     (this Moqqer moq, Expression <Action <T> > action)
     where T : class
 {
     return(new MoqFluentVerifyBuilder <T>(moq.Of <T>(), action));
 }
Exemplo n.º 4
0
        public void ConstrcutorInejction()
        {
            var subject = _moq.Create <SomeClass>();

            var depencyA = _moq.Of <IDepencyA>().Object;
            var depencyB = _moq.Of <IDepencyB>().Object;
            var expected = _moq.Of <IMockSetup>().Object;

            subject.A.Should().BeSameAs(depencyA);
            subject.B.Should().BeSameAs(depencyB);
            subject.Mock.Should().BeSameAs(expected);
        }