private TestHostContext Setup([CallerMemberName] string name = "", bool createWorkDirectory = true, bool useReleaseDefinitionId = true, bool setupArtifactsDirectory = false) { TestHostContext hc = new TestHostContext(this, name); this.stubWorkFolder = hc.GetDirectory(WellKnownDirectory.Work); if (createWorkDirectory) { Directory.CreateDirectory(this.stubWorkFolder); } _ec = new Mock <IExecutionContext>(); _extensionManager = new Mock <IExtensionManager>(); _sourceProvider = new Mock <ISourceProvider>(); _releaseDirectoryManager = new Mock <IReleaseDirectoryManager>(); var _configurationStore = new Mock <IConfigurationStore>(); _configurationStore.Setup(store => store.GetSettings()).Returns(new AgentSettings { WorkFolder = this.stubWorkFolder }); List <string> warnings; var releaseVariables = useReleaseDefinitionId ? GetReleaseVariables(id.ToString(), bool.TrueString) : GetReleaseVariables(null, bool.TrueString); if (setupArtifactsDirectory) { releaseVariables.Add(Constants.Variables.Release.ArtifactsDirectory, this.stubWorkFolder); } _variables = new Variables(hc, releaseVariables, out warnings); hc.SetSingleton(_releaseDirectoryManager.Object); hc.SetSingleton(_extensionManager.Object); hc.SetSingleton(_configurationStore.Object); _ec.Setup(x => x.Variables).Returns(_variables); _ec.Setup(x => x.SetVariable(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>())).Callback((string varName, string varValue, bool isSecret, bool isOutput, bool isFilePath, bool isReadOnly) => { _variables.Set(varName, varValue, false); }); _extensionManager.Setup(x => x.GetExtensions <ISourceProvider>()) .Returns(new List <ISourceProvider> { _sourceProvider.Object }); _sourceProvider.Setup(x => x.RepositoryType).Returns(RepositoryTypes.TfsGit); releaseJobExtension = new ReleaseJobExtension(); releaseJobExtension.Initialize(hc); return(hc); }
private TestHostContext Setup([CallerMemberName] string name = "", bool createWorkDirectory = true, bool useReleaseDefinitionId = true) { this.stubWorkFolder = Path.Combine( Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), $"_work_{Path.GetRandomFileName()}"); if (createWorkDirectory) { Directory.CreateDirectory(this.stubWorkFolder); } TestHostContext hc = new TestHostContext(this, name); _ec = new Mock <IExecutionContext>(); _extensionManager = new Mock <IExtensionManager>(); _sourceProvider = new Mock <ISourceProvider>(); _releaseDirectoryManager = new Mock <IReleaseDirectoryManager>(); var _configurationStore = new Mock <IConfigurationStore>(); _configurationStore.Setup(store => store.GetSettings()).Returns(new AgentSettings { WorkFolder = this.stubWorkFolder }); List <string> warnings; var releaseVariables = useReleaseDefinitionId ? GetReleaseVariables(id.ToString(), bool.TrueString) : GetReleaseVariables(null, bool.TrueString); _variables = new Variables(hc, releaseVariables, new List <MaskHint>(), out warnings); hc.SetSingleton(_releaseDirectoryManager.Object); hc.SetSingleton(_extensionManager.Object); hc.SetSingleton(_configurationStore.Object); _ec.Setup(x => x.Variables).Returns(_variables); _extensionManager.Setup(x => x.GetExtensions <ISourceProvider>()) .Returns(new List <ISourceProvider> { _sourceProvider.Object }); _sourceProvider.Setup(x => x.RepositoryType).Returns(WellKnownRepositoryTypes.TfsGit); releaseJobExtension = new ReleaseJobExtension(); releaseJobExtension.Initialize(hc); return(hc); }