示例#1
0
        public void Adapter_registered_two_two_properties_of_the_same_object_shall_react_on_events_for_both()
        {
            TestObject TestObject = new TestObject();
            TestProxy  TestProxy  = new TestProxy(TestObject);

            TestObject.Property  = 42;
            TestObject.Property2 = 42;

            bool EventCalled;

            TestProxy.PropertyChanged += (s, e) => { if (e.PropertyName == "TwoProperties")
                                                     {
                                                         EventCalled = true;
                                                     }
            };

            Assert.AreEqual(84, TestProxy.TwoProperties);

            EventCalled         = false;
            TestObject.Property = 21;

            Assert.AreEqual(63, TestProxy.TwoProperties);
            Assert.IsTrue(EventCalled);

            EventCalled          = false;
            TestObject.Property2 = 21;

            Assert.AreEqual(42, TestProxy.TwoProperties);
            Assert.IsTrue(EventCalled);
        }
示例#2
0
    public override void Execute(INotification notification)
    {
        var       testFacade = Facade;
        TestProxy proxy      = (TestProxy)testFacade.RetrieveProxy(TestProxy.NAME);

        proxy.ChangeLevel(1);
    }
示例#3
0
        public void UnderstandsMethod()
        {
            var getDescriptionMethod = typeof(ITestObject).GetMethod("GetDescription", new Type[0]);
            var understandsMethod    = typeof(AssertUtils).GetMethod("Understands", BindingFlags.Public | BindingFlags.Static, null,
                                                                     new Type[] { typeof(object), typeof(string), typeof(MethodBase) }, null);

            // null target, static method
            AssertUtils.Understands(null, "target", understandsMethod);
            // null target, instance method
            AssertNotUnderstandsMethod(null, "target", getDescriptionMethod, typeof(NotSupportedException),
                                       "Target 'target' is null and target method 'Solenoid.Expressions.Tests.Objects.ITestObject.GetDescription' is not static.");
            // compatible target, instance method
            AssertUtils.Understands(new TestObject(), "target", getDescriptionMethod);
            // incompatible target, instance method
            AssertNotUnderstandsMethod(new object(), "target", getDescriptionMethod, typeof(NotSupportedException),
                                       "Target 'target' of type 'System.Object' does not support methods of 'Solenoid.Expressions.Tests.Objects.ITestObject'.");
            // compatible transparent proxy, instance method
            var compatibleProxy = new TestProxy(new TestObject()).GetTransparentProxy();

            AssertUtils.Understands(compatibleProxy, "compatibleProxy", getDescriptionMethod);
            // incompatible transparent proxy, instance method
            var incompatibleProxy = new TestProxy(new object()).GetTransparentProxy();

            AssertNotUnderstandsMethod(incompatibleProxy, "incompatibleProxy", getDescriptionMethod,
                                       typeof(NotSupportedException),
                                       "Target 'incompatibleProxy' is a transparent proxy that does not support methods of 'Solenoid.Expressions.Tests.Objects.ITestObject'.");
        }
示例#4
0
        public void WrapClassCreatesWrappingProxy(ILogger logger, IMessageBroker messageBroker)
        {
            var timer = new ExecutionTimer(Stopwatch.StartNew());

            var sut = new CastleDynamicProxyFactory(logger, messageBroker, () => timer, () => RuntimePolicy.On);

            var overrideMeAlternate          = new OverrideMeAlternateMethod <TestProxy>();
            var protectedOverrideMeAlternate = new ProtectedOverrideMeAlternateMethod <TestProxy>();

            var methodInvocations = new List <IAlternateMethod> {
                overrideMeAlternate, protectedOverrideMeAlternate
            };

            var target = new TestProxy();
            var result = sut.WrapClass(target, methodInvocations);

            result.OverrideMe();

            Assert.Equal(1, overrideMeAlternate.HitCount);
            Assert.Equal(0, protectedOverrideMeAlternate.HitCount);
            Assert.Equal(0, result.HitCountOverrideMe);
            Assert.Equal(0, result.HitCountProtectedOverrideMe);
            Assert.Equal(1, target.HitCountOverrideMe);
            Assert.Equal(1, target.HitCountProtectedOverrideMe);
        }
