Example #1
0
        public void InvokesEvents()
        {
            var handle = invoker.Create(OnFoovent, TimeSpan.Zero);

            Expect(eventAwaiter.Invocations.Count(), EqualTo(0));

            invoker.Trigger(handle);

            eventAwaiter.WaitInvocations(1);
        }
        public async Task ReactsToLiveEvents()
        {
            timeScope.AdvanceTime(1);

            var player = ClientMock.AddPlayer("Newguy");

            player.Logs.WriteEventLog("42 other players are online. You are on Exodus (765 totally in Wurm).");

            var skillApi = Fixture.WurmApiManager.Characters.Get("Newguy")
                           .Skills;

            // allow WurmApi to pick everything
            await Task.Delay(1000);

            timeScope.AdvanceTime(1);

            var awaiter = new EventAwaiter <SkillsChangedEventArgs>();

            skillApi.SkillsChanged += awaiter.GetEventHandler();

            player.Logs.WriteSkillLog("Masonry", 58.754f);
            awaiter.WaitInvocations(1);
            awaiter.WaitUntilMatch(list => list.Any(args => args.HasSkillChanged("Masonry")));

            var skill = await skillApi.TryGetCurrentSkillLevelAsync("Masonry", new ServerGroup("FREEDOM"), TimeSpan.MaxValue);

            Expect(skill.Value, EqualTo(58.754f));
        }
        public void SubscribePmLog_TriggerWithSingleEvent()
        {
            EventAwaiter <LogsMonitorEventArgs> anotherGuyAwaiter        = new EventAwaiter <LogsMonitorEventArgs>();
            EventAwaiter <LogsMonitorEventArgs> unrelatedGuyAwaiter      = new EventAwaiter <LogsMonitorEventArgs>();
            EventHandler <LogsMonitorEventArgs> anotherGuyEventHandler   = anotherGuyAwaiter.GetEventHandler();
            EventHandler <LogsMonitorEventArgs> unrelatedGuyEventHandler = unrelatedGuyAwaiter.GetEventHandler();

            System.SubscribePm(TestGuyCharacterName.Capitalized, "Anotherguy", anotherGuyEventHandler);
            System.SubscribePm(TestGuyCharacterName.Capitalized, "Unrelatedguy", unrelatedGuyEventHandler);

            WriteToLogFile("PM__Anotherguy.2014-01-01.txt", "Logging started 2014-01-01");
            WriteToLogFile("PM__Anotherguy.2014-01-01.txt",
                           "[00:00:12] <Anotherguy> Horses like this one have many uses.");

            anotherGuyAwaiter.WaitInvocations(1);
            anotherGuyAwaiter.WaitUntilMatch(list =>
            {
                var match1 = list.Any(
                    args =>
                    args.CharacterName == TestGuyCharacterName &&
                    args.PmRecipientNormalized == "ANOTHERGUY" &&
                    args.PmRecipientCapitalized == "Anotherguy" &&
                    args.WurmLogEntries.Any(
                        entry =>
                        entry.Content == "Horses like this one have many uses." &&
                        entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 12) &&
                        entry.Source == "Anotherguy"));
                return(match1);
            });

            Expect(unrelatedGuyAwaiter.Invocations.Count(), EqualTo(0));

            System.UnsubscribePm(TestGuyCharacterName.Capitalized, "Anotherguy", anotherGuyEventHandler);

            WriteToLogFile("PM__Anotherguy.2014-01-01.txt",
                           "[00:00:13] <Anotherguy> Horses like this one have many uses.");

            Thread.Sleep(1000);
            var unexpected1 = anotherGuyAwaiter.Invocations.Any(
                args =>
                args.WurmLogEntries.Any(
                    entry =>
                    entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 13)));
            var unexpected2 = anotherGuyAwaiter.Invocations.Any(
                args =>
                args.WurmLogEntries.Any(
                    entry =>
                    entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 13)));

            Expect(unexpected1, False);
            Expect(unexpected2, False);
        }
        public void TriggersEventOnChanged()
        {
            IWurmConfig config = System.GetConfig(configMock.Name);

            Expect(config.NoSkillMessageOnFavorChange, False);

            var configAwaiter = new EventAwaiter <EventArgs>();

            config.ConfigChanged += configAwaiter.Handle;

            configMock.GameSettings.ChangeValue("skillgain_no_favor", "true");

            awaiter.WaitInvocations(2, 10000);

            Expect(config.NoSkillMessageOnFavorChange, True);
        }
