/// <summary>Initializes the communication.</summary> /// <param name="clientPort">The client port.</param> private void InitializeCommunication(uint clientPort) { var msgClientHello = new ClientHelloMessage() { ClientId = ClientId, ClientPort = clientPort, Message = $"Hello from {ClientId}", Version = Shared.Constants.Version.PROTOCOL }; UdpTransferFrame frame = new UdpTransferFrame(FrameType.ClientHello, msgClientHello.Serialize()); ReliableMessaging.OnSendFrame(frame); }
private IActorRef CreateAuthenticatedActor(TestProbe authenticationProbe, TestProbe clientSocketProbe) { //setup const uint CLIENTID = 1234567890; const string TOKEN = "TOKEN"; string EXPECTEDRESPONSE = $"HELLO {CLIENTID}"; var testeeRef = Sys.ActorOf(Props.Create(() => new ClientTwinActor(clientSocketProbe, authenticationProbe, defaultEndpoint, defaultShardRegionArea, defaultObjectRegionArea))); var clientHelloMessage = new ClientHelloMessage() { Message = string.Empty, ClientId = CLIENTID, ClientPort = 9999, Version = Shared.Constants.Version.PROTOCOL, }; var clientAuthenticationResponse = new ClientAuthenticationResponse() { AuthenticationToken = TOKEN, }; //execute - client hello testeeRef.Tell(new UdpTransferFrame(FrameType.ClientHello, clientHelloMessage.Serialize())); //verify clientSocketProbe.ExpectMsg <Udp.Send>(s => { var msg = new UdpTransferFrame(s.Payload.ToArray()); Assert.Equal(FrameType.ServerAuthenticationRequest, msg.Type); }); //execute - client authentication response testeeRef.Tell(new UdpTransferFrame(FrameType.ClientAuthenticationResponse, clientAuthenticationResponse.Serialize())); //verify authenticationProbe.ExpectMsg <RequestAuthenticationCommand>(c => { Assert.Equal(TOKEN, c.Token); }); //execute - authentication actor response testeeRef.Tell(new AuthenticationSuccess()); //verify clientSocketProbe.ExpectMsg <Udp.Send>(s => { var msg = new UdpTransferFrame(s.Payload.ToArray()); Assert.Equal(FrameType.ServerHello, msg.Type); var serverHello = new ServerHelloMessage(msg.MessageBuffer); Assert.Equal(EXPECTEDRESPONSE, serverHello.Message); Assert.Equal(clientHelloMessage.Version, serverHello.Version); }); return(testeeRef); }