示例#5
0
        public async Task RemoteProxyBase_WithCancellation_Cancelled()
        {
            var mre   = new ManualResetEvent(false);
            var svc   = new TestService(mre);
            var proxy = new TestProxy(svc);

            var val = 42;
            var cts = new CancellationTokenSource();
            var t   = proxy.IncrementAsync(val, cts.Token);

            Assert.IsFalse(t.IsCompleted);
            Assert.IsFalse(t.IsFaulted);
            cts.Cancel();

            try
            {
                await t;
            }
            catch (TaskCanceledException)
            {
                mre.Set();
                return;
            }

            mre.Set();
            Assert.Fail();
        }
        public void SegmentProperty()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic chain = proxy.segment1;

            Assert.AreEqual("http://example.com/segment1", chain);
        }
        public void WhenTransparentProxyIsInterceptedUsingInterfaceInterceptor()
        {
            bool intercepted = false;
            InterfaceInterceptor interceptor = new InterfaceInterceptor();

            TestProxy <ITest, TestClass> myProxy = new TestProxy <ITest, TestClass>();

            ITest instance = myProxy.CreateProxy();

            var interceptedMethodList = from i in interceptor.GetInterceptableMethods(typeof(ITest), instance.GetType())
                                        where i.InterfaceMethodInfo.Name == "TestMethod"
                                        select i;

            bool containsMethod = interceptedMethodList.Count() == 1;

            Assert.IsTrue(containsMethod);

            var interceptedProxy = interceptor.CreateProxy(typeof(ITest), instance);

            interceptedProxy.AddInterceptionBehavior(
                new ActionInterceptionBehavior(() => intercepted = true));

            int result = ((ITest)interceptedProxy).TestMethod("sample");

            Assert.IsTrue(intercepted);
        }
示例#8
0
    void Start()
    {
        TestProxy proxy = new TestProxy("haha");

        proxy.Data = "dddddddddd";
        Facade.Instance.RegisterProxy(proxy);
    }
示例#9
0
    public static void Main()
    {
        TestProxy tp = new TestProxy(typeof(TestClass));
        TestClass tc = (TestClass)tp.GetTransparentProxy();

        Derived d = (Derived)tc;
    }
        public void TwoSegmentProperties()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic chain = proxy.segment1.segment2;

            Assert.AreEqual("http://example.com/segment1/segment2", chain);
        }
示例#11
0
        public void Subscribe_CustomProxyFilterStrongReference_DoesNotThrow()
        {
            var messenger = UtilityMethods.GetMessenger();
            var proxy     = new TestProxy();

            messenger.Subscribe <TestMessage>(new Action <TestMessage>(UtilityMethods.FakeDeliveryAction <TestMessage>), new Func <TestMessage, bool>(UtilityMethods.FakeMessageFilter <TestMessage>), true, proxy);
        }
        public void EscapeTwoSequentialSegmentsThenProperty()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic chain = proxy.segment1("escaped")("escaped2").segment2;

            Assert.AreEqual("http://example.com/segment1/escaped/escaped2/segment2", chain);
        }
        public void AddSoapClientProxyTest()
        {
            ServiceCollection ServiceCollection = new ServiceCollection();

            ServiceCollection
            .AddSoapClient <ITestProxy, TestProxy>((serviceProvider, soapClientFactory)
                                                   => new ChannelFactory <ITestProxy>(new BasicHttpBinding(), new EndpointAddress("http://localhost:9999/")));

            ServiceProvider ServiceProvider = ServiceCollection.BuildServiceProvider();

            ITestProxy TestProxy;

            using (IServiceScope Scope = ServiceProvider.CreateScope())
            {
                TestProxy = Scope.ServiceProvider.GetRequiredService <ITestProxy>();

                Assert.IsNotNull(TestProxy);

                try
                {
                    TestProxy.GetStatus();
                }
                catch (CommunicationException)
                {
                }
            }

            Assert.AreEqual(CommunicationState.Closed, TestProxy.ChannelState);
        }
示例#14
0
        public static TestProxy Create()
        {
            StartSignal.WaitOne();
            var p = new TestProxy();

            return(p);
        }
