Example #1
0
            public override void use(ClientPlayerInfo p, string message)
            {
                var match = Regex.Match(message, parent.voteCtrlPattern);

                if (!match.Success)
                {
                    help(p);
                    return;
                }

                string voteType = match.Groups[1].Value.ToLower();
                string percentS = match.Groups[2].Value;
                int    percent  = int.Parse(percentS);

                if (!parent.voteCommand.voteThresholds.ContainsKey(voteType))
                {
                    MessageUtilities.sendMessage(p, $"Invalid <voteType>. ({voteType})");
                    help(p);
                    return;
                }

                parent.voteCommand.voteThresholds[voteType] = Convert.ToDouble(percent) / 100.0;
                Entry.save();
                MessageUtilities.sendMessage(p, $"Pass threshold for {voteType} changed to {percent}%");
            }
Example #2
0
        IEnumerable <float> waitForMinPlayers()
        {
            int myIndex;

            if (G.Sys.PlayerManager_.PlayerList_.Count < getMinPlayers() && autoMode)
            {
                AutoSpecCmd autoSpecCommand = list.getCommand <AutoSpecCmd>("autospec");
                var         specCount       = autoSpecCommand.getAutoSpecPlayers().Count;
                if (specCount != 0)
                {
                    string specWord = specCount == 1 ? "is" : "are";
                    MessageUtilities.sendMessage($"Waiting for there to be {minPlayers} players. ({specCount} {specWord} auto-spectating)");
                }
                else
                {
                    MessageUtilities.sendMessage($"Waiting for there to be {minPlayers} players.");
                }
                while (G.Sys.PlayerManager_.PlayerList_.Count < getMinPlayers() && autoMode)
                {
                    myIndex = index;
                    yield return(5.0f);

                    if (index != myIndex)
                    {
                        yield break;
                    }
                }
            }
        }
Example #3
0
        public override void use(ClientPlayerInfo p, string message)
        {
            if (!GeneralUtilities.isOnGamemode())
            {
                MessageUtilities.sendMessage(p, "Can't restart on lobby !");
                return;
            }

            var serverLogic = G.Sys.GameManager_.GetComponent <ServerLogic>();

            if (serverLogic == null)
            {
                MessageUtilities.sendMessage(p, "ServerLogic null !");
                return;
            }

            var clients = (IEnumerable)PrivateUtilities.getPrivateField(serverLogic, "clientInfoList_");

            foreach (var c in clients)
            {
                if (p.NetworkPlayer_ == (UnityEngine.NetworkPlayer)PrivateUtilities.getPrivateField(c, "networkPlayer_"))
                {
                    exec(serverLogic, c);
                    break;
                }
            }
        }
Example #4
0
        public override void use(ClientPlayerInfo p, string message)
        {
            LevelPlaylist playlist = new LevelPlaylist();

            playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_);

            if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify)
            {
                MessageUtilities.sendMessage(p, "You can't manage the playlist in trackmogrify");
                return;
            }

            if (playlist.Count_ == 0)
            {
                MessageUtilities.sendMessage(p, "The playlist is empty !");
                return;
            }

            var item = playlist.Playlist_[G.Sys.GameManager_.LevelPlaylist_.Index_];

            playlist.Playlist_.Clear();

            G.Sys.GameManager_.LevelPlaylist_.Clear();
            G.Sys.GameManager_.LevelPlaylist_.Add(item);

            G.Sys.GameManager_.NextLevelName_ = item.levelNameAndPath_.levelName_;
            G.Sys.GameManager_.NextLevelPath_ = item.levelNameAndPath_.levelPath_;
            G.Sys.GameManager_.LevelPlaylist_.SetIndex(0);

            MessageUtilities.sendMessage(p, "Playlist cleared !");
        }
Example #5
0
        IEnumerator waitUtilEnd()
        {
            if (advanceMessage != "")
            {
                MessageUtilities.sendMessage(advanceMessage);
            }
            didFinish = false;
            int currentIndex = index;

            if (maxRunTime > 60)
            {
                yield return(new WaitForSeconds(maxRunTime - 60));

                CountdownCmd countdownCommand = list.getCommand <CountdownCmd>("countdown");
                if (currentIndex == index && autoMode && !countdownCommand.countdownStarted)
                {
                    MessageUtilities.sendMessage("This map has run for the maximum time.");

                    // start countdown for 60 seconds. Everyone is marked DNF at 60 seconds.
                    countdownCommand.startCountdown(60);
                }
            }
            else
            {
                CountdownCmd countdownCommand = list.getCommand <CountdownCmd>("countdown");
                countdownCommand.startCountdown(maxRunTime);
            }
            yield return(null);
        }
