Example #1
0
        public void ExcludedNonVirtualMethods()
        {
            // Arrange
            CollectingLogger logger    = new CollectingLogger();
            ProxyGenerator   generator = new ProxyGenerator {
                Logger = logger
            };

            // Act
            generator.CreateClassProxy <NonVirtualMethodClass>();

            // Assert
            Assert.True(
                logger.RecordedMessage(
                    LoggerLevel.Debug,
                    "Excluded non-overridable method ClassMethod on "
                    + "Castle.DynamicProxy.Tests.LoggingTestCase+NonVirtualMethodClass because it cannot be intercepted."
                    )
                );
            Assert.True(
                logger.RecordedMessage(
                    LoggerLevel.Debug,
                    "Excluded non-overridable method InterfaceMethod on "
                    + "Castle.DynamicProxy.Tests.LoggingTestCase+NonVirtualMethodClass because it cannot be intercepted."
                    )
                );
        }
Example #2
0
        public void ProxyGenerationOptionsEqualsAndGetHashCodeNotOverriden()
        {
            // Arrange
            CollectingLogger logger    = new CollectingLogger();
            ProxyGenerator   generator = new ProxyGenerator {
                Logger = logger
            };

            // Act
            ProxyGenerationOptions options = new ProxyGenerationOptions {
                Hook = new EmptyHook()
            };

            generator.CreateClassProxy(typeof(EmptyClass), options);

            // Assert
            Assert.True(
                logger.RecordedMessage(
                    LoggerLevel.Warn,
                    "The IProxyGenerationHook type "
                    + "Castle.DynamicProxy.Tests.LoggingTestCase+EmptyHook does not override both Equals and GetHashCode. "
                    + "If these are not correctly overridden caching will fail to work causing performance problems."
                    )
                );
        }
Example #3
0
		public void CacheMiss()
		{
			// Arrange
			CollectingLogger logger = new CollectingLogger();
			ProxyGenerator generator = new ProxyGenerator { Logger = logger };

			// Act
			generator.CreateClassProxy<EmptyClass>();

			// Assert
			Assert.That(logger.RecordedMessage(LoggerLevel.Debug, "No cached proxy type was found for target type " +
				"CastleTests.DynamicProxy.Tests.Classes.EmptyClass."));
		}
		public void CacheMiss()
		{
			// Arrange
			CollectingLogger logger = new CollectingLogger();
			ProxyGenerator generator = new ProxyGenerator { Logger = logger };

			// Act
			generator.CreateClassProxy<EmptyClass>();

			// Assert
			Assert.True(logger.RecordedMessage(LoggerLevel.Debug, "No cached proxy type was found for target type " +
				"CastleTests.DynamicProxy.Tests.Classes.EmptyClass."));
		}
Example #5
0
		public void CacheHitInterfaceProxy()
		{
			// Arrange
			CollectingLogger logger = new CollectingLogger();
			ProxyGenerator generator = new ProxyGenerator { Logger = logger };

			// Act
			generator.CreateInterfaceProxyWithoutTarget<IEmptyInterface>();
			generator.CreateInterfaceProxyWithoutTarget<IEmptyInterface>();

			// Assert
			Assert.That(logger.RecordedMessage(LoggerLevel.Debug, "Found cached proxy type Castle.Proxies.IEmptyInterfaceProxy " +
				"for target type Castle.DynamicProxy.Tests.LoggingTestCase+IEmptyInterface."));
		}
		public void CacheHitInterfaceProxy()
		{
			// Arrange
			CollectingLogger logger = new CollectingLogger();
			ProxyGenerator generator = new ProxyGenerator { Logger = logger };

			// Act
			generator.CreateInterfaceProxyWithoutTarget<IEmptyInterface>();
			generator.CreateInterfaceProxyWithoutTarget<IEmptyInterface>();

			// Assert
			Assert.True(logger.RecordedMessage(LoggerLevel.Debug, "Found cached proxy type Castle.Proxies.IEmptyInterfaceProxy " +
				"for target type Castle.DynamicProxy.Tests.LoggingTestCase+IEmptyInterface."));
		}