示例#15
0
        public async Task ReturnAResponseFromAnyProxyRequest()
        {
            // Setup your mocked stuff
            var mockedProxyRequest = ProxyRequestBuilder <string[]>
                                     .CreateBuilder("https://www.this.is/fake", HttpRequestMethod.Get)
                                     .AppendToRoute("api/example")
                                     .Accept("application/json")
                                     .Build();

            var mockedProxyResponse = new ProxyResponse <string[]>
            {
                IsSuccessfulStatusCode = true,
                StatusCode             = HttpStatusCode.OK,
                ResponseDto            = new[] { "Mocked Value From Any Request 1", "Mocked Value From Any Request 2" }
            };

            // Create and configure TestProxy
            var testProxy = new TestProxy();

            testProxy.WhenIReceiveAnyRequest <Missing, string[]>().ThenIShouldReturnThisResponse(mockedProxyResponse);

            // Use the TetProxy in the class that needs it
            var classThatUsesProxy          = new ClassThatUsesProxy(testProxy);
            var methodThatUsesProxyResponse = await classThatUsesProxy.MethodThatUsesProxyAsync(mockedProxyRequest).ConfigureAwait(false);

            Assert.Equal("Mocked Value From Any Request 1", methodThatUsesProxyResponse[0]);
            Assert.Equal("Mocked Value From Any Request 2", methodThatUsesProxyResponse[1]);
        }
示例#16
0
        public void CanRekey()
        {
            var proxy = new TestProxy(null);

            proxy.SendFromOmm("012d00209bc21bab186210cd8d619849d192e75f28e79d0744696a53ba172a916a48d877");
            proxy.SendFromRfp("01200104000000040007010000304212ebe2000000000000000003dce046da34" +
                              "17566137f9d6760257c68b2fadf109e904128438319bb0bffc0cee6b28e7fd28" +
                              "6bd92586861a59a9323b16491b95fc2ec42fdfb41dafcca7b0f2464600070100" +
                              "00000000000000005349502d4445435420372e312d434b313400000000000000" +
                              "0000000000000000000000000000000000000000000000000000000000000000" +
                              "0000000000000000000000000000000000000000000000000000000000000000" +
                              "0000000000000000000000000000000000000000000000000000000000000000" +
                              "00000000000000000000000000000000000000000000000042f9c74578cf9a17" +
                              "2fcc638d5761802d");
            proxy.SendFromOmm("000100080120ffff01000000");
            var data = File.ReadAllBytes("rekey.bin").AsSpan(0x108);

            proxy.SendFromRfp(data.Slice(0, data.Length - 16));
            var resetEvent = proxy.RfpMessageEvent;

            while (resetEvent.Wait(TimeSpan.FromSeconds(1)))
            {
                resetEvent.Reset();
            }
            proxy.SendFromRfp(data.Slice(data.Length - 16));
            Assert.Equal("00030008f73bde0264190000", proxy.LastRfpMessageHex);
        }
示例#17
0
        public void GivenAGenericList_WhenRenderingUsingTypeTemplate_ThenTheExpectedOutcomeIsRendered()
        {
            // Arrange
            var parser   = new TemplateParser();
            var template = parser.Parse("[foreach]{}[/]");

            var source = new List <int>()
            {
                1, 2, 3
            };

            // Act
            var testProxy = new TestProxy();

            testProxy.WriteTemplate(template, source);
            var preTemplateResult = testProxy.ToString();

            parser.AddTypeTemplate <int>("{v}", t => new{ v = (10 - t).ToString() });

            var testProxy2 = new TestProxy();

            testProxy2.WriteTemplate(template, source);
            var postTemplateResult = testProxy2.ToString();

            // Assert
            Assert.Equal("123", preTemplateResult);
            Assert.Equal("987", postTemplateResult);
        }
示例#18
0
        public void Subscribe_CustomProxyNoFilter_DoesNotThrow()
        {
            var messenger = UtilityMethods.GetMessenger();
            var proxy     = new TestProxy();

            messenger.Subscribe <TestMessage>(new Action <TestMessage>(UtilityMethods.FakeDeliveryAction <TestMessage>), proxy);
        }
