Created
November 16, 2017 14:27
-
-
Save bmcdavid/9cd1d6a959006f7af87b169045a90bf6 to your computer and use it in GitHub Desktop.
LightInject GetAll Sequence Order Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LightInject; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using System.Linq; | |
namespace _LightInjectTests | |
{ | |
public interface IFoo { } | |
public class FooOne : IFoo { } | |
public class FooTwo : IFoo { } | |
public class FooThree : IFoo { } | |
public class FooFour : IFoo { } | |
[TestClass] | |
public class UnitTest1 | |
{ | |
[TestMethod] | |
public void ShouldGetOrderedFoo() | |
{ | |
var container = new ServiceContainer(); | |
// mock dependency sort | |
container.Register<IFoo, FooThree>("A"); | |
container.Register<IFoo, FooOne>("B"); | |
container.Register<IFoo, FooFour>("C"); | |
container.Register<IFoo, FooTwo>(); | |
var allFoo = container.GetAllInstances<IFoo>().ToList(); | |
Assert.IsTrue(allFoo.Count == 4); | |
// expected order | |
//Assert.IsTrue(allFoo[0] is FooThree, "First item"); | |
//Assert.IsTrue(allFoo[1] is FooOne, "Second item"); | |
//Assert.IsTrue(allFoo[2] is FooFour, "Third item"); | |
//Assert.IsTrue(allFoo[3] is FooTwo, "Fourth item"); | |
// actual order seems random | |
Assert.IsTrue(allFoo[0] is FooTwo, "First item"); | |
Assert.IsTrue(allFoo[1] is FooThree, "Second item"); | |
Assert.IsTrue(allFoo[2] is FooFour, "Third item"); | |
Assert.IsTrue(allFoo[3] is FooOne, "Fourth item"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment