Skip to content

Commit

Permalink
Merge pull request #57 from HiVR/remaining_tests
Browse files Browse the repository at this point in the history
Add remaining tests
  • Loading branch information
keohnoel authored Jun 17, 2016
2 parents 25455e7 + ed76821 commit be364e3
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 8 deletions.
62 changes: 62 additions & 0 deletions HiVRClient.Test/Converter/MarginConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using HiVRClient.Converter;
using NUnit.Framework;
using System.Windows;

namespace HiVRClient.Test.Converter
{
/// <summary>
/// Test <see cref="MarginConverter"/> class.
/// </summary>
[TestFixture]
public class MarginConverterTest
{
#region Fields

/// <summary>
/// Contains margin converter instance for each test.
/// </summary>
private MarginConverter marginConverter;

#endregion Fields

#region Methods

/// <summary>
/// Create a margin converter instance.
/// </summary>
[SetUp]
public void SetUp()
{
this.marginConverter = new MarginConverter();
}

/// <summary>
/// Set margin converter to null to prevent test contamination.
/// </summary>
[TearDown]
public void TearDown()
{
this.marginConverter = null;
}

/// <summary>
/// Test with valid doubles.
/// </summary>
[Test]
public void TestConvertValid()
{
Assert.That(this.marginConverter.Convert(new object[] { 1, 2, 3, 4 }, null, null, null), Is.EqualTo(new Thickness(1, 2, 3, 4)));
}

/// <summary>
/// Test not implemented convert back method.
/// </summary>
[Test]
public void TestConvertBack()
{
Assert.That(this.marginConverter.ConvertBack(null, null, null, null), Is.Null);
}

#endregion Methods
}
}
3 changes: 3 additions & 0 deletions HiVRClient.Test/HiVRClient.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Rhino.Mocks, Version=3.6.0.0, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<HintPath>..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll</HintPath>
<Private>True</Private>
Expand All @@ -50,6 +51,7 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Converter\MarginConverterTest.cs" />
<Compile Include="Model\DrawableModel\BenchTest.cs" />
<Compile Include="Model\DrawableModel\BuildingTest.cs" />
<Compile Include="Model\DrawableModel\CarTest.cs" />
Expand All @@ -60,6 +62,7 @@
<Compile Include="Model\DrawableModel\PatientTest.cs" />
<Compile Include="Model\DrawableModel\TelevisionTest.cs" />
<Compile Include="Model\Network\ObjectReceivedEventArgsTest.cs" />
<Compile Include="Utility\SerializableConverterTest.cs" />
<Compile Include="ViewModel\ConnectControlViewModelTest.cs" />
<Compile Include="ViewModel\DrawableViewModel\BenchControlTest.cs" />
<Compile Include="ViewModel\DrawableViewModel\BuildingControlTest.cs" />
Expand Down
209 changes: 209 additions & 0 deletions HiVRClient.Test/Utility/SerializableConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
using HiVRClient.Utility;
using HiVRClient.ViewModel.DrawableViewModel;
using NUnit.Framework;
using SerializedObjects;
using System;

