-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5eac143
commit 4e52f89
Showing
24 changed files
with
293 additions
and
703 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
tests/LocalStack.Client.Extensions.Tests/AwsClientFactoryWrapperTests.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,65 @@ | ||
namespace LocalStack.Client.Extensions.Tests; | ||
|
||
public class AwsClientFactoryWrapperTests | ||
{ | ||
private readonly IAwsClientFactoryWrapper _awsClientFactoryWrapper; | ||
private readonly Mock<IServiceProvider> _mockServiceProvider; | ||
private readonly AWSOptions _awsOptions; | ||
|
||
public AwsClientFactoryWrapperTests() | ||
{ | ||
_awsClientFactoryWrapper = new AwsClientFactoryWrapper(); | ||
_mockServiceProvider = new Mock<IServiceProvider>(); | ||
_awsOptions = new AWSOptions(); | ||
} | ||
|
||
[Fact] | ||
public void CreateServiceClient_Should_Throw_LocalStackClientConfigurationException_When_ClientFactoryType_Is_Null() | ||
{ | ||
Type type = _awsClientFactoryWrapper.GetType(); | ||
const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Static; | ||
|
||
FieldInfo? clientFactoryFullNameField = type.GetField("ClientFactoryFullName", bindingFlags); | ||
FieldInfo? createServiceClientMethodNameFieldInfo = type.GetField("CreateServiceClientMethodName", bindingFlags); | ||
|
||
Assert.NotNull(clientFactoryFullNameField); | ||
Assert.NotNull(createServiceClientMethodNameFieldInfo); | ||
|
||
SetPrivateReadonlyField(clientFactoryFullNameField, "NonExistingType"); | ||
SetPrivateReadonlyField(createServiceClientMethodNameFieldInfo, "NonExistingMethod"); | ||
|
||
Assert.Throws<LocalStackClientConfigurationException>( | ||
() => _awsClientFactoryWrapper.CreateServiceClient<MockAmazonServiceClient>(_mockServiceProvider.Object, _awsOptions)); | ||
} | ||
|
||
[Fact] | ||
public void CreateServiceClient_Should_Create_Client_When_UseLocalStack_False() | ||
{ | ||
ConfigurationBuilder configurationBuilder = new(); | ||
configurationBuilder.AddInMemoryCollection(new KeyValuePair<string, string?>[] { new("LocalStack:UseLocalStack", "false") }); | ||
IConfigurationRoot configurationRoot = configurationBuilder.Build(); | ||
|
||
ServiceCollection serviceCollection = new(); | ||
serviceCollection.AddLocalStack(configurationRoot); | ||
serviceCollection.AddAWSServiceLocalStack<IAmazonS3>(); | ||
ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); | ||
|
||
var requiredService = serviceProvider.GetRequiredService<IAmazonS3>(); | ||
|
||
Assert.NotNull(requiredService); | ||
} | ||
|
||
private static void SetPrivateReadonlyField(FieldInfo field, string value) | ||
{ | ||
var method = new DynamicMethod("SetReadOnlyField", null, new[] { typeof(object), typeof(object) }, typeof(AwsClientFactoryWrapper), true); | ||
var il = method.GetILGenerator(); | ||
|
||
il.Emit(OpCodes.Ldarg_0); | ||
il.Emit(OpCodes.Castclass, field.DeclaringType!); | ||
il.Emit(OpCodes.Ldarg_1); | ||
il.Emit(OpCodes.Stfld, field); | ||
il.Emit(OpCodes.Ret); | ||
|
||
method.Invoke(null, new object[] { null!, value }); | ||
} | ||
} |
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
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
5 changes: 0 additions & 5 deletions
5
tests/LocalStack.Client.Tests/Mocks/MockServiceClients/MockAwsServiceEndpoint.cs
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
// Global using directives | ||
|
||
global using System; | ||
global using System.Collections.Generic; | ||
|
||
global using Amazon.Runtime; | ||
global using Amazon.Runtime.Internal; | ||
global using Amazon.Runtime.Internal.Auth; | ||
global using Amazon.Util.Internal; | ||
|
||
global using LocalStack.Client; | ||
global using LocalStack.Client.Contracts; | ||
global using LocalStack.Client.Models; | ||
|
||
global using Moq; |
20 changes: 20 additions & 0 deletions
20
tests/common/LocalStack.Tests.Common/LocalStack.Tests.Common.csproj
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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net461;net6.0;net7.0</TargetFrameworks> | ||
<NoWarn>$(NoWarn);CA1707;MA0006</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AWSSDK.Core"/> | ||
<PackageReference Include="Moq" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\LocalStack.Client\LocalStack.Client.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\LocalStack.Client\LocalStack.Client.csproj" /> | ||
</ItemGroup> | ||
</Project> |
17 changes: 9 additions & 8 deletions
17
...calStack.Client.Tests/Mocks/Extensions.cs → ...calStack.Tests.Common/Mocks/Extensions.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
2 changes: 1 addition & 1 deletion
2
.../MockServiceClients/IMockAmazonService.cs → .../MockServiceClients/IMockAmazonService.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
2 changes: 1 addition & 1 deletion
2
.../IMockAmazonServiceWithServiceMetadata.cs → .../IMockAmazonServiceWithServiceMetadata.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
2 changes: 1 addition & 1 deletion
2
...ServiceClients/MockAmazonServiceClient.cs → ...ServiceClients/MockAmazonServiceClient.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
2 changes: 1 addition & 1 deletion
2
...AmazonServiceWithServiceMetadataClient.cs → ...AmazonServiceWithServiceMetadataClient.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
4 changes: 4 additions & 0 deletions
4
tests/common/LocalStack.Tests.Common/Mocks/MockServiceClients/MockAwsServiceEndpoint.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,4 @@ | ||
namespace LocalStack.Tests.Common.Mocks.MockServiceClients; | ||
|
||
public record MockAwsServiceEndpoint() : AwsServiceEndpoint(MockServiceMetadata.MockServiceId, "mockService", Client.Enums.AwsService.ApiGateway, 1234, "localhost", | ||
new Uri("http://localhost:1234/")); |
2 changes: 1 addition & 1 deletion
2
...ks/MockServiceClients/MockClientConfig.cs → ...ks/MockServiceClients/MockClientConfig.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
2 changes: 1 addition & 1 deletion
2
...nts/MockClientConfigWithForcePathStyle.cs → ...nts/MockClientConfigWithForcePathStyle.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
2 changes: 1 addition & 1 deletion
2
...cks/MockServiceClients/MockCredentials.cs → ...cks/MockServiceClients/MockCredentials.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
2 changes: 1 addition & 1 deletion
2
...MockServiceClients/MockServiceMetadata.cs → ...MockServiceClients/MockServiceMetadata.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
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