コード例 #1
0
        /// <summary>
        ///     The initialize.
        /// </summary>
        public AspectRegistrationTests()
        {
            services = new ServiceCollection();
            services.AddAspectSupport();
            services.AddTransient <ITestInterface, MyTestInterface>();
            services.AddLogging(x => { x.AddConsole(); });
            IAspectConfigurationProvider aspectConfigurationProvider = new InMemoryAspectConfigurationProvider();
            var aspectConfiguration = new AspectConfiguration(new ServiceDescriptor(IInterfaceType, MyTestInterfaceType, ServiceLifetime.Transient));

            aspectConfiguration.AddEntry(TestAspectFactory.Type, methodsToIntercept: IInterfaceType.GetMethods());
            aspectConfiguration.AddEntry(TestAspectFactory2.Type, methodsToIntercept: IInterfaceType.GetMethods());
            aspectConfigurationProvider.AddEntry(aspectConfiguration);
            services.AddAspectSupport(aspectConfigurationProvider);
        }
        /// <summary>
        ///     The test initialize.
        /// </summary>
        public BaseAspectTests()
        {
            var loggerFactory = new Mock <ILoggerFactory>();

            logger = new Mock <ILogger>();
            loggerFactory.Setup(x => x.CreateLogger(typeof(MyTestInterface).FullName)).Returns(logger.Object);
            var aspectConfigurationProvider = new Mock <IAspectConfigurationProvider>().Object;
            var aspectConfiguration         = new AspectConfiguration(new ServiceDescriptor(ITestInterfaceType, MyTestInterface.Type, ServiceLifetime.Transient));

            aspectConfiguration.AddEntry(TestAspectFactory.Type, methodsToIntercept: ITestInterfaceType.GetMethods());
            aspectConfiguration.AddEntry(TestAspectFactory2.Type, methodsToIntercept: ITestInterfaceType.GetMethods());
            aspectConfigurationProvider.AddEntry(aspectConfiguration);
            instance = BaseAspectTestClass <ITestInterface> .Create(new MyTestInterface(), typeof(MyTestInterface), loggerFactory.Object, aspectConfigurationProvider);
        }
コード例 #3
0
        /// <summary>
        ///     The test initialize.
        /// </summary>
        public LoggingAspectTests()
        {
            loggerFactory = new Mock <ILoggerFactory>();
            logger        = new Mock <ILogger>();
            aspectConfigurationProvider = new InMemoryAspectConfigurationProvider();
            var aspectConfiguration = new AspectConfiguration(new ServiceDescriptor(AspectRegistrationTests.IInterfaceType, AspectRegistrationTests.MyTestInterfaceType, ServiceLifetime.Transient));

            aspectConfiguration.AddEntry(LoggingAspectFactory.LoggingAspectFactoryType, methodsToIntercept: AspectRegistrationTests.IInterfaceType.GetMethods());
            aspectConfiguration.AddEntry(LoggingAspectFactory.LoggingAspectFactoryType, methodsToIntercept: AspectRegistrationTests.IInterfaceType.GetMethods());
            aspectConfigurationProvider.AddEntry(aspectConfiguration);
            loggerFactory.Setup(x => x.CreateLogger(typeof(MyTestInterface).FullName)).Returns(logger.Object);
            instance = LoggingAspect <ITestInterface> .Create(
                new MyTestInterface(),
                typeof(MyTestInterface),
                loggerFactory.Object,
                aspectConfigurationProvider,
                LoggingAspectFactory.LoggingAspectFactoryType);
        }
コード例 #4
0
        public void ShouldInterceptReturnsFalseWhenRegistrationFoundButNoMatchingAspectRegistered()
        {
            var configuration =
                new AspectConfiguration(ServiceDescriptor.Scoped(typeof(ITestInterface), MyTestInterface.Type));

            configuration.AddEntry(MyTestInterface.Type);
            inMemoryAspectConfigurationProvider.AddEntry(configuration);
            inMemoryAspectConfigurationProvider.ShouldIntercept(MyTestInterface2.Type, typeof(ITestInterface),
                                                                MyTestInterface.Type, MyTestInterface.Type.GetMethods().First()).Should().BeFalse();
        }
コード例 #5
0
        public void ShouldInterceptReturnsTrueWhenAllConditionsAreMet()
        {
            var methods       = typeof(ITestInterface).GetMethods();
            var configuration =
                new AspectConfiguration(ServiceDescriptor.Scoped(typeof(ITestInterface), MyTestInterface.Type));

            configuration.AddEntry(MyTestInterface.Type, methodsToIntercept: methods.First());
            inMemoryAspectConfigurationProvider.AddEntry(configuration);
            inMemoryAspectConfigurationProvider
            .ShouldIntercept(MyTestInterface.Type, typeof(ITestInterface), MyTestInterface.Type, methods.First())
            .Should().BeTrue();
        }
        public void EnsureServicesAreProperlyResolvedWithFactory()
        {
            var configuration = new AspectConfiguration(ServiceDescriptor.Describe(typeof(ITestInterface), typeof(MyTestInterface), ServiceLifetime.Transient));

            configuration.AddEntry(TestAspectFactory.Type);
            aspectConfigurationProviderMock.Setup(x => x.GetTypeAspectConfiguration(typeof(ITestInterface), typeof(MyTestInterface))).Returns(configuration);
            serviceCollection.AddLogging();
            serviceCollection.TryAddTransient <ITestInterface, MyTestInterface>();
            serviceCollection.AddAspectSupport(aspectConfigurationProviderMock.Object);
            aspectConfigurationProviderMock.Verify(x => x.GetTypeAspectConfiguration(typeof(ITestInterface), typeof(MyTestInterface)), Times.Once);
            serviceCollection.BuildServiceProvider().GetService <ITestInterface>().Should().NotBeNull();
        }
 public void AddEntryAddsAllMethodsWhenMethodsToInterceptIsEmptyArray()
 {
     instance.AddEntry(MyTestInterface.Type, 0);
     instance.GetAspects().First().GetMethodsToIntercept()
     .SequenceEqual(TypeOfITestInterface.GetMethods()).Should().BeTrue();
 }