Example #1
0
        public void Should_Pass_Token_And_Stop()
        {
            // Arrange
            const string tenantToken = "mock token";

            _firstResolver.Setup(r => r.GetTenantToken()).Returns(Task.FromResult <string>(null));
            _secondResolver.Setup(r => r.GetTenantToken()).Returns(Task.FromResult(tenantToken));
            _thirdResolver.Setup(r => r.GetTenantToken()).Throws <Exception>();
            var firstPair = new TenantIdentificationStrategy(new List <ITenantTokenResolver>()
            {
                _firstResolver.Object
            }, _identifier.Object);
            var secondPair = new TenantIdentificationStrategy(new List <ITenantTokenResolver>()
            {
                _secondResolver.Object
            }, _identifier.Object);
            var thirdPair = new TenantIdentificationStrategy(new List <ITenantTokenResolver>()
            {
                _thirdResolver.Object
            }, _identifier.Object);
            var sut = new DefaultTenantIdentificationService(new List <TenantIdentificationStrategy>()
            {
                firstPair, secondPair, thirdPair
            });

            // Act
            var _ = sut.GetTenantIdAsync().Result;

            // Assert
            _identifier.Verify(i => i.GetTenantIdAsync(It.Is <string>(s => string.Equals(s, tenantToken))), Times.Once());
        }
Example #2
0
        public void Try_Method_Should_Return_Null_If_All_Resolvers_Return_Null()
        {
            // Arrange
            _firstResolver.Setup(r => r.GetTenantToken()).Returns(Task.FromResult <string>(null));
            _secondResolver.Setup(r => r.GetTenantToken()).Returns(Task.FromResult <string>(null));
            _thirdResolver.Setup(r => r.GetTenantToken()).Returns(Task.FromResult <string>(null));
            var identifierPair = new TenantIdentificationStrategy(new List <ITenantTokenResolver>()
            {
                _firstResolver.Object, _secondResolver.Object, _thirdResolver.Object
            }, _identifier.Object);
            var sut = new DefaultTenantIdentificationService(new List <TenantIdentificationStrategy>()
            {
                identifierPair
            });

            // Act
            var result = sut.TryGetTenantIdAsync().Result;

            // Assert
            result.Should().BeNull();
        }
Example #3
0
        public void Should_Throw_TenantNotFoundException_If_All_Resolvers_Return_Null()
        {
            // Arrange
            _firstResolver.Setup(r => r.GetTenantToken()).Returns(Task.FromResult <string>(null));
            _secondResolver.Setup(r => r.GetTenantToken()).Returns(Task.FromResult <string>(null));
            _thirdResolver.Setup(r => r.GetTenantToken()).Returns(Task.FromResult <string>(null));
            var identifierPair = new TenantIdentificationStrategy(new List <ITenantTokenResolver>()
            {
                _firstResolver.Object, _secondResolver.Object, _thirdResolver.Object
            }, _identifier.Object);
            var sut = new DefaultTenantIdentificationService(new List <TenantIdentificationStrategy>()
            {
                identifierPair
            });

            // Act
            Action act = () => Task.WaitAll(sut.GetTenantIdAsync());

            // Assert
            act.Should().Throw <TenantNotFoundException>();
        }