public async Task GetETokenTest() { var mockHttp = new MockHttpMessageHandler(); this.ComposeETokenPayload(new TimeSpan(1, 0, 0), string.Empty, string.Empty, out string defaultRequest, out string defaultXdtsResponse); this.ComposeETokenPayload(new TimeSpan(1, 0, 0), DefaultScid, DefaultSandbox, out string sandboxRequest, out string sandboxResponse); mockHttp.Expect(DefaultXtdsEndpoint) .WithContent(defaultRequest) .Respond("application/json", defaultXdtsResponse); mockHttp.Expect(DefaultXtdsEndpoint) .WithContent(sandboxRequest) .Respond("application/json", sandboxResponse); TestHook.MockHttpHandler = mockHttp; var devAccount = await this.SignInAsync(DevAccountSource.WindowsDevCenter, string.Empty); Assert.AreEqual(DefaultId, devAccount.Id); Assert.AreEqual(DefaultName, devAccount.Name); Assert.AreEqual(DefaultAccountId, devAccount.AccountId); Assert.AreEqual(DefaultMoniker, devAccount.AccountMoniker); Assert.AreEqual(DefaultAccountType, devAccount.AccountType); Assert.AreEqual(DevAccountSource.WindowsDevCenter, devAccount.AccountSource); var token2 = await ToolAuthentication.GetDevTokenSilentlyAsync(DefaultScid, DefaultSandbox); Assert.AreEqual(token2, ToolAuthentication.PrepareForAuthHeader(DefaultEToken + DefaultScid + DefaultSandbox)); }
public async Task TokenCacheTest() { var mockHttp = new MockHttpMessageHandler(); this.ComposeETokenPayload(new TimeSpan(1, 0, 0), string.Empty, string.Empty, out string defaultRequest, out string defaultXdtsResponse); // Expect to be hit twice, the second call for token will be fetched from cache mockHttp.Expect(DefaultXtdsEndpoint) .WithContent(defaultRequest) .Respond("application/json", defaultXdtsResponse); TestHook.MockHttpHandler = mockHttp; var devAccount = await this.SignInAsync(DevAccountSource.WindowsDevCenter, string.Empty); Assert.AreEqual(devAccount.Id, DefaultId); Assert.AreEqual(devAccount.Name, DefaultName); Assert.AreEqual(devAccount.AccountId, DefaultAccountId); Assert.AreEqual(devAccount.AccountMoniker, DefaultMoniker); Assert.AreEqual(devAccount.AccountType, DefaultAccountType); Assert.AreEqual(devAccount.AccountSource, DevAccountSource.WindowsDevCenter); var token = await ToolAuthentication.GetDevTokenSilentlyAsync(string.Empty, string.Empty); Assert.AreEqual(token, ToolAuthentication.PrepareForAuthHeader(DefaultEToken)); mockHttp.VerifyNoOutstandingExpectation(); }