You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/framework/test/Volo.Abp.Autofac.Tests/Volo/Abp/Autofac/AutoFacInjectingPropertiesS...

68 lines
2.0 KiB

using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Autofac.Interception;
using Volo.Abp.DependencyInjection;
using Xunit;
namespace Volo.Abp.Autofac;
public class AutoFacInjectingPropertiesService_Tests : Autofac_Interception_Test
{
[Fact]
public void AutoFacInjectingPropertiesService_Should_Replaces_NullInjectingPropertiesService()
{
ServiceProvider.GetRequiredService<IInjectPropertiesService>().GetType().ShouldBe(typeof(AutoFacInjectPropertiesService));
}
[Fact]
public void InjectProperties()
{
var injectPropertiesService = ServiceProvider.GetRequiredService<IInjectPropertiesService>();
var serviceB = new TestServiceB();
injectPropertiesService.InjectProperties(serviceB);
serviceB.NullTestServiceA.ShouldNotBeNull();
serviceB.NullTestServiceA.Name.ShouldBe("Default Name");
serviceB.NotNullTestServiceA.ShouldNotBeNull();
serviceB.NotNullTestServiceA.Name.ShouldBe("Default Name");
}
[Fact]
public void InjectUnsetProperties()
{
var injectPropertiesService = ServiceProvider.GetRequiredService<IInjectPropertiesService>();
var serviceB = new TestServiceB();
injectPropertiesService.InjectUnsetProperties(serviceB);
serviceB.NullTestServiceA.ShouldNotBeNull();
serviceB.NullTestServiceA.Name.ShouldBe("Default Name");
serviceB.NotNullTestServiceA.ShouldNotBeNull();
serviceB.NotNullTestServiceA.Name.ShouldBe("My Name"); // This is not null property.
}
}
interface ITestServiceA
{
public string Name { get; set; }
}
class TestServiceA : ITestServiceA, ITransientDependency
{
public string Name { get; set; } = "Default Name";
}
interface ITestServiceB
{
}
class TestServiceB : ITestServiceB, ITransientDependency
{
public ITestServiceA NullTestServiceA { get; set; }
public ITestServiceA NotNullTestServiceA { get; set; } = new TestServiceA()
{
Name = "My Name"
};
}