Beispiel #1
0
        public static ISetup <T, TResult> AndResolveWith <T, TResult>(this ISetup <T, TResult> setup, Moqer magic)
            where T : class
        {
            setup.Returns(magic.Resolve <TResult>());

            return(setup);
        }
Beispiel #2
0
        public void ShouldResolveManyNestedConcreteOrNotDependencies()
        {
            var    magic = new MagicMoq.Moqer();
            Action act   = () => magic.Resolve <A>();

            act.ShouldNotThrow <ArgumentException>();
        }
Beispiel #3
0
        public void ShouldCreateClassWithDependenciesAndSetup_WithMoqAPI()
        {
            var magic = new MagicMoq.Moqer();
            var foo   = magic.Resolve <Foo>();

            magic.Setup <IFooDependency, int>(a => a.DoSomethingDifferent()).Returns(2);

            foo.DoSomething().Should().Be(2);
        }
Beispiel #4
0
        public void ShouldCreateClassWithDependenciesAndVerify_WithMoqAPI()
        {
            var magic = new MagicMoq.Moqer();
            var foo   = magic.Resolve <Foo>();

            foo.DoSomething();

            magic.Verify <IFooDependency>(a => a.DoSomethingDifferent(), Times.Once());
        }
Beispiel #5
0
        public void ShouldCreateClassWithConcreteDependency()
        {
            var magic = new MagicMoq.Moqer();

            magic.SetInstance(new ConcreteDependency(11));

            var classWithConcreteDependency = magic.Resolve <ClassWithConcreteDependency>();

            classWithConcreteDependency.DifferentStuff().Should().Be(11);
        }
Beispiel #6
0
        public void ShouldBeAbleToResolveNestedAndChainedSetups()
        {
            var magic = new MagicMoq.Moqer();

            magic.Setup <ISessionFactory, ISession>(a => a.OpenSession()).AndResolveWith(magic);
            magic.Setup <ISession, ITransaction>(a => a.OpenTransaction()).AndResolveWith(magic);

            var someoneThatUseSessionFactory = magic.Resolve <SomeoneThatUseISessionFactory>();

            someoneThatUseSessionFactory.DoSomething();

            magic.Verify <ISessionFactory>(a => a.OpenSession(), Times.Once());
            magic.Verify <ISession>(a => a.OpenTransaction(), Times.Once());
            magic.Verify <ISession>(a => a.DoSomething(), Times.Once());
            magic.Verify <ITransaction>(a => a.Commit(), Times.Once());
        }
Beispiel #7
0
        public void ShouldBeAbleToResolveNestedAndChainedSetups()
        {
            var magic = new MagicMoq.Moqer();

            magic.Setup<ISessionFactory, ISession>(a => a.OpenSession()).AndResolveWith(magic);
            magic.Setup<ISession, ITransaction>(a => a.OpenTransaction()).AndResolveWith(magic);

            var someoneThatUseSessionFactory = magic.Resolve<SomeoneThatUseISessionFactory>();

            someoneThatUseSessionFactory.DoSomething();

            magic.Verify<ISessionFactory>(a => a.OpenSession(), Times.Once());
            magic.Verify<ISession>(a => a.OpenTransaction(), Times.Once());
            magic.Verify<ISession>(a => a.DoSomething(), Times.Once());
            magic.Verify<ITransaction>(a => a.Commit(), Times.Once());
        }
Beispiel #8
0
        public void ShouldCreateClassWithConcreteDependency()
        {
            var magic = new MagicMoq.Moqer();
            magic.SetInstance(new ConcreteDependency(11));

            var classWithConcreteDependency = magic.Resolve<ClassWithConcreteDependency>();

            classWithConcreteDependency.DifferentStuff().Should().Be(11);
        }
Beispiel #9
0
        public void ShouldResolveManyNestedConcreteOrNotDependencies()
        {
            var magic = new MagicMoq.Moqer();
            Action act = () => magic.Resolve<A>();

            act.ShouldNotThrow<ArgumentException>();
        }
Beispiel #10
0
        public void ShouldCreateClassWithDependenciesAndVerify_WithMoqAPI()
        {
            var magic = new MagicMoq.Moqer();
            var foo = magic.Resolve<Foo>();

            foo.DoSomething();

            magic.Verify<IFooDependency>(a => a.DoSomethingDifferent(), Times.Once());
        }
Beispiel #11
0
        public void ShouldCreateClassWithDependenciesAndSetup_WithMoqAPI()
        {
            var magic = new MagicMoq.Moqer();
            var foo = magic.Resolve<Foo>();

            magic.Setup<IFooDependency, int>(a => a.DoSomethingDifferent()).Returns(2);

            foo.DoSomething().Should().Be(2);
        }