/// <summary> /// Initializes a new instance of ServiceBusMessenger with Service Principle authentication. /// </summary> /// <param name="config">The Service Principle configuration.</param> /// <param name="logger">The logger.</param> public ServiceBusMessenger([NotNull] ServicePrincipleConfig config, ILogger logger = null) { // Ensure all required configuration is as expected. config.Validate(); Name = config.InstanceName; Logger = logger; _spConfig = config; Config = config; }
public void Test_KeyVault_ServicePrincipleConfigValidate() { // Arrange var spConfigGood = new ServicePrincipleConfig { KeyVaultInstanceName = "test", AppSecret = "test", TenantId = "test", AppId = "test" }; var spConfigBad = new ServicePrincipleConfig(); var spConfigString = spConfigGood.ToString(); // Act/Assert AssertExtensions.DoesNotThrow(() => spConfigGood.Validate()); var validationResult = spConfigBad.Validate(); validationResult.IsValid.Should().BeFalse(); validationResult.Errors.Count().Should().Be(4); spConfigBad.KeyVaultInstanceName = "test"; validationResult = spConfigBad.Validate(); validationResult.IsValid.Should().BeFalse(); validationResult.Errors.Count().Should().Be(3); spConfigBad.AppId = "test"; validationResult = spConfigBad.Validate(); validationResult.IsValid.Should().BeFalse(); validationResult.Errors.Count().Should().Be(2); spConfigBad.AppSecret = "test"; validationResult = spConfigBad.Validate(); validationResult.IsValid.Should().BeFalse(); validationResult.Errors.Count().Should().Be(1); spConfigBad.TenantId = "test"; validationResult = spConfigBad.Validate(); validationResult.IsValid.Should().BeTrue(); validationResult.Errors.Count().Should().Be(0); }
public void Test_Configuration_ServicePrincipleValidation() { // Arrange var spConfig = new ServicePrincipleConfig(); // Act/Assert var validationRes = spConfig.Validate(); validationRes.IsValid.Should().BeFalse(); validationRes.Errors.ToList().Count.Should().Be(6); spConfig.InstanceName = "test"; validationRes = spConfig.Validate(); validationRes.IsValid.Should().BeFalse(); validationRes.Errors.ToList().Count.Should().Be(5); spConfig.AppId = "test"; validationRes = spConfig.Validate(); validationRes.IsValid.Should().BeFalse(); validationRes.Errors.ToList().Count.Should().Be(4); spConfig.AppSecret = "test"; validationRes = spConfig.Validate(); validationRes.IsValid.Should().BeFalse(); validationRes.Errors.ToList().Count.Should().Be(3); spConfig.TenantId = "test"; validationRes = spConfig.Validate(); validationRes.IsValid.Should().BeFalse(); validationRes.Errors.ToList().Count.Should().Be(2); spConfig.DatabaseName = "test"; validationRes = spConfig.Validate(); validationRes.IsValid.Should().BeFalse(); validationRes.Errors.ToList().Count.Should().Be(1); spConfig.SubscriptionId = "test"; validationRes = spConfig.Validate(); validationRes.IsValid.Should().BeTrue(); validationRes.Errors.ToList().Count.Should().Be(0); spConfig.ToString().Length.Should().BeGreaterThan(0); }
public void Test_ervicePrincipleConfig_Validate() { // Arrange var spConfig = new ServicePrincipleConfig() { SharedAccessPolicyName = "" }; // Act/Assert - Check the service Principle config validation. Assert.Throws <ArgumentException>(() => spConfig.Validate()); spConfig.InstanceName = "test"; Assert.Throws <ArgumentException>(() => spConfig.Validate()); spConfig.AppId = "test"; Assert.Throws <ArgumentException>(() => spConfig.Validate()); spConfig.AppSecret = "test"; Assert.Throws <ArgumentException>(() => spConfig.Validate()); spConfig.TenantId = "test"; Assert.Throws <ArgumentException>(() => spConfig.Validate()); spConfig.SubscriptionId = "test"; Assert.Throws <ArgumentException>(() => spConfig.Validate()); spConfig.SharedAccessPolicyName = "test"; AssertExtensions.DoesNotThrow(() => spConfig.Validate()); spConfig.ToString().Should().NotBeNullOrEmpty(); }