Skip to content

Commit 9a5e556

Browse files
test: Importer tests
1 parent 8d841ba commit 9a5e556

11 files changed

Lines changed: 111 additions & 14 deletions

File tree

FreeFrame.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.1.32228.430
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreeFrame", "FreeFrame\FreeFrame.csproj", "{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeFrame", "FreeFrame\FreeFrame.csproj", "{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreeFrameTests", "FreeFrameTests\FreeFrameTests.csproj", "{C9665752-3F93-4FA8-8F2C-BF701D932E8A}"
79
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
1517
{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

FreeFrame/Components/Importer.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace FreeFrame.Components
1010
{
11-
static class Importer
11+
public static class Importer
1212
{
1313
static public void Import()
1414
{
@@ -17,32 +17,50 @@ static public void Import()
1717
//{
1818
//}
1919
}
20-
static public List<Shape> Import(string filename)
20+
static public List<Shape> ImportFromStream(Stream pStream)
2121
{
22-
if (!File.Exists(filename))
23-
throw new ArgumentException($"'{nameof(filename)}' file cannot be found.", nameof(filename)); //TODO: replace by a simple alert window
24-
2522
List<Shape> shapes = new List<Shape>();
2623

27-
using (XmlReader reader = XmlReader.Create(filename))
24+
using (XmlReader reader = XmlReader.Create(pStream))
2825
{
29-
while(reader.Read())
26+
while (reader.Read())
3027
{
3128
if (reader.HasAttributes)
3229
{
3330
Console.WriteLine("Attributes of <" + reader.Name + ">");
3431
switch (reader.Name)
3532
{
33+
case "xml":
34+
case "svg":
35+
case "rect":
36+
case "path":
37+
break;
3638
case "circle":
3739
shapes.Add(new SVGCircle(reader));
3840
break;
3941
default:
42+
// TODO: show all the elemnt are not valid, be careful
4043
break;
4144
}
4245
}
4346
}
4447
}
4548
return (shapes);
4649
}
50+
static public List<Shape> ImportFromFile(string pFilename)
51+
{
52+
if (!File.Exists(pFilename))
53+
throw new ArgumentException($"'{nameof(pFilename)}' file cannot be found.", nameof(pFilename)); //TODO: replace by a simple alert window
54+
55+
byte[] byteArray = Encoding.UTF8.GetBytes(File.ReadAllText(pFilename));
56+
57+
return ImportFromStream(new MemoryStream(byteArray));
58+
}
59+
static public List<Shape> ImportFromString(string pString)
60+
{
61+
byte[] byteArray = Encoding.UTF8.GetBytes(pString);
62+
63+
return ImportFromStream(new MemoryStream(byteArray));
64+
}
4765
}
4866
}

FreeFrame/Components/Shapes/SVGCircle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace FreeFrame.Components.Shapes
88
{
9-
class SVGCircle : Shape
9+
public class SVGCircle : Shape
1010
{
1111
#region Geometry properties
1212
private float _cx;

FreeFrame/Components/Shapes/SVGPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace FreeFrame.Components.Shapes
77
{
8-
class SVGPath : Shape
8+
public class SVGPath : Shape
99
{
1010
// https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
1111
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d

FreeFrame/Components/Shapes/SVGPolygon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace FreeFrame.Components.Shapes
66
{
7-
class SVGPolygon : Shape
7+
public class SVGPolygon : Shape
88
{
99
#region Geometry properties
1010
List<float> points = new List<float>();

FreeFrame/Components/Shapes/SVGRectangle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace FreeFrame.Components.Shapes
77
{
8-
class SVGRectangle : Shape
8+
public class SVGRectangle : Shape
99
{
1010
#region Geometry properties
1111
private float _x;

FreeFrame/Components/Shapes/Shape.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace FreeFrame.Components.Shapes
77
{
8-
abstract class Shape
8+
public abstract class Shape
99
{
1010
public Shape()
1111
{

FreeFrame/FreeFrame.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
<PackageReference Include="OpenTK" Version="4.7.1" />
1212
</ItemGroup>
1313

14+
<ItemGroup>
15+
<Folder Include="Tests\" />
16+
</ItemGroup>
17+
1418
</Project>

FreeFrame/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Program
99
{
1010
static void Main()
1111
{
12-
List<Shape> shapes = Importer.Import("test.svg");
12+
List<Shape> shapes = Importer.ImportFromFile("test.svg");
1313

1414
shapes.ForEach(shape => Console.WriteLine(shape));
1515
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
12+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
13+
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
14+
<PackageReference Include="coverlet.collector" Version="3.1.0" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\FreeFrame\FreeFrame.csproj" />
19+
</ItemGroup>
20+
21+
</Project>

0 commit comments

Comments
 (0)