diff --git a/.idea/.idea.yTools/.idea/.gitignore b/.idea/.idea.yTools/.idea/.gitignore
new file mode 100644
index 0000000..8354724
--- /dev/null
+++ b/.idea/.idea.yTools/.idea/.gitignore
@@ -0,0 +1 @@
+workspace.xml
\ No newline at end of file
diff --git a/.idea/.idea.yTools/.idea/indexLayout.xml b/.idea/.idea.yTools/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/.idea/.idea.yTools/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.yTools/.idea/projectSettingsUpdater.xml b/.idea/.idea.yTools/.idea/projectSettingsUpdater.xml
new file mode 100644
index 0000000..4bb9f4d
--- /dev/null
+++ b/.idea/.idea.yTools/.idea/projectSettingsUpdater.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.yTools/.idea/vcs.xml b/.idea/.idea.yTools/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/.idea.yTools/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/yTools.Tests/GeneralTests.cs b/yTools.Tests/GeneralTests.cs
new file mode 100644
index 0000000..e3b64ac
--- /dev/null
+++ b/yTools.Tests/GeneralTests.cs
@@ -0,0 +1,18 @@
+namespace yTools.Tests;
+
+[TestClass]
+public class GeneralTests
+{
+ [TestMethod]
+ [DataRow(50)]
+ [DataRow("FooBar")]
+ [DataRow(24f)]
+ [DataRow(32L)]
+ [DataRow(new[] { 6, 7, 8, 9 })]
+ public void GetInput(object expected)
+ {
+ var actual = General.GetInput(expected);
+
+ Assert.AreSame(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/yTools.Tests/SerializationTests.cs b/yTools.Tests/SerializationTests.cs
index 7683c96..1dd625b 100644
--- a/yTools.Tests/SerializationTests.cs
+++ b/yTools.Tests/SerializationTests.cs
@@ -1,9 +1,20 @@
-using System;
-namespace yTools.Tests
+namespace yTools.Tests
{
[TestClass]
public class SerializationTests
{
+ [TestCleanup]
+ public void Cleanup()
+ {
+ const string testDirectory = @"yTools";
+
+ var fullDir = $"{Environment.GetFolderPath(
+ Environment.SpecialFolder.LocalApplicationData
+ )}\\{testDirectory}";
+ if (Directory.Exists(fullDir))
+ Directory.Delete(fullDir, true);
+ }
+
[TestMethod]
public void CheckObjectsBinarySerialized()
{
@@ -12,9 +23,15 @@ public void CheckObjectsBinarySerialized()
BinarySerializer serializer = new();
- serializer.SetSerializationDirectoryInLocalAppData(@"yTools\Tests\Serialization");
+ const string directory = @"yTools\Tests\Serialization";
+ serializer.SetSerializationDirectoryInLocalAppData(directory);
+
+ Assert.IsTrue(Directory.Exists(
+ $"{Environment.GetFolderPath(
+ Environment.SpecialFolder.LocalApplicationData
+ )}\\{directory}"));
- bool serialized = serializer.SerializeInDefault("testObject1.bin", testObject1, out Exception? exception, out _);
+ var serialized = serializer.SerializeInDefault("testObject1.bin", testObject1, out Exception? exception, out _);
if (!serialized && exception != null) throw exception;
serialized = serializer.SerializeInDefault("testObject2.bin", testObject2, out exception, out _);
if (!serialized && exception != null) throw exception;
@@ -38,7 +55,13 @@ public void CheckObjectsJsonSerialized()
JsonSerializer serializer = new();
- serializer.SetSerializationDirectoryInLocalAppData(@"yTools\Tests\Serialization");
+ const string directory = @"yTools\Tests\Serialization";
+ serializer.SetSerializationDirectoryInLocalAppData(directory);
+
+ Assert.IsTrue(Directory.Exists(
+ $"{Environment.GetFolderPath(
+ Environment.SpecialFolder.LocalApplicationData
+ )}\\{directory}"));
bool serialized = serializer.SerializeInDefault("testObject1.json", testObject1, out Exception? exception, out _);
if (!serialized && exception != null) throw exception;
@@ -64,7 +87,13 @@ public void CheckObjectsXmlSerialized()
XmlSerializer serializer = new();
- serializer.SetSerializationDirectoryInLocalAppData(@"yTools\Tests\Serialization");
+ const string directory = @"yTools\Tests\Serialization";
+ serializer.SetSerializationDirectoryInLocalAppData(directory);
+
+ Assert.IsTrue(Directory.Exists(
+ $"{Environment.GetFolderPath(
+ Environment.SpecialFolder.LocalApplicationData
+ )}\\{directory}"));
bool serialized = serializer.SerializeInDefault("testObject1.xml", testObject1, out Exception? exception, out _);
if (!serialized && exception != null) throw exception;
diff --git a/yTools.Tests/StringsTests.cs b/yTools.Tests/StringsTests.cs
index f9ce3fa..8c1843a 100644
--- a/yTools.Tests/StringsTests.cs
+++ b/yTools.Tests/StringsTests.cs
@@ -85,5 +85,17 @@ public void IsNullOrWhitespace(string str)
Assert.AreEqual(expected, actual);
}
+
+ [TestMethod]
+ public void Writes()
+ {
+ var str = "Hello from Strings.Write test!";
+ var color = ConsoleColor.Green;
+
+ Strings.Write(str);
+ Strings.WriteColored(str, color);
+ Strings.WriteWithoutEndLine(str);
+ Strings.WriteColoredWithoutEndLine(str, color);
+ }
}
}
\ No newline at end of file
diff --git a/yTools.Tests/VectorsTests.cs b/yTools.Tests/VectorsTests.cs
index cff46da..01432df 100644
--- a/yTools.Tests/VectorsTests.cs
+++ b/yTools.Tests/VectorsTests.cs
@@ -26,4 +26,38 @@ public void Vector3ToString()
Assert.AreEqual(expected, actual);
}
+
+ [TestMethod]
+ public void Vector2Casts()
+ {
+ Vector2 vector = new(5, 6.5);
+ var castedSystemVector = (System.Numerics.Vector2)vector;
+
+ System.Numerics.Vector2 systemVector = new(4f, 8.5f);
+ Vector2 castedVector = systemVector;
+
+ Assert.AreEqual(vector.X, castedSystemVector.X);
+ Assert.AreEqual(vector.Y, castedSystemVector.Y);
+
+ Assert.AreEqual(systemVector.X, castedVector.X);
+ Assert.AreEqual(systemVector.Y, castedVector.Y);
+ }
+
+ [TestMethod]
+ public void Vector3Casts()
+ {
+ Vector3 vector = new(5, 6.5, 8);
+ var castedSystemVector = (System.Numerics.Vector3)vector;
+
+ System.Numerics.Vector3 systemVector = new(4.1f, 8.5f, 45f);
+ Vector3 castedVector = systemVector;
+
+ Assert.AreEqual(vector.X, castedSystemVector.X);
+ Assert.AreEqual(vector.Y, castedSystemVector.Y);
+ Assert.AreEqual(vector.Z, castedSystemVector.Z);
+
+ Assert.AreEqual(systemVector.X, castedVector.X);
+ Assert.AreEqual(systemVector.Y, castedVector.Y);
+ Assert.AreEqual(systemVector.Z, castedVector.Z);
+ }
}
\ No newline at end of file
diff --git a/yTools/Serialization/BinarySerializer.cs b/yTools/Serialization/BinarySerializer.cs
index ed25eef..7d119c0 100644
--- a/yTools/Serialization/BinarySerializer.cs
+++ b/yTools/Serialization/BinarySerializer.cs
@@ -18,12 +18,9 @@ public class BinarySerializer
/// The directory inside AppData\Local to store serialized objects. Use '\' to nest directories.
public void SetSerializationDirectoryInLocalAppData(string directory)
{
- defaultFolder = directory[0] == '\\'
+ SetSerializationDirectory(directory[0] == '\\'
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + directory
- : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory;
-
- if (!Directory.Exists(defaultFolder))
- Directory.CreateDirectory(defaultFolder);
+ : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory);
}
///
diff --git a/yTools/Serialization/JsonSerializer.cs b/yTools/Serialization/JsonSerializer.cs
index c02317c..159bd4f 100644
--- a/yTools/Serialization/JsonSerializer.cs
+++ b/yTools/Serialization/JsonSerializer.cs
@@ -17,12 +17,9 @@ public class JsonSerializer
/// The directory inside AppData\Local to store serialized objects. Use '\' to nest directories.
public void SetSerializationDirectoryInLocalAppData(string directory)
{
- defaultDirectory = directory[0] == '\\'
+ SetSerializationDirectory(directory[0] == '\\'
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + directory
- : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory;
-
- if (!Directory.Exists(defaultDirectory))
- Directory.CreateDirectory(defaultDirectory);
+ : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory);
}
///
diff --git a/yTools/Serialization/XmlSerializer.cs b/yTools/Serialization/XmlSerializer.cs
index 17ed35c..d33e121 100644
--- a/yTools/Serialization/XmlSerializer.cs
+++ b/yTools/Serialization/XmlSerializer.cs
@@ -17,12 +17,9 @@ public class XmlSerializer
/// The directory inside AppData\Local to store serialized objects. Use '\' to nest directories.
public void SetSerializationDirectoryInLocalAppData(string directory)
{
- defaultFolder = directory[0] == '\\'
+ SetSerializationDirectory(directory[0] == '\\'
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + directory
- : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory;
-
- if (!Directory.Exists(defaultFolder))
- Directory.CreateDirectory(defaultFolder);
+ : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory);
}
///