Esempio n. 1
0
        public void GetSecurityToken_WhenTokenIsNotCached_ReturnsCreatesTokenAndCachesIt()
        {
            // Arrange
            var channelFactory        = new ChannelFactory <IService>(new WS2007FederationHttpBinding(), new EndpointAddress("http://localhost"));
            var channelFactoryManager = StubChannelFactoryManager(channelFactory);
            var expected = StubSecurityToken();
            var securityTokenProvider = MockRepository.GenerateStub <SecurityTokenProvider>();

            securityTokenProvider.Stub(
                x =>
                x.IssueToken(Arg <WS2007FederationHttpBinding> .Is.Anything, Arg <string> .Is.Anything, Arg <SecurityToken> .Is.Anything)).Return(expected);
            var clientManager = new TestableClientManager(this.TestCache, channelFactoryManager, securityTokenProvider);

            Thread.CurrentPrincipal = StubPrincipal <IPrincipal>(StubIdentity <IIdentity>("SomeName"));

            // Act
            var actual = clientManager.GetSecurityToken(channelFactory);

            // Assert
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(this.TestCache.Contains(@"SomeName_http://localhost/"));
        }
Esempio n. 2
0
        public void GetSecurityToken_WhenTokenIsCached_ReturnsCachedToken()
        {
            // Arrange
            var channelFactory = new ChannelFactory <IService>(new WS2007FederationHttpBinding(), new EndpointAddress("http://localhost"));

            channelFactory.ConfigureChannelFactory();
            var channelFactoryManager = StubChannelFactoryManager(channelFactory);
            var securityTokenProvider = MockRepository.GenerateStub <SecurityTokenProvider>();
            var securityToken         = StubSecurityToken();

            this.TestCache.Add("SomeName_http://localhost/", securityToken, new DateTimeOffset(DateTime.Now.AddMinutes(1)));
            var clientManager = new TestableClientManager(this.TestCache, channelFactoryManager, securityTokenProvider);

            Thread.CurrentPrincipal = StubPrincipal <IPrincipal>(StubIdentity <IIdentity>("SomeName"));

            // Act
            var actual = clientManager.GetSecurityToken(channelFactory);

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(securityToken, actual);
        }