示例#19
0
        public void CanHandshakeExistingRFP()
        {
            var proxy = new TestProxy("4685E31451732829A7C1211C21F3A6FAE39835770D27E37374BCFE786B72D30A50A12C6E5B65D55B8654FFFAEFC726F725E0F9233B626DE0AE8285DDB618D4F5");

            proxy.SendFromOmm("012d0020a40a896af9618b5bd0d56b3b6d321e98531e2a752008c5e6d756f5cc8eb4df8c");
            ValidateTypeAndLength(proxy.LastOmmMessage);

            proxy.SendFromRfp("012001100000000d000801000030421b17370000000000000001ef3c2a0d8ce8" +
                              "725371d0d799a0298dc02c734ac5b803abc38663b494de7b2ffbe03d70b616eb" +
                              "facf2e7d85f61b295cba5c76ea515501b3c02b755862261bfc08ffde00080201" +
                              "00000000000000000000000000000000000000005349502d4445435420382e31" +
                              "5350312d46413237000000000000000000000000000000000000000000000000" +
                              "0000000000000000000000000000000000000000000000000000000000000000" +
                              "0000000000000000000000000000000000000000000000000000000000000000" +
                              "0000000000000000000000000000000000000000000000000000000000000000" +
                              "0000000072f90d3b1771c77a7acbfa0a8e7ad3cf");
            ValidateTypeAndLength(proxy.LastRfpMessage);

            proxy.SendFromOmm("000100080120ffff01000000");
            ValidateTypeAndLength(proxy.LastOmmMessage);

            proxy.SendFromOmm("52df58b8ae32f14a");
            ValidateTypeAndLength(proxy.LastOmmMessage);
            Assert.Equal("010c000400000000", proxy.LastOmmMessageHex);
            proxy.SendFromOmm("05b54aca8fa7462d47a00b6027c816d2");
            ValidateTypeAndLength(proxy.LastOmmMessage);
            Assert.Equal("01010008b8b8200606000000", proxy.LastOmmMessageHex);
            proxy.SendFromOmm("dad130112199e1be");
            ValidateTypeAndLength(proxy.LastOmmMessage);
            Assert.Equal("010500040f000000", proxy.LastOmmMessageHex);
            proxy.SendFromOmm("e35dea95cd3a13dd");
            ValidateTypeAndLength(proxy.LastOmmMessage);
            Assert.Equal("0123000401000000", proxy.LastOmmMessageHex);
            proxy.SendFromOmm("f9fde7263e275143");
            ValidateTypeAndLength(proxy.LastOmmMessage);
            Assert.Equal("0102000401010000", proxy.LastOmmMessageHex);
            proxy.SendFromOmm("b30ece1f8c9731c2");
            ValidateTypeAndLength(proxy.LastOmmMessage);
            Assert.Equal("0102000400090000", proxy.LastOmmMessageHex);

            proxy.SendFromOmm("9d8fb229f310b7e994ba405be02d01f5ad4827d383925564" +
                              "925f9fadc6e023f5db5f3f74cd91d17d8814a9946e7abdbe729b59d32d0b4725" +
                              "2b99c39b70fd362802862e0541b876dd4fe8e9291add80e03cf40c5355bfc168" +
                              "e041229eef995b6a74ba52de3ca84dce31510178296fc2fe86325b4663142052" +
                              "fe9c27b34f887a3ab2a9f3222cc8aefb8134c77edfa2b142c39da25a7ea2d8cc" +
                              "1fe10d67c2546499bb41e3645f7b6616a80b51d700b4ed17315298e13b0abf56" +
                              "b02ef601622f4837adde01b885dd370db331318dc1821a660b33e48ec3849542" +
                              "4675da6b111765dca00a7a1a3d1ae0b7a9e65088549347a81e77f512c6b4715b" +
                              "8ee78ca5cba5a5666a37472de28add2e96747ab669febdf4ab3c5b3ef24a7bb7" +
                              "1b3b0e7cb8e29f4926a9aba0a7467e9cb9ac61573b8deb6d6d6518d466256132" +
                              "ba122d69e163adb2997fda7c7b3cd8e2519f62624f38e5bc0604f197b5630337" +
                              "10657db308b8753744e2740a1125f79ea8c934bb34b7a3685a17c75f4221982e" +
                              "e6bc96ec466649fb4669c9afda51af4752a84287ff83c08e");
            ValidateTypeAndLength(proxy.LastOmmMessage);
            proxy.SendFromRfp("4e2da25833e64f92");
            ValidateTypeAndLength(proxy.LastRfpMessage);
            proxy.SendFromRfp("3c54c821a4e5961f32933ca3731667960dfb967332f26106");
            ValidateTypeAndLength(proxy.LastRfpMessage);
        }
