Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
Change namespace of GameCubeBanner
  • Loading branch information
ItsPepperpot committed Aug 2, 2024
1 parent 1ee292c commit dc8c6e2
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ jobs:
run: nuget restore IndustrialPark.sln

- name: Build solution
run: msbuild IndustrialPark.sln -t:rebuild -property:Configuration=Release -property:platform="Any CPU"
run: msbuild IndustrialPark.sln -t:rebuild -property:Configuration=Release -property:platform="Any CPU"

- name: Run unit tests
uses: microsoft/[email protected]
with:
testAssembly: '**\bin\Release\**\*Test.dll'

6 changes: 6 additions & 0 deletions IndustrialPark.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Randomizer", "IndustrialPar
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchiveEditor", "ArchiveEditor\ArchiveEditor.csproj", "{2B20165D-B6D3-4FA5-93B4-64EC117BA732}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IndustrialParkTest", "IndustrialParkTest\IndustrialParkTest.csproj", "{BD22CB98-D975-4E37-8707-9FA07C067806}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -48,6 +50,10 @@ Global
{2B20165D-B6D3-4FA5-93B4-64EC117BA732}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B20165D-B6D3-4FA5-93B4-64EC117BA732}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B20165D-B6D3-4FA5-93B4-64EC117BA732}.Release|Any CPU.Build.0 = Release|Any CPU
{BD22CB98-D975-4E37-8707-9FA07C067806}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD22CB98-D975-4E37-8707-9FA07C067806}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD22CB98-D975-4E37-8707-9FA07C067806}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD22CB98-D975-4E37-8707-9FA07C067806}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 0 additions & 1 deletion IndustrialPark/MainForm/CreateGameCubeBanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using IndustrialPark.Other;
using Image = System.Web.UI.WebControls.Image;

namespace IndustrialPark
Expand Down
2 changes: 1 addition & 1 deletion IndustrialPark/Other/GameCubeBanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.IO;
using System.Text;

namespace IndustrialPark.Other
namespace IndustrialPark
{
/// <summary>
/// Represents a (single-language) GameCube banner (BNR1).
Expand Down
66 changes: 66 additions & 0 deletions IndustrialParkTest/GameCubeBannerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Drawing;
using Xunit;
using IndustrialPark;

namespace IndustrialParkTest
{
public class GameCubeBannerTests
{
private readonly GameCubeBanner banner;

public GameCubeBannerTests()
{
banner = new GameCubeBanner()
{
Title = "Test Title",
TitleFull = "Test Full Title",
Creator = "Test Creator",
CreatorFull = "Test Full Creator",
Description = "Test Description",
Image = new Bitmap(96, 32)
};
}

[Fact]
public void SaveToFile_Output_Banner_Filesize_Is_Correct()
{
int expectedFilesizeBytes = 0x1960;
banner.SaveToFile("test.bnr");
Assert.Equal(expectedFilesizeBytes, new System.IO.FileInfo("test.bnr").Length);
System.IO.File.Delete("test.bnr");
}

[Fact]
public void SaveToFile_Magic_Bytes_Are_Correct()
{
string expectedMagic = "BNR1";
banner.SaveToFile("test.bnr");

using (System.IO.BinaryReader reader = new System.IO.BinaryReader(
System.IO.File.Open("test.bnr", System.IO.FileMode.Open)))
{
string magic = new string(reader.ReadChars(4));
Assert.Equal(expectedMagic, magic);
}
System.IO.File.Delete("test.bnr");
}

[Fact]
public void SaveToFile_Short_Game_Title_Is_Correct()
{
string expectedTitle = "Test Title";

banner.SaveToFile("test.bnr");

using (System.IO.BinaryReader reader = new System.IO.BinaryReader(
System.IO.File.Open("test.bnr", System.IO.FileMode.Open)))
{
// Game title begins at 0x1820
reader.BaseStream.Seek(0x1820, System.IO.SeekOrigin.Begin);
string title = new string(reader.ReadChars(0x20)).TrimEnd('\0');
Assert.Equal(expectedTitle, title);
}
System.IO.File.Delete("test.bnr");
}
}
}
73 changes: 73 additions & 0 deletions IndustrialParkTest/IndustrialParkTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BD22CB98-D975-4E37-8707-9FA07C067806}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IndustrialParkTest</RootNamespace>
<AssemblyName>IndustrialParkTest</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Data"/>
<Reference Include="System.Drawing" />
<Reference Include="System.Xml"/>
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="GameCubeBannerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IndustrialPark\IndustrialPark.csproj">
<Project>{62f1a222-225b-463f-85a7-70f56c34c324}</Project>
<Name>IndustrialPark</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
35 changes: 35 additions & 0 deletions IndustrialParkTest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("IndustrialParkTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IndustrialParkTest")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("BD22CB98-D975-4E37-8707-9FA07C067806")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
9 changes: 9 additions & 0 deletions IndustrialParkTest/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
</packages>

0 comments on commit dc8c6e2

Please sign in to comment.