Example #6
0
        private void printClient()
        {
            var optionsList = MessageUtilities.popAllMessageOptions();

            MessageUtilities.sendMessage(GeneralUtilities.localClient().GetChatName() + " Version " + PluginVersion);
            MessageUtilities.pushMessageOptionsList(optionsList);
        }
Example #7
0
        public override void use(ClientPlayerInfo p, string message)
        {
            if (message == "")
            {
                help(p);
                return;
            }

            var affects = "";

            foreach (ClientPlayerInfo client in GeneralUtilities.getClientsBySearch(message))
            {
                StaticTargetedEvent <Finished.Data> .Broadcast(client.NetworkPlayer_, default(Finished.Data));

                affects += $"{ client.Username_}, ";
            }
            if (affects == "")
            {
                MessageUtilities.sendMessage(p, "Could not find any players with that name or index");
            }
            else
            {
                MessageUtilities.sendMessage(p, affects + "is now spectating.");
            }
        }
Example #8
0
        public void Create_RequestIdTypeMethod_ThrowsForNullOrEmptyRequestId(string requestId)
        {
            var exception = Assert.Throws <ArgumentException>(
                () => MessageUtilities.Create(requestId, MessageType.Request, MessageMethod.Handshake));

            Assert.Equal("requestId", exception.ParamName);
        }
Example #9
0
        public override void help(ClientPlayerInfo p)
        {
            MessageUtilities.sendMessage(p, GeneralUtilities.formatCmd("!level [name]") + ": Find a level who have that keyword on his name");
            MessageUtilities.sendMessage(p, GeneralUtilities.formatCmd("!level [filter] ") + ": Use filters to find a level");
            List <LevelFilter> filters = new List <LevelFilter>();

            foreach (KeyValuePair <string, LevelFilter> filter in FilteredPlaylist.filterTypes)
            {
                if (!filters.Contains(filter.Value))
                {
                    filters.Add(filter.Value);
                }
            }
            string filtersStr = "";

            foreach (LevelFilter filter in filters)
            {
                foreach (string option in filter.options)
                {
                    filtersStr += "-" + option + " ";
                }
            }
            MessageUtilities.sendMessage(p, "Valid filters: " + filtersStr);
            MessageUtilities.sendMessage(p, "Filter types:  default (and): -filter; not default: !filter; and: &filter; or: |filter; and not: &!filter; or not: |!filter");
            MessageUtilities.sendMessage(p, "The level must be known by the server to be shown");
        }
Example #10
0
        private async Task DisplayWinners(string channelId, IEnumerable <string> winners)
        {
            if (winners.Contains("no-winners"))
            {
                await _discordRestClient.PostMessage(channelId,
                                                     $"No winners");

                return;
            }

            if (winners.Count() > 1)
            {
                var userIds = "Winners ";
                foreach (var winner in winners)
                {
                    userIds += $"{MessageUtilities.MentionUser(winner)} ";
                }

                await _discordRestClient.PostMessage(channelId, userIds);
            }
            else
            {
                var winner = winners.First();

                await _discordRestClient.PostMessage(channelId, $"Winner {MessageUtilities.MentionUser(winner)}");
            }
        }
Example #11
0
        public override void use(ClientPlayerInfo p, string message)
        {
            var clientLogic = G.Sys.PlayerManager_.GetComponent <ClientLogic>();

            if (clientLogic == null)
            {
                MessageUtilities.sendMessage(p, "Error : Client logic null !");
                return;
            }

            try
            {
                var client  = clientLogic.GetLocalPlayerInfo();
                var oldName = client.Username_;

                PrivateUtilities.setPrivateField(client, "username_", message);

                MessageUtilities.sendMessage(p, oldName + " renamed to " + client.Username_);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                MessageUtilities.sendMessage(p, "Error : can't change your name !");
            }
        }
