diff --git a/STX.SPAL.Core.Tests.Unit/STX.SPAL.Core.Tests.Unit.csproj b/STX.SPAL.Core.Tests.Unit/STX.SPAL.Core.Tests.Unit.csproj index 9823055..a3b042c 100644 --- a/STX.SPAL.Core.Tests.Unit/STX.SPAL.Core.Tests.Unit.csproj +++ b/STX.SPAL.Core.Tests.Unit/STX.SPAL.Core.Tests.Unit.csproj @@ -10,6 +10,7 @@ + diff --git a/STX.SPAL.Core.Tests.Unit/Services/Foundations/ServicesCollections/ServiceCollectionServiceTests.Logic.RegisterServiceDescriptor.cs b/STX.SPAL.Core.Tests.Unit/Services/Foundations/ServicesCollections/ServiceCollectionServiceTests.Logic.RegisterServiceDescriptor.cs index dce99ef..3b5d1d6 100644 --- a/STX.SPAL.Core.Tests.Unit/Services/Foundations/ServicesCollections/ServiceCollectionServiceTests.Logic.RegisterServiceDescriptor.cs +++ b/STX.SPAL.Core.Tests.Unit/Services/Foundations/ServicesCollections/ServiceCollectionServiceTests.Logic.RegisterServiceDescriptor.cs @@ -4,6 +4,7 @@ using FluentAssertions; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Moq; namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.ServicesCollections @@ -19,16 +20,23 @@ private void ShouldRegisterServiceDescriptor() ServiceDescriptor randomServiceDescriptor = randomProperties.ServiceDescriptor; ServiceDescriptor inputServiceDescriptor = randomServiceDescriptor; + ServiceDescriptor expectedServiceDescriptor = inputServiceDescriptor; IServiceCollection randomServiceCollection = randomProperties.ServiceCollection; IServiceCollection expectedServiceCollection = randomServiceCollection; IServiceCollection returnedServiceCollection = randomServiceCollection; + expectedServiceCollection.Add(inputServiceDescriptor); + this.dependencyInjectionBroker .Setup(broker => broker.RegisterServiceDescriptor( It.Is(actualServiceDescriptor => - actualServiceDescriptor == inputServiceDescriptor))) + SameServiceDescriptorAs( + actualServiceDescriptor, + expectedServiceDescriptor) + .Compile() + .Invoke(actualServiceDescriptor)))) .Returns(returnedServiceCollection); // when @@ -45,7 +53,11 @@ private void ShouldRegisterServiceDescriptor() broker => broker.RegisterServiceDescriptor( It.Is(actualServiceDescriptor => - actualServiceDescriptor == inputServiceDescriptor)), + SameServiceDescriptorAs( + actualServiceDescriptor, + expectedServiceDescriptor) + .Compile() + .Invoke(actualServiceDescriptor))), Times.Once); this.dependencyInjectionBroker.VerifyNoOtherCalls(); diff --git a/STX.SPAL.Core.Tests.Unit/Services/Foundations/ServicesCollections/ServiceCollectionServiceTests.cs b/STX.SPAL.Core.Tests.Unit/Services/Foundations/ServicesCollections/ServiceCollectionServiceTests.cs index 4fa097f..36bb902 100644 --- a/STX.SPAL.Core.Tests.Unit/Services/Foundations/ServicesCollections/ServiceCollectionServiceTests.cs +++ b/STX.SPAL.Core.Tests.Unit/Services/Foundations/ServicesCollections/ServiceCollectionServiceTests.cs @@ -3,8 +3,10 @@ // ---------------------------------------------------------------------------------- using System; +using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; +using KellermanSoftware.CompareNetObjects; using Microsoft.Extensions.DependencyInjection; using Moq; using STX.SPAL.Abstractions; @@ -17,11 +19,13 @@ namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.ServicesCollections public partial class ServiceCollectionServiceTests { private readonly Mock dependencyInjectionBroker; + private readonly ICompareLogic compareLogic; private readonly IServiceCollectionService serviceCollectionService; public ServiceCollectionServiceTests() { this.dependencyInjectionBroker = new Mock(); + this.compareLogic = new CompareLogic(); this.serviceCollectionService = new ServiceCollectionService(dependencyInjectionBroker.Object); @@ -108,6 +112,12 @@ private static dynamic CreateRandomProperties() ServiceLifeTime = randomServiceLifeTime, ServiceDescriptor = + new ServiceDescriptor( + randomSpalInterfaceType, + randomImplementationType, + randomServiceLifeTime), + + ServiceDescriptorWithSpalId = new ServiceDescriptor( randomSpalInterfaceType, randomSpalId, @@ -117,5 +127,16 @@ private static dynamic CreateRandomProperties() ServiceCollection = new ServiceCollection() }; } + + private Expression> SameServiceDescriptorAs( + ServiceDescriptor actualServiceDescriptor, + ServiceDescriptor expectedServiceDescriptor) + { + return actualServiceDescriptor => + this.compareLogic.Compare( + expectedServiceDescriptor, + actualServiceDescriptor) + .AreEqual; + } } } diff --git a/STX.SPAL.Core/Models/Services/Foundations/ServicesCollections/ServiceCollectionService.cs b/STX.SPAL.Core/Models/Services/Foundations/ServicesCollections/ServiceCollectionService.cs index 44898c4..9d1f92b 100644 --- a/STX.SPAL.Core/Models/Services/Foundations/ServicesCollections/ServiceCollectionService.cs +++ b/STX.SPAL.Core/Models/Services/Foundations/ServicesCollections/ServiceCollectionService.cs @@ -22,7 +22,11 @@ public IServiceCollection RegisterServiceDescriptor( Type implementationType, ServiceLifetime serviceLifetime) { - throw new System.NotImplementedException(); + ServiceDescriptor serviceDescriptor = + new ServiceDescriptor(spalInterfaceType, implementationType, serviceLifetime); + + IServiceCollection serviceCollection = dependencyInjectionBroker.RegisterServiceDescriptor(serviceDescriptor); + return serviceCollection; } } }