Exemplo n.º 1
0
 public GenericInterfaceAopProxy(
     IGenericInterface <T, TA> realInstance,
     InterceptionHandler interceptionHandler) : this()
 {
     _realInstance        = realInstance;
     _interceptionHandler = interceptionHandler;
 }
        public void GenericInterfaceExportInRegistrationBuilder()
        {
            CompositionContainer       container = CreateRegistrationBuilderContainer(typeof(ClassExportingInterface <>));
            IGenericInterface <string> v         = container.GetExportedValue <IGenericInterface <string> >();

            Assert.IsAssignableFrom <IGenericInterface <string> >(v);
        }
Exemplo n.º 3
0
        public ImportGeneric(IGenericInterface <T> importGenericInterface)
        {
            if (importGenericInterface == null)
            {
                throw new ArgumentNullException("importGenericInterface");
            }

            Instances++;
        }
 public void SetUp()
 {
     this.mockInterface3 = Mock.Create <IInterface3>();
     this.mockGenericInterfaceListInt = Mock.Create <IGenericInterface <List <int> > >();
     this.mockGenericInterfaceListSomeOtherInterface = Mock.Create <IGenericInterface <List <ISomeOtherInterface> > >();
     this.mockGenericInterfaceBool       = Mock.Create <IGenericInterface <bool> >();
     this.mockGenericInterfaceListString = Mock.Create <IGenericInterface <List <string> > >();
     this.mockSomeInterface = Mock.Create <ISomeInterface>();
 }
        public ImportGeneric(IGenericInterface <T> importGenericInterface)
        {
            if (importGenericInterface == null)
            {
                throw new ArgumentNullException(nameof(importGenericInterface));
            }

            System.Threading.Interlocked.Increment(ref counter);
        }
 public void TestInitialize()
 {
     this.fakeInterface3 = A.Fake <IInterface3>();
     this.fakeGenericInterfaceListInt = A.Fake <IGenericInterface <List <int> > >();
     this.fakeGenericInterfaceListSomeOtherInterface = A.Fake <IGenericInterface <List <ISomeOtherInterface> > >();
     this.fakeGenericInterfaceBool       = A.Fake <IGenericInterface <bool> >();
     this.fakeGenericInterfaceListString = A.Fake <IGenericInterface <List <string> > >();
     this.fakeSomeInterface = A.Fake <ISomeInterface>();
 }
Exemplo n.º 7
0
 public ClassWithGenericInterfaceTests()
 {
     this.subInterface3 = Substitute.For <IInterface3>();
     this.subGenericInterfaceListInt = Substitute.For <IGenericInterface <List <int> > >();
     this.subGenericInterfaceListSomeOtherInterface = Substitute.For <IGenericInterface <List <ISomeOtherInterface> > >();
     this.subGenericInterfaceBool       = Substitute.For <IGenericInterface <bool> >();
     this.subGenericInterfaceListString = Substitute.For <IGenericInterface <List <string> > >();
     this.subSomeInterface = Substitute.For <ISomeInterface>();
 }
Exemplo n.º 8
0
 public void SetUp()
 {
     this.stubInterface3 = MockRepository.GenerateStub <IInterface3>();
     this.stubGenericInterfaceListInt = MockRepository.GenerateStub <IGenericInterface <List <int> > >();
     this.stubGenericInterfaceListSomeOtherInterface = MockRepository.GenerateStub <IGenericInterface <List <ISomeOtherInterface> > >();
     this.stubGenericInterfaceBool       = MockRepository.GenerateStub <IGenericInterface <bool> >();
     this.stubGenericInterfaceListString = MockRepository.GenerateStub <IGenericInterface <List <string> > >();
     this.stubSomeInterface = MockRepository.GenerateStub <ISomeInterface>();
 }
Exemplo n.º 9
0
 public void TestInitialize()
 {
     this.subInterface3 = Substitute.For <IInterface3>();
     this.subGenericInterfaceListInt = Substitute.For <IGenericInterface <List <int> > >();
     this.subGenericInterfaceListSomeOtherInterface = Substitute.For <IGenericInterface <List <ISomeOtherInterface> > >();
     this.subGenericInterfaceBool       = Substitute.For <IGenericInterface <bool> >();
     this.subGenericInterfaceListString = Substitute.For <IGenericInterface <List <string> > >();
     this.subSomeInterface = Substitute.For <ISomeInterface>();
 }
