Пример #1
0
 public static async void ConnectNewClient()
 {
     SignalGo.Client.ClientProvider clientProvider = new SignalGo.Client.ClientProvider();
     clientProvider.Connect("http://localhost:3284/TestServices/SignalGo");
     ITestManager service = clientProvider.RegisterServerServiceInterfaceWrapper <ITestManager>();
     string       result  = await service.HelloWorldAsync("ali123");
 }
Пример #2
0
        public async Task TestUploadAsync()
        {
            GlobalInitalization.Initialize();
            SignalGo.Client.ClientProvider client = GlobalInitalization.InitializeAndConnecteClient();
            using (MemoryStream memoryStream = new MemoryStream())
            {
                byte[] bytes = new byte[1024 * 512];
                for (int i = 0; i < bytes.Length; i++)
                {
                    bytes[i] = (byte)(i / 255);
                }
                memoryStream.Write(bytes, 0, bytes.Length);
                memoryStream.Seek(0, SeekOrigin.Begin);
                ITestServerStreamModel service = client.RegisterStreamServiceInterfaceWrapper <ITestServerStreamModel>();
                string result = await service.UploadImageAsync("hello world", new SignalGo.Shared.Models.StreamInfo()
                {
                    Length = memoryStream.Length,
                    Stream = memoryStream
                }, new TestStreamModel()
                {
                    Name = "test name", Values = new System.Collections.Generic.List <string>()
                    {
                        "value test 1", "value test 2"
                    }
                });

                Assert.IsTrue(result == "success");
            }
        }
Пример #3
0
 public TestStreamService(string serverAddress = null, int?port = null, SignalGo.Client.ClientProvider clientProvider = null)
 {
     ServerAddress   = serverAddress;
     Port            = port;
     CurrentProvider = clientProvider;
     ServiceName     = GetType().GetServerServiceName(true);
 }
        public async Task NormalSignalGoTestAsync()
        {
            GlobalInitalization.Initialize();
            SignalGo.Client.ClientProvider clientAdmin  = GlobalInitalization.InitializeAndConnecteClient();
            IAuthenticationService         serviceAdmin = clientAdmin.RegisterServerServiceInterfaceWrapper <IAuthenticationService>();

            await TestAdminUserASync(serviceAdmin);

            SignalGo.Client.ClientProvider clientNormal  = GlobalInitalization.InitializeAndConnecteClient();
            IAuthenticationService         serviceNormal = clientNormal.RegisterServerServiceInterfaceWrapper <IAuthenticationService>();

            await TestNormalUserASync(serviceNormal);

            string adminWhatIsMyNameAmIGust = await serviceAdmin.WhatIsMyNameAsync();

            Assert.IsTrue(adminWhatIsMyNameAmIGust == "admin user");

            string normalWhatIsMyNameGust = await serviceNormal.WhatIsMyNameAsync();

            Assert.IsTrue(normalWhatIsMyNameGust == "normal user");

            adminWhatIsMyNameAmIGust = await serviceAdmin.WhatIsMyNameAsync();

            Assert.IsTrue(adminWhatIsMyNameAmIGust == "admin user");
        }
        public void TestCallbacks()
        {
            GlobalInitalization.Initialize();
            SignalGo.Client.ClientProvider client  = GlobalInitalization.InitializeAndConnecteClient();
            AuthenticationService          service = client.RegisterServerService <AuthenticationService>(client);

            SignalGoTest2.Models.MessageContract result = service.TestCallbacksAsync();
            Assert.IsTrue(result.IsSuccess);
            SignalGoTest2.Models.MessageContract result2 = service.TestCallbacksSync();
            Assert.IsTrue(result2.IsSuccess);
        }
Пример #6
0
        public void TestValidationsRule()
        {
            GlobalInitalization.Initialize();
            SignalGo.Client.ClientProvider client = GlobalInitalization.InitializeAndConnecteClient();
            ITestServerModel service = client.RegisterServerServiceInterfaceWrapper <ITestServerModel>();
            ArticleInfo      result  = service.AddArticle(new ArticleInfo()
            {
                Name = "ali", Detail = "rezxa"
            });

            Assert.IsTrue(result.CreatedDateTime.HasValue);
            MessageContract <ArticleInfo> resultMessage = service.AddArticleMessage(new ArticleInfo());

            Assert.IsTrue(resultMessage.Errors.Count == 2);
            Assert.IsFalse(resultMessage.IsSuccess);
        }
