Whipped Cream uses this object so it can use Dependency Injection when creating instances of services hosts.
Inheritance: IInstanceProvider
        public void ApplyDispatchBehavior_AppliesCorrectInstanceProvider()
        {
            Mock<IUnityContainer> containerMock = new Mock<IUnityContainer>();
            DataServiceDependencyInstanceProvider expectedResult = new DataServiceDependencyInstanceProvider(containerMock.Object, typeof(int));
            containerMock.Setup(a => a.Resolve(typeof(DataServiceDependencyInstanceProvider), null, It.IsAny<ResolverOverride[]>())).Returns(expectedResult);
            System.ServiceModel.Description.IServiceBehavior target = new DataServiceDependencyBehavior(containerMock.Object);
            var host = new DummyServiceHost();
            var serviceDescription = new System.ServiceModel.Description.ServiceDescription();
            serviceDescription.ServiceType = typeof(int);

            target.ApplyDispatchBehavior(serviceDescription, host);

            foreach (var cd in host.ChannelDispatchers)
            {
                foreach (var ep in (cd as DummyChannelDispatcher).Endpoints)
                {
                    var instanceProvider = (host.ChannelDispatchers[0] as DummyChannelDispatcher).Endpoints[0].DispatchRuntime.InstanceProvider;

                    Assert.IsNotNull(instanceProvider, @"
            The instanceProvider should not be null because the behavior should have set it up.
            ");
                    Assert.AreEqual(expectedResult, instanceProvider, @"
            The instance provider is an instance of an object that wasn't expected.
            ");
                }
            }
        }
        public void Constructor_TypeSet()
        {
            Type targetType = typeof(string);
            DataServiceDependencyInstanceProvider provider = new DataServiceDependencyInstanceProvider(Mock.Of<IUnityContainer>(), targetType);

            Assert.AreEqual(targetType, provider.ServiceType, @"
            The ServiceType property should have been populated with the same type that was passed to the constructor.
            ");
        }
 public void Constructor_NullType()
 {
     try
     {
         DataServiceDependencyInstanceProvider provider = new DataServiceDependencyInstanceProvider(Mock.Of<IUnityContainer>(), null);
         Assert.Fail("We expected a System.ArgumentNullException when we passed null for the service type.");
     }
     catch(System.ArgumentNullException) { }
 }
 public void Constructor_NullContainer()
 {
     try
     {
         DataServiceDependencyInstanceProvider provider = new DataServiceDependencyInstanceProvider(null, typeof(int));
         Assert.Fail("We expected a System.ArgumentNullException when we passed null for the container.");
     }
     catch(System.ArgumentNullException) { }
 }
        public void Constructor_ContainerSet()
        {
            IUnityContainer container = Mock.Of<IUnityContainer>();
            DataServiceDependencyInstanceProvider provider = new DataServiceDependencyInstanceProvider(container, typeof(int));

            Assert.AreEqual(container, provider.Container, @"
            The Container property should have been populated with the same object that was passed to the constructor.
            ");
        }
        public void GetInstance_MultiParameter_ShouldReturnResolvedObjectFromContainer_Again()
        {
            Mock<IUnityContainer> containerMock = new Mock<IUnityContainer>();
            containerMock.Setup(a => a.Resolve(typeof(int), null)).Returns(31);
            IInstanceProvider target = new DataServiceDependencyInstanceProvider(containerMock.Object, typeof(int));

            var result = target.GetInstance(null, null);

            Assert.AreEqual(31, result, @"
            We want to require that the instance provider use the unity container to resolve the instances asked for.

            Since we didn't get 31 back from the call to GetInstance, we have to assume that the unity container wasn't
            used to resolve for the instance.
            ");
        }