/src/UnitTests/IOC/FactoryStorageTests.cs

http://github.com/philiplaureano/LinFu · C# · 50 lines · 38 code · 11 blank · 1 comment · 0 complexity · 17f12367966f2ca7ea0821832ac941cf MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using LinFu.IoC;
  4. using LinFu.IoC.Interfaces;
  5. using Moq;
  6. using Xunit;
  7. namespace LinFu.UnitTests.IOC
  8. {
  9. public class FactoryStorageTests : BaseTestFixture
  10. {
  11. protected override void Init()
  12. {
  13. _storage = new FactoryStorage();
  14. }
  15. protected override void Term()
  16. {
  17. _storage = null;
  18. }
  19. private IFactoryStorage _storage;
  20. [Fact]
  21. public void ShouldDistinguishBetweenTwoServicesOfTheSameTypeButDifferentParameters()
  22. {
  23. var firstFactory = new Mock<IFactory>();
  24. var secondFactory = new Mock<IFactory>();
  25. var serviceType = typeof(int);
  26. IEnumerable<Type> firstParameters = new[] {typeof(int), typeof(int)};
  27. IEnumerable<Type> secondParameters = new[] {typeof(int), typeof(int), typeof(int), typeof(int)};
  28. _storage.AddFactory("", serviceType, firstParameters, firstFactory.Object);
  29. _storage.AddFactory("", serviceType, secondParameters, secondFactory.Object);
  30. Assert.True(_storage.ContainsFactory("", serviceType, firstParameters));
  31. Assert.True(_storage.ContainsFactory("", serviceType, secondParameters));
  32. // Make sure that the factory returns the correct container
  33. var firstResult = _storage.GetFactory("", serviceType, firstParameters);
  34. Assert.Same(firstFactory.Object, firstResult);
  35. var secondResult = _storage.GetFactory("", serviceType, secondParameters);
  36. Assert.Same(secondFactory.Object, secondResult);
  37. }
  38. }
  39. }