Skip to content

Commit f60ca34

Browse files
Move MessageContent into Azure.Core (Azure#27700)
* Move MessageContent into Azure.Core * Update test * snippetse * PR fb * Add additional assertions
1 parent e7279f5 commit f60ca34

16 files changed

+165
-73
lines changed

sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
namespace Azure
22
{
3-
public partial class BinaryContent
4-
{
5-
public BinaryContent() { }
6-
public virtual Azure.Core.ContentType? ContentType { get { throw null; } set { } }
7-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
8-
protected virtual Azure.Core.ContentType? ContentTypeCore { get { throw null; } set { } }
9-
public virtual System.BinaryData? Data { get { throw null; } set { } }
10-
public virtual bool IsReadOnly { get { throw null; } }
11-
}
123
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
134
public readonly partial struct Value
145
{

sdk/core/Azure.Core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
- Added the `MessageContent` type which represents a message containing a content type and data.
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/core/Azure.Core/api/Azure.Core.net461.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,4 +1021,13 @@ public enum CloudEventDataFormat
10211021
Binary = 0,
10221022
Json = 1,
10231023
}
1024+
public partial class MessageContent
1025+
{
1026+
public MessageContent() { }
1027+
public virtual Azure.Core.ContentType? ContentType { get { throw null; } set { } }
1028+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
1029+
protected virtual Azure.Core.ContentType? ContentTypeCore { get { throw null; } set { } }
1030+
public virtual System.BinaryData? Data { get { throw null; } set { } }
1031+
public virtual bool IsReadOnly { get { throw null; } }
1032+
}
10241033
}

sdk/core/Azure.Core/api/Azure.Core.net5.0.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,4 +1021,13 @@ public enum CloudEventDataFormat
10211021
Binary = 0,
10221022
Json = 1,
10231023
}
1024+
public partial class MessageContent
1025+
{
1026+
public MessageContent() { }
1027+
public virtual Azure.Core.ContentType? ContentType { get { throw null; } set { } }
1028+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
1029+
protected virtual Azure.Core.ContentType? ContentTypeCore { get { throw null; } set { } }
1030+
public virtual System.BinaryData? Data { get { throw null; } set { } }
1031+
public virtual bool IsReadOnly { get { throw null; } }
1032+
}
10241033
}

sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,4 +1021,13 @@ public enum CloudEventDataFormat
10211021
Binary = 0,
10221022
Json = 1,
10231023
}
1024+
public partial class MessageContent
1025+
{
1026+
public MessageContent() { }
1027+
public virtual Azure.Core.ContentType? ContentType { get { throw null; } set { } }
1028+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
1029+
protected virtual Azure.Core.ContentType? ContentTypeCore { get { throw null; } set { } }
1030+
public virtual System.BinaryData? Data { get { throw null; } set { } }
1031+
public virtual bool IsReadOnly { get { throw null; } }
1032+
}
10241033
}

sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,4 +1021,13 @@ public enum CloudEventDataFormat
10211021
Binary = 0,
10221022
Json = 1,
10231023
}
1024+
public partial class MessageContent
1025+
{
1026+
public MessageContent() { }
1027+
public virtual Azure.Core.ContentType? ContentType { get { throw null; } set { } }
1028+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
1029+
protected virtual Azure.Core.ContentType? ContentTypeCore { get { throw null; } set { } }
1030+
public virtual System.BinaryData? Data { get { throw null; } set { } }
1031+
public virtual bool IsReadOnly { get { throw null; } }
1032+
}
10241033
}

sdk/core/Azure.Core.Experimental/src/BinaryContent.cs renamed to sdk/core/Azure.Core/src/Messaging/MessageContent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
using System.ComponentModel;
66
using Azure.Core;
77

8-
namespace Azure
8+
namespace Azure.Messaging
99
{
1010
/// <summary>
11-
/// Content containing a content type along with its data.
11+
/// The content of a message containing a content type along with the message data.
1212
/// </summary>
13-
public class BinaryContent
13+
public class MessageContent
1414
{
1515
/// <summary>
1616
/// Gets or sets the data.
@@ -35,7 +35,7 @@ public virtual ContentType? ContentType
3535
protected virtual ContentType? ContentTypeCore { get; set; }
3636

3737
/// <summary>
38-
/// Gets whether the content is read only or not. This
38+
/// Gets whether the message is read only or not. This
3939
/// can be overriden by inheriting classes to specify whether or
4040
/// not the message can be modified.
4141
/// </summary>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using Azure.Messaging;
6+
using NUnit.Framework;
7+
8+
namespace Azure.Core.Tests
9+
{
10+
public class MessageContentTests
11+
{
12+
[Test]
13+
public void CanCreateMessageContent()
14+
{
15+
var messageContent = new MessageContent
16+
{
17+
ContentType = ContentType.ApplicationJson,
18+
Data = new BinaryData("data")
19+
};
20+
21+
Assert.AreEqual(ContentType.ApplicationJson, messageContent.ContentType);
22+
Assert.AreEqual("data", messageContent.Data.ToString());
23+
Assert.IsFalse(messageContent.IsReadOnly);
24+
}
25+
26+
[Test]
27+
public void CanUseDerivedMessageContent()
28+
{
29+
var messageContent = new DerivedMessageContent
30+
{
31+
Data = new BinaryData("data")
32+
};
33+
34+
// we can cast to base type to use the ContentType struct property
35+
((MessageContent) messageContent).ContentType = ContentType.ApplicationJson;
36+
37+
Assert.AreEqual(ContentType.ApplicationJson, messageContent.ContentType);
38+
Assert.AreEqual("data", messageContent.Data.ToString());
39+
40+
// we can also use the derived type string property
41+
messageContent.ContentType = ContentType.ApplicationJson.ToString();
42+
Assert.AreEqual(ContentType.ApplicationJson, messageContent.ContentType);
43+
44+
Assert.IsTrue(messageContent.IsReadOnly);
45+
}
46+
}
47+
48+
#pragma warning disable SA1402
49+
internal class DerivedMessageContent : MessageContent
50+
#pragma warning restore SA1402
51+
{
52+
public new string ContentType { get; set; }
53+
54+
protected override ContentType? ContentTypeCore
55+
{
56+
get => new ContentType(ContentType);
57+
set => ContentType = value.ToString();
58+
}
59+
60+
public override bool IsReadOnly => true;
61+
}
62+
}

sdk/eventhub/Azure.Messaging.EventHubs/api/Azure.Messaging.EventHubs.netstandard2.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Azure.Messaging.EventHubs
22
{
3-
public partial class EventData : Azure.BinaryContent
3+
public partial class EventData : Azure.Messaging.MessageContent
44
{
55
public EventData() { }
66
public EventData(System.BinaryData eventBody) { }

sdk/eventhub/Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
<PackageReference Include="Azure.Core" />
2222
-->
2323
<!-- END TEMP -->
24-
<PackageReference Include="Azure.Core.Experimental" />
25-
24+
<ProjectReference Include="..\..\..\core\Azure.Core\src\Azure.Core.csproj" />
2625
<PackageReference Include="Azure.Core.Amqp" />
2726
<PackageReference Include="Microsoft.Azure.Amqp" />
2827
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />

0 commit comments

Comments
 (0)