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 async Task ReactsToCurrentServerChange() { //mocking current time to avoid test breaking precisely on midnight using (var scope = TimeStub.CreateStubbedScope()) { scope.OverrideNow(new DateTime(2015, 10, 06, 03, 10, 30)); var subscriber = new Subscriber <CharacterDirectoriesChanged>(Fixture.WurmApiManager.InternalEventAggregator); var serverChangeAwaiter = new EventAwaiter <PotentialServerChangeEventArgs>(); var playerdir = ClientMock.AddPlayer("Jack"); playerdir.SetConfigName("default"); // have to immediatelly create file, because during log monitor creation, existing file contents will not trigger events. playerdir.Logs.CreateEventLogFile(); // have to wait until wurmapi picks up this folder subscriber.WaitMessages(1); var character = System.Get("Jack"); character.LogInOrCurrentServerPotentiallyChanged += serverChangeAwaiter.GetEventHandler(); Trace.WriteLine("writing first event"); playerdir.Logs.WriteEventLog("5 other players are online. You are on Exodus (50 totally in Wurm)."); serverChangeAwaiter.WaitUntilMatch( list => list.Any(args => args.ServerName == new ServerName("Exodus"))); var server = await character.TryGetCurrentServerAsync(); Expect(server.ServerName, EqualTo(new ServerName("Exodus"))); Trace.WriteLine( "writing second event"); playerdir.Logs.WriteEventLog( "5 other players are online. You are on Deliverance (50 totally in Wurm)."); serverChangeAwaiter.WaitUntilMatch( list => list.Any(args => args.ServerName == new ServerName("Deliverance"))); server = await character.TryGetCurrentServerAsync(); Expect(server.ServerName, EqualTo(new ServerName("Deliverance"))); Trace.WriteLine("writing third event"); playerdir.Logs.WriteEventLog( "5 other players are online. You are on Deliverance (50 totally in Wurm)."); serverChangeAwaiter.WaitUntilMatch( list => list.Any(args => args.ServerName == new ServerName("Deliverance"))); server = await character.TryGetCurrentServerAsync(); Expect(server.ServerName, EqualTo(new ServerName("Deliverance"))); } }
public void OnChanged_TriggersEvent_UpdatesData() { var subscriber = new Subscriber <CharacterDirectoriesChanged>(Fixture.WurmApiManager.InternalEventAggregator); var batman = ClientMock.AddPlayer("Batman"); subscriber.WaitMessages(1); // verifying event sent Expect(subscriber.ReceivedMessages.Count(), GreaterThan(0)); // verifying data updated var allChars = System.GetAllCharacters().ToList(); var allDirFullPaths = System.AllDirectoriesFullPaths.ToList(); var allDirNames = System.AllDirectoryNamesNormalized.ToList(); Expect(allChars, Member(new CharacterName(batman.Name)).And.Count.EqualTo(1)); Expect(allDirFullPaths, Member(batman.PlayerDir.FullName).And.Count.EqualTo(1)); Expect(allDirNames, Member(batman.PlayerDir.Name.ToUpperInvariant()).And.Count.EqualTo(1)); }
string[] SetupDefaultPlayers() { ClientMock.AddPlayer("Foo"); ClientMock.AddPlayer("Bar"); return(new string[] { "Foo", "Bar" }); }
private void CreateNewCharacterDirWithALog(string characterName, string logFileName) { var player = ClientMock.AddPlayer(characterName); player.Logs.CreateCustomLogFile(logFileName); }
private void CreateNewCharacterEmptyDir(string characterName) { ClientMock.AddPlayer(characterName); }