Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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);
        }
Example #5
0
        /// <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);
        }
Example #6
0
        /// <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 client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await client.ListServerPorts(rolePorts);

                client.CloseConnection();

                // Radius generation.
                R2 = (uint)Rng.Next(R2Min, R2Max);
                R1 = (uint)Rng.Next(R1Min, (int)(R1R2RatioMax * R2));
                R3 = (uint)Rng.Next((int)(R3R2RatioMax * R2), R3Max);
                log.Trace("R1: {0,8} m", R1);
                log.Trace("R2: {0,8} m", R2);
                log.Trace("R3: {0,8} m", R3);

                // Location generation
                for (int i = 0; i < LocationCount; i++)
                {
                    if (PredefinedLocations.Count > i)
                    {
                        GeneratedLocations.Add(GenerateLocation(PredefinedLocations[i], R2));
                    }
                    else
                    {
                        int lat = Rng.Next((int)(GpsLocation.LatitudeMin * GpsLocation.LocationTypeFactor), (int)(GpsLocation.LatitudeMax * GpsLocation.LocationTypeFactor) + 1);
                        int lon = Rng.Next((int)(GpsLocation.LongitudeMin * GpsLocation.LocationTypeFactor) + 1, (int)(GpsLocation.LongitudeMax * GpsLocation.LocationTypeFactor) + 1);
                        GeneratedLocations.Add(new GpsLocation(lat, lon));
                    }
                }

                log.Trace("Generated locations:");
                for (int i = 0; i < LocationCount; i++)
                {
                    log.Trace(" #{0:00}: {1:US}", i, GeneratedLocations[i]);
                }


                bool profileInitializationOk = true;

                uint[] rads = new uint[] { R1, R2, R3 };
                for (int locIndex = 0; locIndex < LocationCount; locIndex++)
                {
                    for (uint radIndex = 0; radIndex < rads.Length; radIndex++)
                    {
                        for (int idIndex = 0; idIndex < RadiusIdentityCount; idIndex++)
                        {
                            GpsLocation basePoint = GeneratedLocations[locIndex];
                            uint        radius    = rads[radIndex];
                            GpsLocation location  = GenerateLocation(basePoint, radius);
                            ProfileLocations.Add(location);

                            string name = string.Format("{0:00}-{1:00}-{2:00} [{3:US}]", locIndex, idIndex, radIndex, location);
                            ProfileNames.Add(name);

                            ProtocolClient profileClient = new ProtocolClient();

                            await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                            bool establishHostingOk = await profileClient.EstablishHostingAsync("test");

                            profileClient.CloseConnection();

                            await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                            bool checkInOk = await profileClient.CheckInAsync();

                            bool initializeProfileOk = await profileClient.InitializeProfileAsync(name, null, location, null);

                            profileInitializationOk = establishHostingOk && checkInOk && initializeProfileOk;
                            profileClient.Dispose();

                            if (!profileInitializationOk)
                            {
                                break;
                            }
                        }
                    }
                }


                log.Trace("Generated profile names:");
                for (int i = 0; i < ProfileNames.Count; i++)
                {
                    log.Trace(" {0}", ProfileNames[i]);
                }


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && profileInitializationOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");


                // Step 2
                log.Trace("Step 2");

                // Start conversation.
                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool startConversationOk = await client.StartConversationAsync();

                // Search all profiles.
                Message requestMessage = mb.CreateProfileSearchRequest(null, null, null, null, 0, 1000, 1000, false, false);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;


                bool totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == ProfileNames.Count;
                bool maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 1000;
                bool profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == ProfileNames.Count;

                bool queryRespOk = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;
                bool resultsOk   = CompareResults(ProfileNames, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                bool query1Ok = queryRespOk && resultsOk;

                bool queriesOk = true;
                // Search queries around target locations.
                for (int locIndex = 0; locIndex < LocationCount; locIndex++)
                {
                    for (uint radIndex = 0; radIndex < rads.Length + 1; radIndex++)
                    {
                        uint        radius         = radIndex < rads.Length ? rads[radIndex] : (uint)Rng.Next(1000000, 10000000);
                        GpsLocation targetLocation = GeneratedLocations[locIndex];
                        requestMessage = mb.CreateProfileSearchRequest(null, null, null, targetLocation, radius, 1000, 1000, false, false);
                        await client.SendMessageAsync(requestMessage);

                        responseMessage = await client.ReceiveMessageAsync();

                        idOk     = responseMessage.Id == requestMessage.Id;
                        statusOk = responseMessage.Response.Status == Status.Ok;

                        List <string> expectedNames = GetProfileNamesInLocation(targetLocation, radius);
                        totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == expectedNames.Count;
                        maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 1000;
                        profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == expectedNames.Count;

                        queryRespOk = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;
                        resultsOk   = CompareResults(expectedNames, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                        queriesOk = queryRespOk && resultsOk;
                        if (!queriesOk)
                        {
                            log.Trace("Search query location {0} with radius {1} should produce {2} profiles, but produced {3} profiles.", targetLocation, radius, expectedNames.Count, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count);
                            log.Trace("Expected names list:");
                            foreach (string name in expectedNames)
                            {
                                log.Trace("  {0}", name);
                            }

                            List <string> resultNames = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Select(r => r.Name).OrderBy(r => r).ToList();
                            log.Trace("Query result names list:");
                            foreach (string name in resultNames)
                            {
                                log.Trace("  {0}", name);
                            }
                            break;
                        }

                        log.Trace("Search query location {0} with radius {1} produced {2} correct profiles.", targetLocation, radius, expectedNames.Count);
                    }

                    if (!queriesOk)
                    {
                        break;
                    }
                }

                // Step 2 Acceptance
                bool step2Ok = startConversationOk && query1Ok && queriesOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #7
0
        /// <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);
        }
Example #8
0
        /// <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);
        }
