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

Release 4.0.0 #73

Merged
merged 9 commits into from
Dec 24, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,4 @@ __pycache__/
*.odx.cs
*.xsd.cs
/binaries
/**/ApiApprovals.CompressionPlugin.received.txt
14 changes: 7 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ skip_commits:
- '**/*.md'
- images/*
matrix:
fast_finish: true
fast_finish: true
image: Previous Visual Studio 2017 #Visual Studio 2017 #use workaround image until https://github.com/appveyor/ci/issues/1404 is resolved
environment:
matrix:
# First build
- DotNetRunTime: net461
# Second build
- DotNetRunTime: netcoreapp2.0
- DotNetRunTime: netcoreapp2.1

#---------------------------------#
# restore nuget packages #
#---------------------------------#
before_build:
- cmd: dotnet restore src\ServiceBus.AttachmentPlugin.sln
- cmd: echo %appveyor_build_version%

#---------------------------------#
# build configuration #
#---------------------------------#

# build Configuration, i.e. Debug, Release, etc.
configuration: Release

build:
parallel: true # enable MSBuild parallel builds
project: src\ServiceBus.AttachmentPlugin.sln # path to Visual Studio project
Expand All @@ -48,7 +48,7 @@ after_build:

artifacts:
- path: '**\*.nupkg'
name: 'ServiceBusExplorer-%GitVersion_MajorMinorPatch%'
name: 'ServiceBus.AttachmentPlugin%GitVersion_MajorMinorPatch%.nupkg'

#---------------------------------#
# GitHub PR notifications #
Expand All @@ -66,8 +66,8 @@ notifications:

deploy:
provider: NuGet
api_key:
api_key:
secure: V0wf6IZuvS9d8cJrjEopB+2/4i1z4TrlUhC27y9r+RRt+HYhtxNwK9E+Htkm76bi # encrypted ServiceBus.AttachmentPlugin API key
artifact: /.*\.nupkg/
on:
branch: master
branch: master
18 changes: 18 additions & 0 deletions src/ServiceBus.AttachmentPlugin.Tests/ApiApprovals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ServiceBus.AttachmentPlugin.Tests
{
using PublicApiGenerator;
using Xunit;

public class ApiApprovals
{
[Fact]
public void AzureStorageAttachmentPlugin()
{
var publicApi = ApiGenerator.GeneratePublicApi(typeof(AzureStorageAttachment).Assembly,
whitelistedNamespacePrefixes: new[] { "Microsoft.Azure.ServiceBus." },
excludeAttributes: new[] { "System.Runtime.Versioning.TargetFrameworkAttribute" });

Approver.Verify(publicApi);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("ServiceBus.AttachmentPlugin.Tests")]
namespace Microsoft.Azure.ServiceBus
{
public class AzureStorageAttachmentConfiguration
{
public AzureStorageAttachmentConfiguration(string connectionString, string containerName = "attachments", string messagePropertyToIdentifyAttachmentBlob = "$attachment.blob", System.Func<Microsoft.Azure.ServiceBus.Message, bool> messageMaxSizeReachedCriteria = null) { }
public AzureStorageAttachmentConfiguration(Microsoft.Azure.ServiceBus.IProvideStorageConnectionString connectionStringProvider, string containerName = "attachments", string messagePropertyToIdentifyAttachmentBlob = "$attachment.blob", System.Func<Microsoft.Azure.ServiceBus.Message, bool> messageMaxSizeReachedCriteria = null) { }
}
public class static AzureStorageAttachmentConfigurationExtensions
{
public static Microsoft.Azure.ServiceBus.AzureStorageAttachmentConfiguration WithSasUri(this Microsoft.Azure.ServiceBus.AzureStorageAttachmentConfiguration azureStorageAttachmentConfiguration, string messagePropertyToIdentifySasUri = "$attachment.sas.uri", System.Nullable<System.TimeSpan> sasTokenValidationTime = null) { }
}
public class static AzureStorageAttachmentExtensions
{
public static Microsoft.Azure.ServiceBus.Core.ServiceBusPlugin RegisterAzureStorageAttachmentPlugin(this Microsoft.Azure.ServiceBus.ClientEntity client, Microsoft.Azure.ServiceBus.AzureStorageAttachmentConfiguration configuration) { }
public static Microsoft.Azure.ServiceBus.Core.ServiceBusPlugin RegisterAzureStorageAttachmentPluginForReceivingOnly(this Microsoft.Azure.ServiceBus.ClientEntity client, string messagePropertyToIdentifySasUri = "$attachment.sas.uri") { }
}
public interface IProvideStorageConnectionString
{
System.Threading.Tasks.Task<string> GetConnectionString();
}
public class PlainTextConnectionStringProvider : Microsoft.Azure.ServiceBus.IProvideStorageConnectionString
{
public PlainTextConnectionStringProvider(string connectionString) { }
public System.Threading.Tasks.Task<string> GetConnectionString() { }
}
}
89 changes: 89 additions & 0 deletions src/ServiceBus.AttachmentPlugin.Tests/ApprovalFiles/Approver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Adopted from https://github.com/Particular/Particular.Approvals/blob/master/src/Particular.Approvals/Approver.cs

namespace Xunit
{
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

/// <summary>
/// Verifies that values contain approved content.
/// </summary>
static class Approver
{
static string TestDirectory
{
get
{
var codeBaseUrl = new Uri(Assembly.GetExecutingAssembly().CodeBase);
var codeBasePath = Uri.UnescapeDataString(codeBaseUrl.AbsolutePath);
var dirPath = Path.GetDirectoryName(codeBasePath);
return Path.Combine(dirPath, "..", "..", "..", "ApprovalFiles");
}
}

static readonly string approvalFilesPath = TestDirectory;
static readonly JsonSerializerSettings jsonSerializerSettings;

static Approver()
{
jsonSerializerSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented
};

jsonSerializerSettings.Converters.Add(new StringEnumConverter());
}

/// <summary>
/// Verifies that the received string matches the contents of the corresponding approval file.
/// </summary>
/// <param name="value">The string to verify.</param>
/// <param name="scrubber">A delegate that modifies the received string before comparing it to the approval file.</param>
/// <param name="scenario">A value that will be added to the name of the approval file.</param>
public static void Verify(string value, Func<string, string> scrubber = null, string scenario = null)
{
var st = new StackTrace();
var sf = st.GetFrame(1);
var currentMethodName = sf.GetMethod();

var className = currentMethodName.DeclaringType.Name;
var methodName = currentMethodName.Name;
var scenarioName = string.IsNullOrEmpty(scenario) ? "" : scenario + ".";

if (scrubber != null)
{
value = scrubber(value);
}

var receivedFile = Path.Combine(approvalFilesPath, $"{className}.{methodName}.{scenarioName}received.txt");
File.WriteAllText(receivedFile, value);

var approvedFile = Path.Combine(approvalFilesPath, $"{className}.{methodName}.{scenarioName}approved.txt");
var approvedText = File.ReadAllText(approvedFile);

var normalizedApprovedText = approvedText.Replace("\r\n", "\n");
var normalizedReceivedText = value.Replace("\r\n", "\n");

Assert.Equal(normalizedApprovedText, normalizedReceivedText);

File.Delete(receivedFile);
}

/// <summary>
/// Verifies that the received object, after it has been serialized, matches the contents of the corresponding approval file.
/// </summary>
/// <param name="value">The object to verify.</param>
/// <param name="scrubber">A delegate that modifies the received object, after it has been serialized, before comparing it to the approval file.</param>
/// <param name="scenario">A value that will be added to the name of the approval file.</param>
public static void Verify(object value, Func<string, string> scrubber = null, string scenario = null)
{
var json = JsonConvert.SerializeObject(value, jsonSerializerSettings);

Verify(json, scrubber, scenario);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task Should_apply_defaults_for_missing_arguments()
[Fact]
public void Should_not_accept_negative_token_validation_time()
{
Assert.Throws<ArgumentException>(() =>
Assert.Throws<ArgumentException>(() =>
new AzureStorageAttachmentConfiguration(new PlainTextConnectionStringProvider("connectionString")).WithSasUri(sasTokenValidationTime: TimeSpan.FromHours(-4)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
using Microsoft.Azure.ServiceBus;

public class AzureStorageEmulatorFixture
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<RootNamespace>ServiceBus.AttachmentPlugin.Tests</RootNamespace>
<Optimize>false</Optimize>
</PropertyGroup>

<ItemGroup>
Expand All @@ -15,4 +17,14 @@
<ProjectReference Include="..\ServiceBus.AttachmentPlugin\ServiceBus.AttachmentPlugin.csproj" />
</ItemGroup>

<ItemGroup Label="API Approvals">
<PackageReference Include="PublicApiGenerator" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="[12.0.1, 13.0.0)" />
<None Remove="ApprovalFiles\ApiApprovals.CompressionPlugin.received.txt" />
</ItemGroup>

<ItemGroup Label="Force the latest of the transitive dependency">
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="3.2.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public override void UnregisterPlugin(string serviceBusPluginName)
RegisteredPlugins.Remove(toRemove);
}

public override string Path { get; }
public override TimeSpan OperationTimeout { get; set; }
public override ServiceBusConnection ServiceBusConnection { get; }
public override IList<ServiceBusPlugin> RegisteredPlugins { get; }

protected override Task OnClosingAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public override void UnregisterPlugin(string serviceBusPluginName)
RegisteredPlugins.Remove(toRemove);
}

public override string Path { get; }
public override TimeSpan OperationTimeout { get; set; }
public override ServiceBusConnection ServiceBusConnection { get; }
public override IList<ServiceBusPlugin> RegisteredPlugins { get; }

protected override Task OnClosingAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ public async Task Should_download_attachment_using_provided_from_sas_uri()
MessageId = Guid.NewGuid().ToString(),
};
var plugin = new AzureStorageAttachment(new AzureStorageAttachmentConfiguration(
connectionStringProvider: AzureStorageEmulatorFixture.ConnectionStringProvider,
containerName: "attachments",
messagePropertyToIdentifyAttachmentBlob:
connectionStringProvider: AzureStorageEmulatorFixture.ConnectionStringProvider,
containerName: "attachments",
messagePropertyToIdentifyAttachmentBlob:
"attachment-id")
.WithSasUri(
sasTokenValidationTime: TimeSpan.FromHours(4),
sasTokenValidationTime: TimeSpan.FromHours(4),
messagePropertyToIdentifySasUri: "mySasUriProperty"));
await plugin.BeforeMessageSend(message);

var messageReceiver = new MessageReceiver(new ServiceBusConnectionStringBuilder(
endpoint: "sb://test.servicebus.windows.net/",
entityPath: "entity",
sharedAccessKey: "---",
endpoint: "sb://test.servicebus.windows.net/",
entityPath: "entity",
sharedAccessKey: "---",
sharedAccessKeyName: "RootManageSharedAccessKey"));
messageReceiver.RegisterAzureStorageAttachmentPluginForReceivingOnly("mySasUriProperty");
var receiveOnlyPlugin = messageReceiver.RegisteredPlugins[0];
Expand Down
6 changes: 3 additions & 3 deletions src/ServiceBus.AttachmentPlugin/AzureStorageAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override async Task<Message> BeforeMessageSend(Message message)
await InitializeClient().ConfigureAwait(false);

var container = client.GetContainerReference(configuration.ContainerName);

if (! await container.ExistsAsync().ConfigureAwait(false))
{
await container.CreateIfNotExistsAsync().ConfigureAwait(false);
Expand All @@ -73,7 +73,7 @@ public override async Task<Message> BeforeMessageSend(Message message)
return message;
}

bool AttachmentBlobAssociated(IDictionary<string, object> messageUserProperties) =>
bool AttachmentBlobAssociated(IDictionary<string, object> messageUserProperties) =>
messageUserProperties.TryGetValue(configuration.MessagePropertyToIdentifyAttachmentBlob, out var _);

async Task InitializeClient()
Expand Down Expand Up @@ -143,7 +143,7 @@ public override async Task<Message> AfterMessageReceive(Message message)
await InitializeClient().ConfigureAwait(false);

var container = client.GetContainerReference(configuration.ContainerName);

if (! await container.ExistsAsync().ConfigureAwait(false))
{
await container.CreateIfNotExistsAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace ServiceBus.AttachmentPlugin
namespace Microsoft.Azure.ServiceBus
{
using System;
using Microsoft.Azure.ServiceBus;

/// <summary>Runtime configuration for <see cref="AzureStorageAttachment"/> plugin.</summary>
/// <summary>Runtime configuration for Azure Storage Attachment plugin.</summary>
public class AzureStorageAttachmentConfiguration
{
/// <summary>Constructor to create new configuration object.</summary>
Expand All @@ -15,7 +14,7 @@ public AzureStorageAttachmentConfiguration(
string connectionString,
string containerName = "attachments",
string messagePropertyToIdentifyAttachmentBlob = "$attachment.blob",
Func<Message, bool> messageMaxSizeReachedCriteria = null)
Func<Message, bool> messageMaxSizeReachedCriteria = null)
: this(new PlainTextConnectionStringProvider(connectionString), containerName, messagePropertyToIdentifyAttachmentBlob, messageMaxSizeReachedCriteria)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace ServiceBus.AttachmentPlugin
namespace Microsoft.Azure.ServiceBus
{
using System;
using Microsoft.Azure.ServiceBus;

/// <summary>
/// Extension method for setting up the SAS uri configuration.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ServiceBus.AttachmentPlugin
namespace Microsoft.Azure.ServiceBus
{
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.ServiceBus.Core;
using Core;
using global::ServiceBus.AttachmentPlugin;

/// <summary>Service Bus plugin to send large messages using attachments stored as Azure Storage blobs.</summary>
public static class AzureStorageAttachmentExtensions
Expand Down
Loading