Пример #7
0
        //public static void PiplineTest()
        //{
        //    TcpListener tcpListener = new TcpListener(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), 4545);

        //    tcpListener.Start();

        //    var socket = tcpListener.AcceptSocket();
        //}


        private static async void ClientAutoReconnectTest()
        {
            SignalGo.Client.ClientProvider clientProvider = new SignalGo.Client.ClientProvider();
            clientProvider.ProviderSetting.PriorityFunctionDelayTime = 0;
            ITestManager service = clientProvider.RegisterServerServiceInterfaceWrapper <ITestManager>();

            clientProvider.RegisterClientService <ClientService>();
            clientProvider.ConnectAsyncAutoReconnect("http://localhost:9752/SignalGoTestService", async(isConnected) =>
            {
                try
                {
                    Console.WriteLine("connection changed: " + isConnected);
                    if (isConnected)
                    {
                        Console.WriteLine("sum async calling");
                        for (int i = 0; i < 100; i++)
                        {
                            int sumResult = await service.SumAsync(10, 5);
                            await Task.Delay(1000);
                            Console.WriteLine("sum async called: " + sumResult);
                        }
                    }
                }
                catch
                {
                }
            });

            clientProvider.AddPriorityAsyncFunction(async() =>
            {
                try
                {
                    Console.WriteLine("HelloWorldAsync Calling");
                    string result = await service.HelloWorldAsync("ali123");
                    Console.WriteLine("HelloWorldAsync Success " + result);
                    if (result == $"Hello ali123")
                    {
                        return(SignalGo.Client.PriorityAction.NoPlan);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                return(SignalGo.Client.PriorityAction.TryAgain);
            });
        }
Пример #8
0
        public void TestDownload()
        {
            GlobalInitalization.Initialize();
            SignalGo.Client.ClientProvider client  = GlobalInitalization.InitializeAndConnecteClient();
            ITestServerStreamModel         service = client.RegisterStreamServiceInterfaceWrapper <ITestServerStreamModel>();

            SignalGo.Shared.Models.StreamInfo <string> result = service.DownloadImage("hello world", new TestStreamModel()
            {
                Name = "test name", Values = new System.Collections.Generic.List <string>()
                {
                    "value test 1", "value test 2"
                }
            });
            byte[] bytes   = new byte[1024];
            int    readLen = result.Stream.ReadAsync(bytes, 1024).GetAwaiter().GetResult();

            System.Diagnostics.Trace.Assert(result.Data == "hello return" && readLen == 4 && bytes[0] == 2 && bytes[1] == 5 && bytes[2] == 8 && bytes[3] == 9);
        }
Пример #9
0
        public async Task TestAsyncs()
        {
            GlobalInitalization.Initialize();
            SignalGo.Client.ClientProvider client = GlobalInitalization.InitializeAndConnecteClient();
            ITestServerModel service = client.RegisterServerServiceInterfaceWrapper <ITestServerModel>();
            string           result  = service.ServerAsyncMethod("hello");

            Assert.IsTrue(result == "hello guys");
            string result2 = service.ServerAsyncMethod("hello2");

            Assert.IsTrue(result2 == "not found");

            result = await service.ServerAsyncMethodAsync("hello");

            Assert.IsTrue(result == "hello guys");
            result2 = await service.ServerAsyncMethodAsync("hello2");

            Assert.IsTrue(result2 == "not found");
        }
        public void NormalSignalGoTest2()
        {
            GlobalInitalization.Initialize();
            SignalGo.Client.ClientProvider clientAdmin  = GlobalInitalization.InitializeAndConnecteClient();
            IAuthenticationService         serviceAdmin = clientAdmin.RegisterServerService <AuthenticationService>(clientAdmin);

            TestAdminUserSync(serviceAdmin);

            SignalGo.Client.ClientProvider clientNormal  = GlobalInitalization.InitializeAndConnecteClient();
            IAuthenticationService         serviceNormal = clientNormal.RegisterServerService <AuthenticationService>(clientNormal);

            TestNormalUserSync(serviceNormal);

            string adminWhatIsMyNameAmIGust = serviceAdmin.WhatIsMyName();

            Assert.IsTrue(adminWhatIsMyNameAmIGust == "admin user");

            string normalWhatIsMyNameGust = serviceNormal.WhatIsMyName();

            Assert.IsTrue(normalWhatIsMyNameGust == "normal user");

            adminWhatIsMyNameAmIGust = serviceAdmin.WhatIsMyName();
            Assert.IsTrue(adminWhatIsMyNameAmIGust == "admin user");
        }
Пример #11
0
 public ChatService(SignalGo.Client.ClientProvider clientProvider)
 {
     CurrentProvider = clientProvider;
     ServiceName     = this.GetType().GetServerServiceName(true);
 }
Пример #12
0
 public TestStreamService(SignalGo.Client.ClientProvider clientProvider = null)
 {
     CurrentProvider = clientProvider;
     ServiceName     = GetType().GetServerServiceName(true);
 }
Пример #13
0
        public void TestDataExchanger()
        {
            GlobalInitalization.Initialize();
            SignalGo.Client.ClientProvider client = GlobalInitalization.InitializeAndConnecteClient();
            ITestServerModel service = client.RegisterServerServiceInterfaceWrapper <ITestServerModel>();
            //while (true)
            //    System.Threading.Thread.Sleep(100);
            UserInfoTest test = new UserInfoTest()
            {
                Age           = 10, Id = 15, Username = "******", LastPostInfo = new PostInfoTest()
                {
                }, Password   = "******", PostInfoes = new System.Collections.Generic.List <PostInfoTest>()
                {
                }, RoleInfoes = new System.Collections.Generic.List <RoleInfoTest>()
                {
                    new RoleInfoTest()
                    {
                    }
                }
            };
            UserInfoTest test1 = new UserInfoTest()
            {
                Age           = 10, Id = 15, Username = "******", LastPostInfo = new PostInfoTest()
                {
                }, Password   = "******", PostInfoes = new System.Collections.Generic.List <PostInfoTest>()
                {
                }, RoleInfoes = new System.Collections.Generic.List <RoleInfoTest>()
                {
                    new RoleInfoTest()
                    {
                        Id = 5
                    }
                }
            };
            UserInfoTest test2 = new UserInfoTest()
            {
                Age           = 10, Id = 15, Username = "******", LastPostInfo = new PostInfoTest()
                {
                }, Password   = "******", PostInfoes = new System.Collections.Generic.List <PostInfoTest>()
                {
                }, RoleInfoes = new System.Collections.Generic.List <RoleInfoTest>()
                {
                    new RoleInfoTest()
                    {
                    }
                }
            };

            bool helloBind = service.HelloBind(test, test1, test2);

            Assert.IsTrue(helloBind);
            System.Collections.Generic.List <UserInfoTest> users = service.GetListOfUsers();
            Assert.IsTrue(string.IsNullOrEmpty(users[0].Password));
            Assert.IsTrue(users[0].LastPostInfo == null);
            Assert.IsTrue(users[0].PostInfoes != null);
            Assert.IsTrue(string.IsNullOrEmpty(users[0].PostInfoes[0].PostSecurityLink));
            Assert.IsTrue(users[0].PostInfoes[0].User == null);

            System.Collections.Generic.List <PostInfoTest> posts = service.GetPostsOfUser(1);
            Assert.IsTrue(string.IsNullOrEmpty(posts[0].PostSecurityLink));
            Assert.IsTrue(posts[0].User == null);

            System.Collections.Generic.List <PostInfoTest> customPosts = service.GetCustomPostsOfUser(1);
            Assert.IsTrue(!string.IsNullOrEmpty(customPosts[0].PostSecurityLink));
            Assert.IsTrue(customPosts[0].User == null);
            Assert.IsTrue(customPosts.Count == 6);
            Assert.IsTrue(customPosts[5].PostSecurityLink == null);
            Assert.IsTrue(customPosts[4].Id > 0 && customPosts[4].PostSecurityLink == null);
            Assert.IsTrue(string.IsNullOrEmpty(customPosts[0].Title) && string.IsNullOrEmpty(customPosts[1].Text) && customPosts[0].Id == customPosts[1].Id);

            System.Collections.Generic.List <UserInfoTest> customUsers = service.GetListOfUsersCustom();
            Assert.IsTrue(!string.IsNullOrEmpty(customUsers[0].Password));
            Assert.IsTrue(string.IsNullOrEmpty((customUsers[1].Username)));
            Assert.IsTrue(string.IsNullOrEmpty((customUsers[1].PostInfoes[0].PostSecurityLink)));
            Assert.IsTrue(!string.IsNullOrEmpty((customUsers[1].PostInfoes[0].Text)));
            bool loginResult = service.Login(new UserInfoTest()
            {
                Id = 1, Age = 20, LastPostInfo = new PostInfoTest()
                {
                    Text = "aa"
                }, Username = "******", Password = "******", PostInfoes = new System.Collections.Generic.List <PostInfoTest>()
                {
                    new PostInfoTest()
                    {
                        Text = "re"
                    }
                }, RoleInfoes = new System.Collections.Generic.List <RoleInfoTest>()
                {
                    new RoleInfoTest()
                    {
                        Type = RoleTypeTest.Admin, User = new UserInfoTest()
                        {
                            Username = "******"
                        }, Id = 5
                    }
                }
            });

            Assert.IsTrue(loginResult);
        }