Example #9
0
        /// <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);

                clientCallee.CloseConnection();

                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk;

                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, "Test Service");
                await clientCaller.SendMessageAsync(requestMessage);

                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool idOk           = responseMessage.Id == requestMessage.Id;
                bool statusOk       = responseMessage.Response.Status == Status.ErrorNotAvailable;
                bool callIdentityOk = idOk && statusOk;

                // 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);
        }
Example #10
0
        /// <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);
        }
Example #11
0
        /// <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 client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await client.ListServerPorts(rolePorts);

                client.CloseConnection();


                ProfilePublicKeys = new List <byte[]>();

                bool profileInitializationOk = true;
                for (int i = 0; i < ProfileNames.Count; i++)
                {
                    ProtocolClient profileClient = new ProtocolClient();
                    ProfilePublicKeys.Add(profileClient.GetIdentityKeys().PublicKey);

                    await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                    bool establishHostingOk = await profileClient.EstablishHostingAsync(ProfileTypes[i]);

                    profileClient.CloseConnection();


                    await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                    bool checkInOk = await profileClient.CheckInAsync();

                    byte[] imageData = ProfileImages[i] != null?File.ReadAllBytes(ProfileImages[i]) : null;

                    bool initializeProfileOk = await profileClient.InitializeProfileAsync(ProfileNames[i], imageData, ProfileLocations[i], ProfileExtraData[i]);

                    profileInitializationOk = establishHostingOk && checkInOk && initializeProfileOk;
                    profileClient.Dispose();

                    if (!profileInitializationOk)
                    {
                        break;
                    }
                }

                bool step1Ok = listPortsOk && profileInitializationOk;
                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.SrNeighbor], true);

                bool verifyIdentityOk = await client.VerifyIdentityAsync();

                // Start neighborhood initialization process.
                Message requestMessage = mb.CreateStartNeighborhoodInitializationRequest(1, 1);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;
                bool startNeighborhoodInitializationOk = idOk && statusOk;

                // Wait for update request.
                Message serverRequestMessage = await client.ReceiveMessageAsync();

                bool typeOk = serverRequestMessage.MessageTypeCase == Message.MessageTypeOneofCase.Request &&
                              serverRequestMessage.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.ConversationRequest &&
                              serverRequestMessage.Request.ConversationRequest.RequestTypeCase == ConversationRequest.RequestTypeOneofCase.NeighborhoodSharedProfileUpdate;

                bool listMatch = CheckProfileList(serverRequestMessage.Request.ConversationRequest.NeighborhoodSharedProfileUpdate.Items);
                bool startNeighborhoodInitializationResponseOk = typeOk && listMatch;

                Message clientResponseMessage = mb.CreateNeighborhoodSharedProfileUpdateResponse(serverRequestMessage);
                await client.SendMessageAsync(clientResponseMessage);


                // Wait for finish request.
                serverRequestMessage = await client.ReceiveMessageAsync();

                typeOk = serverRequestMessage.MessageTypeCase == Message.MessageTypeOneofCase.Request &&
                         serverRequestMessage.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.ConversationRequest &&
                         serverRequestMessage.Request.ConversationRequest.RequestTypeCase == ConversationRequest.RequestTypeOneofCase.FinishNeighborhoodInitialization;

                bool finishNeighborhoodInitializationResponseOk = typeOk;

                clientResponseMessage = mb.CreateFinishNeighborhoodInitializationResponse(serverRequestMessage);
                await client.SendMessageAsync(clientResponseMessage);

                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk && startNeighborhoodInitializationOk && startNeighborhoodInitializationResponseOk && finishNeighborhoodInitializationResponseOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();


            log.Trace("(-):{0}", res);
            return(res);
        }
