-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,3 +287,4 @@ __pycache__/ | |
*.odx.cs | ||
*.xsd.cs | ||
/binaries | ||
/**/ApiApprovals.CompressionPlugin.received.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 CompressionPlugin() | ||
{ | ||
var publicApi = ApiGenerator.GeneratePublicApi(typeof(AzureStorageAttachment).Assembly, | ||
whitelistedNamespacePrefixes: new[] { "Microsoft.Azure.ServiceBus." }, | ||
excludeAttributes: new[] { "System.Runtime.Versioning.TargetFrameworkAttribute" }); | ||
|
||
Approver.Verify(publicApi); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...rviceBus.AttachmentPlugin.Tests/ApprovalFiles/ApiApprovals.CompressionPlugin.approved.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
89
src/ServiceBus.AttachmentPlugin.Tests/ApprovalFiles/Approver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters