public void ctor_withFakeClient_ShouldReturnvalidObject() { IMDPClient fakeMDPClient = new MDPTestClientForTitanicClient(); var sut = new TitanicClient(fakeMDPClient); sut.Should().NotBeNull(); }
public void Request_NullOrEmptyServiceName_ShouldThrowArgumentNullException() { var fakeMDPClient = new MDPTestClientForTitanicClient(); var sut = new TitanicClient(fakeMDPClient); Assert.Throws <ArgumentNullException> (() => sut.Request(string.Empty, "Hello World")); }
public void ctor_withFakeClient_ShouldReturnvalidObject () { IMDPClient fakeMDPClient = new MDPTestClientForTitanicClient (); var sut = new TitanicClient (fakeMDPClient); sut.Should ().NotBeNull (); }
static void Main(string[] arguments) { const string address = "tcp://localhost:5555"; //const string service_name = "echo"; SetParameter(arguments); Console.WriteLine("[TitanicClient] Staring Titanic Client\n"); Console.WriteLine("[TitanicClient] {0} / #{1} Messages\n\n", s_verbose ? "verbose" : "silent", s_runs); // wait to allow MDP/Titanic Broker to complete start up Thread.Sleep(500); using (ITitanicClient client = new TitanicClient(address)) { if (s_verbose) { client.LogInfoReady += (s, e) => Console.WriteLine(e.Info); } for (var i = 0; i < s_runs; i++) { Console.WriteLine("[TitanicClient] Loop #{0} entered ...", i); var data = "ERROR! NO REPLY"; // does 5 retries to get the reply var reply = client.GetResult("echo", "Hallo World", 5); if (reply == null) { Console.WriteLine("\t[TitanicClient] ran into a problem, received 'null' in loop #{0}", i); continue; } data = reply.Item1 != null?Encoding.UTF8.GetString(reply.Item1) : data; if (data != "Hallo World") { Console.WriteLine("\t[TitanicClient] Hallo World != {0} on loop #{1} with status {2}", data, i, reply.Item2); } if (!ReferenceEquals(reply.Item1, null) && reply.Item2 == TitanicReturnCode.Ok) { Console.WriteLine("\t[TitanicClient] Status = {0} - Reply = {1}", reply.Item2, data); } } } Console.WriteLine("\n[TitanicClient] To exit press any key!"); Console.ReadKey(); }
public void GetResult_StringString_ShouldReturnExpectedResult() { const string expected_phrase = "Thank God Its Friday"; var replyFrame = new NetMQFrame(expected_phrase); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient(fakeMDPClient); var result = sut.GetResult("echo", expected_phrase); result.Item2.Should().Be(TitanicReturnCode.Ok); result.Item1.Should().BeSameAs(replyFrame.Buffer); }
public void Reply_ExistingRequestStringIntegerInteger_ShouldReturnExpectedReply() { const string expected_phrase = "Thank God Its Friday"; var replyFrame = new NetMQFrame(expected_phrase); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient(fakeMDPClient); var reply = sut.Reply(Guid.NewGuid(), 0, TimeSpan.FromMilliseconds(0)); reply.Item2.Should().Be(TitanicReturnCode.Ok); Encoding.UTF8.GetString(reply.Item1).Should().Be(expected_phrase); }
public void Request_ValidRequestStringBytes_ShouldReturnExpectedGuid () { var expectedId = Guid.NewGuid (); var replyMessage = new NetMQMessage (); replyMessage.Push (expectedId.ToString ()); replyMessage.Push (TitanicReturnCode.Ok.ToString ()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyMessage = replyMessage, RequestId = expectedId }; var sut = new TitanicClient (fakeMDPClient); var id = sut.Request ("echo", Encoding.UTF8.GetBytes ("Hello World!")); id.Should ().Be (expectedId.ToString ()); }
public void Request_ValidRequestStringGeneric_ShouldReturnExpectedGuid () { var expectedId = Guid.NewGuid (); var replyMessage = new NetMQMessage (); replyMessage.Push (expectedId.ToString ()); replyMessage.Push (TitanicReturnCode.Ok.ToString ()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyMessage = replyMessage, RequestId = expectedId }; var generic = new TestEntity (); var sut = new TitanicClient (fakeMDPClient); var id = sut.Request ("echo", generic.ConvertToBytes ()); id.Should ().Be (expectedId.ToString ()); }
public void GetResult_StringIntegerGeneric_ReturnExpectedResult() { var expected = new TestEntity(); var replyFrame = new NetMQFrame(expected.ConvertToBytes()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient(fakeMDPClient); var result = sut.GetResult <TestEntity, TestEntity> ("echo", expected); result.Item2.Should().Be(TitanicReturnCode.Ok); result.Item1.Id.Should().Be(expected.Id); result.Item1.Name.Should().Be(expected.Name); }
public void Reply_InvalidReply_ShouldReturnFailure() { var replyMessage = new NetMQMessage(); replyMessage.Push(TitanicReturnCode.Failure.ToString()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyMessage = replyMessage }; var sut = new TitanicClient(fakeMDPClient); var reply = sut.Reply(Guid.NewGuid(), TimeSpan.FromMilliseconds(0)); reply.Item2.Should().Be(TitanicReturnCode.Failure); reply.Item1.Should().BeNull(); }
private static void Main (string[] arguments) { const string address = "tcp://localhost:5555"; //const string service_name = "echo"; SetParameter (arguments); Console.WriteLine ("[TitanicClient] Staring Titanic Client\n"); Console.WriteLine ("[TitanicClient] {0} / #{1} Messages\n\n", s_verbose ? "verbose" : "silent", s_runs); // wait to allow MDP/Titanic Broker to complete start up Thread.Sleep (500); using (ITitanicClient client = new TitanicClient (address)) { if (s_verbose) client.LogInfoReady += (s, e) => Console.WriteLine (e.Info); for (var i = 0; i < s_runs; i++) { Console.WriteLine ("[TitanicClient] Loop #{0} entered ...", i); var data = "ERROR! NO REPLY"; // does 5 retries to get the reply var reply = client.GetResult ("echo", "Hallo World", 5); if (reply == null) { Console.WriteLine ("\t[TitanicClient] ran into a problem, received 'null' in loop #{0}", i); continue; } data = reply.Item1 != null ? Encoding.UTF8.GetString (reply.Item1) : data; if (data != "Hallo World") Console.WriteLine ("\t[TitanicClient] Hallo World != {0} on loop #{1} with status {2}", data, i, reply.Item2); if (!ReferenceEquals (reply.Item1, null) && reply.Item2 == TitanicReturnCode.Ok) Console.WriteLine ("\t[TitanicClient] Status = {0} - Reply = {1}", reply.Item2, data); } } Console.WriteLine ("\n[TitanicClient] To exit press any key!"); Console.ReadKey (); }
public void Request_ValidRequestStringBytes_ShouldReturnExpectedGuid() { var expectedId = Guid.NewGuid(); var replyMessage = new NetMQMessage(); replyMessage.Push(expectedId.ToString()); replyMessage.Push(TitanicReturnCode.Ok.ToString()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyMessage = replyMessage, RequestId = expectedId }; var sut = new TitanicClient(fakeMDPClient); var id = sut.Request("echo", Encoding.UTF8.GetBytes("Hello World!")); id.Should().Be(expectedId.ToString()); }
public void Request_ValidRequestStringGeneric_ShouldReturnExpectedGuid() { var expectedId = Guid.NewGuid(); var replyMessage = new NetMQMessage(); replyMessage.Push(expectedId.ToString()); replyMessage.Push(TitanicReturnCode.Ok.ToString()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyMessage = replyMessage, RequestId = expectedId }; var generic = new TestEntity(); var sut = new TitanicClient(fakeMDPClient); var id = sut.Request("echo", generic.ConvertToBytes()); id.Should().Be(expectedId.ToString()); }
public void Reply_ExistingRequestStringIntegerTimeSpanGeneric_ShouldReturnExpectedReply() { var expected = new TestEntity(); var replyFrame = new NetMQFrame(expected.ConvertToBytes()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient(fakeMDPClient); var reply = sut.Reply(Guid.NewGuid(), 0, TimeSpan.FromMilliseconds(0)); reply.Item2.Should().Be(TitanicReturnCode.Ok); var result = new TestEntity(); result.GenerateFrom(reply.Item1); result.Id.Should().Be(expected.Id); result.Name.Should().Be(expected.Name); }
public void Reply_InvalidReply_ShouldReturnFailure () { var replyMessage = new NetMQMessage (); replyMessage.Push (TitanicReturnCode.Failure.ToString ()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyMessage = replyMessage }; var sut = new TitanicClient (fakeMDPClient); var reply = sut.Reply (Guid.NewGuid (), TimeSpan.FromMilliseconds (0)); reply.Item2.Should ().Be (TitanicReturnCode.Failure); reply.Item1.Should ().BeNull (); }
public void Reply_ExistingRequestStringTimeSpan_ShouldReturnExpectedReply () { const string expected_phrase = "Thank God Its Friday"; var replyFrame = new NetMQFrame (expected_phrase); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient (fakeMDPClient); var reply = sut.Reply (Guid.NewGuid (), TimeSpan.FromMilliseconds (0)); reply.Item2.Should ().Be (TitanicReturnCode.Ok); Encoding.UTF8.GetString (reply.Item1).Should ().Be (expected_phrase); }
public void Request_NullOrEmptyServiceName_ShouldThrowArgumentNullException () { var fakeMDPClient = new MDPTestClientForTitanicClient (); var sut = new TitanicClient (fakeMDPClient); Assert.Throws<ArgumentNullException> (() => sut.Request (string.Empty, "Hello World")); }
public void Reply_ExistingRequestStringIntegerTimeSpanGeneric_ShouldReturnExpectedReply () { var expected = new TestEntity (); var replyFrame = new NetMQFrame (expected.ConvertToBytes ()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient (fakeMDPClient); var reply = sut.Reply (Guid.NewGuid (), 0, TimeSpan.FromMilliseconds (0)); reply.Item2.Should ().Be (TitanicReturnCode.Ok); var result = new TestEntity (); result.GenerateFrom (reply.Item1); result.Id.Should ().Be (expected.Id); result.Name.Should ().Be (expected.Name); }
public void GetResult_StringIntegerGeneric_ReturnExpectedResult () { var expected = new TestEntity (); var replyFrame = new NetMQFrame (expected.ConvertToBytes ()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient (fakeMDPClient); var result = sut.GetResult<TestEntity, TestEntity> ("echo", expected); result.Item2.Should ().Be (TitanicReturnCode.Ok); result.Item1.Id.Should ().Be (expected.Id); result.Item1.Name.Should ().Be (expected.Name); }
public void GetResult_StringStringEncoding_ShouldReturnExpectedResult () { var enc = Encoding.Unicode; const string expected_phrase = "Thank God Its Friday"; var replyFrame = new NetMQFrame (enc.GetBytes (expected_phrase)); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient (fakeMDPClient); var result = sut.GetResult ("echo", expected_phrase, enc); result.Item2.Should ().Be (TitanicReturnCode.Ok); result.Item1.Should ().Be (enc.GetString (replyFrame.Buffer)); }