/// <summary> /// Initializes a new instance of the <see cref="PubSubMessenger"/> class. /// </summary> /// <param name="config">The configuration.</param> /// <param name="logger">The logger.</param> public PubSubMessenger([NotNull] PubSubJsonAuthConfig config, ILogger logger = null) { // Validate configuration and throw if invalid. config.ThrowIfInvalid(); Config = config; _logger = logger; _jsonAuthFile = config.JsonAuthFile; Name = config.ProjectId; }
public void Test_PubSubJsonAuthConfig_ToStringFunctionalityNotSet() { // Arrange var config = new PubSubJsonAuthConfig() { JsonAuthFile = "fileLocation", ProjectId = "12345" }; // Act var str = config.ToString(); // Assert str.Should().Be("Auth (jsonFile): fileLocation, ProjectId:12345, ReceiverInfo: [NOT SET], SenderInfo: [NOT SET]"); }
public void Test_JsonAuthConfig_Validate() { // Arrange var invalidConfig1 = new PubSubJsonAuthConfig(); var invalidConfig2 = new PubSubJsonAuthConfig { ProjectId = "test" }; var validConfig = new PubSubJsonAuthConfig { ProjectId = "test", JsonAuthFile = "test" }; // Act/Assert Assert.Throws <ValidateException>(() => invalidConfig1.ThrowIfInvalid()); Assert.Throws <ValidateException>(() => invalidConfig2.ThrowIfInvalid()); AssertExtensions.DoesNotThrow(() => validConfig.ThrowIfInvalid()); }
/// <summary> /// Adds the Gcp Pub/Sub singleton with Json Auth Config. /// </summary> /// <param name="services">The services.</param> /// <param name="config">The configuration.</param> /// <returns>IServiceCollection.</returns> public static IServiceCollection AddPubSubSingleton(this IServiceCollection services, PubSubJsonAuthConfig config) { return(services.AddPubSubSingletonNamed <PubSubMessenger>(null, config)); }
/// <summary> /// Adds the Gcp Pub/Sub singleton. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="services">The services.</param> /// <param name="config">The json auth configuration.</param> /// <returns>ServiceCollection.</returns> public static IServiceCollection AddPubSubSingleton <T>(this IServiceCollection services, PubSubJsonAuthConfig config) where T : IMessageOperations { return(services.AddPubSubSingletonNamed <T>(null, config)); }
/// <summary> /// Add instance of Gcp PubSub (with messaging interface), with JsonAuth config, to the service collection with the NamedInstance factory. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="services">Service collection to extend</param> /// <param name="key">Key to identify the named instance of the PubSub singleton.</param> /// <param name="config">Configuration</param> /// <returns>Modified service collection with the IReactiveMessenger, IMessenger and NamedInstanceFactory{T} configured.</returns> public static IServiceCollection AddPubSubSingletonNamed <T>(this IServiceCollection services, string key, PubSubJsonAuthConfig config) where T : IMessageOperations { return(AddNamedInstance <T>(services, key, new PubSubMessenger(config))); }