Пример #1
0
            public void ResolveDependency_WhenArgumentIsNullAndTypeIsScalar_ResolvesDependencyWithServiceLocatorByType()
            {
                var serviceLocator     = MockRepository.GenerateMock <IServiceLocator>();
                var resourceLocator    = MockRepository.GenerateMock <IResourceLocator>();
                var dependencyResolver = new DefaultObjectDependencyResolver(serviceLocator, resourceLocator);
                var service            = MockRepository.GenerateStub <IService>();

                serviceLocator.Expect(x => x.HasService(typeof(IService))).Return(true);
                serviceLocator.Expect(x => x.Resolve(typeof(IService))).Return(service);

                var result = dependencyResolver.ResolveDependency("service", typeof(IService), null);

                Assert.Multiple(() =>
                {
                    Assert.IsTrue(result.IsSatisfied);
                    Assert.IsInstanceOfType <IService>(result.Value);
                    Assert.AreSame(service, result.Value);
                });

                serviceLocator.VerifyAllExpectations();
                resourceLocator.VerifyAllExpectations();
            }