public async void ClientShouldLoginWhenAttached() { var testContext = TestContext.MockUp(); var domain0Context = new AuthenticationContext( domain0ClientEnvironment: testContext.ClientScopeMock.Object, externalStorage: testContext.LoginInfoStorageMock.Object); var attachedClientMock = new Mock <ITestClient>(); var attachedClient = attachedClientMock.Object; var attachedEnvironmentMock = new Mock <IClientScope <ITestClient> >(); attachedEnvironmentMock .Setup(callTo => callTo.Client) .Returns(() => attachedClient); var profile = await domain0Context.LoginByPhone(123, "2"); Assert.NotNull(profile); var proxy = domain0Context.AttachClientEnvironment(attachedEnvironmentMock.Object); Assert.NotNull(proxy); attachedEnvironmentMock .VerifySet(env => env.Token = It.IsAny <string>(), Times.Once); }
public async void AttachedClientRefresh() { var testContext = TestContext.MockUp(accessValidTime: 0.1); var domain0Context = new AuthenticationContext( domain0ClientEnvironment: testContext.ClientScopeMock.Object, externalStorage: testContext.LoginInfoStorageMock.Object, enableAutoRefreshTimer: true, reserveTimeToUpdateToken: 0); var attachedClientMock = new Mock <ITestClient>(); var attachedClient = attachedClientMock.Object; var attachedEnvironmentMock = new Mock <IClientScope <ITestClient> >(); attachedEnvironmentMock .Setup(callTo => callTo.Client) .Returns(() => attachedClient); var proxy = domain0Context.AttachClientEnvironment(attachedEnvironmentMock.Object); Assert.NotNull(proxy); var profile = await domain0Context.LoginByPhone(123, "2"); Assert.NotNull(profile); await domain0Context.LoginByPhone(123, "2"); await domain0Context.LoginByPhone(123, "2"); await domain0Context.LoginByPhone(123, "2"); await domain0Context.LoginByPhone(123, "2"); await Task.Delay(1000); attachedEnvironmentMock .VerifySet(env => env.Token = It.Is <string>(s => !string.IsNullOrWhiteSpace(s)), Times.AtLeast(5)); }
public async void AttachedClientRefresh() { var testContext = TestContext.MockUp(accessValidTime: 0.1); var domain0Context = new AuthenticationContext( domain0ClientEnvironment: testContext.ClientScopeMock.Object, externalStorage: testContext.LoginInfoStorageMock.Object); var attachedClientMock = new Mock <ITestClient>(); var attachedClient = attachedClientMock.Object; var attachedEnvironmentMock = new Mock <ClientLockScope <ITestClient> >(); attachedEnvironmentMock .Setup(callTo => callTo.Client) .Returns(() => attachedClient); var proxy = domain0Context.AttachClientEnvironment(attachedEnvironmentMock.Object); var profile = await domain0Context.LoginByPhone(123, "2"); Assert.NotNull(profile); proxy.MethodB(); attachedEnvironmentMock .VerifySet(env => env.Token = It.Is <string>(s => !string.IsNullOrWhiteSpace(s)), Times.Exactly(2)); attachedClientMock .Verify(c => c.MethodB(), Times.Once); await proxy.MethodA(); attachedEnvironmentMock .VerifySet(env => env.Token = It.Is <string>(s => !string.IsNullOrWhiteSpace(s)), Times.Exactly(3)); attachedClientMock .Verify(c => c.MethodA(), Times.Once); }