Skip to content

Instantly share code, notes, and snippets.

@bmcdavid
Created November 16, 2017 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmcdavid/9cd1d6a959006f7af87b169045a90bf6 to your computer and use it in GitHub Desktop.
Save bmcdavid/9cd1d6a959006f7af87b169045a90bf6 to your computer and use it in GitHub Desktop.
LightInject GetAll Sequence Order Test
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