public void WriteCurrentSave_LevelSerializedOutAsExpected()
        {
            const string testPath = "TestSaveFile.dat";

            PersistenceFunctions.WriteCurrentSave(testPath, _service);

            using (var fileStream =
                       File.Open(Application.persistentDataPath + testPath, FileMode.Open))
            {
                var decryptedStream = new MemoryStream(PersistantDataOperationFunctions.DecryptFileStream(fileStream, GameDataStorageConstants.AESKey, GameDataStorageConstants.AESIV));
                var binaryFormatter = new BinaryFormatter();

                Assert.AreEqual(SceneManager.GetActiveScene().path, binaryFormatter.Deserialize(decryptedStream));

                Assert.AreEqual(_service.GetEntitiesResult.Count, binaryFormatter.Deserialize(decryptedStream));

                foreach (var entity in _service.GetEntitiesResult)
                {
                    Assert.AreEqual(entity.Key, binaryFormatter.Deserialize(decryptedStream));
                    Assert.AreEqual(entity.Value == null, binaryFormatter.Deserialize(decryptedStream));
                }

                fileStream.Close();
            }
        }
        public void LoadCurrentSave_GameInstanceSetupAsExpected()
        {
            var gameInstanceObject = new GameObject();

            gameInstanceObject.AddComponent <MockInputComponent>();
            var instance = gameInstanceObject.AddComponent <TestGameInstance>();

            instance.TestAwake();

            const string testPath = "TestSaveFile.dat";

            PersistenceFunctions.WriteCurrentSave(testPath, _service);
            PersistenceFunctions.LoadCurrentSave(testPath);

            Assert.IsNotNull(instance.NextSceneSaveData);
            Assert.AreEqual(SceneManager.GetActiveScene().path, instance.NextSceneToLoad);

            GameInstance.ClearGameInstance();
        }
Exemple #3
0
        public void ReceivesRequestRespawnMessage_NonMatchingInstance_DoesNotLoadCurrentSaveIntoInstance()
        {
            var gameInstanceObject = new GameObject();

            gameInstanceObject.AddComponent <MockInputComponent>();
            var instance = gameInstanceObject.AddComponent <TestGameInstance>();

            instance.TestAwake();

            PersistenceFunctions.WriteCurrentSave(GameDataStorageConstants.SaveDataPath, null);

            _gameModeComponent.TestAwake();

            UnityMessageEventFunctions.InvokeMessageEventWithDispatcher(_gameModeComponent.gameObject, new RequestRespawnMessage(null));

            Assert.IsNull(instance.NextSceneSaveData);
            Assert.AreNotEqual(SceneManager.GetActiveScene().path, instance.NextSceneToLoad);

            GameInstance.ClearGameInstance();
        }
        public void InitializeSaveRead_DecryptsSaveDataForReading()
        {
            const string testPath = "TestSaveFile.dat";

            PersistenceFunctions.WriteCurrentSave(testPath, _service);

            using (var fileStream =
                       PersistenceFunctions.InitializeSaveRead(testPath))
            {
                var binaryFormatter = new BinaryFormatter();

                Assert.AreEqual(SceneManager.GetActiveScene().path, binaryFormatter.Deserialize(fileStream));

                Assert.AreEqual(_service.GetEntitiesResult.Count, binaryFormatter.Deserialize(fileStream));

                foreach (var entity in _service.GetEntitiesResult)
                {
                    Assert.AreEqual(entity.Key, binaryFormatter.Deserialize(fileStream));
                    Assert.AreEqual(entity.Value == null, binaryFormatter.Deserialize(fileStream));
                }
            }
        }