private static ISimpleInjectorWrapper Bootstrap() { var container = new Container(); container.Register <IProcessProxy, ProcessProxy>(Lifestyle.Singleton); container.Register <IJsonService, JsonService>(Lifestyle.Singleton); container.Register <IFileService, FileService>(Lifestyle.Singleton); container.Register <IConfigurationService, ConfigurationService>(Lifestyle.Singleton); container.Register <IConfigurationReader, ConfigurationReader>(Lifestyle.Singleton); container.Register <IGoBotFactory, GoBotFactory>(Lifestyle.Singleton); container.Register <IProcessManagerFactory, ProcessManagerFactory>(Lifestyle.Singleton); container.Register <ILogger, DebugLogger>(Lifestyle.Singleton); var wrapper = new SimpleInjectorWrapper(container); container.Register <ISimpleInjectorWrapper>(() => wrapper); return(wrapper); }
public void SimpleInjectorWrapperCtorTest() { ISimpleInjectorWrapper injector = null; try { injector = new SimpleInjectorWrapper(null); Assert.True(false, "Should fail on previous statement"); } catch (Exception ex) { Assert.IsType(typeof(ArgumentNullException), ex); Assert.Equal("Value cannot be null.\r\nParameter name: container", ex.Message); } Container cont = new Container(); injector = new SimpleInjectorWrapper(cont); Assert.NotNull(injector); }
public void SimpleInjectorWrapperGetInstanceTest() { Container cont = new Container(); ISimpleInjectorWrapper injector = new SimpleInjectorWrapper(cont); cont.Register <IFileService, FileService>(); var service = injector.GetInstance <IFileService>(); Assert.NotNull(service); Assert.IsType(typeof(FileService), service); try { var notRegistered = injector.GetInstance <IJsonService>(); Assert.True(false, "Should fail on previous statement"); } catch (Exception ex) { Assert.IsType(typeof(ActivationException), ex); Assert.Equal("No registration for type IJsonService could be found.", ex.Message); } }