Exemplo n.º 1
0
        public void SerializeCheckSumTest()
        {
            var model = MockSaveFileModelFactory.CreateTestModel();

            // Mock
            SetUpMocksForSerialization();

            // Generate
            _serializer = new SaveFileRepository(_charsetMock.Object, _bwriterMock.Object, _breaderMock.Object);
            _serializer.Serialize(_testStream, model);

            // Assert
            _testReader.BaseStream.Seek(0, SeekOrigin.Begin);
            var result = _testReader.ReadBytes(0x2000);

            // Calculate Checksum
            ushort checksum = 0;

            _testReader.BaseStream.Seek(0x2009, SeekOrigin.Begin);
            while (_testReader.BaseStream.Position <= 0x2D68)
            {
                checksum += _testReader.ReadByte();
            }

            // Read Checksum 1
            _testReader.BaseStream.Seek(0x2D69, SeekOrigin.Begin);
            Assert.True(checksum.Equals(_testReader.ReadUInt16()), "Checksum 1");

            // Verify
            _charsetMock.VerifyAll();
            _bwriterMock.VerifyAll();
            _breaderMock.VerifyAll();
        }
Exemplo n.º 2
0
        public void Dispose()
        {
            _testReader.Dispose();
            _testWriter.Dispose();
            _testStream.Dispose();

            _serializer  = null;
            _breaderMock = null;
            _bwriterMock = null;
            _charsetMock = null;
        }
Exemplo n.º 3
0
        public SaveFileRepositoryTests()
        {
            _testFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Gold.sav");
            using (var fileStream = new FileStream(_testFile, FileMode.Open, FileAccess.Read))
            {
                _testStream = new MemoryStream();
                fileStream.CopyTo(_testStream);
                _testStreamShim = new StreamShim(_testStream);
            }

            _saveFileRepository = new SaveFileRepository(new Charset(), new BinaryWriter2(), new BinaryReader2());;
            _expectedModel      = BuildTestModel();
        }
Exemplo n.º 4
0
        public void SerializeBasicValuesTest()
        {
            var model = MockSaveFileModelFactory.CreateTestModel();

            // Mock
            SetUpMocksForSerialization();

            // Generate
            _serializer = new SaveFileRepository(_charsetMock.Object, _bwriterMock.Object, _breaderMock.Object);
            _serializer.Serialize(_testStream, model);

            // Assert
            _testReader.BaseStream.Seek(0, SeekOrigin.Begin);
            var result = _testReader.ReadBytes(0x2000);

            // Read trainer name
            _testReader.BaseStream.Seek(0x200B, SeekOrigin.Begin);
            Assert.True(PadString(model.PlayerName, 11).Equals(Encoding.ASCII.GetString(_testReader.ReadBytes(11))), "Player Name");

            // Read rival name
            _testReader.BaseStream.Seek(0x2021, SeekOrigin.Begin);
            Assert.True(PadString(model.RivalName, 11).Equals(Encoding.ASCII.GetString(_testReader.ReadBytes(11))), "Rival Name");

            // Read Time played
            _testReader.BaseStream.Seek(0x2053, SeekOrigin.Begin);
            Assert.True(model.TimePlayed.Equals(_testReader.ReadUInt32()), "Time played");

            // Read Team Pokemon List Size
            _testReader.BaseStream.Seek(0x288A, SeekOrigin.Begin);
            Assert.True(6 == _testReader.ReadByte(), "Team Pokemon List Size");

            // Read Team Pokemon List Species
            var counter = 0;

            foreach (var pokemon in model.TeamPokemonList.Pokemon)
            {
                _testReader.BaseStream.Seek(0x2892 + counter * 0x30, SeekOrigin.Begin);
                Assert.True(pokemon.SpeciesId.Equals(_testReader.ReadByte()), $"Pokemon ({counter}) Species");
                counter++;
            }

            // Verify
            _charsetMock.VerifyAll();
            _bwriterMock.VerifyAll();
            _breaderMock.VerifyAll();
        }
Exemplo n.º 5
0
        public void SerializeHasCorrectLengthTest()
        {
            var model = MockSaveFileModelFactory.CreateTestModel();

            // Mock
            SetUpMocksForSerialization();

            // Generate
            _serializer = new SaveFileRepository(_charsetMock.Object, _bwriterMock.Object, _breaderMock.Object);
            _serializer.Serialize(_testStream, model);

            // Assert
            _testReader.BaseStream.Seek(0, SeekOrigin.Begin);
            var result = _testReader.ReadBytes((int)_testStream.Length);

            Assert.NotNull(result);
            Assert.Equal(0x7E2E, result.Length); // End of PC Box 14 Pokémon list

            // Verify
            _charsetMock.VerifyAll();
            _bwriterMock.VerifyAll();
            _breaderMock.VerifyAll();
        }
