Ejemplo n.º 1
0
        public async void ClientDetach()
        {
            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 proxy = domain0Context.AttachClientEnvironment(attachedEnvironmentMock.Object);

            Assert.NotNull(proxy);

            var profile = await domain0Context.LoginByPhone(123, "2");

            Assert.NotNull(profile);

            attachedEnvironmentMock
            .VerifySet(env =>
                       env.Token = It.Is <string>(s => string.IsNullOrWhiteSpace(s)),
                       Times.Once);

            domain0Context.DetachClientEnvironment(attachedEnvironmentMock.Object);

            profile = await domain0Context.LoginByPhone(123, "2");

            Assert.NotNull(profile);

            attachedEnvironmentMock
            .VerifySet(env =>
                       env.Token = It.Is <string>(s => string.IsNullOrWhiteSpace(s)),
                       Times.Once);
        }