Skip to content

Commit

Permalink
#1351 Added tests for the Assessments.Transformation project
Browse files Browse the repository at this point in the history
  • Loading branch information
bolsson committed Dec 20, 2023
1 parent 4660360 commit c456606
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Assessments-frontend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Assessments.Data", "Assessm
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ML", "ML", "{A4A32A2F-CF27-4FC8-BFD9-63C6116D56E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assessments.Transformation.Tests", "Assessments.Transformation.Tests\Assessments.Transformation.Tests.csproj", "{14703783-E9F4-43DD-93AB-E400C69028EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -60,6 +62,10 @@ Global
{2B7D3328-8C3A-40ED-9932-66B07374394B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B7D3328-8C3A-40ED-9932-66B07374394B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B7D3328-8C3A-40ED-9932-66B07374394B}.Release|Any CPU.Build.0 = Release|Any CPU
{14703783-E9F4-43DD-93AB-E400C69028EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14703783-E9F4-43DD-93AB-E400C69028EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14703783-E9F4-43DD-93AB-E400C69028EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14703783-E9F4-43DD-93AB-E400C69028EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Assessments.Transformation\Assessments.Transformation.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Assessments.Transformation.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Assessments.Transformation.PublishDynamicProperties;

namespace Assessments.Transformation.Tests
{
[TestClass]
public class DynamicPropertyObjectComparerTests
{
[TestMethod]
public void GetHashCode_SameObject_ReturnsSameHashCode()
{
// Arrange
var comparer = new DynamicPropertyObjectComparer();
var dynamicProperty = new DynamicProperty { Id = "1", References = new string[0], Properties = new DynamicProperty.Property[0] };

// Act
int hashCode1 = comparer.GetHashCode(dynamicProperty);
int hashCode2 = comparer.GetHashCode(dynamicProperty);

// Assert
Assert.AreEqual(hashCode1, hashCode2);
}

[TestMethod]
public void GetHashCode_EqualObjects_ReturnsSameHashCode()
{
// Arrange
var comparer = new DynamicPropertyObjectComparer();
var dynamicProperty1 = new DynamicProperty { Id = "1", References = new string[1] { "Ref1" }, Properties = new DynamicProperty.Property[1] { new DynamicProperty.Property() { Name = "test1" } } };
var dynamicProperty2 = new DynamicProperty { Id = "1", References = new string[1] { "Ref1" }, Properties = new DynamicProperty.Property[1] { new DynamicProperty.Property() { Name = "test1" } } };

// Act
int hashCode1 = comparer.GetHashCode(dynamicProperty1);
int hashCode2 = comparer.GetHashCode(dynamicProperty2);

// Assert
Assert.AreEqual(hashCode1, hashCode2);
}

[TestMethod]
public void GetHashCode_DifferentObjects_ReturnsDifferentHashCode()
{
// Arrange
var comparer = new DynamicPropertyObjectComparer();
var dynamicProperty1 = new DynamicProperty { Id = "1", References = new string[1] { "Ref1" }, Properties = new DynamicProperty.Property[1] { new DynamicProperty.Property() { Name = "test1" } } };
var dynamicProperty2 = new DynamicProperty { Id = "2", References = new string[1] { "Ref2" }, Properties = new DynamicProperty.Property[1] { new DynamicProperty.Property() { Name = "test2" } } };

// Act
int hashCode1 = comparer.GetHashCode(dynamicProperty1);
int hashCode2 = comparer.GetHashCode(dynamicProperty2);

// Assert
Assert.AreNotEqual(hashCode1, hashCode2);
}
}
}
2 changes: 2 additions & 0 deletions Assessments.Transformation.Tests/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

0 comments on commit c456606

Please sign in to comment.