private static ServicesContainer CreateServices(params IExceptionLogger[] loggers) { Mock <ServicesContainer> mock = new Mock <ServicesContainer>(MockBehavior.Strict); mock.Setup(s => s.GetServices(typeof(IExceptionLogger))).Returns(loggers); CompositeExceptionLogger cached = null; mock.Setup(s => s.GetService(typeof(CompositeExceptionLogger))).Returns(() => cached); mock.Protected() .Setup("ReplaceSingle", typeof(CompositeExceptionLogger), ItExpr.IsAny <object>()) .Callback <Type, object>((i, o) => cached = (CompositeExceptionLogger)o); mock.Setup(s => s.IsSingleService(typeof(CompositeExceptionLogger))).Returns(true); mock.Protected().Setup("ResetCache", typeof(CompositeExceptionLogger)); mock.Setup(s => s.Dispose()); return(mock.Object); }
public void ConstructorWithParams_SetsLoggers() { // Arrange IExceptionLogger expectedLogger1 = CreateDummyLogger(); IExceptionLogger expectedLogger2 = CreateDummyLogger(); // Act CompositeExceptionLogger product = new CompositeExceptionLogger(expectedLogger1, expectedLogger2); // Assert IEnumerable<IExceptionLogger> loggers = product.Loggers; Assert.NotNull(loggers); Assert.Equal(2, loggers.Count()); Assert.Same(expectedLogger1, loggers.ElementAt(0)); Assert.Same(expectedLogger2, loggers.ElementAt(1)); }
public void ConstructorWithParams_SetsLoggers() { // Arrange IExceptionLogger expectedLogger1 = CreateDummyLogger(); IExceptionLogger expectedLogger2 = CreateDummyLogger(); // Act CompositeExceptionLogger product = new CompositeExceptionLogger(expectedLogger1, expectedLogger2); // Assert IEnumerable <IExceptionLogger> loggers = product.Loggers; Assert.NotNull(loggers); Assert.Equal(2, loggers.Count()); Assert.Same(expectedLogger1, loggers.ElementAt(0)); Assert.Same(expectedLogger2, loggers.ElementAt(1)); }
public void Loggers_ContainsSpecifiedInstances() { // Arrange IExceptionLogger expectedLogger = CreateDummyLogger(); List <IExceptionLogger> expectedLoggers = new List <IExceptionLogger> { expectedLogger }; CompositeExceptionLogger product = CreateProductUnderTest(expectedLoggers); // Act IEnumerable <IExceptionLogger> loggers = product.Loggers; // Assert Assert.NotNull(loggers); Assert.Equal(1, loggers.Count()); Assert.Same(expectedLogger, loggers.Single()); }
public void Constructor_CapturesLoggersContents() { // Arrange IExceptionLogger expectedLogger = CreateDummyLogger(); List <IExceptionLogger> expectedLoggers = new List <IExceptionLogger> { expectedLogger }; // Act CompositeExceptionLogger product = CreateProductUnderTest(expectedLoggers); // Assert expectedLoggers.Clear(); IEnumerable <IExceptionLogger> loggers = product.Loggers; Assert.NotNull(loggers); Assert.Equal(1, loggers.Count()); Assert.Same(expectedLogger, loggers.Single()); }