Example #7
0
		public void CacheHitClassProxy()
		{
			// Arrange
			CollectingLogger logger = new CollectingLogger();
			ProxyGenerator generator = new ProxyGenerator { Logger = logger };

			// Act
			generator.CreateClassProxy<EmptyClass>();
			generator.CreateClassProxy<EmptyClass>();

			// Assert
			Assert.That(logger.RecordedMessage(LoggerLevel.Debug, "Found cached proxy type Castle.Proxies.EmptyClassProxy " +
				"for target type Castle.DynamicProxy.Tests.LoggingTestCase+EmptyClass."));
		}
Example #8
0
        public void CacheHitClassProxy()
        {
            // Arrange
            CollectingLogger logger    = new CollectingLogger();
            ProxyGenerator   generator = new ProxyGenerator {
                Logger = logger
            };

            // Act
            generator.CreateClassProxy <EmptyClass>();
            generator.CreateClassProxy <EmptyClass>();

            // Assert
            Assert.That(logger.RecordedMessage(LoggerLevel.Debug, "Found cached proxy type Castle.Proxies.EmptyClassProxy " +
                                               "for target type CastleTests.DynamicProxy.Tests.Classes.EmptyClass."));
        }
        public void FoundExplicitlyImplementedInterfaceMethods()
        {
            // Arrange
            CollectingLogger logger    = new CollectingLogger();
            ProxyGenerator   generator = new ProxyGenerator {
                Logger = logger
            };

            // Act
            generator.CreateClassProxy <ClassWithInterfaceMethodExplicitlyImplemented>();

            // Assert
            Assert.That(logger.RecordedMessage(LoggerLevel.Debug, "Excluded explicitly implemented interface method " +
                                               "Castle.DynamicProxy.Tests.LoggingTestCase.ISingleMethodInterface.InterfaceMethod on type " +
                                               "Castle.DynamicProxy.Tests.LoggingTestCase+ClassWithInterfaceMethodExplicitlyImplemented " +
                                               "because it cannot be intercepted."));
        }
Example #10
0
		public void ExcludedNonVirtualMethods()
		{
			// Arrange
			CollectingLogger logger = new CollectingLogger();
			ProxyGenerator generator = new ProxyGenerator { Logger = logger };

			// Act
			generator.CreateClassProxy<NonVirtualMethodClass>();

			// Assert
			Assert.That(logger.RecordedMessage(LoggerLevel.Debug, "Excluded non-virtual method ClassMethod on " +
				"Castle.DynamicProxy.Tests.LoggingTestCase+NonVirtualMethodClass because it cannot be intercepted."));
			Assert.That(logger.RecordedMessage(LoggerLevel.Debug, "Excluded sealed method InterfaceMethod on " +
				"Castle.DynamicProxy.Tests.LoggingTestCase+NonVirtualMethodClass because it cannot be intercepted."));
		}
Example #11
0
		public void ProxyGenerationOptionsEqualsAndGetHashCodeNotOverriden()
		{
			// Arrange
			CollectingLogger logger = new CollectingLogger();
			ProxyGenerator generator = new ProxyGenerator { Logger = logger };

			// Act
			ProxyGenerationOptions options = new ProxyGenerationOptions {
				Hook = new EmptyHook()
			};
			generator.CreateClassProxy(typeof(EmptyClass), options);

			// Assert
			Assert.That(logger.RecordedMessage(LoggerLevel.Warn, "The IProxyGenerationHook type " +
				"Castle.DynamicProxy.Tests.LoggingTestCase+EmptyHook does not override both Equals and GetHashCode. " +
				"If these are not correctly overridden caching will fail to work causing performance problems."));
		}
		public void FoundExplicitlyImplementedInterfaceMethods()
		{
			// Arrange
			CollectingLogger logger = new CollectingLogger();
			ProxyGenerator generator = new ProxyGenerator { Logger = logger };

			// Act
			generator.CreateClassProxy<ClassWithInterfaceMethodExplicitlyImplemented>();

			// Assert
			Assert.That(logger.RecordedMessage(LoggerLevel.Debug, "Excluded explicitly implemented interface method " +
				"Castle.DynamicProxy.Tests.LoggingTestCase.ISingleMethodInterface.InterfaceMethod on type " +
				"Castle.DynamicProxy.Tests.LoggingTestCase+ClassWithInterfaceMethodExplicitlyImplemented " +
				"because it cannot be intercepted."));
		}