Skip to content

Commit

Permalink
#372 Add unit tests for SimpleContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel Sampson committed Jun 28, 2019
1 parent 99df5a7 commit df005d5
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/Caliburn.Micro.Core.Tests/SimpleContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,93 @@ public void Instances_registered_with_different_keys_get_all_instances_return_al
Assert.Equal(2, results.Count());
}
}

public class SimpleContainer_Find_Constructor
{

public class SingleEmptyConstructorType
{
public SingleEmptyConstructorType()
{

}
}

[Fact]
public void Container_Finds_Single_Constructor()
{
var container = new SimpleContainer();
container.Singleton<SingleEmptyConstructorType>();
container.GetInstance(typeof(SingleEmptyConstructorType), null);
}

public class SingleNonEmptyConstructorType
{
public SingleNonEmptyConstructorType(SimpleContainer_Find_Constructor.SingleEmptyConstructorType type)
{
}
}

[Fact]
public void Container_No_EmptyConstructor()
{
var container = new SimpleContainer();
container.Singleton<SingleNonEmptyConstructorType>();
container.GetInstance(typeof(SingleNonEmptyConstructorType), null);
}

public class SingleIntConstructor
{
public int Value { get; private set; }

public SingleIntConstructor(int x)
{
this.Value = x;
}
}

[Fact]
public void Container_SingleIntConstructor()
{
var container = new SimpleContainer();
container.Singleton<SingleIntConstructor>();
container.RegisterInstance(typeof(int), "x", 4);
var inst = (SingleIntConstructor)container.GetInstance(typeof(SingleIntConstructor), null);
Assert.Equal(4, inst.Value);
}

public class TwoConstructors
{
public int Value { get; set; }

public TwoConstructors()
{
this.Value = 42;
}

public TwoConstructors(int value)
{
Value = value;
}
}

[Fact]
public void Container_ChooseConstructorWithRegisteredParameter()
{
var container = new SimpleContainer();
container.Singleton<TwoConstructors>();
container.RegisterInstance(typeof(int), null, 23);
var inst = (TwoConstructors)container.GetInstance(typeof(TwoConstructors), null);
Assert.Equal(23, inst.Value);
}

[Fact]
public void Container_ChooseEmptyConstructorWithoutRegisteredParameter()
{
var container = new SimpleContainer();
container.Singleton<TwoConstructors>();
var inst = (TwoConstructors)container.GetInstance(typeof(TwoConstructors), null);
Assert.Equal(42, inst.Value);
}
}
}

0 comments on commit df005d5

Please sign in to comment.