Exemplo n.º 10
0
 public ClassWithGenericInterfaceTests()
 {
     this.fakeInterface3 = A.Fake <IInterface3>();
     this.fakeGenericInterfaceListInt = A.Fake <IGenericInterface <List <int> > >();
     this.fakeGenericInterfaceListSomeOtherInterface = A.Fake <IGenericInterface <List <ISomeOtherInterface> > >();
     this.fakeGenericInterfaceBool       = A.Fake <IGenericInterface <bool> >();
     this.fakeGenericInterfaceListString = A.Fake <IGenericInterface <List <string> > >();
     this.fakeSomeInterface = A.Fake <ISomeInterface>();
 }
Exemplo n.º 11
0
    public void GenericWithOneTypeParameter()
    {
        IServiceProvider serviceProvider = Build(services => services.AddSingleton(typeof(IGenericInterface <>), typeof(GenericInterface <>)));

        IGenericInterface <T1> simpleInterface = serviceProvider.GetRequiredService <IGenericInterface <T1> >();

        Assert.NotNull(simpleInterface);

        Assert.Equal(typeof(T1), actual: simpleInterface.ItemType);
    }
Exemplo n.º 12
0
        public NonGenericWrapper(IGenericInterface remote)
        {
            instance = remote;

            // wrap generic methods
            getDefaultHolder = new GenericMethodHolder(typeof(IGenericInterface), "GetDefault", 1, new Type[0]);
            equalsHolder = new GenericMethodHolder(typeof(IGenericInterface), "Equals", 1, new Type[] { null, null });
            doSomethingHolder = new GenericMethodHolder(typeof(IGenericInterface), "DoSomething", 3, new Type[] { null, null, null });
            computeHolder = new GenericMethodHolder(typeof(IGenericInterface), "Compute", 2, new Type[] { null, typeof(int), typeof(string) });
        }
Exemplo n.º 13
0
        public static bool GenericTest8()
        {
            GenericClassTest <int> genericObject = new GenericClassTest <int>();

            genericObject.value = 10;

            IGenericInterface <int> genericInterface = genericObject;

            return(genericInterface.ReturnIt() == 10);
        }
Exemplo n.º 14
0
        public NonGenericWrapper(IGenericInterface remote)
        {
            instance = remote;

            // wrap generic methods
            getDefaultHolder  = new GenericMethodHolder(typeof(IGenericInterface), "GetDefault", 1, new Type[0]);
            equalsHolder      = new GenericMethodHolder(typeof(IGenericInterface), "Equals", 1, new Type[] { null, null });
            doSomethingHolder = new GenericMethodHolder(typeof(IGenericInterface), "DoSomething", 3, new Type[] { null, null, null });
            computeHolder     = new GenericMethodHolder(typeof(IGenericInterface), "Compute", 2, new Type[] { null, typeof(int), typeof(string) });
        }
Exemplo n.º 15
0
        public static bool GenericTest10()
        {
            var genericObject = new GenericClassTest <TestObjectInherit>();

            genericObject.SetValue(new TestObjectInherit(5, 9, 6));

            IGenericInterface <TestObject> genericInterface = genericObject;

            TestObject        objBase    = genericInterface.ReturnIt();
            TestObjectInherit objDerived = (TestObjectInherit)objBase;

            return(objDerived.A == 5 && objDerived.B == 9 && objDerived.C == 6);
        }
Exemplo n.º 16
0
        //https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/covariance-contravariance/using-variance-in-delegates
        //https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/covariance-contravariance/using-variance-for-func-and-action-generic-delegates

        static void Main(string[] args)
        {
            //Delegate Covariance / Contrvariance
            {
                Action <A> f1 = ProcessA;
                //Contrvariance - function which accepts less derived type, can be assigned to more derived type delegate
                //All Action delegate are contrvariant
                Action <B> f2 = f1;

                ContrvariantDelegate <A> f3 = ProcessA;
                //Direct contrvariant assignment is always supported (because it is basically wrapping in new Action())
                ContrvariantDelegate <B> f5 = ProcessA;
                //This won't compile if "in" keyword is missing in Delegate definition
                ContrvariantDelegate <B> f6 = f3;

                CovariantDelegate <B> f7 = ReturnB;
                //Direct covariant assignment is always supported (because it is basically wrapping in new Action())
                CovariantDelegate <A> f8 = ReturnB;
                //This won't compile if "out" keyword is missing in Delegate definition
                CovariantDelegate <A> f9 = f7;
            }

            //Collection Invariance
            //Those lines won't compile
            //List<A> list = new List<B>();
            //IList<A> list1 = new List<B>();
            //IEnumerable though supports covariance because you can not change it
            var             list2 = new List <B>();
            IEnumerable <A> list3 = list2;

            //Arrays support variance but can emmit runtime exception
            A[] array = new B[1];
            //Like in this case
            array[0] = new A();

            //Interface Covariance Contrvariance
            //https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/covariance-contravariance/creating-variant-generic-interfaces
            ICovariant <B> interfaceExample = null;
            //This won't compile without "out" keyword
            ICovariant <A> i = interfaceExample;

            IContrvariant <A> interfaceExample2 = null;
            //This won't compile without "in" keyword
            IContrvariant <B> i2 = interfaceExample2;

            //Accepts A, returns B
            IGenericInterface <A, B> interfaceExample3 = null;
            //Accepts B, returns A
            IGenericInterface <B, A> i3 = interfaceExample3;
            //Basically Contrvariance allows to accept more derived arguments and covariance to return less derived arguments
        }
