-
-
Notifications
You must be signed in to change notification settings - Fork 94
filter non serialisable custom attributes from service bus messages #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
adba5d4
112b130
33d36e0
02ff0ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using System; | ||
| using System.IO; | ||
|
|
||
| namespace Eventuous.Azure.ServiceBus.Shared; | ||
|
|
||
| public static class ServiceBusHelper | ||
| { | ||
| public static bool IsSerialisableByServiceBus(object? value) => | ||
| value is not null && ( | ||
| value is string || | ||
| value is bool || | ||
| value is byte || | ||
| value is sbyte || | ||
| value is short || | ||
| value is ushort || | ||
| value is int || | ||
| value is uint || | ||
| value is long || | ||
| value is ulong || | ||
| value is float || | ||
| value is double || | ||
| value is decimal || | ||
| value is char || | ||
| value is Guid || | ||
| value is DateTime || | ||
| value is DateTimeOffset || | ||
| value is Stream || | ||
alexeyzimarev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| value is Uri || | ||
| value is TimeSpan | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using static Eventuous.Azure.ServiceBus.Shared.ServiceBusHelper; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Eventuous.Tests.Azure.ServiceBus; | ||
|
|
||
| public class IsSerialisableByServiceBus { | ||
| public static IEnumerable<Func<object?>> PassingTestData() { | ||
|
Check warning on line 7 in src/Azure/test/Eventuous.Tests.Azure.ServiceBus/IsSerialisableByServiceBus.cs
|
||
| yield return () => "string"; | ||
| yield return () => 123; // int | ||
| yield return () => 123L; // long | ||
| yield return () => (short)1; | ||
| yield return () => (byte)1; | ||
| yield return () => 123u; // uint | ||
| yield return () => 123UL; // ulong | ||
| yield return () => 1.23f; // float | ||
| yield return () => 1.23d; // double | ||
| yield return () => 12.34m; // decimal | ||
| yield return () => true; // bool | ||
| yield return () => 'c'; // char | ||
| yield return () => Guid.NewGuid(); | ||
| yield return () => DateTime.UtcNow; | ||
| yield return () => DateTimeOffset.UtcNow; | ||
| yield return () => TimeSpan.FromMinutes(5); | ||
| yield return () => new Uri("https://example.com"); | ||
| yield return () => new MemoryStream(); // Stream | ||
| } | ||
|
|
||
| public static IEnumerable<Func<object?>> FailingTestData() { | ||
|
Check warning on line 28 in src/Azure/test/Eventuous.Tests.Azure.ServiceBus/IsSerialisableByServiceBus.cs
|
||
| yield return () => null; | ||
| yield return () => new object(); // plain object | ||
| yield return () => new Dictionary<object, string> { [new object()] = "v" }; // dictionary with non-string key | ||
| yield return () => new Dictionary<string, object> { ["k"] = new object() }; // dictionary with non-serializable value | ||
| yield return () => new List<object> { new() }; // list with non-serializable item | ||
| yield return () => Task.CompletedTask; // Task | ||
| yield return () => new Action(() => { }); // delegate | ||
| yield return () => new WeakReference(new object()); // complex type | ||
| } | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(PassingTestData))] | ||
| public async Task Passes(object value) => await Assert.That(IsSerialisableByServiceBus(value)).IsTrue(); | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(FailingTestData))] | ||
alexeyzimarev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public async Task Fails(object value) => await Assert.That(IsSerialisableByServiceBus(value)).IsFalse(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.