mirror of https://github.com/ogoun/Zero.git
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.
60 lines
1.5 KiB
60 lines
1.5 KiB
using Xunit;
|
|
using ZeroLevel.DependencyInjection;
|
|
|
|
namespace ZeroLevel.UnitTests
|
|
{
|
|
public interface IDependencyContract
|
|
{
|
|
bool Invoke();
|
|
}
|
|
|
|
public class DependencyImplementation
|
|
: IDependencyContract
|
|
{
|
|
public bool Invoke() => true;
|
|
}
|
|
|
|
public interface IMyContract
|
|
{
|
|
string Run();
|
|
}
|
|
|
|
public class MyImplementation
|
|
: IMyContract
|
|
{
|
|
[Resolve]
|
|
private IDependencyContract _dependency;
|
|
[Parameter("delimeter")]
|
|
private string _delimeter;
|
|
[Resolve]
|
|
private IConfiguration _config;
|
|
|
|
public string Run() => $"{_config.First("var")}{_delimeter}{_dependency.Invoke()}";
|
|
}
|
|
|
|
public class DependencyInjectionTests
|
|
{
|
|
[Fact]
|
|
public void ComposeTest()
|
|
{
|
|
// Arrange
|
|
var config = Configuration.Create();
|
|
config.Append("var", "bool isWorking");
|
|
Injector.Default.Register<IDependencyContract, DependencyImplementation>();
|
|
Injector.Default.Register<IMyContract, MyImplementation>();
|
|
Injector.Default.Register<IConfiguration>(config);
|
|
Injector.Default.Save<string>("delimeter", " = ");
|
|
var instance = new MyImplementation();
|
|
|
|
// Act
|
|
Injector.Default.Compose(instance);
|
|
|
|
// Assert
|
|
var result = instance.Run();
|
|
Assert.Equal("bool isWorking = True", result);
|
|
|
|
Injector.Dispose();
|
|
}
|
|
}
|
|
}
|