Skip to content
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

Prevent Type property on DataBusProperty<T> from being serialized #6881

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
namespace NServiceBus.AcceptanceTests.DataBus
{
using System.IO;
using System.Threading.Tasks;
using AcceptanceTesting;
using AcceptanceTesting.Customization;
using EndpointTemplates;
using NUnit.Framework;

public class When_sending_databus_properties_with_systemjsonserializer : NServiceBusAcceptanceTest
{
[Test]
public async Task Should_receive_messages_with_largepayload_correctly()
{
var payloadToSend = new byte[PayloadSize];

var context = await Scenario.Define<Context>()
.WithEndpoint<Sender>(b => b.When(session => session.Send(new MyMessageWithLargePayload
{
Payload = new DataBusProperty<byte[]>(payloadToSend)
})))
.WithEndpoint<Receiver>()
.Done(c => c.ReceivedPayload != null)
.Run();

Assert.AreEqual(payloadToSend, context.ReceivedPayload, "The large payload should be marshalled correctly using the databus");
}

const int PayloadSize = 500;

public class Context : ScenarioContext
{
public byte[] ReceivedPayload { get; set; }
}

public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
EndpointSetup<DefaultServer>(builder =>
{
var basePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "databus", "sender");
builder.UseDataBus<FileShareDataBus, SystemJsonDataBusSerializer>().BasePath(basePath);
builder.UseSerialization<SystemJsonSerializer>();
builder.ConfigureRouting().RouteToEndpoint(typeof(MyMessageWithLargePayload), typeof(Receiver));
});
}
}

public class Receiver : EndpointConfigurationBuilder
{
public Receiver()
{
EndpointSetup<DefaultServer>(builder =>
{
var basePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "databus", "sender");
builder.UseDataBus<FileShareDataBus, SystemJsonDataBusSerializer>().BasePath(basePath);
builder.UseSerialization<SystemJsonSerializer>();
});
}

public class MyMessageHandler : IHandleMessages<MyMessageWithLargePayload>
{
public MyMessageHandler(Context context)
{
testContext = context;
}

public Task Handle(MyMessageWithLargePayload messageWithLargePayload, IMessageHandlerContext context)
{
testContext.ReceivedPayload = messageWithLargePayload.Payload.Value;

return Task.CompletedTask;
}

Context testContext;
}
}

public class MyMessageWithLargePayload : ICommand
{
public DataBusProperty<byte[]> Payload { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ namespace NServiceBus
protected DataBusProperty(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public bool HasValue { get; set; }
public string Key { get; set; }
[System.Text.Json.Serialization.JsonIgnore]
public System.Type Type { get; }
public T Value { get; }
public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
Expand Down
2 changes: 2 additions & 0 deletions src/NServiceBus.Core/DataBus/DataBusProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Runtime.Serialization;
using System.Security;
using System.Text.Json.Serialization;

/// <summary>
/// Default implementation for <see cref="IDataBusProperty" />.
Expand Down Expand Up @@ -55,6 +56,7 @@ protected DataBusProperty(SerializationInfo info, StreamingContext context)
/// <summary>
/// The property <see cref="Type" />.
/// </summary>
[JsonIgnore]
public Type Type { get; }

/// <summary>
Expand Down