public void FixtureSetUp() { importer = new LongoMatchImporter (); mockGUI = new Mock<IGUIToolkit> (); manager = new ProjectsManager (); mockDialog = new Mock<IDialogs> (); manager.Start (); App.Current.ProjectExtension = ".tmp"; }
public void TestGameAnalysis() { Guid projectID; App.Init (); CoreServices.Init (); App.Current.DependencyRegistry.Register<VAS.DB.IFileStorage, FileStorage> (0); AddinsManager.Initialize (App.Current.PluginsConfigDir, App.Current.PluginsDir); AddinsManager.LoadConfigModifierAddins (); App.Current.DrawingToolkit = drawingToolkitMock.Object; App.Current.MultimediaToolkit = multimediaToolkitMock.Object; App.Current.GUIToolkit = guiToolkitMock.Object; App.Current.Dialogs = mockDialogs.Object; App.Current.Config.AutoSave = true; CoreServices.Start (App.Current.GUIToolkit, App.Current.MultimediaToolkit); AddinsManager.LoadImportProjectAddins (CoreServices.ProjectsImporter); // Start importing templates App.Current.TeamTemplatesProvider.Save ( App.Current.TeamTemplatesProvider.LoadFile (Utils.SaveResource ("spain.ltt", tmpPath))); App.Current.TeamTemplatesProvider.Save ( App.Current.TeamTemplatesProvider.LoadFile (Utils.SaveResource ("france.ltt", tmpPath))); App.Current.CategoriesTemplatesProvider.Save ( App.Current.CategoriesTemplatesProvider.LoadFile (Utils.SaveResource ("basket.lct", tmpPath))); Assert.AreEqual (4, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (2, App.Current.CategoriesTemplatesProvider.Templates.Count); // Create a new project and open it ProjectLongoMatch p = CreateProject (); projectID = p.ID; App.Current.DatabaseManager.ActiveDB.Store<ProjectLongoMatch> (p, true); App.Current.EventsBroker.Publish<OpenProjectIDEvent> ( new OpenProjectIDEvent { ProjectID = p.ID, Project = p } ); // Tag some events Assert.AreEqual (0, p.Timeline.Count); AddEvent (p, 5, 3000, 3050, 3025); Assert.AreEqual (1, p.Timeline.Count); ProjectLongoMatch savedP = App.Current.DatabaseManager.ActiveDB.Retrieve<ProjectLongoMatch> (p.ID); Assert.AreEqual (1, savedP.Timeline.Count); AddEvent (p, 6, 3000, 3050, 3025); AddEvent (p, 7, 3000, 3050, 3025); AddEvent (p, 8, 3000, 3050, 3025); AddEvent (p, 5, 3000, 3050, 3025); Assert.AreEqual (5, p.Timeline.Count); savedP = App.Current.DatabaseManager.ActiveDB.Retrieve<ProjectLongoMatch> (p.ID); Assert.AreEqual (5, savedP.Timeline.Count); // Delete some events App.Current.EventsBroker.Publish<EventsDeletedEvent> ( new EventsDeletedEvent { TimelineEvents = new List<TimelineEvent> { p.Timeline [0], p.Timeline [1] } } ); Assert.AreEqual (3, p.Timeline.Count); savedP = App.Current.DatabaseManager.ActiveDB.Retrieve<ProjectLongoMatch> (p.ID); Assert.AreEqual (3, savedP.Timeline.Count); // Now create a new ProjectLongoMatch with the same templates p = CreateProject (); App.Current.DatabaseManager.ActiveDB.Store<ProjectLongoMatch> (p); Assert.AreEqual (2, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); App.Current.EventsBroker.Publish<OpenProjectIDEvent> ( new OpenProjectIDEvent { ProjectID = p.ID, Project = p } ); // Add some events and than remove it from the DB AddEvent (p, 6, 3000, 3050, 3025); AddEvent (p, 7, 3000, 3050, 3025); AddEvent (p, 8, 3000, 3050, 3025); AddEvent (p, 5, 3000, 3050, 3025); App.Current.DatabaseManager.ActiveDB.Delete<ProjectLongoMatch> (p); // Reopen the old project savedP = App.Current.DatabaseManager.ActiveDB.RetrieveAll<ProjectLongoMatch> ().FirstOrDefault (pr => pr.ID == projectID); App.Current.EventsBroker.Publish<OpenProjectIDEvent> ( new OpenProjectIDEvent { ProjectID = savedP.ID, Project = savedP } ); App.Current.EventsBroker.Publish<SaveProjectEvent> ( new SaveProjectEvent { Project = savedP, ProjectType = ProjectType.FileProject } ); // Export this project to a new file savedP = App.Current.DatabaseManager.ActiveDB.Retrieve<ProjectLongoMatch> (projectID); Assert.AreEqual (3, savedP.Timeline.Count); Assert.AreEqual (12, savedP.LocalTeamTemplate.List.Count); Assert.AreEqual (12, savedP.VisitorTeamTemplate.List.Count); string tmpFile = Path.Combine (tmpPath, "longomatch.lgm"); mockDialogs.Setup (g => g.SaveFile (It.IsAny<string> (), It.IsAny<string> (), It.IsAny<string> (), It.IsAny<string> (), It.IsAny<string []> ())).Returns (tmpFile); App.Current.EventsBroker.Publish<ExportProjectEvent> (new ExportProjectEvent { Project = p }); Assert.IsTrue (File.Exists (tmpFile)); savedP = Project.Import (tmpFile) as ProjectLongoMatch; Assert.IsNotNull (savedP); // Import a new project LongoMatchImporter importPlugin = new LongoMatchImporter (); ProjectImporter importer = new ProjectImporter { Description = importPlugin.Description + " test ", ImportFunction = new Func<Project> (importPlugin.ImportProject), FilterName = importPlugin.FilterName, Extensions = importPlugin.FilterExtensions, NeedsEdition = importPlugin.NeedsEdition, CanOverwrite = importPlugin.CanOverwrite, }; CoreServices.toolsManager.ProjectImporters.Add (importer); p = null; string projectPath = Utils.SaveResource ("spain_france_test.lgm", tmpPath); mockDialogs.Setup (g => g.ChooseOption ( It.IsAny<Dictionary<string, object>> (), It.IsAny<string> (), It.IsAny<object> ())). Returns (Task.Factory.StartNew (() => (object)importer) ); mockDialogs.Setup (g => g.OpenFile (It.IsAny<string> (), It.IsAny<string> (), It.IsAny<string> (), It.IsAny<string> (), It.IsAny<string []> ())).Returns (projectPath); App.Current.EventsBroker.Subscribe<OpenedProjectEvent> ((e) => { p = e.Project as ProjectLongoMatch; }); App.Current.EventsBroker.Publish<ImportProjectEvent> (new ImportProjectEvent ()); Assert.IsNotNull (p); Assert.AreEqual (2, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); int eventsCount = p.Timeline.Count; AddEvent (p, 2, 3000, 3050, 3025); AddEvent (p, 3, 3000, 3050, 3025); App.Current.EventsBroker.Publish (new CloseOpenedProjectEvent ()); savedP = App.Current.DatabaseManager.ActiveDB.Retrieve<ProjectLongoMatch> (p.ID); Assert.AreEqual (eventsCount + 2, savedP.Timeline.Count); CoreServices.Stop (); }