/// <summary> /// Constructor for a user /// </summary> /// <param name="username">the username of the current user</param> /// <param name="password">the password of the current user</param> public User(string username, string password) { logged = false; this.username = username; this.password = password; //Sharp bucket has two versions of API so we authenticate with both as well as our own RESTSHARP client v1Api = new SharpBucketV1(); v1Api.BasicAuthentication(username, password); try { this.accountName = v1Api.UserEndPoint().GetInfo().user.username; logged = true; } catch (Exception e) { Console.WriteLine(e.Message); return; } v2Api = new SharpBucketV2(); v2Api.BasicAuthentication(username, password); client = new RestClient("https://api.bitbucket.org/"); client.Authenticator = new HttpBasicAuthenticator(username, password); }
public void BasicAuthentication_BasicAuthentication_AllowToListPrivateRepositories() { var privateRepo = SampleRepositories.PrivateTestRepository.GetRepository(); var sharpBucket = new SharpBucketV2(); sharpBucket.BasicAuthentication(TestHelpers.UserName, TestHelpers.Password); var accountRepos = sharpBucket.RepositoriesEndPoint().ListRepositories(TestHelpers.AccountName); accountRepos.ShouldNotBe(null); accountRepos.Any(p => p.is_private == true && p.name == privateRepo.name).ShouldBe(true); }
public static SharpBucketV2 GetV2ClientAuthenticatedWithBasicAuthentication() { var sharpbucket = new SharpBucketV2(); // Reads test data information from a file, you should structure it like this: // By default it reads from c:\ // Username:yourUsername // Password:yourPassword // AccountName:yourAccountName // Repository:testRepository var lines = File.ReadAllLines(TestInformationPath); var email = lines[0].Split(':')[1]; var password = lines[1].Split(':')[1]; sharpbucket.BasicAuthentication(email, password); return(sharpbucket); }