Example #1
0
        public void GenerateInterfaceProxy_should_be_null_guarded()
        {
            // Arrange

            // Act

            // Assert
            Expression <Action> call = () => CastleDynamicProxyGenerator.GenerateInterfaceProxy(typeof(IInterfaceType), this.noAdditionalInterfaces, Enumerable.Empty <Expression <Func <Attribute> > >(), A.Dummy <IFakeCallProcessorProvider>());

            call.Should().BeNullGuarded();
        }
Example #2
0
        public void Should_ensure_fake_call_processor_is_initialized_but_not_fetched_when_no_method_on_fake_interface_is_called()
        {
            // Arrange
            var fakeCallProcessorProvider = A.Fake <IFakeCallProcessorProvider>();

            // Act
            CastleDynamicProxyGenerator.GenerateInterfaceProxy(typeof(IInterfaceType), this.noAdditionalInterfaces, Enumerable.Empty <Expression <Func <Attribute> > >(), fakeCallProcessorProvider);

            // Assert
            A.CallTo(() => fakeCallProcessorProvider.Fetch(A <object> ._)).MustNotHaveHappened();
            A.CallTo(() => fakeCallProcessorProvider.EnsureInitialized(A <object> ._)).MustHaveHappened();
        }
Example #3
0
            public CreationResult CreateFakeInterface(Type typeOfFake, IProxyOptions proxyOptions)
            {
                if (proxyOptions.ArgumentsForConstructor is not null)
                {
                    throw new ArgumentException(DynamicProxyMessages.ArgumentsForConstructorOnInterfaceType);
                }

                var fakeCallProcessorProvider = this.fakeCallProcessorProviderFactory(typeOfFake, proxyOptions);
                var proxyGeneratorResult      = CastleDynamicProxyGenerator.GenerateInterfaceProxy(
                    typeOfFake,
                    proxyOptions.AdditionalInterfacesToImplement,
                    proxyOptions.Attributes,
                    fakeCallProcessorProvider);

                return(proxyGeneratorResult.ProxyWasSuccessfullyGenerated
                    ? CreationResult.SuccessfullyCreated(proxyGeneratorResult.GeneratedProxy)
                    : CreationResult.FailedToCreateFake(typeOfFake, proxyGeneratorResult.ReasonForFailure !));
            }