示例#20
0
        public void Test_If_AddInMemoryConfiguration_Adds_InMemoryConfigurationSource_WithGivenSourceReference()
        {
            var builder = new ConfigBuilderStub();

            TestProxy.AddInMemoryConfigurationProxy(builder, new Dictionary <string, string>());

            Assert.Contains(builder.Sources, (s) => { return(s is InMemoryConfigurationSource); });
        }
        public void EscapeSegmentAsInvoke()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic segment1 = proxy.segment1;
            dynamic chain = segment1("escaped");

            Assert.AreEqual("http://example.com/segment1/escaped", chain);
        }
        public void EscapeSegment()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic chain = proxy.segment1("escaped").segment2;

            string s = chain.ToString();
            Assert.AreEqual("http://example.com/segment1/escaped/segment2", chain);
        }
示例#23
0
        public void WhenAddingProxyBehavior_ThenCanAddLambda()
        {
            var proxy = new TestProxy();

            proxy.AddBehavior((m, n) => null);

            Assert.Equal(1, proxy.Behaviors.Count);
        }
        public void EscapeSegmentAsInvokeContinueChaining()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic segment1 = proxy.segment1;
            dynamic chain = segment1("escaped")("escaped2").segment2;

            Assert.AreEqual("http://example.com/segment1/escaped/escaped2/segment2", chain);
        }
示例#25
0
        public void WhenAddingProxyBehavior_ThenCanAddLambdaWithAppliesTo()
        {
            var proxy = new TestProxy();

            proxy.AddBehavior((m, n) => null, m => true);

            Assert.True(proxy.Behaviors[0].AppliesTo(null));
        }
示例#26
0
        public void WhenAddingProxyBehavior_ThenCanAddInterface()
        {
            var proxy = new TestProxy();

            proxy.AddBehavior(new TestProxyBehavior());

            Assert.Equal(1, proxy.Behaviors.Count);
        }
示例#27
0
        public void WhenAddingProxyBehaviorToObject_ThenCanAddLambda()
        {
            object proxy = new TestProxy();

            proxy.AddBehavior((m, n) => null);

            Assert.Equal(1, ((IProxy)proxy).Behaviors.Count);
        }
示例#28
0
        private void Setup()
        {
            _services = new ServiceCollection();
            _proxy    = new TestProxy();
            _services.AddSingleton(s => _proxy);

            _factory = new EventHandlerFactory();
        }
示例#29
0
        public void WhenAddingProxyBehaviorToObject_ThenCanAddLambdaWithAppliesTo()
        {
            object proxy = new TestProxy();

            proxy.AddBehavior((m, n) => null, m => true);

            Assert.True(((IProxy)proxy).Behaviors[0].AppliesTo(null));
        }
示例#30
0
        public void Test_If_AddWebConfiguration_Adds_WebConfigurationSource()
        {
            var builder = new ConfigBuilderStub();

            TestProxy.AddWebConfiguration(builder);

            Assert.Contains(builder.Sources, (s) => { return(s is WebConfigurationSource); });
        }
示例#31
0
        public void WhenAddingProxyBehaviorToObject_ThenCanAddInterface()
        {
            object proxy = new TestProxy();

            proxy.AddBehavior(new TestProxyBehavior());

            Assert.Equal(1, ((IProxy)proxy).Behaviors.Count);
        }
示例#32
0
        public void DisabledProxy()
        {
            var proxy = new TestProxy(new InvocationHandler(
                invocation => Task.FromResult((object)"foo"),
                (_, method, property) => false));

            var value = proxy.StringProperty;
            Assert.IsNull(value);
        }
示例#33
0
        public void EnableProxy()
        {
            var proxy = new TestProxy(new InvocationHandler(
                invocation => Task.FromResult((object)"foo"),
                (_, method, property) => true));

            var value = proxy.StringProperty;
            Assert.AreEqual("foo", value);
        }
        public async Task ReturnTypePassesThrough()
        {
            using (var source = new CancellationTokenSource())
            {
                dynamic proxy = new TestProxy("http://example.com");
                dynamic expando = await proxy.get(typeof(ExpandoObject), name: "value");

                Assert.AreEqual(typeof(ExpandoObject), expando.ReturnType);
            }
        }
