public void BenchmarkZoneMapFfxi() { string mapName = SetupPersister.GetCurrentMethodName(); var persister = new FilePersister(mapName); var want = SetupZoneMap.SetupFfxiSizeGrid(); // Path assumes to start from ./debug/ so we want to set it to the test fixtures dir. string grandParentDirectory = Directory.GetParent(persister.FilePath).FullName; string parentDirectory = Directory.GetParent(grandParentDirectory).FullName; persister.FilePath = Path.Combine(parentDirectory, "fixtures"); int time = Benchmark.Run("StreamReader.ReadToEnd", 5, () => { persister.Save(want); var got = persister.Load <ZoneMap>(); persister.Delete(); }); int benchTime = 1200; // Best time so far: 23548ms // New record!: 10214ms Assert.True(time < benchTime, "time per iteration was: " + time + "ms which is greater than expected time of: " + benchTime + "ms"); }
public void SaveAndLoad() { var filePersister = new FilePersister(string.Empty); WorkflowEntity workflowEntity = new WorkflowEntity { CurrentState = "CurrentState", DomainContextId = Guid.NewGuid(), DomainContextStatusProperty = "DomainContextStatusProperty", DomainContextTypeDescription = "DomainContextTypeDescription", MachineConfiguration = "MachineConfiguration", WorkflowId = Guid.NewGuid() }; filePersister.Save(workflowEntity); var path = string.Format("{0}.xml", workflowEntity.WorkflowId); Assert.That(File.Exists(path)); var workflowEntity1 = filePersister.Load(workflowEntity.WorkflowId); Assert.AreEqual(workflowEntity1.CurrentState, workflowEntity.CurrentState); Assert.AreEqual(workflowEntity1.DomainContextId, workflowEntity.DomainContextId); Assert.AreEqual(workflowEntity1.DomainContextStatusProperty, workflowEntity.DomainContextStatusProperty); Assert.AreEqual(workflowEntity1.DomainContextTypeDescription, workflowEntity.DomainContextTypeDescription); Assert.AreEqual(workflowEntity1.MachineConfiguration, workflowEntity.MachineConfiguration); Assert.AreEqual(workflowEntity1.WorkflowId, workflowEntity.WorkflowId); Assert.AreEqual(workflowEntity1.WorkflowId, workflowEntity.WorkflowId); File.Delete(path); }
public void KnownNodeActorCanUpdateKnownNodes() { var map = SetupZoneMap.SetupSmallGrid(); string mapName = SetupPersister.GetCurrentMethodName(); var persister = new FilePersister(mapName); var actor = new KnownNodeActor(persister, map); var traveler = new Traveler(); var watcher = new Watcher(traveler, actor); var newPos = new Vector3(1, 0, 1); traveler.Position = newPos; var wantGrid = SetupZoneMap.SetupSmallGrid(); wantGrid.AddKnownNode(newPos); var want = wantGrid.UnknownNodes; var got = persister.Load <ZoneMap>(); Assert.Equal(want.Count, got.UnknownNodes.Count); for (var i = 0; i < want.Count; i++) { Assert.Equal(want[i], got.UnknownNodes[i]); } }
public void ReadNonExistingProjectReturnsEmptyList() { IPersister toTest = new FilePersister(); var result = toTest.Read("nothing!" + DateTime.Now.Ticks); Assert.IsEmpty(result); }
public static FilePersister SetupTestFilePersister() { var persister = new FilePersister(); persister.DefaultExtension = "json"; string grandParentDirectory = Directory.GetParent(persister.FilePath).FullName; string parentDirectory = Directory.GetParent(grandParentDirectory).FullName; persister.FilePath = Path.Combine(parentDirectory, "fixtures"); persister.FileName = GetCurrentMethodName(); return(persister); }
public static FilePersister SetupPersonPersister(string mapName, string directory) { var persister = new FilePersister(); persister.DefaultExtension = "json"; string greatGrandParentDirectory = Directory.GetParent(persister.FilePath).FullName; string grandParentDirectory = Directory.GetParent(greatGrandParentDirectory).FullName; string parentDirectory = Directory.GetParent(grandParentDirectory).FullName; persister.FilePath = Path.Combine(parentDirectory, directory); persister.FileName = mapName; return(persister); }
public void TestCanSaveToFile() { var want = SetupZoneMap.SetupSmallGrid(); var mapName = SetupPersister.GetCurrentMethodName(); var persister = new FilePersister(mapName); persister.Save(want); var got = persister.Load <ZoneMap>(); persister.Delete(); SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid); }
public void TestCanLoadGridFromFile() { var want = SetupZoneMap.SetupSmallGrid(); var mapName = SetupPersister.GetCurrentMethodName(); var persister = new FilePersister(mapName); // Path assumes to start from ./debug/ so we want to set it to the test fixtures dir. string grandParentDirectory = Directory.GetParent(persister.FilePath).FullName; string parentDirectory = Directory.GetParent(grandParentDirectory).FullName; persister.FilePath = Path.Combine(parentDirectory, "fixtures"); // Uncomment to make golden file if zoneMap changes. persister.Save(want); var got = persister.Load <ZoneMap>(); SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid); }
public void TestPersistThenRead() { IPersister toTest = new FilePersister(); var transactions = new List <UpdatableElement>(); for (int i = 0; i < 10; i++) { transactions.Add(GetFakeTransaction(i)); } toTest.Persist(ProjectId, transactions); var result = toTest.Read(ProjectId); Assert.AreEqual(result.Count, transactions.Count); var stringInput = JsonConvert.SerializeObject(transactions); var stringResult = JsonConvert.SerializeObject(result); Assert.AreEqual(stringInput, stringResult); }
private void LoadCurrentFile() { Log.Instance.LogDebug(string.Format("MainViewModel.LoadCurrentFile")); if (VooDoo.Settings.AppSettings.Instance.CurrentFile != null) { Log.Instance.LogDebug(string.Format("MainViewModel.LoadCurrentFile - loading file {0}", VooDoo.Settings.AppSettings.Instance.CurrentFile)); TaskListGroup = new FilePersister(VooDoo.Settings.AppSettings.Instance.CurrentFile).Load(); if (TaskListGroup != null) { TaskListGroup.SetPersistCallback(this); if (TaskListGroup.NumLists == 0) { UpdateView(-1); } else { UpdateView(TaskListGroup.ActiveList); } } // one off update //VooDooModel.TaskListGroup tlg = new VooDooModel.TaskListGroup(); //for (int i = 0; i < TaskListGroup.NumLists; i++) //{ // tlg.AddNewList(TaskListGroup.ListName(i), false); // for (int j = 0; j < TaskListGroup.NumTasks(i); j++) // { // tlg.AddNewTask(i, TaskListGroup.GetTask(i,j), TaskListGroup.GetTaskColour(i,j), TaskListGroup.GetTaskNote(i,j)); // } // } //new FilePersister(VooDoo.Settings.AppSettings.Instance.CurrentFile + ".new").Save(tlg); } }