Ejemplo n.º 1
0
        public static IMultiService Create(int depth)
        {
            var endpoint = "Multi_" + depth;

            TinyService.Host(new MultiService(depth)).AtEndpoint(endpoint);
            return(TinyClient.Create <IMultiService>(endpoint));
        }
Ejemplo n.º 2
0
 private void TestClient_Load(object sender, EventArgs e)
 {
     client            = new TinyClient();
     client.ClientPort = 7000;
     client.Encode     = EncodingType.ASCII;
     client.Protocol   = ProtocolType.Udp;
 }
        public void ShouldCollectDisposedInstances()
        {
            var instance = client.GetInstance("1");

            instance.Call().ShouldBe("1");
            TinyClient.Dispose(instance);
            Should.Throw <Exception>(() => instance.Call());
        }
        public void ShouldKeepDesignatedInstances()
        {
            var instance = client.GetInstance("1");

            TinyClient.KeepAlive(instance);
            Thread.Sleep(5000);
            instance.Call().ShouldBe("1");
        }
Ejemplo n.º 5
0
 public static void Run()
 {
     using (TinyService.Host(new Service()).AtEndpoint("test"))
     {
         var client = TinyClient.Create <IService>("test");
         Console.WriteLine(client.Call("1"));
         Console.WriteLine(client.Call(1));
         Console.WriteLine(client.Call(1.0));
     }
 }
Ejemplo n.º 6
0
 public static void Run()
 {
     using (TinyService.Host(new Server()).AtEndpoint("test"))
     {
         var client = TinyClient.Create <IServer>("test");
         client.Register(new Callback());
         client.Raise("x");
         client.Register(new Callback());
         client.Raise("y");
     }
 }
        public void NullablesTest()
        {
            var service = new Mock <INullableTestService>();

            service.Setup(x => x.Test(null)).Returns <double?>(null);
            service.Setup(x => x.Test(1.23)).Returns(1.23);

            using (TinyService.Host(service.Object).AtEndpoint("test"))
            {
                var client = TinyClient.Create <INullableTestService>("test");
                client.Test(null).ShouldBe(null);
                client.Test(1.23).ShouldBe(1.23);
            }
        }
Ejemplo n.º 8
0
        public static void Run()
        {
            var service = new ValueContainer <ValueContainer <string> >();

            service.UpdateValue(new ValueContainer <string>());

            using (TinyService.Host(service).AtEndpoint("test"))
            {
                var client = TinyClient.Create <IValueContainer <IValueContainer <string> > >("test");
                client.Value.UpdateValue("abc");
                client.Value.UpdateValue("cde");
                Console.WriteLine(client.Value.Value);
            }
        }
        public void SetUp()
        {
            var service = new Mock <IRetentionService>();

            service.Setup(x => x.GetInstance(It.IsAny <string>())).Returns <string>(text =>
            {
                var instance = new Mock <IRetentionInstance>();
                instance.Setup(x => x.Call()).Returns(text);
                return(instance.Object);
            });

            endpoint = TinyService.Host(service.Object).WithCleanupInterval(TimeSpan.FromSeconds(2)).AtEndpoint("test");
            client   = TinyClient.Create <IRetentionService>("test");
        }
Ejemplo n.º 10
0
        public void ShouldThrowIfTimedOut()
        {
            var service = new Mock <INullableTestService>();

            service.Setup(x => x.Test(null)).Returns <double?>(x =>
            {
                Thread.Sleep(2000);
                return(null);
            });

            using (TinyService.Host(service.Object).AtEndpoint("test"))
            {
                TinyClient.InitDefaultEndpoint(executionTimeout: TimeSpan.FromSeconds(1));
                var client = TinyClient.Create <INullableTestService>("test");
                Should.Throw <TimeoutException>(() => client.Test(null));
            }
        }
Ejemplo n.º 11
0
        public static void Run()
        {
            var service = new ValueContainer <IService> {
                Value = new Service()
            };

            using (TinyService.Host(service).AtEndpoint("test"))
            {
                var client = TinyClient.Create <IValueContainer <IService> >("test");
                var base1  = client.Value.GetNewBase();
                base1.Call();
                var specific1 = TinyClient.CastProxy <ISpecific>(base1);
                specific1.Call();
                specific1.CallSpecific();

                var base2 = client.Value.Base;
                base2.Call();
                var specific2 = TinyClient.CastProxy <ISpecific>(base2);
                specific2.Call();
                specific2.CallSpecific();
            }
        }
Ejemplo n.º 12
0
        public static void Run()
        {
            var service = new ValueContainer <IEnumerable <IValueContainer <int> > >();

            service.UpdateValue(
                new[]
            {
                new ValueContainer <int>(),
                new ValueContainer <int>()
            });

            using (TinyService.Host(service).AtEndpoint("test"))
            {
                var client     = TinyClient.Create <IValueContainer <IEnumerable <IValueContainer <int> > > >("test");
                var containers = client.Value.ToList();
                for (int i = 0; i < containers.Count; ++i)
                {
                    containers[i].UpdateValue(i);
                    Console.WriteLine(service.Value.ElementAt(i).Value);
                    Console.WriteLine(containers[i].Value);
                }
            }
        }
 public void NoServiceTest()
 {
     Should.Throw <TinyWebServiceException>(() => TinyClient.Create <INullableTestService>("test"));
 }
 public void ShouldSerializeCustomTypes()
 {
     TinyClient.RegisterCustomSerializer(x => Convert.ToInt64(x.TotalMilliseconds).ToString(), x => TimeSpan.FromMilliseconds(long.Parse(x)));
     Serialize(TimeSpan.FromSeconds(1.234)).ShouldBe("1234");
     Deserialize <TimeSpan>("1234").TotalMilliseconds.ShouldBe(1234);
 }