Exemplo n.º 17
0
        public void SelectorWorksForGenericMethods()
        {
            ProxyGenerationOptions  options             = new ProxyGenerationOptions();
            CallCountingInterceptor countingInterceptor = new CallCountingInterceptor();

            options.Selector = new TypeInterceptorSelector <CallCountingInterceptor>();
            IGenericInterface target =
                generator.CreateInterfaceProxyWithTarget(typeof(IGenericInterface), new GenericClass(), options,
                                                         new AddTwoInterceptor(),
                                                         countingInterceptor) as IGenericInterface;

            Assert.IsNotNull(target);
            int result = target.GenericMethod <int>();

            Assert.AreEqual(1, countingInterceptor.Count);
            Assert.AreEqual(0, result);
            string result2 = target.GenericMethod <string>();

            Assert.AreEqual(2, countingInterceptor.Count);
            Assert.AreEqual(default(string), result2);
        }
Exemplo n.º 18
0
 public ClosedGenericDecorator(IGenericInterface <SimpleImplementation1> d)
 {
     this.Inner = d;
 }
Exemplo n.º 19
0
 public OpenGenericDecorator(IGenericInterface <T> d)
 {
     Inner = d;
 }
 public void SetUp()
 {
     this.subGenericInterfaceBool       = Substitute.For <IGenericInterface <bool> >();
     this.subGenericInterfaceListString = Substitute.For <IGenericInterface <List <string> > >();
     this.subSomeInterface = Substitute.For <ISomeInterface>();
 }
 public ClassWithGenericInterfaceTests()
 {
     this.stubGenericInterfaceBool       = MockRepository.GenerateStub <IGenericInterface <bool> >();
     this.stubGenericInterfaceListString = MockRepository.GenerateStub <IGenericInterface <List <string> > >();
     this.stubSomeInterface = MockRepository.GenerateStub <ISomeInterface>();
 }
Exemplo n.º 22
0
 public UoWData()
 {
     context       = new CentisoftContext();
     CustomerRepo  = new GenericRepo <Customer>(context);
     DeveloperRepo = new GenericRepo <Developer>(context);
 }
Exemplo n.º 23
0
 public GenericInterfaceAdapter(IGenericInterface <T> inner)
 {
     this.inner = inner;
 }
Exemplo n.º 24
0
 public ClassWithGenericInterfaceTests()
 {
     this.mockGenericInterfaceBool       = Mock.Create <IGenericInterface <bool> >();
     this.mockGenericInterfaceListString = Mock.Create <IGenericInterface <List <string> > >();
     this.mockSomeInterface = Mock.Create <ISomeInterface>();
 }
Exemplo n.º 25
0
 public void TestInitialize()
 {
     this.stubGenericInterfaceBool       = MockRepository.GenerateStub <IGenericInterface <bool> >();
     this.stubGenericInterfaceListString = MockRepository.GenerateStub <IGenericInterface <List <string> > >();
     this.stubSomeInterface = MockRepository.GenerateStub <ISomeInterface>();
 }
 public void TestInitialize()
 {
     this.mockGenericInterfaceBool       = Mock.Create <IGenericInterface <bool> >();
     this.mockGenericInterfaceListString = Mock.Create <IGenericInterface <List <string> > >();
     this.mockSomeInterface = Mock.Create <ISomeInterface>();
 }
Exemplo n.º 27
0
 public ClassWithGenericInterface(IGenericInterface <bool> theGenericInterface, IGenericInterface <List <string> > theOtherGenericInterface, ISomeInterface someInterface)
 {
 }
Exemplo n.º 28
0
 private static void Foo(IGenericInterface <Ford> o)
 {
 }
Exemplo n.º 29
0
 public CtorOrderProcessor(IGenericInterface <string> orderRepository)
 {
     OrderRepository = orderRepository;
 }
Exemplo n.º 30
0
 public ClosedGenericAdapter(IGenericInterface <SimpleImplementation2> inner)
 {
     Inner = inner;
 }
Exemplo n.º 31
0
 public GenericConsumerB(IGenericInterface <object> _)
 {
     Console.WriteLine("{0} got {1}", nameof(NonGenericConsumerA), _.GetType().Name);
 }