Exemple #1
0
        public void TestOverloadResolution()
        {
            var svcName = TestUtils.TestName;

            ServerServices.DeployClusterSingleton(svcName, new TestServiceOverloads());
            var svc = Client.GetServices().GetServiceProxy <ITestServiceOverloads>(svcName);

            Assert.AreEqual(true, svc.Foo());
            Assert.AreEqual(1, svc.Foo(default(int)));
            Assert.AreEqual(3, svc.Foo(default(byte)));
            Assert.AreEqual(4, svc.Foo(default(short)));
            Assert.AreEqual(6, svc.Foo(new Person()));
            Assert.AreEqual(8, svc.Foo(new[] { 1 }));
            Assert.AreEqual(9, svc.Foo(new[] { new object() }));

            // Unsigned types are not preserved by the binary protocol and resolve to signed counterparts.
            Assert.AreEqual(1, svc.Foo(default(uint)));
            Assert.AreEqual(4, svc.Foo(default(ushort)));

            if (!_useBinaryArray)
            {
                // Array types are not distinguished.
                Assert.AreEqual(9, svc.Foo(new[] { new Person(0) }));
            }
            else
            {
                Assert.AreEqual(9, svc.Foo(new object[] { new Person(0) }));
                Assert.AreEqual(10, svc.Foo(new[] { new Person(0) }));
                Assert.AreEqual(10, svc.Foo(new Person[] { new Person(0) }));
            }
        }
        public void TestGenericMethodCall()
        {
            var svcName = TestUtils.TestName;

            ServerServices.DeployClusterSingleton(svcName, new TestServiceGenericMethods());

            var svc = Client.GetServices().GetServiceProxy <ITestServiceGenericMethods>(svcName);

            Assert.AreEqual("1", svc.GetGeneric("1"));
        }
        /// <summary>
        /// Deploys test service and returns client-side proxy.
        /// </summary>
        private T DeployAndGetTestService <T>(Func <IServicesClient, IServicesClient> transform = null) where T : class
        {
            ServerServices.DeployClusterSingleton(ServiceName, new TestService());

            var services = Client.GetServices();

            if (transform != null)
            {
                services = transform(services);
            }

            return(services.GetServiceProxy <T>(ServiceName));
        }
        public void TestAllArgumentTypes()
        {
            ServerServices.DeployClusterSingleton(ServiceName, new TestServiceDataTypes());
            var svc = Client.GetServices().GetServiceProxy <ITestServiceDataTypes>(ServiceName);

            Assert.AreEqual(2, svc.GetByte(1));
            Assert.AreEqual(new byte[] { 3, 4, 5 }, svc.GetByteArray(new byte[] { 2, 3, 4 }));

            Assert.AreEqual(3, svc.GetSbyte(2));
            Assert.AreEqual(new sbyte[] { -4, 6 }, svc.GetSbyteArray(new sbyte[] { -5, 5 }));

            Assert.AreEqual(3, svc.GetShort(2));
            Assert.AreEqual(new short[] { -4, 6 }, svc.GetShortArray(new short[] { -5, 5 }));

            Assert.AreEqual(3, svc.GetUShort(2));
            Assert.AreEqual(new ushort[] { 1, 6 }, svc.GetUShortArray(new ushort[] { 0, 5 }));

            Assert.AreEqual(3, svc.GetInt(2));
            Assert.AreEqual(new [] { -4, 6 }, svc.GetIntArray(new[] { -5, 5 }));

            Assert.AreEqual(3, svc.GetUInt(2));
            Assert.AreEqual(new uint[] { 1, 6 }, svc.GetUIntArray(new uint[] { 0, 5 }));

            Assert.AreEqual(long.MaxValue - 9, svc.GetLong(long.MaxValue - 10));
            Assert.AreEqual(new [] { long.MinValue + 1, 6 }, svc.GetLongArray(new[] { long.MinValue, 5 }));

            Assert.AreEqual(ulong.MaxValue - 9, svc.GetULong(ulong.MaxValue - 10));
            Assert.AreEqual(new ulong[] { 1, 10 }, svc.GetULongArray(new ulong[] { 0, 9 }));

            Assert.AreEqual('d', svc.GetChar('c'));
            Assert.AreEqual(new[] { 'b', 'c' }, svc.GetCharArray(new[] { 'a', 'b' }));

            var guid = Guid.NewGuid();

            Assert.AreEqual(guid, svc.GetGuid(guid));
            Assert.AreEqual(new[] { guid, Guid.Empty }, svc.GetGuidArray(new[] { guid, Guid.Empty }));

            var dt = DateTime.Now;

            Assert.AreEqual(dt.AddDays(1), svc.GetDateTime(dt));
            Assert.AreEqual(new[] { dt.AddDays(1), dt.AddDays(2) }, svc.GetDateTimeArray(new[] { dt, dt.AddDays(1) }));
            Assert.AreEqual(new List <DateTime> {
                dt.AddDays(1), dt.AddDays(2)
            },
                            svc.GetDateTimeList(new[] { dt, dt.AddDays(1) }.ToList()));

            var ts       = TimeSpan.FromSeconds(25);
            var minuteTs = TimeSpan.FromMinutes(1);

            Assert.AreEqual(ts.Add(minuteTs), svc.GetTimeSpan(ts));
            Assert.AreEqual(new[] { ts.Add(minuteTs), minuteTs }, svc.GetTimeSpanArray(new[] { ts, TimeSpan.Zero }));

            Assert.AreEqual(true, svc.GetBool(false));
            Assert.AreEqual(new[] { true, false }, svc.GetBoolArray(new[] { false, true }));

            Assert.AreEqual(1.5f, svc.GetFloat(0.5f));
            Assert.AreEqual(new[] { -0.5f, 1.1f }, svc.GetFloatArray(new[] { -1.5f, 0.1f }));

            Assert.AreEqual(1.5d, svc.GetDouble(0.5d));
            Assert.AreEqual(new[] { -7.02d, 1.1d }, svc.GetDoubleArray(new[] { -8.02d, 0.1d }));

            Assert.AreEqual(1.666m, svc.GetDecimal(0.666m));
            Assert.AreEqual(new[] { -7.66m, 1.33m }, svc.GetDecimalArray(new[] { -8.66m, 0.33m }));

            Assert.AreEqual("foo", svc.GetString("FOO"));
            Assert.AreEqual(new[] { "foo", "bar" }, svc.GetStringArray(new[] { "FoO", "bAr" }));
        }