namespace HiVRClient.Test.Utility
{
/// <summary>
/// Test <see cref="SerializableConverter"/> class.
/// </summary>
[TestFixture]
public class SerializableConverterTest
{
#region Methods

/// <summary>
/// Test creating a building.
/// </summary>
[Test]
public void TestCreateBuilding()
{
var ser = new SerializableTransformObject(
1,
SerializableType.Building,
false,
new SerializableVector3(1, 2, 3),
new SerializableVector3(4, 5, 6),
new SerializableVector3(7, 8, 9),
null
);

var result = SerializableConverter.CreateDrawableControlFromSerializableObject(ser);

Assert.That(result.Id, Is.EqualTo(1));
Assert.That(result, Is.TypeOf<BuildingControl>());
}

/// <summary>
/// Test creating a car.
/// </summary>
[Test]
public void TestCreateCar()
{
var ser = new SerializableTransformObject(
1,
SerializableType.Car,
false,
new SerializableVector3(1, 2, 3),
new SerializableVector3(4, 5, 6),
new SerializableVector3(7, 8, 9),
null
);

var result = SerializableConverter.CreateDrawableControlFromSerializableObject(ser);

Assert.That(result.Id, Is.EqualTo(1));
Assert.That(result, Is.TypeOf<CarControl>());
}

/// <summary>
/// Test creating a garden.
/// </summary>
[Test]
public void TestCreateGarden()
{
var ser = new SerializableTransformObject(
1,
SerializableType.Garden,
false,
new SerializableVector3(1, 2, 3),
new SerializableVector3(4, 5, 6),
new SerializableVector3(7, 8, 9),
null
);

var result = SerializableConverter.CreateDrawableControlFromSerializableObject(ser);

Assert.That(result.Id, Is.EqualTo(1));
Assert.That(result, Is.TypeOf<GardenControl>());
}

/// <summary>
/// Test creating a bench.
/// </summary>
[Test]
public void TestCreateBench()
{
var ser = new SerializableTransformObject(
1,
SerializableType.Bench,
false,
new SerializableVector3(1, 2, 3),
new SerializableVector3(4, 5, 6),
new SerializableVector3(7, 8, 9),
null
);

var result = SerializableConverter.CreateDrawableControlFromSerializableObject(ser);

Assert.That(result.Id, Is.EqualTo(1));
Assert.That(result, Is.TypeOf<BenchControl>());
}

/// <summary>
/// Test creating a television.
/// </summary>
[Test]
public void TestCreateTelevision()
{
var ser = new SerializableTransformObject(
1,
SerializableType.Television,
false,
new SerializableVector3(1, 2, 3),
new SerializableVector3(4, 5, 6),
new SerializableVector3(7, 8, 9),
null
);

var result = SerializableConverter.CreateDrawableControlFromSerializableObject(ser);

Assert.That(result.Id, Is.EqualTo(1));
Assert.That(result, Is.TypeOf<TelevisionControl>());
}

/// <summary>
/// Test creating a character.
/// </summary>
[Test]
public void TestCreateCharacter()
{
var ser = new SerializableTransformObject(
1,
SerializableType.Character,
false,
new SerializableVector3(1, 2, 3),
new SerializableVector3(4, 5, 6),
new SerializableVector3(7, 8, 9),
new SerializableCharacter(false, "")
);

var result = SerializableConverter.CreateDrawableControlFromSerializableObject(ser);

Assert.That(result.Id, Is.EqualTo(1));
Assert.That(result, Is.TypeOf<CharacterControl>());
}

/// <summary>
/// Test creating a patient.
/// </summary>
[Test]
public void TestCreatePatient()
{
var ser = new SerializableTransformObject(
1,
SerializableType.Character,
false,
new SerializableVector3(1, 2, 3),
new SerializableVector3(4, 5, 6),
new SerializableVector3(7, 8, 9),
new SerializableCharacter(true, "")
);

var result = SerializableConverter.CreateDrawableControlFromSerializableObject(ser);

Assert.That(result.Id, Is.EqualTo(1));
Assert.That(result, Is.TypeOf<PatientControl>());
}

/// <summary>
/// Test creating an invalid object.
/// </summary>
[Test]
public void TestCreateInvalid()
{
var ser = new SerializableTransformObject(
1,
SerializableType.Unknown,
false,
new SerializableVector3(1, 2, 3),
new SerializableVector3(4, 5, 6),
new SerializableVector3(7, 8, 9),
null
);

Assert.Throws<ArgumentOutOfRangeException>(() =>
{
SerializableConverter.CreateDrawableControlFromSerializableObject(ser);
});
}

/// <summary>
/// Test <see cref="SerializableConverter.ConvertSerializableVector3ToVector3D"/> method.
/// </summary>
[Test]
public void TestConvertSerializableVector()
{
var vec = new SerializableVector3(1, 2, 3);
var toVec = SerializableConverter.ConvertSerializableVector3ToVector3D(vec);

Assert.That(toVec.X, Is.EqualTo(1));
Assert.That(toVec.Y, Is.EqualTo(2));
Assert.That(toVec.Z, Is.EqualTo(3));
}

#endregion Methods
}
}
Loading

0 comments on commit be364e3

Please sign in to comment.