Skip to content

Commit

Permalink
Added Unit test and modified ErrorKeyNames.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
garywoodfine committed Jun 1, 2022
1 parent 3c70c8e commit d176ed0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ApiResponse/ErrorKeyNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public static class ErrorKeyNames
{
public const string Conflict = "conflict";
public const string Validation = "validation";
public const string NotFound = "not-found";
public const string NotFound = "notfound";

}
22 changes: 21 additions & 1 deletion tests/Unit/ListResponseTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -43,8 +44,27 @@ public void Should_set_and_get_properties()


}
}

[Theory, Description("Ensure ListResponse has properties defined")]
[InlineData("Items", typeof(List<DummyListResponseClass>))]
[InlineData("Size", typeof(int))]
[InlineData("Page", typeof(int))]
[InlineData("PerPage", typeof(int))]
[InlineData("TotalPages", typeof(int))]
[InlineData("HasPrevious", typeof(bool))]
[InlineData("HasNext", typeof(bool))]
public void Should_have_base_fields_defined(string name, Type type)
{
var testClass = typeof(ListResponse<DummyListResponseClass>);
var prop = testClass.GetProperty(name);

prop.ShouldSatisfyAllConditions(
() => prop.ShouldNotBeNull(),
() => prop?.PropertyType.ShouldBeEquivalentTo(type)
);
}
}

public class DummyListResponseClass
{
public string Name { get; set; }
Expand Down
27 changes: 27 additions & 0 deletions tests/Unit/SIngleResponseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.ComponentModel;
using Shouldly;
using Xunit;

namespace Threenine.ApiResponse.Tests;

public class SIngleResponseTests
{
[Theory, Description("Ensure SingleResponse has properties defined")]
[InlineData("Item", typeof(TestClass))]
public void Should_have_base_fields_defined(string name, Type type)
{
var testClass = typeof(SingleResponse<TestClass>);
var prop = testClass.GetProperty(name);

prop.ShouldSatisfyAllConditions(
() => prop.ShouldNotBeNull(),
() => prop?.PropertyType.ShouldBeEquivalentTo(type)
);
}
}

public class TestClass
{

}

0 comments on commit d176ed0

Please sign in to comment.