/// <summary> /// Method save playgrounds to file (as JSON form). /// </summary> /// <param name="playgroundArray"> Playground Array example. </param> public void WriteInformationInFile(IPlaygroundArray playgroundArray) { if (_fileSystem.File.Exists(_path)) { _fileSystem.File.Delete(_path); } var jsonObject = JsonConvert.SerializeObject(playgroundArray); _fileSystem.File.WriteAllText(_path, jsonObject); }
/// <summary> /// Method to display selected Playgrounds. /// </summary> /// <param name="gamePlaygroundArrays"> Arrays of playgrounds; </param> /// <param name="arrayWithSelectedPlaygrounds"> Array with selected playgrounds ID; </param> public void DisplayPlaygroundArray(IPlaygroundArray gamePlaygroundArrays, int[] arrayWithSelectedPlaygrounds) { Console.Clear(); for (var index = 0; index < arrayWithSelectedPlaygrounds.Length; index++) { DisplayPlayground(gamePlaygroundArrays.PlaygroundArrays[index]); } Console.WriteLine("Number of living playgrounds: {0}", gamePlaygroundArrays.GetNumberOfLivePlaygrounds()); Console.WriteLine("Press 'Esc' to end the game."); }
/// <summary> /// Method save playgrounds to file (as binary form). /// </summary> /// <param name="playgroundArray"> Playground Array example. </param> public void WriteInformationInFile(IPlaygroundArray playgroundArray) { if (_fileSystem.File.Exists(_path)) { _fileSystem.File.Delete(_path); } BinaryFormatter binary = new BinaryFormatter(); FileStream strem = new FileStream(_path, FileMode.Create); binary.Serialize(strem, playgroundArray); strem.Close(); }
public void JSON_WriteInformationInFile_SerializateObjectAndSaveIt_JSONSAreSame() { GameEngine gameEngine = new GameEngine(); string Path = @"Resurses\MyTest.json"; var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { Path, "" } }); IPlaygroundArray playgroundArr = JsonConvert.DeserializeObject <PlaygroundArray>(jsonForTest); IWorkWithFile file = new FileWriterJSON(fileSystem, Path); file.WriteInformationInFile(playgroundArr); string text = fileSystem.File.ReadAllText(Path); Assert.Equal(text, jsonForTest); }
public void JSON_CreateSaveDownload_CreateClassSaveItAndDownloadFromFile_True() { IPlaygroundArray expectedArray = new PlaygroundArray(10, 10, 1); string Path = @"Resurses\MyTest.json"; var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { Path, "" } }); IWorkWithFile file = new FileWriterJSON(fileSystem, Path); file.WriteInformationInFile(expectedArray); IPlaygroundArray actualArray = file.OpenFileAndGatInformation(); Assert.Equal(expectedArray.NumberOfArrays, actualArray.NumberOfArrays); Assert.Equal(expectedArray.PlaygroundArrays[0].IterationNumber, actualArray.PlaygroundArrays[0].IterationNumber); Assert.Equal(expectedArray.PlaygroundArrays[0].GetNumberOfLivePoints(), actualArray.PlaygroundArrays[0].GetNumberOfLivePoints()); Assert.Equal(expectedArray.PlaygroundArrays[0].GetPlaygroundArray(), actualArray.PlaygroundArrays[0].GetPlaygroundArray()); }