public void CreateEventSenderCreatesDefaultWhenOptionsAreNotSet() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var senderOptions = new SenderOptions { PartitionId = "123", Retry = null, Timeout = TimeSpan.Zero }; var expected = new SenderOptions { PartitionId = senderOptions.PartitionId, Retry = clientOptions.Retry, Timeout = clientOptions.DefaultTimeout }; var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, clientOptions); mockClient.CreateSender(senderOptions); Assert.That(mockClient.SenderOptions, Is.Not.Null, "The sender options should have been set."); Assert.That(mockClient.SenderOptions, Is.Not.SameAs(senderOptions), "The options should have been cloned."); Assert.That(mockClient.SenderOptions.PartitionId, Is.EqualTo(expected.PartitionId), "The partition identifiers should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)mockClient.SenderOptions.Retry, (ExponentialRetry)expected.Retry), "The retries should match."); Assert.That(mockClient.SenderOptions.TimeoutOrDefault, Is.EqualTo(expected.TimeoutOrDefault), "The timeouts should match."); }
/// <summary> /// Add mail services into service collection object /// </summary> /// <param name="services">Service collection object</param> /// <param name="configuration">Configuration parameters object</param> public static IServiceCollection AddMailServices(this IServiceCollection services, IConfiguration configuration) { services.Configure <SmtpOptions>(options => configuration.GetSection("Sender:Smtp").Bind(options)); services.Configure <SendGridOptions>(options => configuration.GetSection("Sender:SendGrid").Bind(options)); services.Configure <RedirectToOptions>(options => configuration.GetSection("Sender:RedirectTo").Bind(options)); services.Configure <SenderOptions>(options => configuration.GetSection("Sender").Bind(options)); services.Configure <CultureOptions>(options => configuration.GetSection("Application:Culture").Bind(options)); services.AddScoped <IMailRepository, MailRepository>(); services.AddScoped <IMailService, MailService>(); SenderOptions options = new SenderOptions(); configuration.Bind("Sender", options); switch (options.Type) { case SenderType.Smtp: //BACKLOG: NotImplementedException throw new NotImplementedException(); break; case SenderType.SendGrid: services.AddScoped <ISender, SendGridSender>(); services.AddScoped <ISendGridClient>(s => new SendGridClient(options.SendGrid.AppKey)); break; } return(services); }
public void CreateEventSenderCreatesDefaultWhenNoOptionsArePassed() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expected = new SenderOptions { Retry = clientOptions.Retry, Timeout = clientOptions.DefaultTimeout }; var actual = default(SenderOptions); var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new Mock <EventHubClient>(connectionString, clientOptions) { CallBase = true }; mockClient .Protected() .Setup <EventSender>("BuildEventSender", ItExpr.IsAny <ConnectionType>(), ItExpr.IsAny <string>(), ItExpr.IsAny <SenderOptions>()) .Returns(Mock.Of <EventSender>()) .Callback <ConnectionType, string, SenderOptions>((type, path, options) => actual = options); mockClient.Object.CreateSender(); Assert.That(actual, Is.Not.Null, "The sender options should have been set."); Assert.That(actual.PartitionId, Is.EqualTo(expected.PartitionId), "The partition identifiers should match."); Assert.That(actual.Retry, Is.EqualTo(expected.Retry), "The retries should match."); Assert.That(actual.TimeoutOrDefault, Is.EqualTo(expected.TimeoutOrDefault), "The timeouts should match."); }
public void DefaultTimeoutUsesDefaultValueIfNormalizesValueINotSpecified(int?noTimeoutValue) { var options = new SenderOptions(); var timeoutValue = (noTimeoutValue.HasValue) ? TimeSpan.Zero : (TimeSpan?)null; options.Timeout = timeoutValue; Assert.That(options.Timeout, Is.EqualTo(timeoutValue), "The value supplied by the caller should be preserved."); Assert.That(options.TimeoutOrDefault, Is.Null, "The timeout value should be normalized to null internally."); }
protected void CreateSender() { var options = new SenderOptions { Name = messageConfig.AnalysisQueue, QueueName = messageConfig.AnalysisQueue, QueueType = QueueType.ExchangeFanout }; sender = connection.CreateSenderChannel(options); }
public void CloneProducesACopy() { var options = new SenderOptions { PartitionId = "some_partition_id_123", Retry = new ExponentialRetry(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(5), 6), Timeout = TimeSpan.FromMinutes(65) }; var clone = options.Clone(); Assert.That(clone, Is.Not.Null, "The clone should not be null."); Assert.That(clone.PartitionId, Is.EqualTo(options.PartitionId), "The partition identifier of the clone should match."); Assert.That(clone.Timeout, Is.EqualTo(options.Timeout), "The timeout of the clone should match."); Assert.That(clone.Retry, Is.EqualTo(options.Retry), "The retry of the clone should be considered equal."); Assert.That(clone.Retry, Is.Not.SameAs(options.Retry), "The retry of the clone should be a copy, not the same instance."); }
public void ParsesEqualsIntAsString() { Assert.AreEqual(ValueTuple.Create("key", "42"), SenderOptions.ParseItem("key=42")); }
public void ParseTildeStringAsString() { Assert.AreEqual(ValueTuple.Create("key", "aString"), SenderOptions.ParseItem("key~aString")); }
public void ParsesTildeIntAsInt() { Assert.AreEqual(ValueTuple.Create("key", 42), SenderOptions.ParseItem("key~42")); }
public void ParsesTildeDoubleAsDouble() { Assert.AreEqual(ValueTuple.Create("key", 3.14d), SenderOptions.ParseItem("key~3.14")); }
public void ParsesTildeBoolAsBool() { Assert.AreEqual(ValueTuple.Create("key", false), SenderOptions.ParseItem("key~False")); }
public void ParsesEmptyEqualsAsEmptyStringKey() { Assert.AreEqual(ValueTuple.Create("", "aString"), SenderOptions.ParseItem("=aString")); }
public void ParsesTildeEmptyAsNull() { Assert.AreEqual(ValueTuple.Create("key", (String)null), SenderOptions.ParseItem("key~")); }
public void ParsesDoubleEqualsAsString() { Assert.AreEqual(ValueTuple.Create("key", "=1"), SenderOptions.ParseItem("key==1")); }
public void ParsesEqualsEmptyAsEmptyString() { Assert.AreEqual(ValueTuple.Create("key", ""), SenderOptions.ParseItem("key=")); }
internal override EventSender BuildEventSender(TransportType connectionType, string eventHubPath, SenderOptions options) { SenderOptions = options; return base.BuildEventSender(connectionType, eventHubPath, options); }
public void ParsesEqualsTildeAsString() { Assert.AreEqual(ValueTuple.Create("key", "~1"), SenderOptions.ParseItem("key=~1")); }
public void ParsesTildeIntAsInt() { Assert.AreEqual(42, SenderOptions.ParseValue("~42")); }
public void ParsesDoubleTildeAsString() { Assert.AreEqual("~", SenderOptions.ParseValue("~~")); }
public void ParsesTildeAsNull() { Assert.AreEqual(null, SenderOptions.ParseValue("~")); }
public void ParsesEmptyStringAsEmptyString() { Assert.AreEqual(string.Empty, SenderOptions.ParseValue("")); }
public void ThrowsOnEmptyString() { Assert.Throws <ArgumentException>(() => SenderOptions.ParseItem("")); }