Example #12
0
 private void spectatePlayer(ClientPlayerInfo player, bool force = false)
 {
     if (!GeneralUtilities.isOnGamemode())
     {
         return;
     }
     if (!autoSpecAllowPlayers && !player.IsLocal_ && !force)
     {
         return;
     }
     if (spectators.Contains(GeneralUtilities.getUniquePlayerString(player)))
     {
         MessageUtilities.sendMessage(player, "You are in auto-spectate mode. Say " + GeneralUtilities.formatCmd("!autospec") + " to turn it off.");
     }
     Entry.Instance.chatReplicationManager.ReplicateNeeded();
     if (player.IsLocal_)
     {
         if (G.Sys.PlayerManager_.PlayerList_.Count == 1 && GeneralUtilities.isHost() && autoSpecReturnToLobby)
         {
             G.Sys.GameManager_.GoToLobby();
         }
         else
         {
             G.Sys.PlayerManager_.Current_.playerData_.Spectate();
         }
     }
     else
     {
         StaticTargetedEvent <Finished.Data> .Broadcast(player.NetworkPlayer_, default(Finished.Data));
     }
 }
Example #13
0
        public override void use(ClientPlayerInfo p, string message)
        {
            if (message == "")
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p));
                printPlaylists();
                MessageUtilities.popMessageOptions();
                return;
            }

            var name = Resource.PersonalLevelPlaylistsDirPath_ + message + ".xml";

            if (!Resource.FileExist(name))
            {
                MessageUtilities.sendMessage(p, "The playlist " + message + " don't exist !");
                return;
            }

            var item = G.Sys.GameManager_.LevelPlaylist_.Count_ == 0 ? null : G.Sys.GameManager_.LevelPlaylist_.Playlist_[G.Sys.GameManager_.LevelPlaylist_.Index_];

            var gameObject   = LevelPlaylist.Load(name);
            var playlistComp = gameObject.GetComponent <LevelPlaylist>();

            G.Sys.GameManager_.LevelPlaylist_.CopyFrom(playlistComp);

            MessageUtilities.sendMessage(p, "Playlist Loaded : " + G.Sys.GameManager_.LevelPlaylist_.Count_ + " levels.");

            if (GeneralUtilities.isOnGamemode() && item != null)
            {
                G.Sys.GameManager_.LevelPlaylist_.Playlist_.Insert(0, item);
            }
        }
        public void Port_DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            int index = portsGrid.SelectedIndex;

            if ((index < portsGrid.Items.Count) && (index >= 0))
            {
                PortDefenition portDef = portsGrid.Items[index] as PortDefenition;
                bool           delete  = MessageUtilities.AskToDelete("Do you want to delete " + portDef.Name + "?");
                if (delete == true)
                {
                    AutosarApplication.GetInstance().DeletePort(composition.GetInternalPortPainter(portDef));
                    AutosarApplication.GetInstance().DeletePort(composition.GetExternalPortPainter(portDef));

                    PortPainter internalPort = composition.GetInternalPortPainter(portDef);
                    if (internalPort != null)
                    {
                        composition.InternalPortsInstances.Remove(internalPort);
                    }

                    PortPainter externalPort = composition.GetExternalPortPainter(portDef);
                    if (externalPort != null)
                    {
                        composition.Ports.Remove(externalPort);
                    }

                    composition.PortsDefenitions.Remove(portDef);
                    tree.UpdateAutosarTreeView(tree.SelectedItem);
                    UpdatePortsGrid();
                }
            }
        }
Example #15
0
        public override void use(ClientPlayerInfo p, string message)
        {
            LevelPlaylist currentList = G.Sys.GameManager_.LevelPlaylist_;

            if (currentList.Index_ >= currentList.Count_)
            {
                MessageUtilities.sendMessage(p, "There are no levels in the playlist!");
                return;
            }
            else if (currentList.Index_ == currentList.Count_ - 1)
            {
                MessageUtilities.sendMessage(p, "You are on the last level of the playlist!");
                return;
            }

            LevelCmd levelCmd = Cmd.all.getCommand <LevelCmd>("level");

            var levelsUpcoming        = currentList.Playlist_.GetRange(currentList.Index_ + 1, currentList.Count_ - currentList.Index_ - 1);
            FilteredPlaylist filterer = new FilteredPlaylist(levelsUpcoming);

            GeneralUtilities.addFiltersToPlaylist(filterer, p, message, false);

            MessageUtilities.sendMessage(p, "[FFFFFF]Upcoming:[-]");
            MessageUtilities.sendMessage(p, GeneralUtilities.getPlaylistText(filterer, GeneralUtilities.IndexMode.Initial, levelCmd.levelFormat));
        }
