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.
Zero/Tests/ZeroLevel.UnitTests/DependencyInjectionTests.cs

60 lines
1.5 KiB

4 years ago
using Xunit;
5 years ago
using ZeroLevel.DependencyInjection;
5 years ago
5 years ago
namespace ZeroLevel.UnitTests
5 years ago
{
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()}";
}
5 years ago
public class DependencyInjectionTests
5 years ago
{
5 years ago
[Fact]
public void ComposeTest()
5 years ago
{
5 years ago
// Arrange
5 years ago
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();
5 years ago
// Act
5 years ago
Injector.Default.Compose(instance);
5 years ago
// Assert
var result = instance.Run();
Assert.Equal("bool isWorking = True", result);
5 years ago
Injector.Dispose();
}
}
}

Powered by TurnKey Linux.