|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Azure.Core; |
| 7 | +using NUnit.Framework; |
| 8 | + |
| 9 | +namespace Azure.MixedReality.Authentication.Tests |
| 10 | +{ |
| 11 | + public class MixedRealityAccountKeyCredentialTests |
| 12 | + { |
| 13 | + private const string ExpectedTestToken = "87e9abb1-79b9-4502-bbae-cfae8c610f23:my_account_key"; |
| 14 | + |
| 15 | + private static readonly Guid s_testAccountId = Guid.Parse("87e9abb1-79b9-4502-bbae-cfae8c610f23"); |
| 16 | + |
| 17 | + private static readonly string s_testAccountKey = "my_account_key"; |
| 18 | + |
| 19 | + private static readonly AzureKeyCredential s_testKeyCredential = new AzureKeyCredential(s_testAccountKey); |
| 20 | + |
| 21 | + [Test] |
| 22 | + public void Create() |
| 23 | + { |
| 24 | + new MixedRealityAccountKeyCredential(s_testAccountId, s_testAccountKey); |
| 25 | + new MixedRealityAccountKeyCredential(s_testAccountId, s_testKeyCredential); |
| 26 | + } |
| 27 | + |
| 28 | + [Test] |
| 29 | + public void CreateWithInvalidParameters() |
| 30 | + { |
| 31 | + ArgumentException ex = Assert.Throws<ArgumentException>(() => new MixedRealityAccountKeyCredential(Guid.Empty, s_testAccountKey)); |
| 32 | + Assert.AreEqual("accountId", ex.ParamName); |
| 33 | + |
| 34 | + ex = Assert.Throws<ArgumentNullException>(() => new MixedRealityAccountKeyCredential(s_testAccountId, (string)null!)); |
| 35 | + Assert.AreEqual("key", ex.ParamName); |
| 36 | + |
| 37 | + ex = Assert.Throws<ArgumentException>(() => new MixedRealityAccountKeyCredential(s_testAccountId, "")); |
| 38 | + Assert.AreEqual("key", ex.ParamName); |
| 39 | + |
| 40 | + ex = Assert.Throws<ArgumentNullException>(() => new MixedRealityAccountKeyCredential(s_testAccountId, (AzureKeyCredential)null!)); |
| 41 | + Assert.AreEqual("keyCredential", ex.ParamName); |
| 42 | + } |
| 43 | + |
| 44 | + [Test] |
| 45 | + public void GetToken() |
| 46 | + { |
| 47 | + MixedRealityAccountKeyCredential credential = new MixedRealityAccountKeyCredential(s_testAccountId, s_testKeyCredential); |
| 48 | + AccessToken token = credential.GetToken(default, default); |
| 49 | + Assert.AreEqual(ExpectedTestToken, token.Token); |
| 50 | + Assert.AreEqual(DateTimeOffset.MaxValue, token.ExpiresOn); |
| 51 | + } |
| 52 | + |
| 53 | + [Test] |
| 54 | + public async Task GetTokenAsync() |
| 55 | + { |
| 56 | + MixedRealityAccountKeyCredential credential = new MixedRealityAccountKeyCredential(s_testAccountId, s_testKeyCredential); |
| 57 | + AccessToken token = await credential.GetTokenAsync(default, default); |
| 58 | + Assert.AreEqual(ExpectedTestToken, token.Token); |
| 59 | + Assert.AreEqual(DateTimeOffset.MaxValue, token.ExpiresOn); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments