public void ViewModelFactoryService_CreateLMTeamVM() { var model = new LMTeam(); var vm = factoryService.CreateViewModel <TeamVM, Team> (model); Assert.IsTrue(vm is LMTeamVM); }
public void TestCopyOverwrite() { TemplatesService ts = new TemplatesService(storage); ts.Start(); ITeamTemplatesProvider teamtemplateprovider = ts.TeamTemplateProvider; LMTeam teamB = LMTeam.DefaultTemplate(5); teamB.Name = "B"; teamB.TeamName = "Template B"; teamB.FormationStr = "1-4"; teamB.List [0].Name = "Paco"; teamtemplateprovider.Save(teamB); LMTeam teamA = new LMTeam(); teamA.Name = "A"; teamA.TeamName = "Template A"; teamA.FormationStr = "1-4-3-3"; teamtemplateprovider.Save(teamA); LMTeam auxdelete = teamA; teamtemplateprovider.Copy(teamB, "A"); teamtemplateprovider.Delete(auxdelete); teamA = teamtemplateprovider.Templates [0] as LMTeam; Assert.AreEqual(4, teamtemplateprovider.Templates.Count); Assert.AreEqual("A", teamA.Name); Assert.AreEqual("Template B", teamA.TeamName); Assert.AreEqual(teamB.List.Count, teamA.List.Count); Assert.AreEqual("1-4", teamA.FormationStr); Assert.AreEqual("Paco", teamA.List [0].Name); }
public void TestDeleteProjectItems() { LMProject p = new LMProject(); p.Dashboard = LMDashboard.DefaultTemplate(10); p.UpdateEventTypesAndTimers(); p.LocalTeamTemplate = LMTeam.DefaultTemplate(10); for (int i = 0; i < 10; i++) { LMTimelineEvent evt = new LMTimelineEvent { EventType = p.EventTypes [i], Start = new Time(1000), Stop = new Time(2000), }; p.Timeline.Add(evt); } storage.Store(p); p = storage.Retrieve <LMProject> (p.ID); // Removing this object should not remove the EvenType from the database, which might be referenced by // LMTimelineEvent's in the timeline EventType evtType = (p.Dashboard.List [0] as AnalysisEventButton).EventType; p.Dashboard.List.Remove(p.Dashboard.List [0]); storage.Store(p); Assert.DoesNotThrow(() => storage.Retrieve <LMProject> (p.ID)); // Delete an event with a LMPlayer, a Team and an EventType, it should delete only the timeline event p.Timeline [0].Teams.Add(p.LocalTeamTemplate); p.Timeline [0].Players.Add(p.LocalTeamTemplate.List [0]); p.Timeline.Remove(p.Timeline [0]); Assert.DoesNotThrow(() => storage.Retrieve <LMProject> (p.ID)); }
void HandleFileChangedEvent(FileChangeType eventType, string path) { // Event from the monitor usually comes from non-UI threads. App.Current.GUIToolkit.Invoke((s, e) => { if (eventType == FileChangeType.Created) { string ext = Path.GetExtension(path); try { if (ImportTeams && ext == Constants.TEAMS_TEMPLATE_EXT) { LMTeam team = App.Current.DependencyRegistry. Retrieve <IFileStorage> (InstanceType.Default, null).RetrieveFrom <LMTeam> (path); App.Current.TeamTemplatesProvider.Add(team); File.Delete(path); } else if (ImportDashboards && ext == Constants.CAT_TEMPLATE_EXT) { Dashboard team = App.Current.DependencyRegistry. Retrieve <IFileStorage> (InstanceType.Default, null).RetrieveFrom <Dashboard> (path); App.Current.CategoriesTemplatesProvider.Add(team as LMDashboard); File.Delete(path); } else if (ImportProjects && ext == Constants.PROJECT_EXT) { LMProject project = App.Current.DependencyRegistry. Retrieve <IFileStorage> (InstanceType.Default, null).RetrieveFrom <LMProject> (path); App.Current.DatabaseManager.ActiveDB.Store <LMProject> (project, true); File.Delete(path); } } catch (Exception ex) { Log.Exception(ex); } } }); }
public void SetTeam(LMTeam template, IEnumerable <LMTimelineEvent> plays) { Dictionary <Player, TreeIter> playersDict = new Dictionary <Player, TreeIter> (); Log.Debug("Updating teams models with template:" + template); team = new TreeStore(typeof(object)); foreach (var player in template.List) { /* Add a root in the tree with the option name */ var iter = team.AppendValues(player); playersDict.Add(player, iter); Log.Debug("Adding new player to the model: " + player); } foreach (var play in plays) { foreach (var player in play.Players) { if (playersDict.ContainsKey(player)) { team.AppendValues(playersDict [player], new object[1] { play }); Log.Debug("Adding new play to player: " + player); } } } playerstreeview.Model = team; playerstreeview.Colors = true; playerstreeview.Project = Project; }
public void TestQueryEventsByNoPlayerOrTeam() { LMPlayer messi = new LMPlayer { Name = "Messi" }; LMTimelineEvent evt = new LMTimelineEvent(); evt.Players.Add(messi); storage.Store(evt); evt = new LMTimelineEvent(); storage.Store(evt); QueryFilter filter = new QueryFilter(); LMPlayer nullPlayer = null; LMTeam nullTeam = null; filter.Add("Player", nullPlayer); Assert.AreEqual(1, storage.Retrieve <LMTimelineEvent> (filter).Count()); filter = new QueryFilter(); filter.Add("Team", nullTeam); Assert.AreEqual(2, storage.Retrieve <LMTimelineEvent> (filter).Count()); filter = new QueryFilter(); QueryFilter teamsAndPlayersFilter = new QueryFilter { Operator = QueryOperator.Or }; filter.Children.Add(teamsAndPlayersFilter); teamsAndPlayersFilter.Add("Team", nullTeam); teamsAndPlayersFilter.Add("Player", nullPlayer); filter.Operator = QueryOperator.Or; Assert.AreEqual(2, storage.Retrieve <LMTimelineEvent> (filter).Count()); }
LMProject CreateProject(bool fill = true) { LMProject p = new LMProject(); p.Dashboard = LMDashboard.DefaultTemplate(10); p.UpdateEventTypesAndTimers(); p.LocalTeamTemplate = LMTeam.DefaultTemplate(10); p.VisitorTeamTemplate = LMTeam.DefaultTemplate(12); MediaFile mf = new MediaFile("path", 34000, 25, true, true, "mp4", "h264", "aac", 320, 240, 1.3, null, "Test asset"); var pd = new ProjectDescription(); pd.FileSet = new MediaFileSet(); pd.FileSet.Add(mf); p.Description = pd; if (fill) { p.AddEvent(p.EventTypes [0], new Time(1000), new Time(2000), null, null); p.AddEvent(p.EventTypes [0], new Time(1000), new Time(2000), null, null); p.AddEvent(p.EventTypes [1], new Time(1000), new Time(2000), null, null); p.AddEvent(p.EventTypes [2], new Time(1000), new Time(2000), null, null); p.AddEvent(p.EventTypes [2], new Time(1000), new Time(2000), null, null); p.AddEvent(p.EventTypes [2], new Time(1000), new Time(2000), null, null); p.AddEvent(p.EventTypes [6], new Time(1000), new Time(2000), null, null); } return(p); }
public void TestIsChanged() { LMTeam t = LMTeam.DefaultTemplate(10); Assert.IsTrue(t.IsChanged); t.IsChanged = false; t.List.Remove(t.Players [0]); Assert.IsTrue(t.IsChanged); t.IsChanged = false; t.List.Add(new LMPlayer()); Assert.IsTrue(t.IsChanged); t.IsChanged = false; t.FormationStr = "1-2"; Assert.IsTrue(t.IsChanged); t.IsChanged = false; t.Colors = null; Assert.IsTrue(t.IsChanged); t.IsChanged = false; t.Shield = new Image(10, 10); Assert.IsTrue(t.IsChanged); t.IsChanged = false; t.TeamName = "new"; Assert.IsTrue(t.IsChanged); t.IsChanged = false; t.Name = "new"; Assert.IsTrue(t.IsChanged); t.IsChanged = false; }
public void TestRemovePlayers() { LMTeam t = LMTeam.DefaultTemplate(15); t.FormationStr = "1-2-3-4"; /* Removing a player from the starting list must be swapped * with the first player in the bench to keep the same lineup */ t.RemovePlayers(new List <LMPlayer> { t.Players [0] }, false); Assert.AreEqual(15, t.Players.Count); Assert.AreEqual(11, t.Players [0].Number); Assert.AreEqual(2, t.Players [1].Number); Assert.AreEqual(1, t.Players [14].Number); t.RemovePlayers(new List <LMPlayer> { t.Players [0] }, true); Assert.AreEqual(14, t.Players.Count); Assert.AreEqual(12, t.Players [0].Number); t.RemovePlayers(new List <LMPlayer> { new LMPlayer() }, true); Assert.AreEqual(14, t.Players.Count); t.RemovePlayers(new List <LMPlayer> { new LMPlayer(), t.Players [12] }, true); Assert.AreEqual(13, t.Players.Count); }
public SubstitutionEvent SubsitutePlayer(LMTeam team, LMPlayer playerIn, LMPlayer playerOut, SubstitutionReason reason, Time subsTime) { LineupEvent lineup; SubstitutionEvent se; lineup = Timeline.OfType <LineupEvent> ().FirstOrDefault(); if (lineup == null) { throw new SubstitutionException(Catalog.GetString("No lineup events found")); } if (subsTime < lineup.EventTime) { throw new SubstitutionException(Catalog.GetString("A substitution can't happen before the lineup event")); } se = new SubstitutionEvent(); se.EventType = SubstitutionsEventType; se.In = playerIn; se.Out = playerOut; se.Reason = reason; se.EventTime = subsTime; se.Teams.Add(team); Timeline.Add(se); return(se); }
public void TestListTeams() { LMTeam t = LMTeam.DefaultTemplate(5); t.Name = "Team1"; t.Shield = Utils.LoadImageFromFile(); storage.Store(t); List <Team> teams = storage.RetrieveAll <Team> ().ToList(); Assert.AreEqual(1, teams.Count); Assert.AreEqual(t.ID, teams [0].ID); Assert.AreEqual(t.Name, teams [0].Name); Assert.IsNotNull(teams [0].Shield); Assert.IsTrue(teams.All(i => i.DocumentID != null)); for (int i = 0; i < 5; i++) { var te = LMTeam.DefaultTemplate(5); te.Name = "Team" + (i + 2); storage.Store(te); } Assert.AreEqual(6, storage.RetrieveAll <Team> ().Count()); }
public void TestStartingPlayers() { LMTeam t = LMTeam.DefaultTemplate(15); t.FormationStr = "1-2-3-4"; Assert.AreEqual(10, t.StartingPlayers); Assert.AreEqual(10, t.StartingPlayersList.Count); Assert.AreEqual(t.Players [0], t.StartingPlayersList [0]); Assert.AreEqual(t.Players [9], t.StartingPlayersList [9]); /* Players not playing are skipped */ t.Players [0].Playing = false; Assert.AreEqual(t.Players [1], t.StartingPlayersList [0]); Assert.AreEqual(t.Players [10], t.StartingPlayersList [9]); /* Unless we are editing the team */ t.TemplateEditorMode = true; Assert.AreEqual(t.Players [0], t.StartingPlayersList [0]); Assert.AreEqual(t.Players [9], t.StartingPlayersList [9]); t.TemplateEditorMode = false; /* If the list of playing players is smaller than the formation * the list of starting players is of the same size as the list * of playing players */ for (int i = 0; i < 8; i++) { t.Players [i].Playing = false; } Assert.AreEqual(7, t.StartingPlayersList.Count); Assert.AreEqual(t.Players [8], t.StartingPlayersList [0]); }
public void TestPlayingPlayers() { LMTeam t = new LMTeam(); LMPlayer p1, p2, p3; t.Name = "test"; t.TeamName = "team"; Assert.AreEqual(t.CalledPlayersList.Count, 0); p1 = new LMPlayer { Name = "P1", Playing = true }; p2 = new LMPlayer { Name = "P2", Playing = false }; p3 = new LMPlayer { Name = "P3", Playing = true }; t.List.Add(p1); Assert.AreEqual(t.CalledPlayersList.Count, 1); t.List.Add(p2); Assert.AreEqual(t.CalledPlayersList.Count, 1); t.List.Add(p3); Assert.AreEqual(t.CalledPlayersList.Count, 2); Assert.AreEqual(t.CalledPlayersList [0], p1); Assert.AreEqual(t.CalledPlayersList [1], p3); }
public void TestIsChangedResetted() { LMTeam t, t1; ObjectChangedParser parser; List <IStorable> storables = null, changed = null; StorableNode parent = null; parser = new ObjectChangedParser(); t = LMTeam.DefaultTemplate(10); storage.Store(t); // After loading an object t1 = DocumentsSerializer.LoadObject(typeof(LMTeam), t.ID, db) as LMTeam; Assert.IsTrue(parser.ParseInternal(out parent, t1, Serializer.JsonSettings)); Assert.IsTrue(parent.ParseTree(ref storables, ref changed)); Assert.AreEqual(0, changed.Count); Assert.NotNull(t1.DocumentID); // After filling an object t1 = new LMTeam(); t1.ID = t.ID; t1.DocumentID = t.ID.ToString(); t1.IsChanged = true; DocumentsSerializer.FillObject(t1, db); Assert.IsTrue(parser.ParseInternal(out parent, t1, Serializer.JsonSettings)); Assert.IsTrue(parent.ParseTree(ref storables, ref changed)); Assert.AreEqual(0, changed.Count); }
public void TestSerialization() { LMTeam t = new LMTeam(); Utils.CheckSerialization(t); t.Name = "test"; t.TeamName = "team"; t.Shield = Utils.LoadImageFromFile(); t.List.Add(new LMPlayer { Name = "P1" }); t.List.Add(new LMPlayer { Name = "P2" }); t.List.Add(new LMPlayer { Name = "P3" }); Utils.CheckSerialization(t); LMTeam newt = Utils.SerializeDeserialize(t); Assert.AreEqual(t.ID, newt.ID); Assert.AreEqual(t.Name, newt.Name); Assert.AreEqual(t.TeamName, newt.TeamName); Assert.AreEqual(t.Shield.Width, 16); Assert.AreEqual(t.Shield.Height, 16); Assert.AreEqual(t.Players.Count, newt.Players.Count); Assert.AreEqual(t.Players [0].Name, newt.Players [0].Name); Assert.AreEqual(t.Players [1].Name, newt.Players [1].Name); Assert.AreEqual(t.Players [2].Name, newt.Players [2].Name); }
public void TestProject() { LMProject p = new LMProject(); p.Dashboard = LMDashboard.DefaultTemplate(10); p.UpdateEventTypesAndTimers(); p.LocalTeamTemplate = LMTeam.DefaultTemplate(10); p.VisitorTeamTemplate = LMTeam.DefaultTemplate(12); MediaFile mf = new MediaFile("path", 34000, 25, true, true, "mp4", "h264", "aac", 320, 240, 1.3, null, "Test asset"); var pd = new ProjectDescription(); pd.FileSet = new MediaFileSet(); pd.FileSet.Add(mf); p.Description = pd; p.AddEvent(new LMTimelineEvent()); storage.Store <LMProject> (p); Assert.AreEqual(45, db.DocumentCount); p = storage.RetrieveAll <LMProject> ().First(); Assert.IsNotNull(p.DocumentID); p.Load(); Assert.IsTrue(Object.ReferenceEquals(p.Description.FileSet, p.Timeline [0].FileSet)); storage.Store(p); Assert.AreEqual(45, db.DocumentCount); storage.Delete(p); Assert.AreEqual(1, db.DocumentCount); }
public void TestCreateDefaultTemplate() { LMTeam t = LMTeam.DefaultTemplate(10); Assert.AreEqual(t.Players.Count, 10); t.AddDefaultItem(8); Assert.AreEqual(t.Players.Count, 11); }
public void Setup() { // Initialize LongoMath.Core by using a type, this will call the module initialization var st = new LMTeam(); VFS.SetCurrent(new FileSystem()); Initialize(); }
public void SetFilter(EventsFilter filter, LMProject project) { this.local = project.LocalTeamTemplate; this.visitor = project.VisitorTeamTemplate; localTeam.Name = local.TeamName; visitorTeam.Name = visitor.TeamName; this.filter = filter; FillTree(); }
//Specific LongoMatch objects public static LMProject CreateProject(bool withEvents = true) { LMTimelineEvent pl; LMProject p = new LMProject(); p.Dashboard = LMDashboard.DefaultTemplate(10); p.LocalTeamTemplate = LMTeam.DefaultTemplate(5); p.LocalTeamTemplate.FormationStr = "2-2"; p.VisitorTeamTemplate = LMTeam.DefaultTemplate(5); p.VisitorTeamTemplate.FormationStr = "2-2"; var pd = new ProjectDescription(); pd.FileSet = new MediaFileSet(); pd.FileSet.Add(new MediaFile(Path.GetTempFileName(), 34000, 25, true, true, "mp4", "h264", "aac", 320, 240, 1.3, null, "Test asset 1")); pd.FileSet.Add(new MediaFile(Path.GetTempFileName(), 34000, 25, true, true, "mp4", "h264", "aac", 320, 240, 1.3, null, "Test asset 2")); p.Description = pd; p.UpdateEventTypesAndTimers(); if (withEvents) { AnalysisEventButton b = p.Dashboard.List [0] as AnalysisEventButton; /* No tags, no players */ pl = new LMTimelineEvent { EventType = b.EventType, Start = new Time(0), Stop = new Time(100), FileSet = pd.FileSet }; p.Timeline.Add(pl); /* tags, but no players */ b = p.Dashboard.List [1] as AnalysisEventButton; pl = new LMTimelineEvent { EventType = b.EventType, Start = new Time(0), Stop = new Time(100), FileSet = pd.FileSet }; pl.Tags.Add(b.AnalysisEventType.Tags [0]); p.Timeline.Add(pl); /* tags and players */ b = p.Dashboard.List [2] as AnalysisEventButton; pl = new LMTimelineEvent { EventType = b.EventType, Start = new Time(0), Stop = new Time(100), FileSet = pd.FileSet }; pl.Tags.Add(b.AnalysisEventType.Tags [1]); pl.Players.Add(p.LocalTeamTemplate.List [0]); p.Timeline.Add(pl); } return(p); }
void AddTeam(LMTeam tpl, Dashboard cats) { TreeIter iter = store.AppendValues(tpl.TeamName, null); foreach (Player p in tpl.List) { store.AppendValues(iter, p.Name, p); } }
#pragma warning restore 0618 public static void Migrate1(LMTeam team) { if (team.Version != 1) { return; } team.Preview = App.Current.PreviewService.CreatePreview(team); team.Version = 2; }
public IEnumerable <LMTimelineEvent> EventsByTeam(LMTeam team) { var timelineEventsLongomatch = new ObservableCollection <LMTimelineEvent> (); foreach (var timeLineEvent in Timeline) { timelineEventsLongomatch.Add(timeLineEvent as LMTimelineEvent); } return(timelineEventsLongomatch.Where(e => e.Teams.Contains(team) || e.Players.Intersect(team.List).Any())); }
public void SetUp() { controller = new LMTeamEditorController(); var teamsManager = new TeamsManagerVM(); teamsManager.LoadedTemplate.Model = LMTeam.DefaultTemplate(5); viewModel = teamsManager.TeamEditor; controller.SetViewModel(teamsManager); controller.Start(); }
public void TestBenchPlayers() { LMTeam t = LMTeam.DefaultTemplate(15); t.FormationStr = "1-2-3-4"; Assert.AreEqual(5, t.BenchPlayersList.Count); Assert.AreEqual(t.Players [10], t.BenchPlayersList [0]); Assert.AreEqual(t.Players [14], t.BenchPlayersList [4]); t.FormationStr = "10-2-3-4"; Assert.AreEqual(0, t.BenchPlayersList.Count); }
public void TestResetPlayers() { LMTeam t = LMTeam.DefaultTemplate(10); for (int i = 0; i < 5; i++) { t.Players [0].Playing = false; } t.ResetPlayers(); Assert.IsEmpty(t.Players.Where(p => !p.Playing)); }
public void TestColor() { LMTeam t = new LMTeam(); Assert.AreEqual(t.Color, t.Colors [0]); t.ActiveColor = -1; Assert.AreEqual(t.Color, t.Colors [0]); t.ActiveColor = t.Colors.Length + 1; Assert.AreEqual(t.Color, t.Colors [0]); t.ActiveColor = 1; Assert.AreEqual(t.Color, t.Colors [1]); }
public void TestAddTeam() { service.Start(); LMTeam team = LMTeam.DefaultTemplate(1); string outPath = Path.Combine(tmpDir, "test" + Constants.TEAMS_TEMPLATE_EXT); App.Current.DependencyRegistry.Retrieve <IFileStorage> (InstanceType.Default, null).StoreAt(team, outPath); monitor.AddFile(outPath); teamsProviderMock.Verify(s => s.Add(team), Times.Once()); Assert.IsFalse(File.Exists(outPath)); service.Stop(); }
public void TestCopy() { LMTeam team = LMTeam.DefaultTemplate(10); LMTeam copy = (LMTeam)team.Copy("newName"); Assert.AreNotEqual(team.ID, copy.ID); for (int i = 0; i < team.List.Count; i++) { Assert.AreNotEqual(team.List [i].ID, copy.List [i].ID); } Assert.AreEqual("newName", copy.Name); Assert.AreNotEqual(team.Name, copy.Name); }
public void TestTeam() { LMTeam team1 = LMTeam.DefaultTemplate(10); storage.Store <LMTeam> (team1); Assert.AreEqual(12, db.DocumentCount); LMTeam team2 = storage.Retrieve <LMTeam> (team1.ID); Assert.AreEqual(team1.ID, team2.ID); Assert.AreEqual(team1.List.Count, team2.List.Count); Assert.IsNotNull(team2.DocumentID); storage.Delete(team1); Assert.AreEqual(1, db.DocumentCount); }