/// <inheritdoc/> public async Task ConfigureAsync(TfsServiceProviderConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if(string.IsNullOrEmpty(configuration.WorkItemType)) { throw new ArgumentNullException(nameof(configuration.WorkItemType)); } this.logger.Debug("Configure of TfsSoapServiceProvider started..."); var networkCredential = new NetworkCredential(configuration.Username, configuration.Password); var tfsClientCredentials = new TfsClientCredentials(new BasicAuthCredential(networkCredential)) { AllowInteractive = false }; var tfsProjectCollection = new TfsTeamProjectCollection(this.serviceUri, tfsClientCredentials); this.workItemType = configuration.WorkItemType; tfsProjectCollection.Authenticate(); tfsProjectCollection.EnsureAuthenticated(); this.logger.Debug("Authentication successful for {serviceUri}.", this.serviceUri.AbsoluteUri); await Task.Run( () => { this.logger.Debug("Fetching workitem for id {parentWorkItemId}.", configuration.ParentWorkItemId); this.workItemStore = new WorkItemStore(tfsProjectCollection); this.parentWorkItem = this.workItemStore.GetWorkItem(configuration.ParentWorkItemId); this.logger.Debug("Found parent work item '{title}'.", this.parentWorkItem.Title); }); this.logger.Verbose("Tfs service provider configuration complete."); }
public void TfsServiceProviderConfigureThrowsIfAuthenticationFails() { var invalidCredentialConfig = new TfsServiceProviderConfiguration("invalidUsername", "invalidPassword"); invalidCredentialConfig.ParentWorkItemId = this.tfsServiceProviderDefaultConfig.ParentWorkItemId; Func<Task> action = async () => await this.tfsServiceProvider.ConfigureAsync(invalidCredentialConfig); action.ShouldThrow<TeamFoundationServerUnauthorizedException>(); }
/// <inheritdoc/> public async Task ConfigureAsync(TfsServiceProviderConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (string.IsNullOrEmpty(configuration.WorkItemType)) { throw new ArgumentNullException(nameof(configuration.WorkItemType)); } this.logger.Debug("Configure of TfsSoapServiceProvider started..."); var networkCredential = new NetworkCredential(configuration.Username, configuration.Password); TfsClientCredentials tfsClientCredentials = new TfsClientCredentials(new BasicAuthCredential(networkCredential)) { AllowInteractive = false }; var tfsProjectCollection = new TfsTeamProjectCollection(this.serviceUri, tfsClientCredentials); this.workItemType = configuration.WorkItemType; try { tfsProjectCollection.Authenticate(); } catch { tfsClientCredentials = new TfsClientCredentials(); // fall back to login page tfsProjectCollection = new TfsTeamProjectCollection(this.serviceUri, tfsClientCredentials); tfsProjectCollection.Authenticate(); } tfsProjectCollection.EnsureAuthenticated(); this.logger.Debug("Authentication successful for {serviceUri}.", this.serviceUri.AbsoluteUri); await Task.Run( () => { this.logger.Debug("Fetching workitem for id {parentWorkItemId}.", configuration.ParentWorkItemId); this.workItemStore = new WorkItemStore(tfsProjectCollection); this.parentWorkItem = this.workItemStore.GetWorkItem(configuration.ParentWorkItemId); this.logger.Debug("Found parent work item '{title}'.", this.parentWorkItem.Title); }); this.logger.Verbose("Tfs service provider configuration complete."); }
/// <summary> /// Initializes a new instance of the <see cref="TfsSink"/> class. /// </summary> /// <param name="tfsServiceProvider"> /// Service endpoint. /// </param> /// <param name="credential"> /// The credential. /// </param> /// <param name="parentWorkItem"> /// Parent work item id for all tasks. /// </param> /// <param name="fieldMap">Map of work item fields to mail properties.</param> protected TfsSink(ITfsServiceProvider tfsServiceProvider, NetworkCredential credential, int parentWorkItem, string workItemType, IDictionary<string, object> fieldMap) { if (credential == null) { throw new ArgumentNullException(nameof(credential)); } if (fieldMap == null) { throw new ArgumentNullException(nameof(fieldMap)); } this.logger = Log.Logger.ForContext<TfsSink>(); this.tfsServiceProvider = tfsServiceProvider; this.fieldMap = fieldMap; this.tfsServiceProviderConfiguration = new TfsServiceProviderConfiguration(credential.UserName, credential.Password) { ParentWorkItemId = parentWorkItem, WorkItemType = string.IsNullOrEmpty(workItemType) ? "Task" : workItemType }; }
public void InitializeTest() { // Reset the connection state at start of test this.tfsServiceProvider = this.CreateTfsServiceProvider(); this.tfsServiceProviderDefaultConfig = this.CreateDefaultConfiguration(); }