Ejemplo n.º 1
0
        public void RegisterObjectResolver()
        {
            var resolver = new Mock <ArgumentResolver <object> >();

            var obj = new object();

            resolver.Setup(_ => _.CanResolve(It.IsAny <ArgumentModel>())).Returns(true);
            resolver.Setup(_ => _.Resolve(It.IsAny <ArgumentModel>())).Returns(obj);

            var factory  = new DefaultArgumentResolverFactory();
            var dummyArg = new ArgumentModel();

            factory.Register(resolver.Object);

            var createdResolver_1 = factory.CreateResolver(typeof(object));
            var createdResolver_2 = factory.CreateResolver <object>();

            Assert.NotNull(createdResolver_1);
            Assert.NotNull(createdResolver_2);

            Assert.True(createdResolver_1.CanResolve(dummyArg));
            Assert.True(createdResolver_2.CanResolve(dummyArg));

            Assert.Same(obj, createdResolver_1.Resolve(dummyArg));
            Assert.Same(obj, createdResolver_2.Resolve(dummyArg));
        }
Ejemplo n.º 2
0
        public void CreateEnumResolver()
        {
            var factory = new DefaultArgumentResolverFactory();

            var output  = factory.CreateResolver <Output>();
            var output2 = factory.CreateResolver(typeof(Output));

            Assert.NotNull(output);
            Assert.NotNull(output2);

            Assert.Same(output, output2);
        }
Ejemplo n.º 3
0
        public void RegisterAndGet()
        {
            var instance = new RandomType();

            var mockResolver = new Mock <ArgumentResolver <RandomType> >();

            mockResolver.Setup(_ => _.CanResolve(It.IsAny <ArgumentModel>())).Returns(true);
            mockResolver.Setup(_ => _.Resolve(It.IsAny <ArgumentModel>())).Returns(instance);

            var factory = new DefaultArgumentResolverFactory();

            factory.Register(mockResolver.Object);

            var resolver = factory.CreateResolver <RandomType>();

            var model = new ArgumentModel();

            Assert.Same(mockResolver.Object, resolver);
            Assert.True(resolver.CanResolve(model));
            Assert.Same(instance, resolver.Resolve(model));

            mockResolver.VerifyAll();
        }