Пример #1
0
 /// <summary>
 /// Executes all of the tests.
 /// </summary>
 /// <param name="game"></param>
 public void Execute(ISandboxProtocolController game)
 {
     this.Execute(game, this.Tests);
 }
Пример #2
0
        /// <summary>
        /// Executes only the tests passed in
        /// </summary>
        /// <param name="game"></param>
        /// <param name="tests"></param>
        public void Execute(ISandboxProtocolController game, List<ProtocolUnitTest> tests)
        {
            this.Start = DateTime.Now;

            this.ReplaceText();

            this.FalseAllFoundFlags();

            foreach (ProtocolUnitTest test in tests) {

                this.OnTestBegin(new ProtocolUnitTestEventArgs() {
                    Test = test
                });

                if (test.Execute(game, this.ConnecionIsolation) == true) {
                    this.OnTestSuccess(new ProtocolUnitTestEventArgs() {
                        Test = test
                    });
                }
                else {
                    this.OnTestFailed(new ProtocolUnitTestEventArgs() {
                        Test = test
                    });
                }
            }

            this.End = DateTime.Now;
        }
Пример #3
0
        /// <summary>
        /// Asserts the game client disconnects, or is already disconnected.
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        protected bool Disconnect(ISandboxProtocolController game)
        {
            bool disconnected = true;

            if (game.State != null && game.State.Settings.Current.ConnectionState != ConnectionState.ConnectionDisconnected) {
                AutoResetEvent disconnectEvent = new AutoResetEvent(false);

                Action<IClientEventArgs> handler = (args) => {
                    if (args.EventType == ClientEventType.ClientConnectionStateChange) {
                        if (args.ConnectionState == ConnectionState.ConnectionDisconnected) {
                            disconnectEvent.Set();
                        }
                    }
                };

                ISandboxProtocolCallbackProxy originalBubbleProxy = game.Bubble;

                game.Bubble = new SandboxProtocolCallbackProxy() {
                    ClientEvent = new Action<IClientEventArgs>(handler)
                };

                game.Shutdown();

                if ((disconnected = disconnectEvent.WaitOne(this.Timeout * 1000)) == false) {
                    this.OnTestEvent(new ProtocolUnitTestEventArgs() { Message = "Timeout on client disconnection." });
                }

                game.Bubble = originalBubbleProxy;
            }

            return disconnected;
        }
Пример #4
0
        /// <summary>
        /// Asserts a connection has been established to the server and has properly logged in to begin testing.
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        protected bool LoggedIn(ISandboxProtocolController game)
        {
            bool loggedIn = true;

            if (game.State == null || game.State.Settings.Current.ConnectionState != ConnectionState.ConnectionLoggedIn) {
                AutoResetEvent loginEvent = new AutoResetEvent(false);

                Action<IClientEventArgs> handler = (args) => {
                    if (args.EventType == ClientEventType.ClientConnectionStateChange) {
                        if (args.ConnectionState == ConnectionState.ConnectionLoggedIn) {
                            loginEvent.Set();
                        }
                    }
                };

                ISandboxProtocolCallbackProxy originalBubbleProxy = game.Bubble;

                game.Bubble = new SandboxProtocolCallbackProxy() {
                    ClientEvent = new Action<IClientEventArgs>(handler)
                };

                game.AttemptConnection();

                if ((loggedIn = loginEvent.WaitOne(this.Timeout * 1000)) == false) {
                    this.OnTestEvent(new ProtocolUnitTestEventArgs() { Message = "Timeout on client connection + login. (check end point & credentials)" });
                }

                game.Bubble = originalBubbleProxy;
            }

            return loggedIn;
        }
Пример #5
0
        public bool Execute(ISandboxProtocolController game, bool connectionIsolation)
        {
            bool success = true;

            if (connectionIsolation == true) {
                // 1. Assert the game is disconnected.
                success = this.Disconnect(game);
            }

            // 2. Assert the game is connected and logged in, ready to go.
            success = success && this.LoggedIn(game);

            this.Start = DateTime.Now;

            if (success == true) {
                this.OnTestSetup(new ProtocolUnitTestEventArgs() {
                    Message = "Test connection reconnected and logged in."
                });

                // 3. Assert each command is successful in whole from sending a command.
                foreach (ProtocolUnitTestCommand command in this.TestCommands) {

                    AutoResetEvent expectedResults = new AutoResetEvent(false);

                    // List of packets recieved that were not matched.
                    List<String> unmatchedReceived = new List<String>();

                    ProtocolUnitTestCommand localCommand = command;

                    Action<IClientEventArgs> handler = (args) => {
                        if (args.EventType == ClientEventType.ClientPacketReceived) {
                            ProtocolUnitTestPacket matchedPacket = args.Now.Packets.First().Type == PacketType.Response ? localCommand.Responses.FirstOrDefault(response => response.Matches(args.Now.Packets.First().Text)) : localCommand.Requests.FirstOrDefault(request => request.Matches(args.Now.Packets.First().Text));

                            if (matchedPacket != null) {
                                matchedPacket.Found = true;
                            }
                            else {
                                // Add it to the alternative packets received for debug output.
                                unmatchedReceived.Add(args.Now.Packets.First().Text);
                            }

                            // If we don't have any packets remaining that have not been found yet.
                            if (localCommand.Responses.Count(response => response.Found == false) + localCommand.Requests.Count(request => request.Found == false) == 0) {
                                expectedResults.Set();
                            }
                        }
                    };

                    ISandboxProtocolCallbackProxy originalBubbleProxy = game.Bubble;

                    game.Bubble = new SandboxProtocolCallbackProxy() {
                        ClientEvent = new Action<IClientEventArgs>(handler)
                    };

                    // 3 b. Send our packet to initiate this command test
                    game.Action(new NetworkAction() {
                        ActionType = NetworkActionType.NetworkPacketSend,
                        Now = {
                            Content = new List<String>() {
                                command.Send.Text
                            }
                        }
                    });

                    if ((success = success && expectedResults.WaitOne(this.Timeout * 1000)) == false) {
                        String[] expecting = command.Responses.Where(response => response.Found == false).Select(response => response.ToString()).Union(command.Requests.Where(request => request.Found == false).Select(request => request.ToString())).ToArray();

                        this.OnTestEvent(new ProtocolUnitTestEventArgs() { Message = String.Format("Expecting: {0}; Received: {1}", String.Join(", ", expecting), String.Join(", ", unmatchedReceived.ToArray())) });
                    }

                    game.Bubble = originalBubbleProxy;
                }
            }
            this.End = DateTime.Now;

            return success;
        }