public void Create_GetNewAndExistingEvent_ShouldReturnTheSameSettings() { // Prepare var settingStoreMock = new Mock <ISettingStore>(); var eventAggregatorMock = new Mock <IEventAggregator>(); ISettingFactory settingFactory = new SettingFactory(settingStoreMock.Object, eventAggregatorMock.Object); // Act var setting1 = settingFactory.Create <ApplicationSettings>(); var setting2 = settingFactory.Create <ApplicationSettings>(); // Assert Assert.Equal(setting1, setting2); }
public static void Register(Action <ContainerBuilder> action) { var builder = new Autofac.ContainerBuilder(); builder.Register(x => SettingFactory.Create <PackSetting>()).As <PackSetting>().InstancePerLifetimeScope(); builder.RegisterType <GitCommandHelper>().As <IGitCommandHelper>().InstancePerLifetimeScope(); builder.RegisterType <PathService>().As <IPathService>().SingleInstance(); builder.RegisterType <GitPackEngine>().As <IGitPackEngine>().InstancePerLifetimeScope(); builder.RegisterType <FileAnalysisFactory>().As <IFileAnalysisFactory>().InstancePerLifetimeScope(); builder.RegisterType <ProjectFilePreparer>().As <IChangedFilePreparer>().InstancePerLifetimeScope(); builder.RegisterType <ScreenLogger>().As <ILogger>().SingleInstance(); builder.RegisterType <VisualStudioProjectCompiler>().As <IVisualStudioProjectCompiler>().InstancePerLifetimeScope(); //builder.RegisterType<FakeCompilier>().As<IVisualStudioProjectCompiler>().InstancePerLifetimeScope(); builder.RegisterType <FilePackService>().As <IFilePackService>().InstancePerLifetimeScope(); builder.RegisterType <BuildServiceFactory>().As <IBuildServiceFactory>().InstancePerLifetimeScope(); builder.RegisterType <ProjectParserServiceFactory>().As <IProjectParserServiceFactory>().InstancePerLifetimeScope(); builder.RegisterType <VisualStudioProjectFinder>().As <IProjectFinder>().InstancePerLifetimeScope(); builder.RegisterType <ProjectFilter>().As <IProjectFilter>().SingleInstance(); builder.RegisterType <PackageCompressService>().As <IPackageCompressService>().InstancePerLifetimeScope(); builder.RegisterType <ProjectDiffer>().As <IProjectDiffer>().InstancePerLifetimeScope(); builder.RegisterType <VisualStudioSolutionFinder>().As <ISolutionFinder>().InstancePerLifetimeScope(); builder.RegisterType <VisualStudioSolutionParser>().As <ISolutionParser>().InstancePerLifetimeScope(); builder.RegisterType <NugetPackageManager>().As <INugetPackageManager>().InstancePerLifetimeScope(); action(builder); IContainer iocContainer = builder.Build(); ContainerManager.SetContainer(iocContainer); }
public void CreateTest() { _objectsCreated = 0; var config = A.Fake <IConfiguration>(); A.CallTo(() => config.GetItem <object>()) .Returns(CreateNewObject()) .NumberOfTimes(1) .Then .Returns(CreateNewObject()); var factory = new SettingFactory <object>(config); var obj0 = factory.Create(); var obj1 = factory.Create(); Assert.Equal(2, _objectsCreated); Assert.Equal("c", obj0); Assert.Equal("cc", obj1); Assert.NotSame(obj0, obj1); }
public static IContainer Register(Action <ContainerBuilder> action) { var builder = new ContainerBuilder(); builder.Register(x => SettingFactory.Create <SystemSetting>()).As <SystemSetting>().SingleInstance(); builder.RegisterGeneric(typeof(MongoRepository <>)).As(typeof(IBaseRepository <>)).InstancePerLifetimeScope(); builder.RegisterType <LogService>().As <ILogService>().InstancePerLifetimeScope(); builder.Register(x => SettingFactory.Create <AliyunMnsSetting>()).As <AliyunMnsSetting>().SingleInstance(); builder.RegisterGeneric(typeof(MqClient <>)).As(typeof(IQueue <>)).InstancePerLifetimeScope(); action(builder); var container = builder.Build(); Container = container; return(container); }