Exemplo n.º 6
0
        public void SerializeComplexValuesTest()
        {
            var model = MockSaveFileModelFactory.CreateTestModel();

            // Mock
            SetUpMocksForSerialization();

            // Generate
            _serializer = new SaveFileRepository(_charsetMock.Object, _bwriterMock.Object, _breaderMock.Object);
            _serializer.Serialize(_testStream, model);

            // Assert
            var counter = 0;

            foreach (var expectedPokemon in model.TeamPokemonList.Pokemon)
            {
                _testReader.BaseStream.Seek(0x2892 + counter * 0x30, SeekOrigin.Begin);

                byte buffer;
                var  actualPokemon = new Pokemon
                {
                    SpeciesId   = _testReader.ReadByte(),
                    HeldItem    = _testReader.ReadByte(),
                    MoveIndex1  = _testReader.ReadByte(),
                    MoveIndex2  = _testReader.ReadByte(),
                    MoveIndex3  = _testReader.ReadByte(),
                    MoveIndex4  = _testReader.ReadByte(),
                    TrainerId   = _testReader.ReadUInt16(),
                    Experience  = BitConverter.ToUInt32(_testReader.ReadBytes(3).Cast <byte>().Concat(new byte[] { 0x00 }).ToArray(), 0),
                    HitPointsEV = _testReader.ReadUInt16(),
                    AttackEV    = _testReader.ReadUInt16(),
                    DefenseEV   = _testReader.ReadUInt16(),
                    SpeedEV     = _testReader.ReadUInt16(),
                    SpecialEV   = _testReader.ReadUInt16()
                };

                buffer = _testReader.ReadByte();
                actualPokemon.AttackIV  = (byte)(buffer >> 4);
                actualPokemon.DefenseIV = (byte)(0xf & buffer);

                buffer = _testReader.ReadByte();
                actualPokemon.SpeedIV   = (byte)(buffer >> 4);
                actualPokemon.SpecialIV = (byte)(0xf & buffer);

                buffer = _testReader.ReadByte();
                actualPokemon.Move1PowerPointsUps     = (byte)(buffer >> 6);
                actualPokemon.Move1PowerPointsCurrent = (byte)(0x3f & buffer);

                buffer = _testReader.ReadByte();
                actualPokemon.Move2PowerPointsUps     = (byte)(buffer >> 6);
                actualPokemon.Move2PowerPointsCurrent = (byte)(0x3f & buffer);

                buffer = _testReader.ReadByte();
                actualPokemon.Move3PowerPointsUps     = (byte)(buffer >> 6);
                actualPokemon.Move3PowerPointsCurrent = (byte)(0x3f & buffer);

                buffer = _testReader.ReadByte();
                actualPokemon.Move4PowerPointsUps     = (byte)(buffer >> 6);
                actualPokemon.Move4PowerPointsCurrent = (byte)(0x3f & buffer);

                actualPokemon.Friendship = _testReader.ReadByte();

                buffer = _testReader.ReadByte();
                actualPokemon.PokerusStrain   = (byte)(buffer >> 4);
                actualPokemon.PokerusDuration = (byte)(0xf & buffer);

                buffer = _testReader.ReadByte();
                actualPokemon.CaughtTime  = (byte)(buffer >> 6);
                actualPokemon.CaughtLevel = (byte)(0x3f & buffer);

                buffer = _testReader.ReadByte();
                actualPokemon.OTGender       = (byte)(buffer >> 7);
                actualPokemon.CaughtLocation = (byte)(0x7f & buffer);

                actualPokemon.Level = _testReader.ReadByte();

                actualPokemon.Status    = _testReader.ReadByte();
                actualPokemon.Unused    = _testReader.ReadByte();
                actualPokemon.CurrentHp = _testReader.ReadUInt16();
                actualPokemon.MaxHp     = _testReader.ReadUInt16();
                actualPokemon.Attack    = _testReader.ReadUInt16();
                actualPokemon.Defense   = _testReader.ReadUInt16();
                actualPokemon.Speed     = _testReader.ReadUInt16();
                actualPokemon.SpAttack  = _testReader.ReadUInt16();
                actualPokemon.SpDefense = _testReader.ReadUInt16();
                actualPokemon.OTName    = expectedPokemon.OTName;
                actualPokemon.Name      = expectedPokemon.Name;

                AssertPokemonEqualityThorough(expectedPokemon, actualPokemon);
                counter++;
            }

            // Verify
            _charsetMock.VerifyAll();
            _bwriterMock.VerifyAll();
            _breaderMock.VerifyAll();
        }
 public SaveFileProvider(ISaveFileRepository saveFileRepository)
 {
     _saveFileRepository = saveFileRepository;
 }