Example #16
0
        public override void use(ClientPlayerInfo p, string message)
        {
            LevelPlaylist playlist = new LevelPlaylist();

            playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_);

            if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify)
            {
                MessageUtilities.sendMessage(p, "You can't manage the playlist in trackmogrify");
                return;
            }

            if (playlist.Count_ == 0)
            {
                MessageUtilities.sendMessage(p, "The playlist is empty !");
                return;
            }

            if (GeneralUtilities.isOnGamemode())
            {
                shuffleOnGame(playlist);
            }
            else
            {
                shuffleOnLobby(playlist);
            }

            G.Sys.GameManager_.LevelPlaylist_.SetIndex(0);
            G.Sys.GameManager_.NextLevelName_ = G.Sys.GameManager_.LevelPlaylist_.Playlist_[0].levelNameAndPath_.levelName_;
            G.Sys.GameManager_.NextLevelPath_ = G.Sys.GameManager_.LevelPlaylist_.Playlist_[0].levelNameAndPath_.levelPath_;

            MessageUtilities.sendMessage(p, "Playlist shuffled !");
        }
        public void HandleResponse_SecondResponseIsIgnored()
        {
            using (var test = new OutboundRequestContextTest())
            {
                var payload = new HandshakeResponse(MessageResponseCode.Error, protocolVersion: null);
                var firstResponse = MessageUtilities.Create(
                    test.Request.RequestId,
                    MessageType.Response,
                    test.Request.Method,
                    payload);

                test.Context.HandleResponse(firstResponse);

                var response = test.Context.CompletionTask.Result;

                payload = new HandshakeResponse(MessageResponseCode.Success, ProtocolConstants.CurrentVersion);
                var secondResponse = MessageUtilities.Create(
                    test.Request.RequestId,
                    MessageType.Response,
                    test.Request.Method,
                    payload);

                test.Context.HandleResponse(secondResponse);

                Assert.Same(response, test.Context.CompletionTask.Result);
            }
        }
Example #18
0
 public override void help(ClientPlayerInfo p)
 {
     MessageUtilities.sendMessage(p, GeneralUtilities.formatCmd("!server") + ": Show the server name");
     MessageUtilities.sendMessage(p, GeneralUtilities.formatCmd("!server [new name]") + ": Modify the server name");
     MessageUtilities.sendMessage(p, GeneralUtilities.formatCmd("!server private [password]") + ": Set the server private");
     MessageUtilities.sendMessage(p, GeneralUtilities.formatCmd("!server public") + ": Set the server public");
 }
Example #19
0
        public override void use(ClientPlayerInfo p, string message)
        {
            Random r     = new Random();
            float  color = (float)r.NextDouble() * 360;

            MessageUtilities.sendMessage("[b][" + ColorEx.ColorToHexNGUI(new ColorHSB(color, 1.0f, 1.0f, 1f).ToColor()) + "]" + winList[r.Next(winList.Count)] + "[-][/b]");
        }
Example #20
0
        public void DeserializePayload_ThrowsForNullMessage()
        {
            var exception = Assert.Throws <ArgumentNullException>(
                () => MessageUtilities.DeserializePayload <Payload>(message: null));

            Assert.Equal("message", exception.ParamName);
        }
Example #21
0
 public override void use(ClientPlayerInfo p, string message)
 {
     index++;  // Tracks when new levels load. Some code needs to stop running if a new level loads.
     if (!autoMode)
     {
         autoMode = true;
         MessageUtilities.sendMessage("Auto mode started!");
         if (GeneralUtilities.isOnLobby())
         {
             G.Sys.GameManager_.StartCoroutine(startFromLobby());
         }
         else if (GeneralUtilities.isModeFinished())
         {
             G.Sys.GameManager_.StartCoroutine(waitAndGoNext());
         }
         else
         {
             onModeStart();
         }
     }
     else
     {
         autoMode = false;
         MessageUtilities.sendMessage("Auto mode stopped!");
     }
 }
        /// <inheritdoc cref="IRequestHandler.HandleResponseAsync"/>
        public async Task HandleResponseAsync(IConnection connection, Message message, IResponseHandler responseHandler, CancellationToken cancellationToken)
        {
            Connection        = connection;
            CancellationToken = cancellationToken;

            TRequest request = MessageUtilities.DeserializePayload <TRequest>(message);

            Logger.Verbose(string.Format(Resources.HandlingRequest, message.Type, message.Method, message.Payload.ToString(Formatting.None)));

            TResponse response = null;

            using (GetProgressReporter(connection, message, cancellationToken))
            {
                response = await HandleRequestAsync(request).ConfigureAwait(continueOnCapturedContext: false);
            }

            // We don't want to print credentials on auth responses
            if (message.Method != MessageMethod.GetAuthenticationCredentials)
            {
                var logResponse = JsonConvert.SerializeObject(response, new JsonSerializerSettings {
                    Formatting = Formatting.None
                });
                Logger.Verbose(string.Format(Resources.SendingResponse, logResponse));
            }

            await responseHandler.SendResponseAsync(message, response, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);

            CancellationToken = CancellationToken.None;
        }
