private void Proxy_Client_OnClientDisconnected() { if (FakeClient.IsRunning) { FakeClient.Disconnect(); } }
public async Task WhenAddingClientWithKnownLastEventId_AllSubsequentEventsShouldBeSendToClient() { _sut.EnableResend(10); await _sut.BroadcastEvent("Ignored 1", id : "1"); await _sut.BroadcastEvent("M2", id : "2"); await _sut.BroadcastEvent("M3", id : null); await _sut.BroadcastEvent("M4", id : "4"); var client = new FakeClient() { LastEventId = "1" }; _sut.Clients.Add(client); var body = await client.ReadStreamFromStart(); body.Should().Be( "id:2\ndata:M2\n\n" + "data:M3\n\n" + "id:4\ndata:M4\n\n"); }
public void Lint(Type api) { var client = new FakeClient(); var instance = Activator.CreateInstance(api, client); var apiInterface = GetApiInterface(api); ApiClientHasAPropertyForApi(api, apiInterface); var apiMethods = api.GetMethods(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance); AllPublicMethodsAreExposedOnInterface(apiInterface, apiMethods); string slackMethodGroup = null; foreach (var method in apiMethods) { client.Reset(); method.Invoke(instance, method.GetParameters().Select(DummyValue).ToArray()); LastParamShouldBeOptionalCancellationToken(method); AllMethodsShouldUseSameSlackMethodGroup(client, method, ref slackMethodGroup); AllArgsShouldBeSnakeCase(client.Args, method); } }
public void ResumableUploadObjectWithFailedTimeMoreThanRetryTime() { var key = OssTestUtils.GetObjectKey(_className); try { var client = new FakeClient(Config.Endpoint, Config.AccessKeyId, Config.AccessKeySecret); client.beginFailedIndex = 2; client.endFailedIndex = 100; client.currentIndex = 0; client.ResumableUploadObject(_bucketName, key, Config.MultiUploadTestFile, null, Config.DownloadFolder); Assert.IsFalse(true); } catch (Exception) { Assert.IsTrue(true); } finally { if (OssTestUtils.ObjectExists(_ossClient, _bucketName, key)) { _ossClient.DeleteObject(_bucketName, key); } } }
public async Task MaxActiveViolation_WaitOnResourcesExhausted_Blocks() { using (var pool = new SessionPool()) { pool.Options.WaitOnResourcesExhausted = true; pool.Options.MaximumActiveSessions = 2; var client = new FakeClient(); var session1 = await CreateSessionAsync(pool, client); var session2 = await CreateSessionAsync(pool, client); var createTask = CreateSessionAsync(pool, client); await Task.WhenAll(createTask, ReleaseAfterDelay(session1)); Assert.Same(session1, await createTask); async Task ReleaseAfterDelay(Session session) { await Task.Delay(TimeSpan.FromMilliseconds(10)); pool.ReleaseToPool(client, session); } } }
public static void HandleCharacterCreationResultMessage(FakeClient client, CharacterCreationResultMessage message) { if ((CharacterCreationResultEnum)message.result != CharacterCreationResultEnum.OK) { client.Log("Cannot create character : " + (CharacterCreationResultEnum)message.result); } }
public void AddClient_ClientShouldBeAddedToManager() { var client = new FakeClient(); _sut.Add(client); _sut.GetAll().Should().HaveCount(1).And.Contain(client); }
public static void HandleSelectedServerDataMessage(FakeClient client, SelectedServerDataMessage message) { client.Disconnect(true); client.Ticket = new string(message.ticket.Select(x => (char)x).ToArray()); client.WorldIp = message.address; client.WorldPort = message.port; //client.Connect(message.address, message.port); }
public void AddClient_IfClientWasAlreadyAdded_ClientShouldBeInManagerOnlyOnce() { var client = new FakeClient(); _sut.Add(client); _sut.Add(client); _sut.GetAll().Should().HaveCount(1); }
private async Task <string> GetResponseBodyAfterCommentBeingSent(string comment) { var sut = new EventTransmitter(); var client = new FakeClient(); await sut.SendComment(client, comment); return(await client.ReadStreamFromStart()); }
private static void ResetClient(FakeClient client, object body) { client.RequestCounter = 0; client.DefaultResponseData = new ResponseData { Body = client.ObjectMapper.WriteValue(body), HttpStatus = HttpStatusCode.OK }; }
private void Initialize() { m_client1 = new FakeClient(new MouseAndKbInput(), "Clien 1", "client-1-address"); m_client2 = new FakeClient(null, "Clien 2", "client-2-address"); m_netCom = new FakeClientNetworkCommunication(m_client1, m_client2); // m_gameServer = GameObject.Find("ServerScene").GetComponent<ServerScene>().GameServer; }
public static void HandleGameContextCreateMessage(FakeClient client, GameContextCreateMessage message) { if (client.Id == 1) { client.Send(new NpcGenericActionRequestMessage(-1, 3, 83887104)); Thread.Sleep(1000); client.Send(new NpcDialogReplyMessage(259)); } }
public static void HandleHelloConnectMessage(FakeClient client, HelloConnectMessage message) { var writer = new BigEndianWriter(); writer.WriteUTF(FakeClientManager.AccountName + client.Id); writer.WriteUTF(FakeClientManager.AccountPassword); /*client.Send(new IdentificationMessage(false, false, false, VersionExtension.ExpectedVersion.ToVersionExtended(0,0), "fr", * writer.Data.Select(x => (sbyte)x), (short)WorldServer.ServerInformation.Id));*/ }
public void WhenClientConnectionIsClosed_ClientShouldBeRemoved() { var client = new FakeClient(); _sut.Add(client); client.CloseConnection(); _sut.GetAll().Should().NotContain(client); }
public void RemoveClient_ClientShouldBeRemovedFromManager() { var client = new FakeClient(); _sut.Add(client); _sut.Remove(client); _sut.GetAll().Should().NotContain(client); }
public void Start_should_accept_a_shutdown_request() { var client = new FakeClient(); var server = new ConsoleStreamServer(new NullLogger()); server.Start(client.SendCommand, client.ReceiveResponse, new FakeRegistry()); client.LastResponse.Should() .Be("{\"CommandName\":\"ShutdownServer\",\"CommandResult\":true,\"ErrorCode\":\"Success\"}"); }
public void Start_should_accept_echo_request() { var client = new FakeClient(new EchoCommand("Hello!")); var server = new ConsoleStreamServer(new NullLogger()); server.Start(client.SendCommand, client.ReceiveResponse, new FakeRegistry()); client.Responses.First().Should() .Be("{\"CommandName\":\"Echo\",\"CommandResult\":\"Hello!\",\"ErrorCode\":\"Success\"}"); }
public static void HandleHelloConnectMessage(FakeClient client, HelloConnectMessage message) { var writer = new BigEndianWriter(); writer.WriteUTF(client.AccountName); writer.WriteUTF(client.AccountPassword); client.Send(new IdentificationMessage(false, false, false, new Version(2, 10, 0, 65664, 0, (sbyte)BuildTypeEnum.RELEASE).ToVersionExtended(0, 0), "fr", writer.Data.Select(x => (sbyte)x), (short)WorldServer.ServerInformation.Id, 0, new short [0])); }
public async Task CanClearResources() { var client = new FakeClient(); var session = await CreateSessionAsync(SessionPool.Default, client); SessionPool.Default.ReleaseToPool(client, session); await SpannerConnection.ClearPooledResourcesAsync(); Assert.Equal(0, SessionPool.Default.CurrentPooledSessions); }
public static void HandleCharactersListMessage(FakeClient client, CharactersListMessage message) { if (client.Id == 1) { client.Send(new CharacterSelectionMessage(message.characters.First(x => x.name == "Loom2").id)); } if (client.Id == 2) { client.Send(new CharacterSelectionMessage(message.characters.First(x => x.name == "Loom").id)); } }
public async Task BodyShouldContainRetryFieldWithReconnectionTime() { var sut = new EventTransmitter(); var client = new FakeClient(); await sut.SendWaitRequest(client, TimeSpan.FromMilliseconds(1000)); var body = await client.ReadStreamFromStart(); body.Should().Be("retry:1000\n\n"); }
public void AddClient_ClientAddedEventShouldBeRaised() { var client = new FakeClient(); ClientAddedEventArgs eventArgs = null; _sut.ClientAdded += (sender, args) => eventArgs = args; _sut.Add(client); eventArgs.NewClient.Should().Be(client); }
public void Start_should_accept_a_registry_read_request() { var client = new FakeClient( new RegistryReadIntValueCommand(RegistryBaseKey.CurrentUser, "SubKey", "IntValue", -1)); var server = new ConsoleStreamServer(new NullLogger()); server.Start(client.SendCommand, client.ReceiveResponse, new FakeRegistry(@"HKCU\SubKey\IntValue=123")); client.Responses.First().Should() .Be("{\"CommandName\":\"RegistryReadIntValue\",\"CommandResult\":123,\"ErrorCode\":\"Success\"}"); }
public async Task EmptyPoolCreatesNewSession() { using (var pool = new SessionPool()) { var client = new FakeClient(); var session = await CreateSessionAsync(pool, client); Assert.Single(client.Sessions, session); Assert.Single(client.SessionDatabases, s_defaultName); } }
public async Task Should_be_able_to_override_minimu_size_for_compression() { var client = new FakeClient("fake-client", string.Empty, RetryPolicy.NoRetry); var plugin = CompressionPluginExtensions.RegisterCompressionPlugin(client, 2); var message = new Message(new byte[] { 1, 2, 3 }); await plugin.BeforeMessageSend(message); Assert.Equal(2, client.RegisteredPluginMinimumCompressionSize); }
private async Task <string> GetResponseBodyAfterEventBeingSent( string data, string type = null, string id = null) { var sut = new EventTransmitter(); var client = new FakeClient(); await sut.SendEvent(client, data, type, id); return(await client.ReadStreamFromStart()); }
public void AddClientRange_AllClientsShouldBeAddedToManager() { var clients = new FakeClient[] { new FakeClient(), new FakeClient() }; _sut.AddRange(clients); _sut.GetAll().Should().Contain(clients); }
private static void TestGetBillInfo_OnRequest(FakeClient sender, FakeClientRequestEventArgs args) { var billResponse = sender.ObjectMapper.ReadValue <BillResponse>(args.ResponseData.Body); Assert.AreEqual(1, args.Counter, "One request"); Assert.AreEqual("GET", args.Method, "Equal method"); Assert.AreEqual(BillPaymentsClient.BillsUrl + billResponse.BillId, args.Url, "Equal url"); Assert.AreEqual("Bearer " + Config.MerchantSecretKey, args.Headers["Authorization"], "Authorization bearer"); Assert.AreEqual("application/json", args.Headers["Accept"], "Accept bearer"); Assert.IsNull(args.EntityOpt, "No body request"); }
private static void AllMethodsShouldUseSameSlackMethodGroup(FakeClient client, MethodInfo method, ref string slackMethodGroup) { var methodGroup = string.Join('.', client.SlackMethod.Split('.').SkipLast(1)); if (slackMethodGroup == null) { slackMethodGroup = methodGroup; } else { methodGroup.ShouldBe(slackMethodGroup, $"{method.DeclaringType.Name}.{method.Name} uses a different API method group than other methods"); } }
public void Post_CallsRestClient() { var restClient = Substitute.For<RestClient>(); var client = new FakeClient(new ApiContext("token")) { Client = restClient }; client.Post<Contact, FakeApiModel>("/res", new FakeApiModel {Firstname = "Angelina", Lastname = "Jolie"}); restClient.Received(1).Execute(Arg.Any<RestRequest>()); }
public void Get_CallsRestClient() { var restClient = Substitute.For<RestClient>(); restClient.Get(Arg.Any<RestRequest>()).Returns(x => new RestResponse()); var client = new FakeClient(new ApiContext("token")) { Client = restClient }; client.Get<FakeApiModel>("/resource"); restClient.Received(1).Execute(Arg.Any<RestRequest>()); }
public void Post_ModelNotValid_ThrowsApplicationException() { var restClient = Substitute.For<RestClient>(); var client = new FakeClient(new ApiContext("token")) { Client = restClient }; Assert.Throws<ApplicationException>(delegate { client.Post<Contact, FakeApiModel>("/resource", new FakeApiModel()); }); }
public void CreateRequest_ContainsAllHeaders() { var restClient = Substitute.For<RestClient>(); var client = new FakeClient(new ApiContext("token") { AppName = "My app", AppVersion = "1.0.9" }) { Client = restClient }; var request = client.ResquestTest("/resource", Method.GET); Assert.That(request.Method, Is.EqualTo(Method.GET)); Assert.True(request.Parameters.Any(x => x.Type == ParameterType.HttpHeader && x.Name == ApiHeaders.Token)); Assert.True(request.Parameters.Any(x => x.Type == ParameterType.HttpHeader && x.Name == ApiHeaders.App && x.Value == "My app")); Assert.True(request.Parameters.Any(x => x.Type == ParameterType.HttpHeader && x.Name == ApiHeaders.AppVersion && x.Value == "1.0.9")); Assert.True(request.Parameters.Any(x => x.Type == ParameterType.HttpHeader && x.Name == ApiHeaders.SdkVersion && x.Value == SdkSettings.Version)); }
static void Main(string[] args) { FakeClient client = new FakeClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080)); Console.Title = "Test client."; while(true) { Console.WriteLine("Input:"); String input = Console.ReadLine(); if(input.Equals("test")) { client.doTestRun(6); continue; } if(input.StartsWith("test")) { client.doTestRun(Int32.Parse(input.Split(' ').Skip(1).First())); continue; } switch(input) { case "large": client.doTestLarge(); break; case "clear": client.clearSession(); break; default: break; } } }