Example #12
0
        /// <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       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(ServerIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", ServerIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient        client         = new ProtocolClient();
            List <ProtocolClient> testIdentities = new List <ProtocolClient>();

            for (int i = 0; i < IdentityTypes.Count; i++)
            {
                testIdentities.Add(new ProtocolClient());
            }
            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                bool error = false;
                for (int i = 0; i < IdentityTypes.Count - 2; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                    if (!await cl.EstablishHostingAsync(IdentityTypes[i]))
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }

                bool hostingOk = !error;

                error = false;
                for (int i = 0; i < IdentityTypes.Count - 3; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClCustomerPort, true);

                    if (await cl.CheckInAsync())
                    {
                        if (!await cl.InitializeProfileAsync(i.ToString(), null, new GpsLocation(1, 1), null))
                        {
                            error = true;
                            break;
                        }
                    }
                    else
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }
                bool profileInitOk = !error;


                await client.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                Message requestMessage = mb.CreateProfileStatsRequest();
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;
                bool countOk  = responseMessage.Response.SingleResponse.ProfileStats.Stats.Count == 5;

                List <ProfileStatsItem> controlList = new List <ProfileStatsItem>()
                {
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type A", Count = 2
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type B", Count = 3
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type Alpha", Count = 1
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type A B", Count = 1
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type Beta", Count = 1
                    },
                };

                foreach (ProfileStatsItem item in responseMessage.Response.SingleResponse.ProfileStats.Stats)
                {
                    ProfileStatsItem controlItem = controlList.Find(i => (i.IdentityType == item.IdentityType) && (i.Count == item.Count));
                    if (!controlList.Remove(controlItem))
                    {
                        error = true;
                        break;
                    }
                }

                bool contentOk = (controlList.Count == 0) && !error;

                // Step 1 Acceptance
                bool step1Ok = idOk && statusOk && hostingOk && profileInitOk && countOk && contentOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                for (int i = IdentityTypes.Count - 2; i < IdentityTypes.Count; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                    if (!await cl.EstablishHostingAsync(IdentityTypes[i]))
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }

                hostingOk = !error;

                error = false;
                for (int i = IdentityTypes.Count - 2; i < IdentityTypes.Count; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClCustomerPort, true);

                    if (await cl.CheckInAsync())
                    {
                        if (!await cl.InitializeProfileAsync(i.ToString(), null, new GpsLocation(1, 1), null))
                        {
                            error = true;
                            break;
                        }
                    }
                    else
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }
                profileInitOk = !error;

                requestMessage = mb.CreateProfileStatsRequest();
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                countOk  = responseMessage.Response.SingleResponse.ProfileStats.Stats.Count == 6;

                controlList = new List <ProfileStatsItem>()
                {
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type A", Count = 2
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type B", Count = 3
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type Alpha", Count = 1
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type A B", Count = 2
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type Beta", Count = 1
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type C", Count = 1
                    },
                };

                foreach (ProfileStatsItem item in responseMessage.Response.SingleResponse.ProfileStats.Stats)
                {
                    ProfileStatsItem controlItem = controlList.Find(i => (i.IdentityType == item.IdentityType) && (i.Count == item.Count));
                    if (!controlList.Remove(controlItem))
                    {
                        error = true;
                        break;
                    }
                }

                contentOk = (controlList.Count == 0) && !error;

                // Step 2 Acceptance
                bool step2Ok = idOk && statusOk && hostingOk && profileInitOk && countOk && contentOk;

                log.Trace("Step 2: {0}", step1Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }

            foreach (ProtocolClient cl in testIdentities)
            {
                cl.Dispose();
            }

            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #13
