Skip to content

Commit

Permalink
test: append AddTransientAttributeTests with LifeCycle validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Wannesrebry committed Oct 18, 2023
1 parent 883f77c commit c74589f
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/Bindicate.Tests/Transient/AddTransientAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,37 @@ public void AddTransient_AlwaysReturnsNewInstance()
[Fact]
public void AddTransient_WithInterface_RegistersCorrectly()
{
// Arrange
var services = new ServiceCollection();
services.AddAutowiringForAssembly(_testAssembly);
var serviceProvider = services.BuildServiceProvider();

// Act
using var scope = serviceProvider.CreateScope();
var service = scope.ServiceProvider.GetService<ITransientInterface>();
ServiceDescriptor serviceDescriptor = services.First(x => x.ServiceType == typeof(ITransientInterface));

using (var scope = serviceProvider.CreateScope())
{
var service = scope.ServiceProvider.GetService<ITransientInterface>();

service.Should().NotBeNull().And.BeOfType<TransientWithInterface>();
}
// Assert
service.Should().NotBeNull().And.BeOfType<TransientWithInterface>();
serviceDescriptor.Lifetime.Should().Be(ServiceLifetime.Transient);
}

[Fact]
public void AddSingleton_RegistersCorrectly()
{
// Arrange
var services = new ServiceCollection();
services.AddAutowiringForAssembly(_testAssembly);
var serviceProvider = services.BuildServiceProvider();

using (var scope = serviceProvider.CreateScope())
{
var service = scope.ServiceProvider.GetService<SimpleTransientClass>();
// Act
using var scope = serviceProvider.CreateScope();
var service = scope.ServiceProvider.GetService<SimpleTransientClass>();
ServiceDescriptor serviceDescriptor = services.First(x => x.ServiceType == typeof(SimpleTransientClass));

service.Should().NotBeNull().And.BeOfType<SimpleTransientClass>();
}
// Assert
service.Should().NotBeNull().And.BeOfType<SimpleTransientClass>();
serviceDescriptor.Lifetime.Should().Be(ServiceLifetime.Transient);
}
}

Expand Down

0 comments on commit c74589f

Please sign in to comment.