示例#35
0
        public void WhenInsertingProxyBehaviorToObject_ThenCanAddLambda()
        {
            object proxy = new TestProxy();

            proxy.AddProxyBehavior((m, n) => null);
            proxy.InsertProxyBehavior(0, (m, n) => throw new NotImplementedException());

            Assert.Equal(2, ((IProxy)proxy).Behaviors.Count);
            Assert.Throws <NotImplementedException>(() => ((IProxy)proxy).Behaviors[0].Invoke(null, null));
        }
        public async Task CancellationTokenPassesThrough()
        {
            using (var source = new CancellationTokenSource())
            {
                dynamic proxy = new TestProxy("http://example.com");
                dynamic expando = await proxy.get(source.Token, name: "value");

                Assert.AreEqual(source.Token, expando.CancelToken);
            }
        }
示例#37
0
        public void EnableProxy()
        {
            var proxy = new TestProxy(new InvocationHandler(
                                          invocation => Task.FromResult((object)"foo"),
                                          (_, method, property) => true));

            var value = proxy.StringProperty;

            Assert.AreEqual("foo", value);
        }
示例#38
0
        public void DisabledProxy()
        {
            var proxy = new TestProxy(new InvocationHandler(
                                          invocation => Task.FromResult((object)"foo"),
                                          (_, method, property) => false));

            var value = proxy.StringProperty;

            Assert.IsNull(value);
        }
        public void Test_AddControllers_AddsOnlyClassesEndsWithControllersAndImplementationOfIController()
        {
            var services = new ServiceCollection();

            TestProxy.AddControllersProxy(services);

            Assert.Contains(services, (desc) => desc?.ImplementationType?.FullName == "PivotalServices.AspNet.Bootstrap.Extensions.Tests.TestApiController");
            Assert.Contains(services, (desc) => desc?.ImplementationType?.FullName == "PivotalServices.AspNet.Bootstrap.Extensions.Tests.TestMvcController");
            Assert.True(!services.Any((desc) => desc?.ImplementationType?.FullName == "PivotalServices.AspNet.Bootstrap.Extensions.Tests.TestController3"));
        }
示例#40
0
        public void WhenInsertingProxyBehavior_ThenCanAddLambda()
        {
            var proxy = new TestProxy();

            proxy.AddBehavior((m, n) => null);
            proxy.InsertBehavior(0, (m, n) => throw new NotImplementedException());

            Assert.Equal(2, proxy.Behaviors.Count);
            Assert.Throws <NotImplementedException>(() => proxy.Behaviors[0].Invoke(null, null));
        }
        public async Task UnnamedArgsArePassedCorrectly()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic expando = await proxy.get("object");

            Assert.AreEqual(0, ((IDictionary<string, object>)expando.NamedArgs).Count);

            IEnumerable<object> unnamedArgs = expando.UnnamedArgs;

            Assert.AreEqual("object", unnamedArgs.First().ToString());
        }
        public async Task NamedArgsArePassedCorrectly()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic expando = await proxy.get(name: "value");

            Assert.IsFalse(((IEnumerable<object>)expando.UnnamedArgs).Any());

            IDictionary<string, object> namedArgs = expando.NamedArgs;
            Assert.IsTrue(namedArgs.ContainsKey("name"));
            Assert.AreEqual("value", namedArgs["name"]);
        }
        public async Task NamedAndUnnamedArgsArePassedCorrectly()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic expando = await proxy.get("object", name: "value");

            IEnumerable<object> unnamedArgs = expando.UnnamedArgs;
            IDictionary<string, object> namedArgs = expando.NamedArgs;

            Assert.AreEqual(1, unnamedArgs.Count());
            Assert.AreEqual(1, namedArgs.Count);

            Assert.AreEqual("object", unnamedArgs.First().ToString());

            Assert.IsTrue(namedArgs.ContainsKey("name"));
            Assert.AreEqual("value", namedArgs["name"]);
        }
示例#44
0
  public static void Main () {
    TestProxy tp = new TestProxy (typeof(TestClass));
    TestClass tc = (TestClass) tp.GetTransparentProxy();

    Derived d = (Derived) tc;
  }
示例#45
0
 public static TestProxy Create()
 {
     StartSignal.WaitOne();
     var p = new TestProxy();
     return p;
 }
