Beispiel #1
0
        public void MockBot_AccellerateCallsReadSpeedMessage()
        {
            Hub testHub        = new Hub(true);
            var actionProvider = new bd2MessageBasedBotSupport();

            actionProvider.InjectHub(testHub);
            bool messageRecieved = false;

            testHub.LookFor <Message_Query>(ab => {
                if (ab.SubKind == KnownSubkinds.ReadSpeed)
                {
                    messageRecieved           = true;
                    NavigationInfoContext nic = new NavigationInfoContext();
                    nic.SpeedDelta            = 1;
                    ab.ResponseContext        = nic;
                }
            });
            var sut = new MockBotFactory().CreateBasicMockBot().WithThisActionProvider(actionProvider, actionProvider).ToBot();

            sut.Accelerate();
            Assert.True(messageRecieved, "The query speed message was not requested by the accelerate function");
        }
Beispiel #2
0
        public void MockBot_AccellerateCallsAccellerateMessage()
        {
            var testHub = new Hub(true);

            testHub.UseStrongReferences = true;
            var engineHub = new bd2MessageBasedBotSupport();

            engineHub.InjectHub(testHub);
            bool messageRecieved = false;
            int  valueChange     = 0;

            testHub.LookFor <Message_Query>(ab => {
                if (ab.SubKind == KnownSubkinds.ReadSpeed)
                {
                    NavigationInfoContext nic = new NavigationInfoContext();
                    nic.SpeedDelta            = 1;
                    ab.ResponseContext        = nic;
                }
            });

            testHub.LookFor <Message_BotPerformAction>(ab => {
                if (ab.SubKind == KnownSubkinds.ChangeSpeed)
                {
                    messageRecieved           = true;
                    NavigationInfoContext nic = (NavigationInfoContext)ab.RequestContext;
                    Assert.NotNull(nic);
                    valueChange = nic.SpeedDelta;
                }
            });

            var sut = new MockBotFactory().CreateBasicMockBot().WithThisActionProvider(engineHub, engineHub).ToBot();

            sut.Accelerate();
            Assert.True(messageRecieved, "The accellerate call did not send the change speed request message");
            Assert.True(valueChange == 1, "The accelerate value should be 1");
        }
Beispiel #3
0
 protected abstract void ActualNavitationEvent_UI(MainMessageKind messageKind, KnownSubkinds subKind, NavigationInfoContext nicspd);
Beispiel #4
0
        protected override void ActualNavitationEvent_UI(MainMessageKind messageKind, KnownSubkinds subKind, NavigationInfoContext nic)
        {
            string msgtxt;

            if (subKind == KnownSubkinds.ChangeDirection)
            {
                msgtxt = string.Format(GetContestantName(nic.BotId) + " changes to direction " + nic.NewHeading.ToString());
            }
            else
            {
                msgtxt = string.Format(GetContestantName(nic.BotId) + " changes speed " + nic.SpeedDelta.ToString());
            }
            Console.WriteLine(msgtxt);
        }
Beispiel #5
0
 protected override void ActualNavitationEvent_UI(MainMessageKind messageKind, KnownSubkinds subKind, NavigationInfoContext nicspd)
 {
     UIMessageCount++;
 }
Beispiel #6
0
        private void LogXmlNavigationEvent(MainMessageKind mainMessageKind, KnownSubkinds uIMessageSubKind, NavigationInfoContext nic)
        {
            var el = GetEventElement(mainMessageKind.ToString(), uIMessageSubKind.ToString());

            using (var w = el.CreateWriter()) {
                var sr = new DataContractSerializer(nic.GetType());
                sr.WriteObject(w, nic);
            }
            eventsParentElement.Add(el);
        }
Beispiel #7
0
 protected override void ActualNavitationEvent_UI(MainMessageKind messageKind, KnownSubkinds subKind, NavigationInfoContext nicspd)
 {
     LogXmlNavigationEvent(messageKind, subKind, nicspd);
 }