Hi, I've been having some trouble passing a list to a class that is the instance of a MockingContainer.
And the test class is:
The registration on line 51 seems to be ignored. Is there something else I should be doing?
01.using System.Collections.Generic;02. 03.namespace JustMock_AutoContainer04.{05. public interface IWorker06. {07. void DoSomething();08. }09. 10. public interface IService11. {12. string Moo { get; }13. 14. void DoLotsOfThings();15. }16. 17. public class Service : IService18. {19. private readonly IList<IWorker> workers;20. 21. public Service(IList<IWorker> workers, string moo)22. {23. this.workers = workers;24. this.Moo = moo;25. }26. 27. public string Moo { get; private set; }28. 29. public void DoLotsOfThings()30. {31. foreach (var worker in this.workers)32. {33. worker.DoSomething();34. }35. }36. }37.}And the test class is:
01.using JustMock_AutoContainer;02.using Microsoft.VisualStudio.TestTools.UnitTesting;03.using System.Collections.Generic;04.using Telerik.JustMock;05.using Telerik.JustMock.AutoMock;06.using Telerik.JustMock.Helpers;07. 08.namespace JustMock_AutoContainer_Tests09.{10. [TestClass]11. public class ServiceTest12. {13. #region Fields14. private MockingContainer<Service> container;15. #endregion16. 17. #region Test Configuration18. [TestInitialize]19. public void CreateTargetContainer()20. {21. this.container = new MockingContainer<Service>();22. }23. #endregion24. 25. [TestMethod]26. public void DoLotsOfWork_TwoWorkers_AllWorkersCalled()27. {28. // Arrange29. var provider1 = StubWorker();30. var provider2 = StubWorker();31. var target = this.CreateTarget(provider1, provider2);32. 33. // Act34. target.DoLotsOfThings();35. 36. // Assert37. Assert.AreEqual("moo", target.Moo);38. provider1.Assert(p => p.DoSomething()); // Fails here :(39. provider2.Assert(p => p.DoSomething());40. }41. 42. #region Support Methods43. private static IWorker StubWorker()44. {45. var dataTraceProvider = Mock.Create<IWorker>();46. return dataTraceProvider;47. }48. 49. private IService CreateTarget(params IWorker[] providers)50. {51. this.container52. .Bind<IList<IWorker>>() 53. .ToConstant((IList<IWorker>)providers);54. 55. //TODO: fix line above; the list is not being picked up in the target.56. // JustMock seems keen on giving us a list with one and only one item in it, rather than57. // what we've registered above.58. this.container59. .Bind<string>()60. .ToConstant("moo");61. 62. return this.container.Instance;63. }64. 65. #endregion66. }67.}The registration on line 51 seems to be ignored. Is there something else I should be doing?