public void Test_Configuration_MsiValidation()
        {
            // Arrange
            var msiConfig = new MsiConfig();

            // Act/Assert - Check the msi config validation.
            var validationRes = msiConfig.Validate();

            validationRes.IsValid.Should().BeFalse();
            validationRes.Errors.ToList().Count.Should().Be(4);

            msiConfig.InstanceName = "test";
            validationRes          = msiConfig.Validate();
            validationRes.IsValid.Should().BeFalse();
            validationRes.Errors.ToList().Count.Should().Be(3);

            msiConfig.TenantId = "test";
            validationRes      = msiConfig.Validate();
            validationRes.IsValid.Should().BeFalse();
            validationRes.Errors.ToList().Count.Should().Be(2);

            msiConfig.DatabaseName = "test";
            validationRes          = msiConfig.Validate();
            validationRes.IsValid.Should().BeFalse();
            validationRes.Errors.ToList().Count.Should().Be(1);

            msiConfig.SubscriptionId = "test";
            validationRes            = msiConfig.Validate();
            validationRes.IsValid.Should().BeTrue();
            validationRes.Errors.ToList().Count.Should().Be(0);
            msiConfig.ToString().Length.Should().BeGreaterThan(0);
        }
        public void Test_KeyVault_MsiConfigValidate()
        {
            // Arrange
            var msiConfigGood = new MsiConfig {
                KeyVaultInstanceName = "test"
            };
            var msiConfigBad    = new MsiConfig();
            var msiConfigString = msiConfigGood.ToString();

            // Act/Assert
            AssertExtensions.DoesNotThrow(() => msiConfigGood.Validate());
            var validationResult = msiConfigGood.Validate();

            validationResult.IsValid.Should().BeTrue();
            validationResult.Errors.Count().Should().Be(0);

            validationResult = msiConfigBad.Validate();
            validationResult.IsValid.Should().BeFalse();
            validationResult.Errors.Count().Should().Be(1);

            msiConfigBad.KeyVaultInstanceName = "test";
            validationResult = msiConfigBad.Validate();
            validationResult.IsValid.Should().BeTrue();
            validationResult.Errors.Count().Should().Be(0);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of ServiceBusMessenger with Managed Service Identity (MSI) authentication.
        /// </summary>
        /// <param name="config">The Msi ServiceBus configuration.</param>
        /// <param name="logger">The logger.</param>
        public ServiceBusMessenger([NotNull] MsiConfig config, ILogger logger = null)
        {
            // Ensure all required configuration is as expected.
            config.Validate();
            Name = config.InstanceName;

            Logger     = logger;
            _msiConfig = config;
            Config     = config;
        }
예제 #4
0
        public void Test_MsiConfig_Validate()
        {
            // Arrange
            var msiConfig = new MsiConfig()
            {
                SharedAccessPolicyName = ""
            };

            // Act/Assert - Check the msi config validation.
            Assert.Throws <ArgumentException>(() => msiConfig.Validate());
            msiConfig.InstanceName = "test";
            Assert.Throws <ArgumentException>(() => msiConfig.Validate());
            msiConfig.TenantId = "test";
            Assert.Throws <ArgumentException>(() => msiConfig.Validate());
            msiConfig.SubscriptionId = "test";
            Assert.Throws <ArgumentException>(() => msiConfig.Validate());
            msiConfig.SharedAccessPolicyName = "test";
            AssertExtensions.DoesNotThrow(() => msiConfig.Validate());
            msiConfig.ToString().Should().NotBeNullOrEmpty();
        }