示例#1
0
        public void TestSerializeZoneMapToJson()
        {
            var want = SetupZoneMap.SetupSmallGrid();

            var    serializer = new ZoneMapSerializer();
            string json       = serializer.Serialize(want);
            var    got        = serializer.DeSerialize(json);

            SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid);
        }
示例#2
0
        public void CreateGridCanGenerateGridFromCorner()
        {
            var want = new Node[1, 1];

            want[0, 0] = new Node(Vector3.Zero);

            var zoneMap = ZoneMap.NewGridFromVector2(Vector2.One);
            var got     = zoneMap.MapGrid;

            Assert.Equal(want.Length, got.Length);
            SetupZoneMap.AssertGridMapEqual(want, got);
        }
示例#3
0
        public void CanCreateGridWithMultipleNodes()
        {
            // Arrange
            var want = SetupZoneMap.SetupThreeByThreeGrid();

            // Act
            var grid = ZoneMap.NewGridFromVector2(new Vector2(3f, 3f));
            var got  = grid.MapGrid;

            // Assert
            Assert.Equal(want.Length, got.Length);
            SetupZoneMap.AssertGridMapEqual(want, got);
        }
        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);
        }
示例#5
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);
        }
        public void LoadGridOrCreateNewCreatesNewIfItDoesntExist()
        {
            var want        = SetupZoneMap.SetupMediumGrid();
            var gridFactory = GridFactorySetup.SetupGridFactory();

            gridFactory.DefaultGridSize = new Vector2(5f, 5f);

            string mapName = Path.GetRandomFileName();

            want.MapName = mapName;

            var got = gridFactory.LoadGridOrCreateNew(mapName);

            SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid);
            Assert.Equal(want.MapName, got.MapName);
        }
        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);
        }
示例#8
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);
        }