Example #5
0
        public void SubscribeAll_TriggerWithSingleEvent()
        {
            EventAwaiter<LogsMonitorEventArgs> allAwaiter = new EventAwaiter<LogsMonitorEventArgs>();
            EventHandler<LogsMonitorEventArgs> allEventHandler = allAwaiter.GetEventHandler();
            System.SubscribeAllActive(allEventHandler);

            WriteToLogFile("_Event.2014-01-01.txt", "Logging started 2014-01-01");
            WriteToLogFile("_Event.2014-01-01.txt", "[00:00:12] Horses like this one have many uses.");

            allAwaiter.WaitInvocations(1);
            allAwaiter.WaitUntilMatch(list =>
            {
                var match1 = list.Any(
                    args =>
                        args.CharacterName == TestGuyCharacterName
                        && args.WurmLogEntries.Any(
                            entry =>
                                entry.Content == "Horses like this one have many uses."
                                && entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 12)));
                return match1;
            });
        }
        public void SubscribeAll_TriggerWithSingleEvent()
        {
            EventAwaiter <LogsMonitorEventArgs> allAwaiter      = new EventAwaiter <LogsMonitorEventArgs>();
            EventHandler <LogsMonitorEventArgs> allEventHandler = allAwaiter.GetEventHandler();

            System.SubscribeAllActive(allEventHandler);

            WriteToLogFile("_Event.2014-01-01.txt", "Logging started 2014-01-01");
            WriteToLogFile("_Event.2014-01-01.txt", "[00:00:12] Horses like this one have many uses.");

            allAwaiter.WaitInvocations(1);
            allAwaiter.WaitUntilMatch(list =>
            {
                var match1 = list.Any(
                    args =>
                    args.CharacterName == TestGuyCharacterName &&
                    args.WurmLogEntries.Any(
                        entry =>
                        entry.Content == "Horses like this one have many uses." &&
                        entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 12)));
                return(match1);
            });
        }
        public void SubscribeSingleLogType_TriggerWithSingleEvent()
        {
            EventAwaiter <LogsMonitorEventArgs> awaiter = new EventAwaiter <LogsMonitorEventArgs>();
            var handler = awaiter.GetEventHandler();

            System.Subscribe(TestGuyCharacterName.Capitalized, LogType.Event, handler);

            WriteToLogFile("_Event.2014-01-01.txt", "Logging started 2014-01-01");
            WriteToLogFile("_Event.2014-01-01.txt", "[00:00:12] Horses like this one have many uses.");

            awaiter.WaitInvocations(1);
            awaiter.WaitUntilMatch(list =>
            {
                var match1 = list.Any(
                    args =>
                    args.CharacterName == TestGuyCharacterName &&
                    args.WurmLogEntries.Any(
                        entry =>
                        entry.Content == "Horses like this one have many uses." &&
                        entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 12)));
                return(match1);
            });

            System.Unsubscribe(TestGuyCharacterName.Capitalized, handler);

            WriteToLogFile("_Event.2014-01-01.txt", "[00:00:13] Horses like this one have many uses.");

            Thread.Sleep(1000);
            var unexpected = awaiter.Invocations.Any(
                args =>
                args.WurmLogEntries.Any(
                    entry =>
                    entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 13)));

            Expect(unexpected, False);
        }
