/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public override async Task <bool> RunAsync() { IPAddress ServerIp = (IPAddress)ArgumentValues["Server IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; log.Trace("(ServerIp:'{0}',PrimaryPort:{1})", ServerIp, PrimaryPort); bool res = false; Passed = false; ProtocolClient clientCallee = new ProtocolClient(); ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys()); ProtocolClient clientCaller = new ProtocolClient(); ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, clientCaller.GetIdentityKeys()); try { MessageBuilder mbCallee = clientCallee.MessageBuilder; MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder; MessageBuilder mbCaller = clientCaller.MessageBuilder; MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder; // Step 1 log.Trace("Step 1"); // Get port list. byte[] pubKeyCallee = clientCallee.GetIdentityKeys().PublicKey; byte[] identityIdCallee = clientCallee.GetIdentityId(); byte[] pubKeyCaller = clientCaller.GetIdentityKeys().PublicKey; byte[] identityIdCaller = clientCaller.GetIdentityId(); await clientCallee.ConnectAsync(ServerIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await clientCallee.ListServerPorts(rolePorts); clientCallee.CloseConnection(); // Establish hosting agreement for identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool establishHostingOk = await clientCallee.EstablishHostingAsync(); clientCallee.CloseConnection(); // Check-in and initialize the profile of identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true); bool checkInOk = await clientCallee.CheckInAsync(); bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null); // Add application service to the current session. string serviceName = "Test Service"; bool addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName }); // Step 1 Acceptance bool step1Ok = listPortsOk && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); await clientCaller.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync(); Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, "Test Service Invalid"); await clientCaller.SendMessageAsync(requestMessage); Message responseMessage = await clientCaller.ReceiveMessageAsync(); bool idOk = responseMessage.Id == requestMessage.Id; bool statusOk = responseMessage.Response.Status == Status.ErrorInvalidValue; bool detailsOk = responseMessage.Response.Details == "serviceName"; bool callIdentityOk = idOk && statusOk && detailsOk; // Step 2 Acceptance bool step2Ok = verifyIdentityOk && callIdentityOk; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); Passed = step1Ok && step2Ok; res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } clientCallee.Dispose(); clientCalleeAppService.Dispose(); clientCaller.Dispose(); clientCallerAppService.Dispose(); log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public override async Task <bool> RunAsync() { IPAddress ServerIp = (IPAddress)ArgumentValues["Server IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; log.Trace("(ServerIp:'{0}',PrimaryPort:{1})", ServerIp, PrimaryPort); bool res = false; Passed = false; ProtocolClient clientCallee = new ProtocolClient(); ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys()); ProtocolClient clientCaller = new ProtocolClient(); ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, clientCaller.GetIdentityKeys()); try { MessageBuilder mbCallee = clientCallee.MessageBuilder; MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder; MessageBuilder mbCaller = clientCaller.MessageBuilder; MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder; // Step 1 log.Trace("Step 1"); // Get port list. byte[] pubKeyCallee = clientCallee.GetIdentityKeys().PublicKey; byte[] identityIdCallee = clientCallee.GetIdentityId(); byte[] pubKeyCaller = clientCaller.GetIdentityKeys().PublicKey; byte[] identityIdCaller = clientCaller.GetIdentityId(); await clientCallee.ConnectAsync(ServerIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await clientCallee.ListServerPorts(rolePorts); clientCallee.CloseConnection(); // Establish hosting agreement for identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool establishHostingOk = await clientCallee.EstablishHostingAsync(); clientCallee.CloseConnection(); // Check-in and initialize the profile of identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true); bool checkInOk = await clientCallee.CheckInAsync(); bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null); // Add application service to the current session. string serviceName = "Test Service"; bool addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName }); // Step 1 Acceptance bool step1Ok = listPortsOk && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); await clientCaller.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync(); Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); await clientCaller.SendMessageAsync(requestMessage); // Step 2 Acceptance bool step2Ok = verifyIdentityOk; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); // Step 3 log.Trace("Step 3"); Message serverRequestMessage = await clientCallee.ReceiveMessageAsync(); byte[] receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); bool pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0; bool serviceNameOk = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk = pubKeyOk && serviceNameOk; byte[] calleeToken = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage); await clientCallee.SendMessageAsync(serverResponseMessage); // Connect to clAppService and send initialization message. await clientCalleeAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null); await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); // Step 3 Acceptance bool step3Ok = incomingCallNotificationOk; log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED"); // Step 4 log.Trace("Step 4"); Message responseMessage = await clientCaller.ReceiveMessageAsync(); bool idOk = responseMessage.Id == requestMessage.Id; bool statusOk = responseMessage.Response.Status == Status.Ok; byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray(); bool callIdentityOk = idOk && statusOk; // Connect to clAppService and send initialization message. await clientCallerAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null); await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; bool initAppServiceMessageOk = idOk && statusOk; // And close connection to clNonCustomer port. clientCaller.CloseConnection(); // Step 4 Acceptance bool step4Ok = callIdentityOk && initAppServiceMessageOk; log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 5 log.Trace("Step 5"); Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) && (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) && (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage); bool appServiceSendOk = idOk && statusOk && typeOk; // Step 5 Acceptance bool step5Ok = appServiceSendOk; log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED"); // Step 6 log.Trace("Step 6"); string callerMessage1 = "Message #1 to callee."; byte[] messageBytes = Encoding.UTF8.GetBytes(callerMessage1); string testStr = "test"; byte[] invalidCallerToken = Encoding.UTF8.GetBytes(testStr); requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(invalidCallerToken, messageBytes); uint callerMessage1Id = requestMessageAppServiceCaller.Id; await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == callerMessage1Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.ErrorNotFound; bool sendMessageOk = idOk && statusOk; // The caller should be disconnected by now, send or receive should throw. string callerMessage2 = "Message #2 to callee."; messageBytes = Encoding.UTF8.GetBytes(callerMessage2); requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes); bool disconnectedOk = false; try { await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); await clientCallerAppService.ReceiveMessageAsync(); } catch { log.Trace("Expected exception occurred."); disconnectedOk = true; } // Step 6 Acceptance bool step6Ok = sendMessageOk && disconnectedOk; log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED"); // Step 7 log.Trace("Step 7"); string calleeMessage1 = "Message #1 to CALLER."; messageBytes = Encoding.UTF8.GetBytes(calleeMessage1); requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes); disconnectedOk = false; try { await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); await clientCalleeAppService.ReceiveMessageAsync(); } catch { log.Trace("Expected exception occurred."); disconnectedOk = true; } // Step 7 Acceptance bool step7Ok = sendMessageOk && disconnectedOk; log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED"); Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok; res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } clientCallee.Dispose(); clientCalleeAppService.Dispose(); clientCaller.Dispose(); clientCallerAppService.Dispose(); log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public async Task <bool> RunAsyncInternal(int Index) { IPAddress ServerIp = (IPAddress)ArgumentValues["Server IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; log.Trace("(ServerIp:'{0}',PrimaryPort:{1},Index:{2})", ServerIp, PrimaryPort, Index); bool res = false; PassedArray[Index] = false; ProtocolClient clientCallee = new ProtocolClient(); ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys()); ProtocolClient clientCaller = new ProtocolClient(); ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, clientCaller.GetIdentityKeys()); try { MessageBuilder mbCallee = clientCallee.MessageBuilder; MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder; MessageBuilder mbCaller = clientCaller.MessageBuilder; MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder; // Step 1 log.Trace("Step 1"); // Get port list. byte[] pubKeyCallee = clientCallee.GetIdentityKeys().PublicKey; byte[] identityIdCallee = clientCallee.GetIdentityId(); byte[] pubKeyCaller = clientCaller.GetIdentityKeys().PublicKey; byte[] identityIdCaller = clientCaller.GetIdentityId(); await clientCallee.ConnectAsync(ServerIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await clientCallee.ListServerPorts(rolePorts); clientCallee.CloseConnection(); // Establish hosting agreement for identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool establishHostingOk = await clientCallee.EstablishHostingAsync(); clientCallee.CloseConnection(); // Check-in and initialize the profile of identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true); bool checkInOk = await clientCallee.CheckInAsync(); bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null); // Add application service to the current session. string serviceName = "Test Service"; bool addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName }); // Step 1 Acceptance bool step1Ok = listPortsOk && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); await clientCaller.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync(); Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); await clientCaller.SendMessageAsync(requestMessage); // Step 2 Acceptance bool step2Ok = verifyIdentityOk; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); // Step 3 log.Trace("Step 3"); Message serverRequestMessage = await clientCallee.ReceiveMessageAsync(); byte[] receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); bool pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0; bool serviceNameOk = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk = pubKeyOk && serviceNameOk; byte[] calleeToken = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage); await clientCallee.SendMessageAsync(serverResponseMessage); // Connect to clAppService and send initialization message. await clientCalleeAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null); await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); // Step 3 Acceptance bool step3Ok = incomingCallNotificationOk; log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED"); // Step 4 log.Trace("Step 4"); Message responseMessage = await clientCaller.ReceiveMessageAsync(); bool idOk = responseMessage.Id == requestMessage.Id; bool statusOk = responseMessage.Response.Status == Status.Ok; byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray(); bool callIdentityOk = idOk && statusOk; // Connect to clAppService and send initialization message. await clientCallerAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null); await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; bool initAppServiceMessageOk = idOk && statusOk; // And close connection to clNonCustomer port. clientCaller.CloseConnection(); // Step 4 Acceptance bool step4Ok = callIdentityOk && initAppServiceMessageOk; log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 5 log.Trace("Step 5"); Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) && (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) && (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage); bool appServiceSendOk = idOk && statusOk && typeOk; // Step 5 Acceptance bool step5Ok = appServiceSendOk; log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED"); // Step 6 UnfinishedRequestCounter callerCounter = new UnfinishedRequestCounter() { Name = string.Format("Caller-{0}", Index) }; UnfinishedRequestCounter calleeCounter = new UnfinishedRequestCounter() { Name = string.Format("Callee-{0}", Index) }; SemaphoreSlim callerWriteLock = new SemaphoreSlim(1); SemaphoreSlim calleeWriteLock = new SemaphoreSlim(1); Task <byte[]> messageReceivingTaskCaller = MessageReceivingLoop(clientCallerAppService, mbCallerAppService, "CallerReceiving", callerWriteLock, callerCounter); Task <byte[]> messageReceivingTaskCallee = MessageReceivingLoop(clientCalleeAppService, mbCalleeAppService, "CalleeReceiving", calleeWriteLock, calleeCounter); Task <byte[]> messageSendingTaskCaller = MessageSendingLoop(clientCallerAppService, mbCallerAppService, "CallerSending", callerToken, callerWriteLock, callerCounter); Task <byte[]> messageSendingTaskCallee = MessageSendingLoop(clientCalleeAppService, mbCalleeAppService, "CalleeSending", calleeToken, calleeWriteLock, calleeCounter); byte[] callerSendMessageHash = messageSendingTaskCaller.Result; byte[] calleeSendMessageHash = messageSendingTaskCallee.Result; byte[] callerReceiveMessageHash = messageReceivingTaskCaller.Result; byte[] calleeReceiveMessageHash = messageReceivingTaskCallee.Result; bool callerMessageHashOk = StructuralComparisons.StructuralComparer.Compare(callerSendMessageHash, calleeReceiveMessageHash) == 0; bool calleeMessageHashOk = StructuralComparisons.StructuralComparer.Compare(calleeSendMessageHash, callerReceiveMessageHash) == 0; // Step 6 Acceptance bool step6Ok = callerMessageHashOk && calleeMessageHashOk; log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED"); PassedArray[Index] = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok; log.Trace("PassedArray[{0}] = {1}", Index, PassedArray[Index]); res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } clientCallee.Dispose(); clientCalleeAppService.Dispose(); clientCaller.Dispose(); clientCallerAppService.Dispose(); log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public override async Task <bool> RunAsync() { IPAddress NodeIp = (IPAddress)ArgumentValues["Node IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort); bool res = false; Passed = false; ProtocolClient clientCallee = new ProtocolClient(); ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys()); ProtocolClient clientCaller = new ProtocolClient(); ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys()); try { MessageBuilder mbCallee = clientCallee.MessageBuilder; MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder; MessageBuilder mbCaller = clientCaller.MessageBuilder; MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder; // Step 1 log.Trace("Step 1"); // Get port list. byte[] pubKeyCallee = clientCallee.GetIdentityKeys().PublicKey; byte[] identityIdCallee = clientCallee.GetIdentityId(); byte[] pubKeyCaller = clientCaller.GetIdentityKeys().PublicKey; byte[] identityIdCaller = clientCaller.GetIdentityId(); await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await clientCallee.ListNodePorts(rolePorts); clientCallee.CloseConnection(); // Establish home node for identity 1. await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync(); clientCallee.CloseConnection(); // Check-in and initialize the profile of identity 1. await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true); bool checkInOk = await clientCallee.CheckInAsync(); bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null); // Add application service to the current session. string serviceName = "Test Service"; bool addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName }); // Step 1 Acceptance bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync(); Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); await clientCaller.SendMessageAsync(requestMessage); // Step 2 Acceptance bool step2Ok = verifyIdentityOk; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); // Step 3 log.Trace("Step 3"); Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync(); byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); bool pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0; bool serviceNameOk = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk = pubKeyOk && serviceNameOk; byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage); await clientCallee.SendMessageAsync(nodeResponseMessage); // Connect to clAppService and send initialization message. await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null); await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); // Step 3 Acceptance bool step3Ok = incomingCallNotificationOk; log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED"); // Step 4 log.Trace("Step 4"); Message responseMessage = await clientCaller.ReceiveMessageAsync(); bool idOk = responseMessage.Id == requestMessage.Id; bool statusOk = responseMessage.Response.Status == Status.Ok; byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray(); bool callIdentityOk = idOk && statusOk; // Connect to clAppService and send initialization message. await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null); await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; bool initAppServiceMessageOk = idOk && statusOk; // And close connection to clNonCustomer port. clientCaller.CloseConnection(); // Step 4 Acceptance bool step4Ok = callIdentityOk && initAppServiceMessageOk; log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 5 log.Trace("Step 5"); Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) && (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) && (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage); bool appServiceSendOk = idOk && statusOk && typeOk; // Step 5 Acceptance bool step5Ok = appServiceSendOk; log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED"); // Step 6 log.Trace("Step 6"); string callerMessage1 = "Message #1 to callee."; byte[] messageBytes = Encoding.UTF8.GetBytes(callerMessage1); requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes); uint callerMessage1Id = requestMessageAppServiceCaller.Id; await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); // Step 6 Acceptance bool step6Ok = true; log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED"); // Step 7 log.Trace("Step 7"); // Receive message #1. Message nodeRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); byte[] receivedVersion = nodeRequestAppServiceCallee.Request.SingleRequest.Version.ToByteArray(); bool versionOk = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0; typeOk = (nodeRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (nodeRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (nodeRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); string receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); bool messageOk = receivedMessage == callerMessage1; bool receiveMessageOk = versionOk && typeOk && messageOk; // ACK message #1. Message nodeResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(nodeRequestAppServiceCallee); await clientCalleeAppService.SendMessageAsync(nodeResponseAppServiceCallee); // Send our message #1. string calleeMessage1 = "Message #1 to CALLER."; messageBytes = Encoding.UTF8.GetBytes(calleeMessage1); requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes); uint calleeMessage1Id = requestMessageAppServiceCallee.Id; await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); // Step 7 Acceptance bool step7Ok = receiveMessageOk; log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED"); // Step 8 log.Trace("Step 8"); // Receive ACK message #1. responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == callerMessage1Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; receivedVersion = responseMessageAppServiceCaller.Response.SingleResponse.Version.ToByteArray(); versionOk = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0; bool receiveAckOk = idOk && statusOk && versionOk; // Receive message #1 from callee. Message nodeRequestAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); receivedVersion = nodeRequestAppServiceCaller.Request.SingleRequest.Version.ToByteArray(); versionOk = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0; typeOk = (nodeRequestAppServiceCaller.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (nodeRequestAppServiceCaller.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (nodeRequestAppServiceCaller.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCaller.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); messageOk = receivedMessage == calleeMessage1; receiveMessageOk = versionOk && typeOk && messageOk; // ACK message #1 from callee. Message nodeResponseAppServiceCaller = mbCallerAppService.CreateApplicationServiceReceiveMessageNotificationResponse(nodeRequestAppServiceCaller); await clientCallerAppService.SendMessageAsync(nodeResponseAppServiceCaller); // Step 8 Acceptance bool step8Ok = receiveAckOk && receiveMessageOk; log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED"); // Step 9 log.Trace("Step 9"); // Receive ACK message #1. responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == calleeMessage1Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; receivedVersion = responseMessageAppServiceCallee.Response.SingleResponse.Version.ToByteArray(); versionOk = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0; receiveAckOk = idOk && statusOk && versionOk; log.Trace("Going to wait for 3 minutes..."); await Task.Delay(180 * 1000); log.Trace("Waiting done."); // Step 9 Acceptance bool step9Ok = receiveAckOk; log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED"); // Step 10 string callerMessage2 = "Message #1 to callee."; messageBytes = Encoding.UTF8.GetBytes(callerMessage2); requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes); // We should be disconnected now, send or receive should throw. bool disconnectedOk = false; try { await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); await clientCallerAppService.ReceiveMessageAsync(); } catch { log.Trace("Expected exception occurred."); disconnectedOk = true; } // Step 10 Acceptance bool step10Ok = disconnectedOk; log.Trace("Step 10: {0}", step10Ok ? "PASSED" : "FAILED"); // Step 11 string calleeMessage2 = "Message #1 to CALLER."; messageBytes = Encoding.UTF8.GetBytes(calleeMessage2); requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes); // We should be disconnected now, send or receive should throw. disconnectedOk = false; try { await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); await clientCalleeAppService.ReceiveMessageAsync(); } catch { log.Trace("Expected exception occurred."); disconnectedOk = true; } // Step 11 Acceptance bool step11Ok = disconnectedOk; log.Trace("Step 11: {0}", step11Ok ? "PASSED" : "FAILED"); Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok && step10Ok && step11Ok; res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } clientCallee.Dispose(); clientCalleeAppService.Dispose(); clientCaller.Dispose(); clientCallerAppService.Dispose(); log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public override async Task <bool> RunAsync() { IPAddress NodeIp = (IPAddress)ArgumentValues["Node IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort); bool res = false; Passed = false; ProtocolClient clientCallee = new ProtocolClient(); ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys()); ProtocolClient clientCaller = new ProtocolClient(); ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys()); try { MessageBuilder mbCallee = clientCallee.MessageBuilder; MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder; MessageBuilder mbCaller = clientCaller.MessageBuilder; MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder; // Step 1 log.Trace("Step 1"); // Get port list. byte[] pubKeyCallee = clientCallee.GetIdentityKeys().PublicKey; byte[] identityIdCallee = clientCallee.GetIdentityId(); byte[] pubKeyCaller = clientCaller.GetIdentityKeys().PublicKey; byte[] identityIdCaller = clientCaller.GetIdentityId(); await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await clientCallee.ListNodePorts(rolePorts); clientCallee.CloseConnection(); // Establish home node for identity 1. await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync(); clientCallee.CloseConnection(); // Check-in and initialize the profile of identity 1. await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true); bool checkInOk = await clientCallee.CheckInAsync(); bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null); // Add application service to the current session. string serviceName = "Test Service"; bool addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName }); // Step 1 Acceptance bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync(); Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); await clientCaller.SendMessageAsync(requestMessage); // Step 2 Acceptance bool step2Ok = verifyIdentityOk; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); // Step 3 log.Trace("Step 3"); Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync(); byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); bool pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0; bool serviceNameOk = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk = pubKeyOk && serviceNameOk; byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage); await clientCallee.SendMessageAsync(nodeResponseMessage); // Step 3 Acceptance bool step3Ok = incomingCallNotificationOk; log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED"); // Step 4 log.Trace("Step 4"); Message responseMessage = await clientCaller.ReceiveMessageAsync(); bool idOk = responseMessage.Id == requestMessage.Id; bool statusOk = responseMessage.Response.Status == Status.Ok; byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray(); bool callIdentityOk = idOk && statusOk; // Step 4 Acceptance bool step4Ok = callIdentityOk; log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 5 // Connect to clAppService and send initialization message. await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true); await Task.Delay(35 * 1000); Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null); await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); // Step 5 Acceptance bool step5Ok = true; log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED"); // Step 6 // Connect to clAppService and send initialization message. await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null); await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.ErrorNotFound; bool initAppServiceMessageOk = idOk && statusOk; // Step 6 Acceptance bool step6Ok = initAppServiceMessageOk; log.Trace("Step 6: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 7 log.Trace("Step 7"); Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.ErrorNotFound; bool appServiceSendOk = idOk && statusOk; // Step 7 Acceptance bool step7Ok = appServiceSendOk; log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED"); Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok; res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } clientCallee.Dispose(); clientCalleeAppService.Dispose(); clientCaller.Dispose(); clientCallerAppService.Dispose(); log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public override async Task <bool> RunAsync() { IPAddress ServerIp = (IPAddress)ArgumentValues["Server IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; log.Trace("(ServerIp:'{0}',PrimaryPort:{1})", ServerIp, PrimaryPort); bool res = false; Passed = false; ProtocolClient clientCallee = new ProtocolClient(); ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys()); ProtocolClient clientCaller = new ProtocolClient(); ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, clientCaller.GetIdentityKeys()); try { MessageBuilder mbCallee = clientCallee.MessageBuilder; MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder; MessageBuilder mbCaller = clientCaller.MessageBuilder; MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder; // Step 1 log.Trace("Step 1"); // Get port list. byte[] pubKeyCallee = clientCallee.GetIdentityKeys().PublicKey; byte[] identityIdCallee = clientCallee.GetIdentityId(); byte[] pubKeyCaller = clientCaller.GetIdentityKeys().PublicKey; byte[] identityIdCaller = clientCaller.GetIdentityId(); await clientCallee.ConnectAsync(ServerIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await clientCallee.ListServerPorts(rolePorts); clientCallee.CloseConnection(); // Establish hosting agreement for identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool establishHostingOk = await clientCallee.EstablishHostingAsync(); clientCallee.CloseConnection(); // Check-in and initialize the profile of identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true); bool checkInOk = await clientCallee.CheckInAsync(); bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null); // Add application service to the current session. string serviceName = "Test Service"; bool addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName }); // Step 1 Acceptance bool step1Ok = listPortsOk && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); await clientCaller.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync(); Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); await clientCaller.SendMessageAsync(requestMessage); // Step 2 Acceptance bool step2Ok = verifyIdentityOk; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); // Step 3 log.Trace("Step 3"); Message serverRequestMessage = await clientCallee.ReceiveMessageAsync(); byte[] receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); bool pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0; bool serviceNameOk = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk = pubKeyOk && serviceNameOk; byte[] calleeToken = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage); await clientCallee.SendMessageAsync(serverResponseMessage); // Connect to clAppService and send initialization message. await clientCalleeAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null); await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); // Step 3 Acceptance bool step3Ok = incomingCallNotificationOk; log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED"); // Step 4 log.Trace("Step 4"); Message responseMessage = await clientCaller.ReceiveMessageAsync(); bool idOk = responseMessage.Id == requestMessage.Id; bool statusOk = responseMessage.Response.Status == Status.Ok; byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray(); bool callIdentityOk = idOk && statusOk; // Connect to clAppService and send initialization message. await clientCallerAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null); await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; bool initAppServiceMessageOk = idOk && statusOk; clientCaller.CloseConnection(); // Step 4 Acceptance bool step4Ok = callIdentityOk && initAppServiceMessageOk; log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 5 log.Trace("Step 5"); Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; bool appServiceSendOk = idOk && statusOk; // Step 5 Acceptance bool step5Ok = appServiceSendOk; log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED"); // Step 6 log.Trace("Step 6"); bool error = false; int messagesDelivered = 0; int messagesSent = 0; bool disconnectedOk = false; for (int i = 0; i < 20; i++) { try { // Caller sends message. string callerMessage = string.Format("Message #{0} to callee.", i + 1); byte[] messageBytes = Encoding.UTF8.GetBytes(callerMessage); requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes); await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); messagesSent++; // Callee receives message. Message serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); SemVer receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version); bool versionOk = receivedVersion.Equals(SemVer.V100); bool typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); string receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); bool messageOk = receivedMessage == callerMessage; bool receiveMessageOk = versionOk && typeOk && messageOk; if (receiveMessageOk) { messagesDelivered++; log.Trace("Delivery of message #{0} succeeded.", i + 1); } else { log.Trace("Delivery of message #{0} failed.", i + 1); error = true; break; } await Task.Delay(10 * 1000); } catch { log.Trace("Expected exception occurred."); disconnectedOk = true; break; } } // Step 6 Acceptance bool step6Ok = !error && disconnectedOk && (messagesDelivered < 20); log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED"); Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok; res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } clientCallee.Dispose(); clientCalleeAppService.Dispose(); clientCaller.Dispose(); clientCallerAppService.Dispose(); log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public override async Task <bool> RunAsync() { IPAddress ServerIp = (IPAddress)ArgumentValues["Server IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; log.Trace("(ServerIp:'{0}',PrimaryPort:{1})", ServerIp, PrimaryPort); bool res = false; Passed = false; ProtocolClient clientCallee = new ProtocolClient(); ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys()); ProtocolClient clientCaller = new ProtocolClient(); ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, clientCaller.GetIdentityKeys()); try { MessageBuilder mbCallee = clientCallee.MessageBuilder; MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder; MessageBuilder mbCaller = clientCaller.MessageBuilder; MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder; // Step 1 log.Trace("Step 1"); // Get port list. byte[] pubKeyCallee = clientCallee.GetIdentityKeys().PublicKey; byte[] identityIdCallee = clientCallee.GetIdentityId(); byte[] pubKeyCaller = clientCaller.GetIdentityKeys().PublicKey; byte[] identityIdCaller = clientCaller.GetIdentityId(); await clientCallee.ConnectAsync(ServerIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await clientCallee.ListServerPorts(rolePorts); clientCallee.CloseConnection(); // Establish hosting agreement for identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool establishHostingOk = await clientCallee.EstablishHostingAsync(); clientCallee.CloseConnection(); // Check-in and initialize the profile of identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true); bool checkInOk = await clientCallee.CheckInAsync(); bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null); // Add application service to the current session. string serviceName = "Test Service"; bool addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName }); // Step 1 Acceptance bool step1Ok = listPortsOk && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); await clientCaller.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync(); Message requestMessage = mbCaller.CreateGetIdentityInformationRequest(identityIdCallee, false, false, true); await clientCaller.SendMessageAsync(requestMessage); Message responseMessage = await clientCaller.ReceiveMessageAsync(); bool idOk = responseMessage.Id == requestMessage.Id; bool statusOk = responseMessage.Response.Status == Status.Ok; bool isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted; bool isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline; byte[] receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray(); bool pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCallee) == 0; HashSet <string> receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices, StringComparer.Ordinal); bool appServiceReadyOk = receivedAsList.Contains(serviceName); bool getInfoOk = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && appServiceReadyOk; // Step 2 Acceptance bool step2Ok = verifyIdentityOk && getInfoOk; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); // Step 3 log.Trace("Step 3"); requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); await clientCaller.SendMessageAsync(requestMessage); // Step 3 Acceptance bool step3Ok = true; log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED"); // Step 4 log.Trace("Step 4"); Message serverRequestMessage = await clientCallee.ReceiveMessageAsync(); receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0; bool serviceNameOk = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk = pubKeyOk && serviceNameOk; byte[] calleeToken = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage); await clientCallee.SendMessageAsync(serverResponseMessage); // Connect to clAppService and send initialization message. await clientCalleeAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null); await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); // Step 4 Acceptance bool step4Ok = incomingCallNotificationOk; log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 5 log.Trace("Step 5"); responseMessage = await clientCaller.ReceiveMessageAsync(); idOk = responseMessage.Id == requestMessage.Id; statusOk = responseMessage.Response.Status == Status.Ok; byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray(); bool callIdentityOk = idOk && statusOk; // Connect to clAppService and send initialization message. await clientCallerAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null); await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; bool initAppServiceMessageOk = idOk && statusOk; // And close connection to clNonCustomer port. clientCaller.CloseConnection(); // Step 5 Acceptance bool step5Ok = callIdentityOk && initAppServiceMessageOk; log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED"); // Step 6 log.Trace("Step 6"); Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) && (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) && (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage); bool appServiceSendOk = idOk && statusOk && typeOk; // Step 6 Acceptance bool step6Ok = appServiceSendOk; log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED"); // Step 7 log.Trace("Step 7"); string callerMessage1 = "Message #1 to callee."; byte[] messageBytes = Encoding.UTF8.GetBytes(callerMessage1); requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes); uint callerMessage1Id = requestMessageAppServiceCaller.Id; await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); string callerMessage2 = "Message #2 to callee."; messageBytes = Encoding.UTF8.GetBytes(callerMessage2); requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes); uint callerMessage2Id = requestMessageAppServiceCaller.Id; await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); string callerMessage3 = "Message #3 to callee."; messageBytes = Encoding.UTF8.GetBytes(callerMessage3); requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes); uint callerMessage3Id = requestMessageAppServiceCaller.Id; await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller); // Step 7 Acceptance bool step7Ok = true; log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED"); // Step 8 log.Trace("Step 8"); // Receive message #1. Message serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); SemVer receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version); bool versionOk = receivedVersion.Equals(SemVer.V100); typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); string receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); bool messageOk = receivedMessage == callerMessage1; bool receiveMessageOk1 = versionOk && typeOk && messageOk; // ACK message #1. Message serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee); await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee); // Receive message #2. serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version); versionOk = receivedVersion.Equals(SemVer.V100); typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); messageOk = receivedMessage == callerMessage2; bool receiveMessageOk2 = versionOk && typeOk && messageOk; // ACK message #2. serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee); await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee); // Send our message #1. string calleeMessage1 = "Message #1 to CALLER."; messageBytes = Encoding.UTF8.GetBytes(calleeMessage1); requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes); uint calleeMessage1Id = requestMessageAppServiceCallee.Id; await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); await Task.Delay(3000); // Send ping request. byte[] payload = Encoding.UTF8.GetBytes("test"); requestMessageAppServiceCallee = mbCalleeAppService.CreatePingRequest(payload); await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); // Receive message #3. serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version); versionOk = receivedVersion.Equals(SemVer.V100); typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); messageOk = receivedMessage == callerMessage3; bool receiveMessageOk3 = versionOk && typeOk && messageOk; // Read ping response. responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; receivedVersion = new SemVer(responseMessageAppServiceCallee.Response.SingleResponse.Version); versionOk = receivedVersion.Equals(SemVer.V100); typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) && (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) && (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.Ping); byte[] receivedPayload = responseMessageAppServiceCallee.Response.SingleResponse.Ping.Payload.ToByteArray(); bool payloadOk = StructuralComparisons.StructuralComparer.Compare(receivedPayload, payload) == 0; bool pingOk = idOk && statusOk && versionOk && typeOk && payloadOk; // ACK message #2. serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee); await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee); // Send our message #2. string calleeMessage2 = "Message #2 to CALLER."; messageBytes = Encoding.UTF8.GetBytes(calleeMessage2); requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes); uint calleeMessage2Id = requestMessageAppServiceCallee.Id; await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); await Task.Delay(3000); // Step 8 Acceptance bool step8Ok = receiveMessageOk1 && receiveMessageOk2 && pingOk && receiveMessageOk3; log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED"); // Step 9 log.Trace("Step 9"); // Receive ACK message #1. responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == callerMessage1Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version); versionOk = receivedVersion.Equals(SemVer.V100); bool receiveAck1Ok = idOk && statusOk && versionOk; // Receive ACK message #2. responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == callerMessage2Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version); versionOk = receivedVersion.Equals(SemVer.V100); bool receiveAck2Ok = idOk && statusOk && versionOk; // Receive message #1 from callee. Message serverRequestAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); receivedVersion = new SemVer(serverRequestAppServiceCaller.Request.SingleRequest.Version); versionOk = receivedVersion.Equals(SemVer.V100); typeOk = (serverRequestAppServiceCaller.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (serverRequestAppServiceCaller.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (serverRequestAppServiceCaller.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCaller.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); messageOk = receivedMessage == calleeMessage1; receiveMessageOk1 = versionOk && typeOk && messageOk; // ACK message #1 from callee. Message serverResponseAppServiceCaller = mbCallerAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCaller); await clientCallerAppService.SendMessageAsync(serverResponseAppServiceCaller); // Receive ACK message #3. responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == callerMessage3Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version); versionOk = receivedVersion.Equals(SemVer.V100); bool receiveAck3Ok = idOk && statusOk && versionOk; // Receive message #2 from callee. serverRequestAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync(); receivedVersion = new SemVer(serverRequestAppServiceCaller.Request.SingleRequest.Version); versionOk = receivedVersion.Equals(SemVer.V100); typeOk = (serverRequestAppServiceCaller.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (serverRequestAppServiceCaller.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (serverRequestAppServiceCaller.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCaller.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); messageOk = receivedMessage == calleeMessage2; receiveMessageOk2 = versionOk && typeOk && messageOk; // ACK message #2 from callee. serverResponseAppServiceCaller = mbCallerAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCaller); await clientCallerAppService.SendMessageAsync(serverResponseAppServiceCaller); // Step 9 Acceptance bool step9Ok = receiveAck1Ok && receiveAck2Ok && receiveMessageOk1 && receiveAck3Ok && receiveMessageOk2; log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED"); // Step 10 log.Trace("Step 10"); // Receive ACK message #1. responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == calleeMessage1Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; receivedVersion = new SemVer(responseMessageAppServiceCallee.Response.SingleResponse.Version); versionOk = receivedVersion.Equals(SemVer.V100); receiveAck1Ok = idOk && statusOk && versionOk; // Receive ACK message #2. responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == calleeMessage2Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; receivedVersion = new SemVer(responseMessageAppServiceCallee.Response.SingleResponse.Version); versionOk = receivedVersion.Equals(SemVer.V100); receiveAck2Ok = idOk && statusOk && versionOk; // Step 10 Acceptance bool step10Ok = receiveAck1Ok && receiveAck2Ok; log.Trace("Step 10: {0}", step10Ok ? "PASSED" : "FAILED"); Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok && step10Ok; res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } clientCallee.Dispose(); clientCalleeAppService.Dispose(); clientCaller.Dispose(); clientCallerAppService.Dispose(); log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public override async Task <bool> RunAsync() { IPAddress NodeIp = (IPAddress)ArgumentValues["Node IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort); bool res = false; Passed = false; ProtocolClient clientCallee = new ProtocolClient(); ProtocolClient clientCallee1AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys()); ProtocolClient clientCallee2AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys()); ProtocolClient clientCaller1 = new ProtocolClient(); ProtocolClient clientCaller1AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller1.GetIdentityKeys()); ProtocolClient clientCaller2 = new ProtocolClient(); ProtocolClient clientCaller2AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller2.GetIdentityKeys()); try { MessageBuilder mbCallee = clientCallee.MessageBuilder; MessageBuilder mbCallee1AppService = clientCallee1AppService.MessageBuilder; MessageBuilder mbCallee2AppService = clientCallee2AppService.MessageBuilder; MessageBuilder mbCaller1 = clientCaller1.MessageBuilder; MessageBuilder mbCaller1AppService = clientCaller1AppService.MessageBuilder; MessageBuilder mbCaller2 = clientCaller2.MessageBuilder; MessageBuilder mbCaller2AppService = clientCaller2AppService.MessageBuilder; // Step 1 log.Trace("Step 1"); byte[] pubKeyCallee = clientCallee.GetIdentityKeys().PublicKey; byte[] identityIdCallee = clientCallee.GetIdentityId(); byte[] pubKeyCaller1 = clientCaller1.GetIdentityKeys().PublicKey; byte[] identityIdCaller1 = clientCaller1.GetIdentityId(); byte[] pubKeyCaller2 = clientCaller2.GetIdentityKeys().PublicKey; byte[] identityIdCaller2 = clientCaller2.GetIdentityId(); // Get port list. await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await clientCallee.ListNodePorts(rolePorts); clientCallee.CloseConnection(); // Establish home node for identity 1. await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync(); clientCallee.CloseConnection(); // Check-in and initialize the profile of identity 1. await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true); bool checkInOk = await clientCallee.CheckInAsync(); bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null); // Add application service to the current session. string serviceName = "Test Service"; bool addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName }); // Step 1 Acceptance bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); await clientCaller1.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk1 = await clientCaller1.VerifyIdentityAsync(); Message requestMessage = mbCaller1.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); uint initMessageCaller1Id = requestMessage.Id; await clientCaller1.SendMessageAsync(requestMessage); await clientCaller2.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk2 = await clientCaller2.VerifyIdentityAsync(); requestMessage = mbCaller2.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); uint initMessageCaller2Id = requestMessage.Id; await clientCaller2.SendMessageAsync(requestMessage); // Step 2 Acceptance bool step2Ok = verifyIdentityOk1 && verifyIdentityOk2; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); // Step 3 log.Trace("Step 3"); Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync(); byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); bool pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller1) == 0; bool serviceNameOk = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk1 = pubKeyOk && serviceNameOk; byte[] calleeToken1 = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage); await clientCallee.SendMessageAsync(nodeResponseMessage); nodeRequestMessage = await clientCallee.ReceiveMessageAsync(); receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller2) == 0; serviceNameOk = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk2 = pubKeyOk && serviceNameOk; byte[] calleeToken2 = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage); await clientCallee.SendMessageAsync(nodeResponseMessage); // Connect to clAppService and send initialization message (FIRST connection). await clientCallee1AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCallee = mbCallee1AppService.CreateApplicationServiceSendMessageRequest(calleeToken1, null); await clientCallee1AppService.SendMessageAsync(requestMessageAppServiceCallee); // Connect to clAppService and send initialization message (SECOND connection). await clientCallee2AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true); requestMessageAppServiceCallee = mbCallee2AppService.CreateApplicationServiceSendMessageRequest(calleeToken2, null); await clientCallee2AppService.SendMessageAsync(requestMessageAppServiceCallee); // Step 3 Acceptance bool step3Ok = incomingCallNotificationOk1 && incomingCallNotificationOk2; log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED"); // Step 4 log.Trace("Step 4"); Message responseMessage = await clientCaller1.ReceiveMessageAsync(); bool idOk = responseMessage.Id == initMessageCaller1Id; bool statusOk = responseMessage.Response.Status == Status.Ok; byte[] callerToken1 = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray(); bool callIdentityOk1 = idOk && statusOk; // Connect to clAppService and send initialization message. await clientCaller1AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken1, null); await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller); Message responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; bool initAppServiceMessageOk1 = idOk && statusOk; responseMessage = await clientCaller2.ReceiveMessageAsync(); idOk = responseMessage.Id == initMessageCaller1Id; statusOk = responseMessage.Response.Status == Status.Ok; byte[] callerToken2 = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray(); bool callIdentityOk2 = idOk && statusOk; // Connect to clAppService and send initialization message. await clientCaller2AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true); requestMessageAppServiceCaller = mbCaller2AppService.CreateApplicationServiceSendMessageRequest(callerToken2, null); await clientCaller2AppService.SendMessageAsync(requestMessageAppServiceCaller); responseMessageAppServiceCaller = await clientCaller2AppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; bool initAppServiceMessageOk2 = idOk && statusOk; // Step 4 Acceptance bool step4Ok = callIdentityOk1 && initAppServiceMessageOk1 && callIdentityOk2 && initAppServiceMessageOk2; log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 5 log.Trace("Step 5"); Message responseMessageAppServiceCallee = await clientCallee1AppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) && (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) && (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage); bool appServiceSendOk1 = idOk && statusOk && typeOk; responseMessageAppServiceCallee = await clientCallee2AppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) && (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) && (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage); bool appServiceSendOk2 = idOk && statusOk && typeOk; // Step 5 Acceptance bool step5Ok = appServiceSendOk1 && appServiceSendOk2; log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED"); // Step 6 log.Trace("Step 6"); string caller1Message1 = "Message #1 to callee from caller1."; byte[] messageBytes = Encoding.UTF8.GetBytes(caller1Message1); requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken1, messageBytes); uint callerMessage1Id = requestMessageAppServiceCaller.Id; await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller); // Step 6 Acceptance bool step6Ok = true; log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED"); // Step 7 log.Trace("Step 7"); // Receive message #1. Message nodeRequestAppServiceCallee = await clientCallee1AppService.ReceiveMessageAsync(); byte[] receivedVersion = nodeRequestAppServiceCallee.Request.SingleRequest.Version.ToByteArray(); bool versionOk = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0; typeOk = (nodeRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (nodeRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (nodeRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); string receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); bool messageOk = receivedMessage == caller1Message1; bool receiveMessageOk = versionOk && typeOk && messageOk; // ACK message #1. Message nodeResponseAppServiceCallee = mbCallee1AppService.CreateApplicationServiceReceiveMessageNotificationResponse(nodeRequestAppServiceCallee); await clientCallee1AppService.SendMessageAsync(nodeResponseAppServiceCallee); // Send invalid message - over the FIRST connection with token from the SECOND connection. await Task.Delay(3000); string calleeMessage = "Invalid Message"; messageBytes = Encoding.UTF8.GetBytes(calleeMessage); requestMessageAppServiceCallee = mbCallee1AppService.CreateApplicationServiceSendMessageRequest(calleeToken2, messageBytes); await clientCallee1AppService.SendMessageAsync(requestMessageAppServiceCallee); Message responseAppServiceCallee = await clientCallee1AppService.ReceiveMessageAsync(); idOk = responseAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseAppServiceCallee.Response.Status == Status.ErrorNotFound; bool sendMessageOk = idOk && statusOk; // Step 7 Acceptance bool step7Ok = sendMessageOk; log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED"); // Step 8 log.Trace("Step 8"); await Task.Delay(3000); string caller2Message1 = "Message #1 to callee from caller2."; messageBytes = Encoding.UTF8.GetBytes(caller2Message1); requestMessageAppServiceCaller = mbCaller2AppService.CreateApplicationServiceSendMessageRequest(callerToken2, messageBytes); // Either the third client is disconnected and this should prevent sending a message or receiving a response, // OR just the relay was destroyed and the client will receive error not found. bool disconnectOk = false; messageOk = false; try { await clientCaller2AppService.SendMessageAsync(requestMessageAppServiceCaller); responseMessage = await clientCaller2AppService.ReceiveMessageAsync(); idOk = responseMessage.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessage.Response.Status == Status.ErrorNotFound; messageOk = idOk && statusOk; } catch { log.Trace("Expected exception occurred."); disconnectOk = true; } // Step 8 Acceptance bool step8Ok = disconnectOk || messageOk; log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED"); // Step 9 log.Trace("Step 9"); // Receive ACK message #1. responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == callerMessage1Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; receivedVersion = responseMessageAppServiceCaller.Response.SingleResponse.Version.ToByteArray(); versionOk = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0; bool receiveAckOk = idOk && statusOk && versionOk; // Step 9 Acceptance bool step9Ok = receiveAckOk; log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED"); Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok; res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } clientCallee.Dispose(); clientCallee1AppService.Dispose(); clientCallee2AppService.Dispose(); clientCaller1.Dispose(); clientCaller1AppService.Dispose(); clientCaller2.Dispose(); clientCaller2AppService.Dispose(); log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public override async Task <bool> RunAsync() { IPAddress ServerIp = (IPAddress)ArgumentValues["Server IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; log.Trace("(ServerIp:'{0}',PrimaryPort:{1})", ServerIp, PrimaryPort); bool res = false; Passed = false; ProtocolClient clientCallee = new ProtocolClient(); ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys()); ProtocolClient clientCaller1 = new ProtocolClient(); ProtocolClient clientCaller1AppService = new ProtocolClient(0, SemVer.V100, clientCaller1.GetIdentityKeys()); ProtocolClient clientCaller2 = new ProtocolClient(); ProtocolClient clientCaller2AppService = new ProtocolClient(0, SemVer.V100, clientCaller2.GetIdentityKeys()); try { MessageBuilder mbCallee = clientCallee.MessageBuilder; MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder; MessageBuilder mbCaller1 = clientCaller1.MessageBuilder; MessageBuilder mbCaller1AppService = clientCaller1AppService.MessageBuilder; MessageBuilder mbCaller2 = clientCaller2.MessageBuilder; MessageBuilder mbCaller2AppService = clientCaller2AppService.MessageBuilder; // Step 1 log.Trace("Step 1"); byte[] pubKeyCallee = clientCallee.GetIdentityKeys().PublicKey; byte[] identityIdCallee = clientCallee.GetIdentityId(); byte[] pubKeyCaller1 = clientCaller1.GetIdentityKeys().PublicKey; byte[] identityIdCaller1 = clientCaller1.GetIdentityId(); byte[] pubKeyCaller2 = clientCaller2.GetIdentityKeys().PublicKey; byte[] identityIdCaller2 = clientCaller2.GetIdentityId(); // Get port list. await clientCallee.ConnectAsync(ServerIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await clientCallee.ListServerPorts(rolePorts); clientCallee.CloseConnection(); // Establish hosting agreement for identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool establishHostingOk = await clientCallee.EstablishHostingAsync(); clientCallee.CloseConnection(); // Check-in and initialize the profile of identity 1. await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true); bool checkInOk = await clientCallee.CheckInAsync(); bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null); // Add application service to the current session. string serviceName = "Test Service"; bool addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName }); // Step 1 Acceptance bool step1Ok = listPortsOk && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); await clientCaller1.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk1 = await clientCaller1.VerifyIdentityAsync(); Message requestMessage = mbCaller1.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); uint initMessageCaller1Id = requestMessage.Id; await clientCaller1.SendMessageAsync(requestMessage); await clientCaller2.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true); bool verifyIdentityOk2 = await clientCaller2.VerifyIdentityAsync(); requestMessage = mbCaller2.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName); uint initMessageCaller2Id = requestMessage.Id; await clientCaller2.SendMessageAsync(requestMessage); // Step 2 Acceptance bool step2Ok = verifyIdentityOk1 && verifyIdentityOk2; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); // Step 3 log.Trace("Step 3"); Message serverRequestMessage = await clientCallee.ReceiveMessageAsync(); // What we received now can actually be either notification about caller1 or caller2, we do not know. // So we have to check, which one is it before we proceed. byte[] receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); bool isCaller1 = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller1) == 0; bool isCaller2 = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller2) == 0; bool pubKeyOk = isCaller1 || isCaller2; bool serviceNameOk = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk1 = pubKeyOk && serviceNameOk; byte[] calleeToken1 = null; byte[] calleeToken2 = null; if (isCaller1) { calleeToken1 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); } else { calleeToken2 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); } Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage); await clientCallee.SendMessageAsync(serverResponseMessage); serverRequestMessage = await clientCallee.ReceiveMessageAsync(); // This time, it has to be the other caller receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray(); if (isCaller1) { pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller2) == 0; } else { pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller1) == 0; } serviceNameOk = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName; bool incomingCallNotificationOk2 = pubKeyOk && serviceNameOk; if (isCaller1) { calleeToken2 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); } else { calleeToken1 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray(); } serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage); await clientCallee.SendMessageAsync(serverResponseMessage); // Connect to clAppService and send initialization message. await clientCalleeAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken1, null); await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); // Step 3 Acceptance bool step3Ok = incomingCallNotificationOk1 && incomingCallNotificationOk2; log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED"); // Step 4 log.Trace("Step 4"); Message responseMessage = await clientCaller1.ReceiveMessageAsync(); bool idOk = responseMessage.Id == initMessageCaller1Id; bool statusOk = responseMessage.Response.Status == Status.Ok; byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray(); bool callIdentityOk = idOk && statusOk; // Connect to clAppService and send initialization message. await clientCaller1AppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true); Message requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken, null); await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller); Message responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; bool initAppServiceMessageOk = idOk && statusOk; // Step 4 Acceptance bool step4Ok = callIdentityOk && initAppServiceMessageOk; log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 5 log.Trace("Step 5"); Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok; bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) && (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) && (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage); bool appServiceSendOk = idOk && statusOk && typeOk; // Step 5 Acceptance bool step5Ok = appServiceSendOk; log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED"); // Step 6 log.Trace("Step 6"); string caller1Message1 = "Message #1 to callee."; byte[] messageBytes = Encoding.UTF8.GetBytes(caller1Message1); requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes); uint callerMessage1Id = requestMessageAppServiceCaller.Id; await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller); // Step 6 Acceptance bool step6Ok = true; log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED"); // Step 7 log.Trace("Step 7"); // Receive message #1. Message serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); SemVer receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version); bool versionOk = receivedVersion.Equals(SemVer.V100); typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) && (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification); string receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray()); bool messageOk = receivedMessage == caller1Message1; bool receiveMessageOk = versionOk && typeOk && messageOk; // ACK message #1. Message serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee); await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee); // Send second intialization message await Task.Delay(3000); requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken2, null); await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee); Message responseAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync(); idOk = responseAppServiceCallee.Id == requestMessageAppServiceCallee.Id; statusOk = responseAppServiceCallee.Response.Status == Status.ErrorNotFound; bool secondInitOk = idOk && statusOk; // Step 7 Acceptance bool step7Ok = secondInitOk; log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED"); // Step 8 log.Trace("Step 8"); // Receive init message response. bool initMessageOk = false; bool disconnectOk = false; try { Message initMessageResponseAppServiceCaller2 = await clientCaller2AppService.ReceiveMessageAsync(); idOk = initMessageResponseAppServiceCaller2.Id == initMessageCaller2Id; statusOk = initMessageResponseAppServiceCaller2.Response.Status == Status.ErrorNotFound; initMessageOk = idOk && statusOk; } catch { log.Trace("Expected exception occurred."); disconnectOk = true; } // Step 8 Acceptance bool step8Ok = initMessageOk || disconnectOk; log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED"); // Step 9 log.Trace("Step 9"); // Receive ACK message #1. responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync(); idOk = responseMessageAppServiceCaller.Id == callerMessage1Id; statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok; receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version); versionOk = receivedVersion.Equals(SemVer.V100); bool receiveAckOk = idOk && statusOk && versionOk; // Step 9 Acceptance bool step9Ok = receiveAckOk; log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED"); Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok; res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } clientCallee.Dispose(); clientCalleeAppService.Dispose(); clientCaller1.Dispose(); clientCaller1AppService.Dispose(); clientCaller2.Dispose(); clientCaller2AppService.Dispose(); log.Trace("(-):{0}", res); return(res); }