public void Instanciating_MustThrow()
        {
            Type interfaceType      = typeof(IProxy);
            Type implementationType = InterfaceProxyHelpers.GetImplementationTypeOfInterface(interfaceType);

            this.Container.RegisterType(interfaceType, implementationType);

            this.Container.Invoking(x => x.Resolve <IProxy>())
            .ShouldThrow <ResolutionFailedException>()
            .WithInnerException <InvalidOperationException>();
        }
        public static IUnityContainer RegisterInterfaceProxy(this IUnityContainer container, Type interfaceType, string name, LifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
        {
            Guard.ArgumentNotNull(interfaceType, "interfaceType");
            Guard.ArgumentNotNull(container, "container");
            Guard.ArgumentNotNull(injectionMembers, "injectionMembers");

            if (!injectionMembers.OfType <Intercept>().Any())
            {
                throw new ArgumentOutOfRangeException(
                          "injectionMembers",
                          @"An interface proxy requires at least one interceptor to provide it's implementation.
Add an Intercept or Intercept<T> injection member to the registration.");
            }

            Type implementationType = InterfaceProxyHelpers.GetImplementationTypeOfInterface(interfaceType);

            return(container.RegisterType(interfaceType, implementationType, name, lifetimeManager, injectionMembers));
        }
Exemple #3
0
 public void GetImplementationTypeOfInterface_WhenTypeIsNotInterface_MustThrow(Type interfaceType)
 {
     this.Invoking(x => InterfaceProxyHelpers.GetImplementationTypeOfInterface(interfaceType))
     .ShouldThrow <ArgumentOutOfRangeException>()
     .Where(ex => ex.ParamName == "interfaceType");
 }
Exemple #4
0
 public void GetImplementationTypeOfInterface_WhenThereIsNoImplementation_MustThrow()
 {
     this.Invoking(x => InterfaceProxyHelpers.GetImplementationTypeOfInterface(typeof(IWithoutImplementation)))
     .ShouldThrow <InvalidOperationException>()
     .Where(ex => ex.Message.Contains("There is no auto-generated implementation"));
 }
Exemple #5
0
 public void GetImplementationTypeOfInterface_MustReturnImplementationType()
 {
     InterfaceProxyHelpers.GetImplementationTypeOfInterface(typeof(IWithImplementation))
     .Should().Be(typeof(IWithImplementationImplementation));
 }