This commit is contained in:
ENikS 2023-04-11 11:49:43 -07:00
Родитель ee8d911681
Коммит 26925a85a0
3 изменённых файлов: 36 добавлений и 1 удалений

Просмотреть файл

@ -1,9 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Unity.Specification.Property.Overrides.SpecificationTests;
namespace Unity.Specification.Field.Overrides
{
public abstract partial class SpecificationTests
{
[TestMethod]
public void CanOverrideValue()
{
Container.RegisterType<ObjectWithField>(Invoke.Constructor(),
Resolve.Field(nameof(ObjectWithField.MyField)))
.RegisterType<ISomething, Something1>()
.RegisterType<ISomething, Something2>(Name);
// Act
var result = Container.Resolve<ObjectWithField>(
Override.Field(nameof(ObjectWithField.MyField), Resolve.Dependency<ISomething>(Name))
.OnType<ObjectWithField>());
// Assert
Assert.IsNotNull(result);
Assert.IsNotNull(result.MyField);
Assert.IsInstanceOfType(result.MyField, typeof(Something2));
}
[TestMethod]
public void FieldOverrideAttribute()
{

Просмотреть файл

@ -1,6 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Unity.Resolution;
using Unity.Specification.Utility;
namespace Unity.Specification.Parameter.Overrides
{

Просмотреть файл

@ -82,6 +82,22 @@ namespace Unity.Specification.Property.Overrides
}
}
public class ObjectWithField
{
public ISomething MyField;
public ObjectWithField()
{
}
public ObjectWithField(ISomething field)
{
MyField = field;
}
}
public class Outer
{
public Outer(Inner inner, int logLevel)