public void Can_reconnect() { var reconnected = false; var client = new DdpClient(_socket, _helper); client.DdpReconnect += () => reconnected = true; var firstMessage = new PortableMessageReceivedEventArgs(JsonConvert.SerializeObject(new { session = AutoFixture.Create<string>(), msg = "connected" })); var secondMessage = new PortableMessageReceivedEventArgs(JsonConvert.SerializeObject(new { session = AutoFixture.Create<string>(), msg = "connected" })); // Act _socket.MessageReceived += Raise.Event<EventHandler<PortableMessageReceivedEventArgs>>(new object(), firstMessage); _socket.Closed += Raise.Event<EventHandler>(); _socket.MessageReceived += Raise.Event<EventHandler<PortableMessageReceivedEventArgs>>(new object(), secondMessage); // Assert _socket.Received().Open(); reconnected.Should().BeTrue(); }
public void DdpClient_ConnectAsync_CalledMultipleTimes() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); connection.Reply( JsonConvert.SerializeObject(new Connected() {Session = "TestSession"})); client.ConnectAsync().Wait(); bool exceptionCaught = false; try { client.ConnectAsync().Wait(); } catch (AggregateException e) { Assert.IsTrue(e.InnerException is InvalidOperationException); exceptionCaught = true; } Assert.IsTrue(exceptionCaught); }
public void DdpClient_Call_GetResult() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); this.Connect(client, connection); this.ClearSentMessages(connection); var task = client.Call<SimpleField>("TestMethod"); var methodString = connection.GetSentMessage(); var method = JsonConvert.DeserializeObject<Method>(methodString); connection.Reply( JsonConvert.SerializeObject(new Result() { Id = method.Id, ResultObject = JToken.FromObject(new SimpleField() {integerField = 11, boolField = false, stringField = "ReturnObject"}) })); connection.Reply(JsonConvert.SerializeObject(new Updated() { Methods = new[] { method.Id } })); task.Wait(); Assert.AreEqual("TestMethod", method.MethodName); Assert.AreEqual(0, method.Parameters.Length); var result = task.Result; Assert.AreEqual(11, result.integerField); Assert.AreEqual(false, result.boolField); Assert.AreEqual("ReturnObject", result.stringField); }
public async Task Can_ping() { var client = new DdpClient(Constants.RocketServer, false, _helper); await client.ConnectAsync(TimeoutToken); // Act await client.PingAsync(TimeoutToken); // Assert }
public void On_error_log() { var logger = Substitute.For<ILogger>(); // ReSharper disable once UnusedVariable var client = new DdpClient(_socket, logger); var message = AutoFixture.Create<string>(); var exception = new Exception(message); // Act _socket.Error += Raise.Event<EventHandler<PortableErrorEventArgs>>(new object(), new PortableErrorEventArgs(exception)); // Assert logger.Received().Info($"ERROR: {message}"); }
public void Connecting_should_set_session() { var client = new DdpClient(_socket, _helper); var sessionId = AutoFixture.Create<string>(); var message = new { session = sessionId, msg = "connected" }; var jsonMessage = new PortableMessageReceivedEventArgs(JsonConvert.SerializeObject(message)); // Act _socket.MessageReceived += Raise.Event<EventHandler<PortableMessageReceivedEventArgs>>(new object(), jsonMessage); // Assert client.SessionId.Should().Be(sessionId); }
public void Can_unsubscribe() { var client = new DdpClient(_socket, _helper); var subId = AutoFixture.Create<string>(); var message = new { id = subId, msg = "nosub" }; var jsonMessage = new PortableMessageReceivedEventArgs(JsonConvert.SerializeObject(message)); // Act var task = client.UnsubscribeAsync(subId, TimeoutToken); _socket.MessageReceived += Raise.Event<EventHandler<PortableMessageReceivedEventArgs>>(new object(), jsonMessage); Action action = async () => await task; // Assert action.ShouldNotThrow<OperationCanceledException>(); }
static void Main(string[] args) { using (DdpClient client = new DdpClient("localhost:3000")) { client.Message += OnMessage; client.MeteorError += OnError; client.MethodResult += OnMessageResult; client.MethodUpdated += OnMessageUpdated; client.ClientError += OnClientError; client.Connect(); String callId = Guid.NewGuid().ToString("N"); client.Subscribe(Guid.NewGuid().ToString("N"), "MeteorPublishTest"); client.Publish(callId, "MeteorMethod", new { Type = "test", @event = "Hello, Meteor!!!" }); Console.WriteLine("Called method with callId: " + callId); Console.ReadLine(); } }
static void Main(string[] args) { using(DdpClient client = new DdpClient("localhost:3000")) { client.Message += OnMessage; client.MeteorError += OnError; client.MethodResult += OnMessageResult; client.MethodUpdated += OnMessageUpdated; client.ClientError += OnClientError; client.Connect(); String callId = Guid.NewGuid().ToString("N"); client.Subscribe(Guid.NewGuid().ToString("N"), "MeteorPublished"); client.Publish(callId, "MeteorMethod", new { Type = "test", @event = "Hello, Meteor!!!" }); Console.WriteLine("Called method with callId: " + callId); Console.ReadLine(); } }
public void DdpClient_Call_ServerMethodInvoked() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); this.Connect(client, connection); this.ClearSentMessages(connection); var task = client.Call("TestMethod"); var methodString = connection.GetSentMessage(); var method = JsonConvert.DeserializeObject<Method>(methodString); connection.Reply(JsonConvert.SerializeObject(new Result() {Id = method.Id})); connection.Reply(JsonConvert.SerializeObject(new Updated() {Methods = new[] {method.Id}})); task.Wait(); Assert.AreEqual("TestMethod", method.MethodName); Assert.AreEqual(0, method.Parameters.Length); }
public void DdpClient_Call_ErrorReturned() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); this.Connect(client, connection); this.ClearSentMessages(connection); var task = client.Call("TestMethod"); var methodString = connection.GetSentMessage(); var method = JsonConvert.DeserializeObject<Method>(methodString); connection.Reply( JsonConvert.SerializeObject(new Result() { Id = method.Id, Error = new Error() {Details = "Failed", ErrorMessage = "TestFailed", Reason = "ReasonFailed"} })); connection.Reply(JsonConvert.SerializeObject(new Updated() { Methods = new[] { method.Id } })); ExceptionAssert.ExpectAggregateException(() => task.Wait(), typeof(DdpServerException)); Assert.AreEqual("TestMethod", method.MethodName); Assert.AreEqual(0, method.Parameters.Length); Assert.IsNotNull(task.Exception); Assert.IsTrue(task.IsFaulted); }
public void TestInitialize() { this.testConnection = new InMemoryConnection(); this.client = new DdpClient(this.testConnection); }
public void DdpClient_GetCollection_GetsTypedCollection() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); this.Connect(client, connection); var collection = client.GetCollection<SimpleDdpObject>("Test"); Assert.IsNotNull(collection); }
public void DdpClient_Call_BeforeConnectThrows() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); PCLTesting.ExceptionAssert.Throws<InvalidOperationException>(() => client.Call("Test")); }
public void DdpClient_CallParametersResult_BeforeConnectThrows() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); PCLTesting.ExceptionAssert.Throws<InvalidOperationException>(() => client.Call<string>("Test", 1 )); }
public void DdpClient_SubscribeParameters_BeforeConnectThrows() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); PCLTesting.ExceptionAssert.Throws<InvalidOperationException>(() => client.Subscribe("TestSub", "Test" )); }
private void Connect(DdpClient client, InMemoryConnection connection) { connection.Reply( JsonConvert.SerializeObject(new Connected() { Session = "TestSession" })); client.ConnectAsync().Wait(); }
public void DdpClient_Subscribe_ServerMethodCalled() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); this.Connect(client, connection); this.ClearSentMessages(connection); var task = client.Subscribe("TestSubscription"); var subscribeString = connection.GetSentMessage(); var subscribe = JsonConvert.DeserializeObject<Subscribe>(subscribeString); connection.Reply(JsonConvert.SerializeObject(new Ready() { SubscriptionsReady = new []{subscribe.Id}})); task.Wait(); Assert.IsTrue(task.IsCompleted); Assert.AreEqual("TestSubscription", subscribe.Name); }