-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from coryleach/dev
Added GetFiles
- Loading branch information
Showing
10 changed files
with
324 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace Gameframe.SaveLoad.Tests | ||
{ | ||
public class SaveLoadUtilityTests | ||
{ | ||
private string TestKey = "TestKey"; | ||
private string TestSalt = "TestSalt"; | ||
|
||
private ISerializationMethod GetSerializationMethod(SerializationMethodType method) | ||
{ | ||
switch (method) | ||
{ | ||
case SerializationMethodType.Default: | ||
return new SerializationMethodUnityJson(); | ||
case SerializationMethodType.Binary: | ||
return new SerializationMethodBinary(); | ||
case SerializationMethodType.BinaryEncrypted: | ||
return new SerializationMethodBinaryEncrypted(TestKey,TestSalt); | ||
case SerializationMethodType.UnityJson: | ||
return new SerializationMethodUnityJson(); | ||
case SerializationMethodType.UnityJsonEncrypted: | ||
return new SerializationMethodUnityJsonEncrypted(TestKey,TestSalt); | ||
case SerializationMethodType.JsonDotNet: | ||
return new SerializationMethodJsonDotNet(); | ||
case SerializationMethodType.JsonDotNetEncrypted: | ||
return new SerializationMethodJsonDotNetEncrypted(TestKey,TestSalt); | ||
case SerializationMethodType.Custom: | ||
return new SerializationMethodBinary(); | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(method), method, null); | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class SaveLoadTestObject | ||
{ | ||
public string testData; | ||
} | ||
|
||
[Test] | ||
public void SaveLoadAndDelete([Values]SerializationMethodType method) | ||
{ | ||
var testSave = new SaveLoadTestObject() {testData = "SaveFileExists"}; | ||
var serializationMethod = GetSerializationMethod(method); | ||
var filename = "TestSave.sav"; | ||
|
||
SaveLoadUtility.Save(testSave,serializationMethod,filename); | ||
|
||
Assert.IsTrue(SaveLoadUtility.Exists(filename)); | ||
|
||
var loadedSave = (SaveLoadTestObject)SaveLoadUtility.Load(typeof(SaveLoadTestObject), serializationMethod, filename); | ||
Assert.NotNull(loadedSave); | ||
Assert.IsTrue(loadedSave.testData == testSave.testData); | ||
|
||
SaveLoadUtility.DeleteSavedFile(filename); | ||
|
||
Assert.IsFalse(SaveLoadUtility.Exists(filename)); | ||
} | ||
|
||
[Test] | ||
public void CanGetFiles_Empty() | ||
{ | ||
var files = SaveLoadUtility.GetSavedFiles(); | ||
Assert.IsTrue(files.Length == 0); | ||
} | ||
|
||
[Test] | ||
public void CanGetFiles() | ||
{ | ||
var testSave = new SaveLoadTestObject() {testData = "SaveFileExists"}; | ||
var serializationMethod = GetSerializationMethod(SerializationMethodType.Binary); | ||
var filename = "TestSave.sav"; | ||
var folder = "TestFolder"; | ||
|
||
SaveLoadUtility.Save(testSave,serializationMethod,filename,folder); | ||
|
||
var files = SaveLoadUtility.GetSavedFiles(folder); | ||
Assert.IsTrue(files.Length == 1); | ||
|
||
//Files should contain a list of names that exactly match the file name used | ||
//omits the path of the file | ||
Assert.IsTrue(files[0] == filename); | ||
|
||
SaveLoadUtility.DeleteSavedFile(filename,folder); | ||
|
||
files = SaveLoadUtility.GetSavedFiles(); | ||
Assert.IsTrue(files.Length == 0); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
var path = SaveLoadUtility.GetSavePath(); | ||
string[] files = {"TestSave.sav"}; | ||
|
||
foreach (var file in files) | ||
{ | ||
var filename = path + file; | ||
if (File.Exists(filename)) | ||
{ | ||
File.Delete(filename); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "com.gameframe.saveload.editor.tests", | ||
"references": [ | ||
"GUID:b894308b0ac81480cb726cb405d83944", | ||
"GUID:0acc523941302664db1f4e527237feb3", | ||
"GUID:27619889b8ba8c24980f49ee34dbb44a" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": false, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.