Esempio n. 1
0
        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");
        }
Esempio n. 2
0
        public void BenchmarkSerializeThenPersistZoneMap()
        {
            var want = SetupZoneMap.SetupBigGrid();

            var    serializer = new ZoneMapSerializer();
            var    persister  = SetupPersister.SetupTestFileTextPersister();
            string mapName    = SetupPersister.GetCurrentMethodName();

            persister.FileName = mapName;

            int time = Benchmark.Run("StreamReader.ReadToEnd", 5, () =>
            {
                string json = serializer.Serialize(want);
                persister.Save(json);

                string got = persister.Load <string>();
                persister.Delete();
                var map = serializer.DeSerialize(got);
            });

            int benchTime = 180;

            Assert.True(time < benchTime,
                        "time per iteration was: " + time + "ms which is greater than expected time of: " + benchTime + "ms");
        }
Esempio n. 3
0
        public void WillGetNpcsFromFileIfExists()
        {
            var mapName = SetupPersister.GetCurrentMethodName();
            var want    = new ObservableCollection <Person>();

            want.Add(new Person(2, "test guy", Vector3.Zero)
            {
                MapName = mapName
            });

            var persister = SetupPersister.SetupTestFilePersister();

            persister.FileName = SetupPersister.GetCurrentMethodName();

            var peopleOverseer = new PeopleOverseer(mapName, _testFileDirectory);

            peopleOverseer.PeopleManager.AddPerson(new Person(2, "test guy", Vector3.Zero));

            // Load up using what was just saved.
            var gotZone = new Zone("D");

            gotZone.Npcs = persister.Load <ObservableCollection <Person> >();

            var got = gotZone.Npcs;

            persister.Delete();

            Assert.Equal(want, got);
        }
Esempio n. 4
0
        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]);
            }
        }
Esempio n. 5
0
        public void TestGridFactoryCanGetGridFromFile()
        {
            var    want        = SetupZoneMap.SetupSmallGrid();
            var    gridFactory = GridFactorySetup.SetupGridFactory();
            string mapName     = SetupPersister.GetCurrentMethodName();

            // Uncomment to make golden file if zoneMap changes.
            gridFactory.Persister.MapName = mapName;
            gridFactory.Persister.Save(want);

            var got = gridFactory.LoadGrid(mapName);

            SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        public void FilePersisterCanSaveAndLoadZone()
        {
            var    want      = World.FinalFantasy().Zones.FirstOrDefault();
            var    persister = SetupPersister.SetupTestFilePersister();
            string mapName   = SetupPersister.GetCurrentMethodName();

            persister.FileName = mapName;

            persister.Save(want);
            var got = persister.Load <Zone>();

            persister.Delete();

            Assert.Equal(want, got);
        }
Esempio n. 8
0
        public void LoadGridOrCreateNewLoadsGridIfExists()
        {
            var    want        = SetupZoneMap.SetupSmallGrid();
            var    gridFactory = GridFactorySetup.SetupGridFactory();
            string mapName     = SetupPersister.GetCurrentMethodName();

            want.MapName = mapName;

            // Uncomment to make golden file if zoneMap changes.
            gridFactory.Persister.MapName = mapName;
            gridFactory.Persister.Save(want);

            var got = gridFactory.LoadGridOrCreateNew(mapName);

            SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid);
            Assert.Equal(want.MapName, got.MapName);
        }
Esempio n. 9
0
        public async void ConcurrentCallsWillNotLockUpFile()
        {
            var sw      = new Stopwatch();
            var mapName = SetupPersister.GetCurrentMethodName();

            var persister = SetupPersister.SetupTestFilePersister();

            persister.FileName = SetupPersister.GetCurrentMethodName();

            var peopleOverseer = new PeopleOverseer(mapName, _testFileDirectory);

            peopleOverseer.PeopleManager.AddPerson(new Person(0, "test guy", Vector3.Zero));
            peopleOverseer.PeopleManager.AddPerson(new Person(0, "test guy", Vector3.Zero));
            peopleOverseer.PeopleManager.AddPerson(new Person(0, "test guy", Vector3.Zero));

            var npcs = new List <Person>();

            for (var i = 2; i < 30; i++)
            {
                peopleOverseer.PeopleManager.AddPerson(new Person(i, "dummy" + i, Vector3.Zero));
            }

            await Init(peopleOverseer.PeopleManager, npcs);

            var want = new ObservableCollection <Person>();

            want.Add(new Person(0, "test guy", Vector3.Zero)
            {
                MapName = mapName
            });
            for (var i = 2; i < 30; i++)
            {
                want.Add(new Person(i, "dummy" + i, Vector3.Zero)
                {
                    MapName = mapName
                });
            }

            var got = persister.Load <ObservableCollection <Person> >();

            persister.Delete();

            Assert.Equal(want.Count, got.Count);
            Assert.Equal(want, got);
            sw.Stop();
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        public void AddingPersonPersistsCollectionToFile()
        {
            var mapName = SetupPersister.GetCurrentMethodName();
            var want    = new ObservableCollection <Person>();

            want.Add(new Person(2, "test guy", Vector3.Zero)
            {
                MapName = mapName
            });

            var persister = SetupPersister.SetupTestFilePersister();

            persister.FileName = mapName;

            var peopleOverseer = new PeopleOverseer(mapName, _testFileDirectory);

            peopleOverseer.PeopleManager.AddPerson(new Person(2, "test guy", Vector3.Zero));
            var got = persister.Load <ObservableCollection <Person> >();

            persister.Delete();

            Assert.Equal(want, got);
        }