0
        /// <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 client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await client.ListServerPorts(rolePorts);

                client.CloseConnection();

                ProfilePublicKeys = new List <byte[]>();

                bool profileInitializationOk = true;
                for (int i = 0; i < ProfileNames.Count; i++)
                {
                    ProtocolClient profileClient = new ProtocolClient();
                    ProfilePublicKeys.Add(profileClient.GetIdentityKeys().PublicKey);

                    await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                    bool establishHostingOk = await profileClient.EstablishHostingAsync(ProfileTypes[i]);

                    profileClient.CloseConnection();


                    await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                    bool checkInOk = await profileClient.CheckInAsync();

                    byte[] imageData = ProfileImages[i] != null?File.ReadAllBytes(ProfileImages[i]) : null;

                    bool initializeProfileOk = await profileClient.InitializeProfileAsync(ProfileNames[i], imageData, ProfileLocations[i], ProfileExtraData[i]);

                    profileInitializationOk = establishHostingOk && checkInOk && initializeProfileOk;
                    profileClient.Dispose();

                    if (!profileInitializationOk)
                    {
                        break;
                    }
                }

                ProtocolClient uninitializedProfileClient = new ProtocolClient();
                await uninitializedProfileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingUninitializedOk = await uninitializedProfileClient.EstablishHostingAsync("Profile Type B");

                uninitializedProfileClient.CloseConnection();
                uninitializedProfileClient.Dispose();


                bool step1Ok = listPortsOk && profileInitializationOk && establishHostingUninitializedOk;
                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool startConversationOk = await client.StartConversationAsync();

                Message requestMessage = mb.CreateProfileSearchRequest(null, null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;


                HashSet <int> numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                bool totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                bool maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                bool profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                bool profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 2 Acceptance
                bool step2Ok = startConversationOk && idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");


                // Step 3
                log.Trace("Step 3");
                requestMessage = mb.CreateProfileSearchRequest("*Type B", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    4, 5
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 3 Acceptance
                bool step3Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");
                requestMessage = mb.CreateProfileSearchRequest("Profile Type C", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 4 Acceptance
                bool step4Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");


                // Step 5
                log.Trace("Step 5");
                requestMessage = mb.CreateProfileSearchRequest(null, "Mumbai *", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    2, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 5 Acceptance
                bool step5Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");


                // Step 6
                log.Trace("Step 6");
                requestMessage = mb.CreateProfileSearchRequest(null, "*ai*", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    1, 2, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 6 Acceptance
                bool step6Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                // Step 7
                log.Trace("Step 7");
                requestMessage = mb.CreateProfileSearchRequest(null, null, null, new GpsLocation(18.961m, 72.82m), 10, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 7 Acceptance
                bool step7Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED");


                // Step 8
                log.Trace("Step 8");
                requestMessage = mb.CreateProfileSearchRequest(null, null, null, new GpsLocation(18.961m, 72.82m), 5000, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    2, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 8 Acceptance
                bool step8Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED");


                // Step 9
                log.Trace("Step 9");
                requestMessage = mb.CreateProfileSearchRequest(null, null, null, new GpsLocation(-12.345678m, 12.345678m), 5000, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 0;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 0;

                // Step 9 Acceptance
                bool step9Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;


                // Step 10
                log.Trace("Step 10");
                requestMessage = mb.CreateProfileSearchRequest(null, null, "no profiles", null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 0;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 0;

                // Step 10 Acceptance
                bool step10Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;

                log.Trace("Step 10: {0}", step10Ok ? "PASSED" : "FAILED");


                // Step 11
                log.Trace("Step 11");
                requestMessage = mb.CreateProfileSearchRequest(null, null, @"(^|;)t=(|[^=]+,)running([;,]|$)", null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    2, 3, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 11 Acceptance
                bool step11Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 11: {0}", step11Ok ? "PASSED" : "FAILED");


                // Step 12
                log.Trace("Step 12");
                requestMessage = mb.CreateProfileSearchRequest(null, null, @".+", null, 0, 2, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 5;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 2;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 2;

                List <IdentityNetworkProfileInformation> setA = new List <IdentityNetworkProfileInformation>(responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                bool firstPartOk = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;


                requestMessage = mb.CreateProfileSearchPartRequest(2, 2);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                bool recordIndexOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordIndex == 2;
                bool recordCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordCount == 2;
                profilesCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles.Count == 2;

                List <IdentityNetworkProfileInformation> setB = new List <IdentityNetworkProfileInformation>(responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles);

                bool secondPartOk = idOk && statusOk && recordIndexOk && recordCountOk && profilesCountOk;


                requestMessage = mb.CreateProfileSearchPartRequest(4, 1);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                recordIndexOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordIndex == 4;
                recordCountOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordCount == 1;
                profilesCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles.Count == 1;

                List <IdentityNetworkProfileInformation> setC = new List <IdentityNetworkProfileInformation>(responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles);

                bool thirdPartOk = idOk && statusOk && recordIndexOk && recordCountOk && profilesCountOk;


                requestMessage = mb.CreateProfileSearchPartRequest(0, 5);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    2, 3, 5, 6, 7
                };
                recordIndexOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordIndex == 0;
                recordCountOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordCount == numberList.Count;
                profilesCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles.Count == numberList.Count;

                bool fourthPartOk = idOk && statusOk && recordIndexOk && recordCountOk && profilesCountOk;


                List <IdentityNetworkProfileInformation> setAll = new List <IdentityNetworkProfileInformation>(responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles);
                bool profileListOk1 = CheckProfileList(numberList, setAll);

                List <IdentityNetworkProfileInformation> setParts = new List <IdentityNetworkProfileInformation>(setA);
                setParts.AddRange(setB);
                setParts.AddRange(setC);
                bool profileListOk2 = CheckProfileList(numberList, setParts);


                // Step 12 Acceptance
                bool step12Ok = firstPartOk && secondPartOk && thirdPartOk && fourthPartOk && profileListOk1 && profileListOk2;

                log.Trace("Step 12: {0}", step12Ok ? "PASSED" : "FAILED");



                // Step 13
                log.Trace("Step 13");
                requestMessage = mb.CreateProfileSearchRequest(null, null, @"(^|;)t=(|[^=]+,)running([;,]|$)", null, 0, 2, 2, false, false);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 2;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 2;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 2;

                numberList = new HashSet <int>()
                {
                    2
                };
                profileListOk1 = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles, false, true);

                numberList = new HashSet <int>()
                {
                    3
                };
                profileListOk2 = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles, false, true);

                numberList = new HashSet <int>()
                {
                    7
                };
                bool profileListOk3 = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles, false, true);

                profileListOk = (profileListOk1 && profileListOk2 && !profileListOk3) ||
                                (profileListOk1 && !profileListOk2 && profileListOk3) ||
                                (!profileListOk1 && profileListOk2 && profileListOk3);

                // Step 13 Acceptance
                bool step13Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 13: {0}", step13Ok ? "PASSED" : "FAILED");


                // Step 14
                log.Trace("Step 14");
                requestMessage = mb.CreateProfileSearchRequest("profile*", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 14 Acceptance
                bool step14Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 14: {0}", step14Ok ? "PASSED" : "FAILED");


                // Step 15
                log.Trace("Step 15");
                requestMessage = mb.CreateProfileSearchRequest("*file*", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 15 Acceptance
                bool step15Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 15: {0}", step15Ok ? "PASSED" : "FAILED");



                // Step 16
                log.Trace("Step 16");
                requestMessage = mb.CreateProfileSearchRequest("**", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 16 Acceptance
                bool step16Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 16: {0}", step16Ok ? "PASSED" : "FAILED");



                // Step 17
                log.Trace("Step 17");
                requestMessage = mb.CreateProfileSearchRequest("*", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 17 Acceptance
                bool step17Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 17: {0}", step17Ok ? "PASSED" : "FAILED");


                // Step 18
                log.Trace("Step 18");
                requestMessage = mb.CreateProfileSearchRequest(null, "*1", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    1, 2
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 18 Acceptance
                bool step18Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 18: {0}", step18Ok ? "PASSED" : "FAILED");


                // Step 19
                log.Trace("Step 19");
                requestMessage = mb.CreateProfileSearchRequest(null, "Shanghai 1", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    1
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 19 Acceptance
                bool step19Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 19: {0}", step19Ok ? "PASSED" : "FAILED");



                // Step 20
                log.Trace("Step 20");
                requestMessage = mb.CreateProfileSearchRequest(null, "**", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 20 Acceptance
                bool step20Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 20: {0}", step20Ok ? "PASSED" : "FAILED");



                // Step 21
                log.Trace("Step 21");
                requestMessage = mb.CreateProfileSearchRequest(null, "*", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 21 Acceptance
                bool step21Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 21: {0}", step21Ok ? "PASSED" : "FAILED");


                // Step 22
                log.Trace("Step 22");
                requestMessage = mb.CreateProfileSearchRequest("*Type A", "*ai*", "water", null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    2
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 22 Acceptance
                bool step22Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

                log.Trace("Step 22: {0}", step22Ok ? "PASSED" : "FAILED");



                // Step 23
                log.Trace("Step 23");
                requestMessage = mb.CreateProfileSearchRequest(null, null, @".+", null, 0, 2, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 5;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 2;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 2;

                firstPartOk = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;

                await Task.Delay(15000);

                requestMessage = mb.CreateProfileSearchPartRequest(8, 2);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.ErrorInvalidValue;
                bool detailsOk = responseMessage.Response.Details == "recordIndex";

                secondPartOk = idOk && statusOk && detailsOk;


                await Task.Delay(15000);

                requestMessage = mb.CreateProfileSearchPartRequest(4, 5);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "recordCount";

                thirdPartOk = idOk && statusOk && detailsOk;



                await Task.Delay(22000);

                requestMessage = mb.CreateProfileSearchPartRequest(0, 500);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "recordCount";

                fourthPartOk = idOk && statusOk && detailsOk;



                requestMessage = mb.CreateProfileSearchPartRequest(0, 5);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;


                numberList = new HashSet <int>()
                {
                    2, 3, 5, 6, 7
                };
                recordIndexOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordIndex == 0;
                recordCountOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordCount == numberList.Count;
                profilesCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles.Count == numberList.Count;

                bool fifthPartOk = idOk && statusOk && recordIndexOk && recordCountOk && profilesCountOk;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles);


                // Step 23 Acceptance
                bool step23Ok = firstPartOk && secondPartOk && thirdPartOk && fourthPartOk && fifthPartOk && profileListOk;

                log.Trace("Step 23: {0}", step23Ok ? "PASSED" : "FAILED");



                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok && step10Ok &&
                         step11Ok && step12Ok && step13Ok && step14Ok && step15Ok && step16Ok && step17Ok && step18Ok && step19Ok && step20Ok &&
                         step21Ok && step22Ok && step23Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #14
0
        /// <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);
        }