Example #23
0
        public override void use(ClientPlayerInfo p, string message)
        {
            if (message == "")
            {
                help(p);
                return;
            }

            if (message == "CHECK" && p == GeneralUtilities.localClient())
            {
                var index = 0;
                foreach (var a in GeneralUtilities.getAllLevelsAndModes())
                {
                    GeneralUtilities.formatLevelInfoText(a, index++, "%NAME% %DIFFICULTY% %MODE% %AUTHOR% %INDEX% %MBRONZE% %MSILVER% %MGOLD% %MDIAMOND% %STARS% %STARSINT% %STARSDEC% %STARSPCT% %CREATED% %UPDATED%");
                }
                Console.WriteLine($"Tried to format {index} levels. Errors are in the console. If you see no errors, it means all levels formatted successfully.");
                MessageUtilities.sendMessage(GeneralUtilities.localClient(), $"Tried to format {index} levels. Errors are in the console. If you see no errors, it means all levels formatted successfully.");
                return;
            }

            FilteredPlaylist filterer = new FilteredPlaylist(GeneralUtilities.getAllLevelsAndModes());

            if (!p.IsLocal_)
            {
                PlayCmd playCmd = Cmd.all.getCommand <PlayCmd>("play");
                filterer.AddFiltersFromString(playCmd.playFilter);
            }

            MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p));
            GeneralUtilities.sendFailures(GeneralUtilities.addFiltersToPlaylist(filterer, p, message, true), 4);
            MessageUtilities.popMessageOptions();

            MessageUtilities.sendMessage(p, GeneralUtilities.getPlaylistText(filterer, GeneralUtilities.IndexMode.Final, levelFormat));
        }
Example #24
0
 IEnumerator autoAutoSpectate()
 {
     while (true)
     {
         try
         {
             if (autoSpecIdleTimeout > 0 && GeneralUtilities.isHost() && GeneralUtilities.isOnline() && !GeneralUtilities.isOnLobby())
             {
                 var debug_playerInfo  = "";
                 var debug_didSpectate = false;
                 var unfinished        = new List <PlayerDataBase>();
                 G.Sys.GameManager_.Mode_.GetSortedListOfUnfinishedPlayers(unfinished);
                 debug_playerInfo += $"Unfinished list size: {unfinished.Count}\n";
                 debug_playerInfo += $"Spectators list size: {spectators.Count}\n";
                 debug_playerInfo += $"autoSpecIdleTimeout: {autoSpecIdleTimeout}\n";
                 debug_playerInfo += $"Players:\n";
                 foreach (var info in Entry.Instance.playerInfos)
                 {
                     var client            = info.playerData;
                     var timeSinceLastMove = info.timeSinceLastMove;
                     var uniq = GeneralUtilities.getUniquePlayerString(client.PlayerInfo_);
                     debug_playerInfo += $"\t{client.Name_}:\n";
                     debug_playerInfo += $"\t\ttimeSinceLastMove: {timeSinceLastMove}\n";
                     debug_playerInfo += $"\t\tguid: {uniq}\n";
                     debug_playerInfo += $"\t\tIn auto-spectators list: {spectators.Contains(uniq)}\n";
                     debug_playerInfo += $"\t\tIn unfinished list: {unfinished.Contains(client)}\n";
                     if (timeSinceLastMove > 0f && timeSinceLastMove > autoSpecIdleTimeout && !spectators.Contains(uniq) && unfinished.Contains(client))
                     {
                         debug_didSpectate = true;
                         if (!autoSpecIdleSingle)
                         {
                             debug_playerInfo += "\t\tSet to auto-spectate\n";
                             spectators.Add(uniq);
                             MessageUtilities.sendMessage($"{MessageUtilities.closeTags(client.PlayerInfo_.GetChatName())} has been set to auto-spec for being idle.");
                         }
                         else
                         {
                             debug_playerInfo += "\t\tSet to regular spectate\n";
                             MessageUtilities.sendMessage($"{MessageUtilities.closeTags(client.PlayerInfo_.GetChatName())} has been set to spectate for being idle.");
                         }
                         spectatePlayer(client.PlayerInfo_, force: true);
                     }
                     else
                     {
                         debug_playerInfo += "\t\tNo action\n";
                     }
                 }
                 if (debug_didSpectate && autoSpecDebug)
                 {
                     Console.WriteLine(debug_playerInfo);
                 }
             }
         } catch (Exception e)
         {
             Console.WriteLine($"Error auto-specing idle players: {e}");
         }
         yield return(new WaitForSeconds(1f));
     }
 }
