コード例 #1
0
            public void ReturnsSaveData()
            {
                // Arrange
                var serializer = new SaveDataSerializer();
                var stream     = new MemoryStream(Encoding.UTF8.GetBytes(Resources.SaveData));

                // Act
                var saveData = serializer.Deserialize(stream);

                // Assert
                Assert.IsAssignableFrom <SaveData>(saveData);
            }
コード例 #2
0
            public void StreamIsNull_ThrowsArgumentNullException()
            {
                // Arrange
                var    serializer = new SaveDataSerializer();
                Stream stream     = null;

                // Act -> Assert
                Assert.Throws <ArgumentNullException>(() =>
                {
                    serializer.Deserialize(stream);
                });
            }
コード例 #3
0
            public void StreamIsNotSeekable_ThrowsArgumentException()
            {
                // Arrange
                var serializer = new SaveDataSerializer();
                var mockStream = new Mock <Stream>();

                mockStream.SetupGet(s => s.CanSeek).Returns(false);
                var stream = mockStream.Object;

                // Act -> Assert
                Assert.Throws <ArgumentException>(() =>
                {
                    serializer.Deserialize(stream);
                });
            }
コード例 #4
0
        public ReplayData ReadReplayData()
        {
            var replay = new ReplayData();

            var remoteHeader = ReadLineAsRemoteHeaderAndVersion();

            replay.KilledBy = remoteHeader.KilledBy;
            replay.IsRemote = remoteHeader.IsRemote;

            replay.Version = remoteHeader.Version;
            if (replay.Version <= 84)
            {
                replay.StartZone      = ReadLineAsInt32();
                replay.StartCoins     = ReadLineAsInt32();
                replay.HasBroadsword  = ReadLineAsBooleanLike();
                replay.IsHardcore     = ReadLineAsBooleanLike();
                replay.IsDaily        = ReadLineAsBooleanLike();
                replay.IsDancePadMode = ReadLineAsBooleanLike();
                replay.IsSeeded       = ReadLineAsBooleanLike();
            }
            else
            {
                replay.Run        = ReadLineAsInt32();
                replay.Unknown0   = ReadLineAsInt32();
                replay.StartCoins = ReadLineAsInt32();
                replay.Unknown2   = ReadLineAsInt32();
            }
            replay.Duration = ReadLineAsDuration();

            var songCount = ReadLineAsInt32();

            for (int i = 0; i < songCount; i++)
            {
                var song = ReadSong();
                replay.Songs.Add(song);
            }
            ReadLine();

            if (!EndOfStream)
            {
                var saveDataSerializer = new SaveDataSerializer();
                replay.SaveData = saveDataSerializer.Deserialize(BaseStream);
            }

            Debug.Assert(EndOfStream);

            return(replay);
        }
コード例 #5
0
            public void SerializesSaveData()
            {
                // Arrange
                var serializer  = new SaveDataSerializer();
                var writeStream = new MemoryStream();
                var readStream  = new MemoryStream(Encoding.UTF8.GetBytes(Resources.SaveData));
                var saveData    = serializer.Deserialize(readStream);

                // Act
                serializer.Serialize(writeStream, saveData);

                // Assert
                writeStream.Position = 0;
                var sr     = new StreamReader(writeStream);
                var actual = sr.ReadToEnd();

                Assert.Equal(Resources.SaveData, actual, ignoreLineEndingDifferences: true);
            }