Skip to content

Commit

Permalink
Update tests/CustomIoCTests.cs.
Browse files Browse the repository at this point in the history
  • Loading branch information
gitauto-ai[bot] authored Oct 22, 2024
1 parent 9b375fd commit a86d1e5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/CustomIoCTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Xunit;
using Microsoft.Extensions.DependencyInjection;

public class CustomIoCTests
{
[Fact]
public void TestTransientRegistration()
{
var services = new ServiceCollection();
var builder = new CustomContainerBuilder();
builder.RegisterTransient<IService, ServiceImplementation>();
builder.Populate(services);
var provider = builder.BuildServiceProvider();

var service1 = provider.GetService<IService>();
var service2 = provider.GetService<IService>();

Assert.NotSame(service1, service2);
}

[Fact]
public void TestSingletonRegistration()
{
var services = new ServiceCollection();
var builder = new CustomContainerBuilder();
builder.RegisterSingleton<IService, ServiceImplementation>();
builder.Populate(services);
var provider = builder.BuildServiceProvider();

var service1 = provider.GetService<IService>();
var service2 = provider.GetService<IService>();

Assert.Same(service1, service2);
}
}

0 comments on commit a86d1e5

Please sign in to comment.