public AxSdkPublicKeyDirectory(string email, Guid apiKey, AxSdkConfiguration configuration) { _email = EmailAddress.Parse(email); _passphrase = new Passphrase(apiKey.ToString()); _client = new AxCryptApiClient(new RestIdentity(email, _passphrase.Text), configuration.ApiBaseUrl, configuration.ApiTimeout); }
/// <summary> /// Initializes a new instance of the <see cref="ApiAccountService"/> class. /// </summary> /// <param name="apiClient">The API client to use.</param> public ApiAccountService(AxCryptApiClient apiClient) { if (apiClient == null) { throw new ArgumentNullException(nameof(apiClient)); } _apiClient = apiClient; }
public async Task TestAnonymousSummary() { RestIdentity identity = new RestIdentity(); UserAccount summary = new UserAccount(identity.User, SubscriptionLevel.Free, DateTime.UtcNow.AddMonths(1), AccountStatus.Verified, Offers.None, new AccountKey[] { new AccountKey("*****@*****.**", Convert.ToBase64String(new byte[16]), new KeyPair("public-key-fake-PEM", String.Empty), DateTime.MinValue, PrivateKeyStatus.PassphraseKnown), }); string content = Resolve.Serializer.Serialize(summary); Mock <IRestCaller> mockRestCaller = new Mock <IRestCaller>(); mockRestCaller.Setup <Task <RestResponse> >(wc => wc.SendAsync(It.Is <RestIdentity>((i) => i.User.Length == 0), It.Is <RestRequest>((r) => r.Url == new Uri("http://localhost/api/users/all/accounts/[email protected]")))).Returns(() => Task.FromResult(new RestResponse(HttpStatusCode.OK, content))); mockRestCaller.Setup <string>(wc => wc.UrlEncode(It.IsAny <string>())).Returns <string>((url) => WebUtility.UrlEncode(url)); TypeMap.Register.New <IRestCaller>(() => mockRestCaller.Object); AxCryptApiClient client = new AxCryptApiClient(identity, new Uri("http://localhost/api/"), TimeSpan.Zero); UserAccount userSummary = await client.GetAllAccountsUserAccountAsync("*****@*****.**"); Assert.That(userSummary.UserName, Is.EqualTo(identity.User)); Assert.That(userSummary.AccountKeys.Count(), Is.EqualTo(1), "There should be an AccountKey here."); Assert.That(userSummary.AccountKeys.First(), Is.EqualTo(summary.AccountKeys.First())); }