Example #25
0
 protected void Dispose(bool disposing)
 {
     if (this.schedulerChannel == null)
     {
         return;
     }
     MessageUtilities.ShutdownCommunicationObject((ICommunicationObject)this.schedulerChannel);
 }
Example #26
0
 private void setServerPrivate(string pass)
 {
     G.Sys.NetworkingManager_.password_      = pass;
     G.Sys.NetworkingManager_.privateServer_ = true;
     Network.incomingPassword = pass;
     updateMaster();
     MessageUtilities.sendMessage("The server is now private !");
 }
Example #27
0
 private void setServerPublic()
 {
     G.Sys.NetworkingManager_.password_      = "";
     G.Sys.NetworkingManager_.privateServer_ = false;
     Network.incomingPassword = "";
     updateMaster();
     MessageUtilities.sendMessage("The server is now public !");
 }
Example #28
0
 public override void help(ClientPlayerInfo p)
 {
     MessageUtilities.sendMessage(p, GeneralUtilities.formatCmd("!welcome") + ": Hear the welcome message.");
     if (GeneralUtilities.isHost())
     {
         MessageUtilities.sendMessage(p, "You can set the welcome message with !settings");
     }
 }
Example #29
0
        public void DeserializePayload_SupportsNullPayload()
        {
            var message = new Message(requestId: "a", type: MessageType.Fault, method: MessageMethod.None, payload: null);

            var payload = MessageUtilities.DeserializePayload <Payload>(message);

            Assert.Null(payload);
        }
Example #30
0
        public void BeginResponseAsync_TranslatesRequestHandlerExceptionIntoFaultResponse()
        {
            using (var test = new InboundRequestContextTest())
                using (var sentEvent = new ManualResetEventSlim(initialState: false))
                {
                    var requestHandler = new Mock <IRequestHandler>(MockBehavior.Strict);

                    requestHandler.Setup(x => x.HandleResponseAsync(
                                             It.IsNotNull <IConnection>(),
                                             It.IsNotNull <Message>(),
                                             It.IsNotNull <IResponseHandler>(),
                                             It.IsAny <CancellationToken>()))
                    .Throws(new Exception("test"));

                    Message response = null;

                    test.Connection.Setup(x => x.SendAsync(It.IsNotNull <Message>(), It.IsAny <CancellationToken>()))
                    .Callback <Message, CancellationToken>(
                        (message, cancellationToken) =>
                    {
                        response = message;

                        sentEvent.Set();
                    })
                    .Returns(Task.FromResult(0));

                    test.Context.BeginResponseAsync(
                        new Message(
                            test.RequestId,
                            MessageType.Request,
                            MessageMethod.GetOperationClaims,
                            payload: null),
                        requestHandler.Object,
                        Mock.Of <IResponseHandler>());

                    sentEvent.Wait();

                    requestHandler.Verify(x => x.HandleResponseAsync(
                                              It.IsNotNull <IConnection>(),
                                              It.IsNotNull <Message>(),
                                              It.IsNotNull <IResponseHandler>(),
                                              It.IsAny <CancellationToken>()), Times.Once);

                    test.Connection.Verify(
                        x => x.SendAsync(It.IsNotNull <Message>(), It.IsAny <CancellationToken>()),
                        Times.Once);

                    Assert.NotNull(response);
                    Assert.Equal(test.RequestId, response.RequestId);
                    Assert.Equal(MessageType.Fault, response.Type);
                    Assert.Equal(MessageMethod.GetOperationClaims, response.Method);

                    var responsePayload = MessageUtilities.DeserializePayload <Fault>(response);

                    Assert.Equal("test", responsePayload.Message);
                }
        }