-
Notifications
You must be signed in to change notification settings - Fork 865
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dynamodb_remove_assembly_scanning' of https://github.co…
…m/Dreamescaper/aws-sdk-net into Dreamescaper-dynamodb_remove_assembly_scanning
- Loading branch information
Showing
2 changed files
with
115 additions
and
39 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
71 changes: 71 additions & 0 deletions
71
sdk/test/Services/DynamoDBv2/UnitTests/Custom/DynamoDBEntryConversionTests.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,71 @@ | ||
using Amazon.DynamoDBv2; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace AWSSDK_DotNet35.UnitTests | ||
{ | ||
[TestClass] | ||
public class DynamoDBEntryConversionTests | ||
{ | ||
[TestMethod] | ||
public void ValidateAllConvertersAreRegisteredForConversionV1() | ||
{ | ||
AssertAllConvertersAreRegistered(DynamoDBEntryConversion.V1, "ConverterV1"); | ||
} | ||
|
||
[TestMethod] | ||
public void ValidateAllConvertersAreRegisteredForConversionV2() | ||
{ | ||
AssertAllConvertersAreRegistered(DynamoDBEntryConversion.V2, "ConverterV2"); | ||
} | ||
|
||
private void AssertAllConvertersAreRegistered(DynamoDBEntryConversion conversion, string suffix) | ||
{ | ||
var converters = GetConverters(suffix); | ||
|
||
var tryGetConverterInfo = conversion.GetType().GetMethod("TryGetConverter", BindingFlags.NonPublic | BindingFlags.Instance); | ||
|
||
foreach (var converter in converters) | ||
{ | ||
var getTargetTypeInfo = converter.GetType().GetMethod("GetTargetTypes"); | ||
IEnumerable<Type> targetTypes = (IEnumerable<Type>)getTargetTypeInfo.Invoke(converter, new object[0]); | ||
foreach (var type in targetTypes) | ||
{ | ||
var tryGetConverterParams = new object[] { type, null }; | ||
tryGetConverterInfo.Invoke(conversion, tryGetConverterParams); | ||
var registeredConverter = tryGetConverterParams[1]; | ||
|
||
Assert.IsNotNull(registeredConverter); | ||
Assert.AreEqual(converter.GetType(), registeredConverter.GetType()); | ||
} | ||
} | ||
} | ||
|
||
private IEnumerable<object> GetConverters(string suffix) | ||
{ | ||
const string converterTypeName = "Amazon.DynamoDBv2.Converter"; | ||
var assembly = typeof(DynamoDBEntryConversion).Assembly; | ||
|
||
var allTypes = assembly.GetTypes(); | ||
var typedConverterType = allTypes.FirstOrDefault(x => string.Equals(converterTypeName, x.FullName)); | ||
|
||
foreach (var type in allTypes) | ||
{ | ||
if (type.IsAbstract) | ||
continue; | ||
|
||
if (!type.Name.EndsWith(suffix, StringComparison.Ordinal)) | ||
continue; | ||
|
||
if (!typedConverterType.IsAssignableFrom(type)) | ||
continue; | ||
|
||
var constructor = type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null); | ||
yield return constructor.Invoke(new object[0]); | ||
} | ||
} | ||
} | ||
} |