Example #8
0
        public void SubscribePmLog_TriggerWithSingleEvent()
        {
            EventAwaiter<LogsMonitorEventArgs> anotherGuyAwaiter = new EventAwaiter<LogsMonitorEventArgs>();
            EventAwaiter<LogsMonitorEventArgs> unrelatedGuyAwaiter = new EventAwaiter<LogsMonitorEventArgs>();
            EventHandler<LogsMonitorEventArgs> anotherGuyEventHandler = anotherGuyAwaiter.GetEventHandler();
            EventHandler<LogsMonitorEventArgs> unrelatedGuyEventHandler = unrelatedGuyAwaiter.GetEventHandler();

            System.SubscribePm(TestGuyCharacterName, new CharacterName("Anotherguy"), anotherGuyEventHandler);
            System.SubscribePm(TestGuyCharacterName, new CharacterName("Unrelatedguy"), unrelatedGuyEventHandler);

            WriteToLogFile("PM__Anotherguy.2014-01-01.txt", "Logging started 2014-01-01");
            WriteToLogFile("PM__Anotherguy.2014-01-01.txt",
                "[00:00:12] <Anotherguy> Horses like this one have many uses.");

            anotherGuyAwaiter.WaitInvocations(1);
            anotherGuyAwaiter.WaitUntilMatch(list =>
            {
                var match1 = list.Any(
                    args =>
                        args.CharacterName == TestGuyCharacterName
                        && args.ConversationNameNormalized == "ANOTHERGUY"
                        && args.WurmLogEntries.Any(
                            entry =>
                                entry.Content == "Horses like this one have many uses."
                                && entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 12)
                                && entry.Source == "Anotherguy"));
                return match1;
            });

            Expect(unrelatedGuyAwaiter.Invocations.Count(), EqualTo(0));

            System.UnsubscribePm(TestGuyCharacterName, new CharacterName("Anotherguy"), anotherGuyEventHandler);

            WriteToLogFile("PM__Anotherguy.2014-01-01.txt",
                "[00:00:13] <Anotherguy> Horses like this one have many uses.");

            Thread.Sleep(1000);
            var unexpected1 = anotherGuyAwaiter.Invocations.Any(
                args =>
                    args.WurmLogEntries.Any(
                        entry =>
                            entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 13)));
            var unexpected2 = anotherGuyAwaiter.Invocations.Any(
                args =>
                    args.WurmLogEntries.Any(
                        entry =>
                            entry.Timestamp == new DateTime(2014, 1, 1, 0, 0, 13)));
            Expect(unexpected1, False);
            Expect(unexpected2, False);
        }
Example #9
0
        public void SubscribeSingleLogType_TriggerWithSingleEvent()
        {
            EventAwaiter<LogsMonitorEventArgs> awaiter = new EventAwaiter<LogsMonitorEventArgs>();
            var handler = awaiter.GetEventHandler();
            System.Subscribe(TestGuyCharacterName, LogType.Event, handler);

            WriteToLogFile("_Event.2014-01-01.txt", "Logging started 2014-01-01");
            WriteToLogFile("_Event.2014-01-01.txt", "[00:00:12] Horses like this one have many uses.");

            awaiter.WaitInvocations(1);
            awaiter.WaitUntilMatch(list =>
            {
                var match1 = list.Any(
                    args =>
                        args.CharacterName == TestGuyCharacterName
                        && args.WurmLogEntries.Any(
                            entry =>
                                entry.Content == "Horses like this one have many uses."
                                && entry.Timestamp == new DateTime(2014,1,1, 0,0,12)));
                return match1;
            });

            System.Unsubscribe(TestGuyCharacterName, handler);

            WriteToLogFile("_Event.2014-01-01.txt", "[00:00:13] Horses like this one have many uses.");

            Thread.Sleep(1000);
            var unexpected = awaiter.Invocations.Any(
                args =>
                    args.WurmLogEntries.Any(
                        entry =>
                            entry.Timestamp == new DateTime(2014,1,1, 0,0,13)));

            Expect(unexpected, False);
        }