public void Intercept4Class()
        {
            var foobar = new ServiceCollection()
                         .AddInterception()
                         .AddSingletonInterceptable <Foobar, Foobar>()
                         .BuildServiceProvider()
                         .GetRequiredService <Foobar>();

            FakeInterceptorAttribute.Reset <Foobar>();
            foobar.Invoke1();
            Assert.Equal("", FakeInterceptorAttribute.GetResult <Foobar>());

            FakeInterceptorAttribute.Reset <Foobar>();
            foobar.Invoke2();
            Assert.Equal("1", FakeInterceptorAttribute.GetResult <Foobar>());

            foobar = new ServiceCollection()
                     .AddSingleton <Foobar, Foobar>()
                     .BuildInterceptableServiceProvider()
                     .GetRequiredService <Foobar>();

            FakeInterceptorAttribute.Reset <Foobar>();
            foobar.Invoke1();
            Assert.Equal("", FakeInterceptorAttribute.GetResult <Foobar>());

            FakeInterceptorAttribute.Reset <Foobar>();
            foobar.Invoke2();
            Assert.Equal("1", FakeInterceptorAttribute.GetResult <Foobar>());

            FakeInterceptorAttribute.Reset <Foobar>();
            foobar.Invoke3();
            Assert.Equal("1", FakeInterceptorAttribute.GetResult <Foobar>());
        }
Ejemplo n.º 2
0
        public async void InterceptInterface()
        {
            var foobar = new ServiceCollection()
                         .AddInterception()
                         .AddSingletonInterceptable <IFoobar, Bar>()
                         .BuildServiceProvider()
                         .GetRequiredService <IFoobar>();

            FakeInterceptorAttribute.Reset <IFoobar>();
            await foobar.Invoke1();

            Assert.Equal("1", FakeInterceptorAttribute.GetResult <IFoobar>());

            foobar = new ServiceCollection()
                     .AddInterception()
                     .AddSingletonInterceptable <IFoobar, Baz>()
                     .BuildServiceProvider()
                     .GetRequiredService <IFoobar>();
            FakeInterceptorAttribute.Reset <IFoobar>();
            await foobar.Invoke1();

            Assert.Equal("1", FakeInterceptorAttribute.GetResult <IFoobar>());

            foobar = new ServiceCollection()
                     .AddSingleton <IFoobar, Bar>()
                     .BuildInterceptableServiceProvider()
                     .GetRequiredService <IFoobar>();
            FakeInterceptorAttribute.Reset <IFoobar>();
            await foobar.Invoke1();

            Assert.Equal("1", FakeInterceptorAttribute.GetResult <IFoobar>());

            foobar = new ServiceCollection()
                     .AddSingleton <IFoobar, Baz>()
                     .BuildInterceptableServiceProvider()
                     .GetRequiredService <IFoobar>();
            FakeInterceptorAttribute.Reset <IFoobar>();
            await foobar.Invoke1();

            Assert.Equal("1", FakeInterceptorAttribute.GetResult <IFoobar>());
        }
Ejemplo n.º 3
0
        public async void Intercept4Class_Normal()
        {
            var foobar = new ServiceCollection()
                         .AddInterception()
                         .AddSingletonInterceptable(typeof(Foo <,>), typeof(Foo <,>))
                         .BuildServiceProvider()
                         .GetRequiredService <Foo <string, string> >();

            FakeInterceptorAttribute.Reset <Foo <int, int> >();
            await foobar.Invoke <int>("1", "2", 3);

            Assert.Equal("1", FakeInterceptorAttribute.GetResult <Foo <int, int> >());

            foobar = new ServiceCollection()
                     .AddInterception()
                     .AddSingleton(typeof(Foo <,>), typeof(Foo <,>))
                     .BuildInterceptableServiceProvider()
                     .GetRequiredService <Foo <string, string> >();

            FakeInterceptorAttribute.Reset <Foo <int, int> >();
            await foobar.Invoke <int>("1", "2", 3);

            Assert.Equal("1", FakeInterceptorAttribute.GetResult <Foo <int, int> >());
        }
Ejemplo n.º 4
0
        public async void Intercept4Interface_ExplicitlyImplemented()
        {
            var foobar = new ServiceCollection()
                         .AddInterception()
                         .AddSingletonInterceptable(typeof(IFoobar <,>), typeof(Bar <,>))
                         .BuildServiceProvider()
                         .GetRequiredService <IFoobar <string, string> >();

            FakeInterceptorAttribute.Reset <IFoobar <int, int> >();
            await foobar.Invoke <int>("1", "2", 3);

            Assert.Equal("1", FakeInterceptorAttribute.GetResult <IFoobar <int, int> >());

            foobar = new ServiceCollection()
                     .AddInterception()
                     .AddSingleton(typeof(IFoobar <,>), typeof(Bar <,>))
                     .BuildInterceptableServiceProvider()
                     .GetRequiredService <IFoobar <string, string> >();

            FakeInterceptorAttribute.Reset <IFoobar <int, int> >();
            await foobar.Invoke <int>("1", "2", 3);

            Assert.Equal("1", FakeInterceptorAttribute.GetResult <IFoobar <int, int> >());
        }