示例#46
0
        public void Publish_CustomProxyNoFilterStrongReference_UsesCorrectProxy()
        {
            var messenger = UtilityMethods.GetMessenger();
            var proxy = new TestProxy();
            messenger.Subscribe<TestMessage>(new Action<TestMessage>(UtilityMethods.FakeDeliveryAction<TestMessage>), true, proxy);
            var message = new TestMessage();

            messenger.Publish<TestMessage>(message);

            Assert.ReferenceEquals(message, proxy.Message);
        }
        public async Task NoArgsPassedCorrectly()
        {
            dynamic proxy = new TestProxy("http://example.com");
            dynamic expando = await proxy.get();

            IEnumerable<object> unnamedArgs = expando.UnnamedArgs;
            IDictionary<string, object> namedArgs = expando.NamedArgs;

            Assert.AreEqual(0, unnamedArgs.Count());
            Assert.AreEqual(0, namedArgs.Count);
        }
        public void Publish_CustomProxyWithFilter_UsesCorrectProxy()
        {
            var messenger = UtilityMethods.GetMessenger();
            var proxy = new TestProxy();
            messenger.Subscribe<TestMessage>(new Action<TestMessage>(UtilityMethods.FakeDeliveryAction<TestMessage>), new Func<TestMessage, bool>(UtilityMethods.FakeMessageFilter<TestMessage>), proxy);
            var message = new TestMessage(this);

            messenger.Publish<TestMessage>(message);

            Assert.ReferenceEquals(message, proxy.Message);
        }
        public void Subscribe_CustomProxyNoFilterStrongReference_DoesNotThrow()
        {
            var messenger = UtilityMethods.GetMessenger();
            var proxy = new TestProxy();

            messenger.Subscribe<TestMessage>(new Action<TestMessage>(UtilityMethods.FakeDeliveryAction<TestMessage>), true, proxy);
        }
        public void Subscribe_CustomProxyWithFilter_DoesNotThrow()
        {
            var messenger = UtilityMethods.GetMessenger();
            var proxy = new TestProxy();

            messenger.Subscribe<TestMessage>(new Action<TestMessage>(UtilityMethods.FakeDeliveryAction<TestMessage>), new Func<TestMessage, bool>(UtilityMethods.FakeMessageFilter<TestMessage>), proxy);
        }
示例#51
0
        public void UnderstandsMethod()
        {
            MethodInfo getDescriptionMethod = typeof(ITestObject).GetMethod("GetDescription", new Type[0]);
            MethodInfo understandsMethod = typeof(AssertUtils).GetMethod("Understands", BindingFlags.Public|BindingFlags.Static, null, new Type[] {typeof (object), typeof(string), typeof (MethodBase)}, null);

            // null target, static method
            AssertUtils.Understands(null, "target", understandsMethod);
            // null target, instance method
            AssertNotUnderstandsMethod(null, "target", getDescriptionMethod, typeof(NotSupportedException), "Target 'target' is null and target method 'Spring.Objects.ITestObject.GetDescription' is not static.");
            // compatible target, instance method
            AssertUtils.Understands(new TestObject(), "target", getDescriptionMethod);
            // incompatible target, instance method
                AssertNotUnderstandsMethod(new object(), "target", getDescriptionMethod, typeof(NotSupportedException), "Target 'target' of type 'System.Object' does not support methods of 'Spring.Objects.ITestObject'.");
            // compatible transparent proxy, instance method
            object compatibleProxy = new TestProxy(new TestObject()).GetTransparentProxy();
            AssertUtils.Understands(compatibleProxy, "compatibleProxy", getDescriptionMethod);
            // incompatible transparent proxy, instance method
            object incompatibleProxy = new TestProxy(new object()).GetTransparentProxy();
            AssertNotUnderstandsMethod(incompatibleProxy, "incompatibleProxy", getDescriptionMethod, typeof(NotSupportedException), "Target 'incompatibleProxy' is a transparent proxy that does not support methods of 'Spring.Objects.ITestObject'.");
        }
示例#52
0
 public void ProxyTest()
 {
     var testService = new TestProxy(typeof(TestService)).GetTransparentProxy() as TestService;
     Assert.NotNull(testService);
     Assert.AreEqual("hi", testService.Echo("hi"));
 }