Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Convert legacy unit tests
  • Loading branch information
bkoelman committed Oct 5, 2023
commit f179362897941a0f0a9f0eeec9be08c60b92080c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
using TestBuildingBlocks;
using Xunit;

namespace UnitTests.Extensions;
namespace JsonApiDotNetCoreTests.UnitTests.Configuration;

public sealed class ServiceCollectionExtensionsTests
{
[Fact]
public void RegisterResource_DeviatingDbContextPropertyName_RegistersCorrectly()
public void Register_resource_from_DbContext_ignores_deviating_DbContext_property_name()
{
// Arrange
var services = new ServiceCollection();
Expand All @@ -39,7 +39,7 @@ public void RegisterResource_DeviatingDbContextPropertyName_RegistersCorrectly()
}

[Fact]
public void AddResourceService_Registers_Service_Interfaces_Of_Int32()
public void Can_register_resource_service_for_Id_type_Int32()
{
// Arrange
var services = new ServiceCollection();
Expand All @@ -63,7 +63,7 @@ public void AddResourceService_Registers_Service_Interfaces_Of_Int32()
}

[Fact]
public void AddResourceService_Registers_Service_Interfaces_Of_Guid()
public void Can_register_resource_service_for_Id_type_Guid()
{
// Arrange
var services = new ServiceCollection();
Expand All @@ -87,7 +87,7 @@ public void AddResourceService_Registers_Service_Interfaces_Of_Guid()
}

[Fact]
public void AddResourceService_Throws_If_Type_Does_Not_Implement_Any_Interfaces()
public void Cannot_register_resource_service_for_type_that_does_not_implement_required_interfaces()
{
// Arrange
var services = new ServiceCollection();
Expand All @@ -101,7 +101,7 @@ public void AddResourceService_Throws_If_Type_Does_Not_Implement_Any_Interfaces(
}

[Fact]
public void AddResourceRepository_Registers_Repository_Interfaces_Of_Int32()
public void Can_register_resource_repository_for_Id_type_Int32()
{
// Arrange
var services = new ServiceCollection();
Expand All @@ -118,7 +118,7 @@ public void AddResourceRepository_Registers_Repository_Interfaces_Of_Int32()
}

[Fact]
public void AddResourceRepository_Registers_Repository_Interfaces_Of_Guid()
public void Can_register_resource_repository_for_Id_type_Guid()
{
// Arrange
var services = new ServiceCollection();
Expand All @@ -135,7 +135,7 @@ public void AddResourceRepository_Registers_Repository_Interfaces_Of_Guid()
}

[Fact]
public void AddResourceDefinition_Registers_Definition_Interface_Of_Int32()
public void Can_register_resource_definition_for_Id_type_Int32()
{
// Arrange
var services = new ServiceCollection();
Expand All @@ -150,7 +150,7 @@ public void AddResourceDefinition_Registers_Definition_Interface_Of_Int32()
}

[Fact]
public void AddResourceDefinition_Registers_Definition_Interface_Of_Guid()
public void Can_register_resource_definition_for_Id_type_Guid()
{
// Arrange
var services = new ServiceCollection();
Expand All @@ -164,25 +164,6 @@ public void AddResourceDefinition_Registers_Definition_Interface_Of_Guid()
provider.GetRequiredService(typeof(IResourceDefinition<ResourceOfGuid, Guid>)).Should().BeOfType<ResourceDefinitionOfGuid>();
}

[Fact]
public void AddJsonApi_With_Context_Uses_Resource_Type_Name_If_NoOtherSpecified()
{
// Arrange
var services = new ServiceCollection();
services.AddLogging();
services.AddDbContext<TestDbContext>(options => options.UseInMemoryDatabase(Guid.NewGuid().ToString()));

// Act
services.AddJsonApi<TestDbContext>();

// Assert
ServiceProvider provider = services.BuildServiceProvider();
var resourceGraph = provider.GetRequiredService<IResourceGraph>();
ResourceType resourceType = resourceGraph.GetResourceType(typeof(ResourceOfInt32));

resourceType.PublicName.Should().Be("resourceOfInt32s");
}

private sealed class ResourceOfInt32 : Identifiable<int>
{
}
Expand Down Expand Up @@ -594,7 +575,7 @@ private sealed class TestDbContext : TestableDbContext
{
public DbSet<ResourceOfInt32> ResourcesOfInt32 => Set<ResourceOfInt32>();
public DbSet<ResourceOfGuid> ResourcesOfGuid => Set<ResourceOfGuid>();
public DbSet<Person> People => Set<Person>();
public DbSet<Person> SetOfPersons => Set<Person>();

public TestDbContext(DbContextOptions<TestDbContext> options)
: base(options)
Expand Down