This repository was archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Feature - redesign library with first cycle of refactoring #27
Merged
stijnmoreels
merged 32 commits into
invictus-integration:master
from
stijnmoreels:feature/redesign-library
Jun 15, 2020
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a8ae60c
Feature - redesign library with first cycle of refactoring
stijnmoreels 844c398
pr-fix: finish renaming
stijnmoreels 92ea233
pr-fix: use string as output result
stijnmoreels 12b9757
pr-sug: test temp enabling logic app
stijnmoreels 7636afc
pr-sug: split 'GetLogicAppTriggerUrlAsync' to better alternative
stijnmoreels f7e159c
pr-sug: use Arcus guidelines for test's names
stijnmoreels d62a856
pr-sug: use date time offset
stijnmoreels 8d8227c
pr-sug: use single or default
stijnmoreels b91a0fc
pr-sug: remove magic number of runs
stijnmoreels 19c7252
pr-sug: increase timeout to 40s
stijnmoreels 761f560
pr-sug: add explicit test cases for logic apps provider
stijnmoreels afa75e6
pr-sug: add extra information to the trigger exception
stijnmoreels f33684d
pr-sug: use '...Async' suffix on all asynchronous methods
stijnmoreels 3944b54
pr-sug: update without booleans in result type
stijnmoreels 947d947
pr-sug: add arg checks
stijnmoreels f406630
pr-sug: add test for temp success static result
stijnmoreels b932c9a
pr-sug: update with any derived exception assertion
stijnmoreels e3e0bc4
pr-sug: using datetime offset
stijnmoreels 233217b
pr-sug: rename to 'LogicAppConverter'
stijnmoreels 11484af
pr-sug: use private disabling func.
stijnmoreels 68ec399
pr-sug: move tenant ID before subscription ID in logic app auth.
stijnmoreels 6b25c73
pr-sug: rename to include 'minimum...' in number of logic app runs to…
stijnmoreels bcb3e9e
pr-sug: add tests for creating/assigning info in custom exceptions
stijnmoreels d106d4b
pr-sug: add tests for logic app converter
stijnmoreels c104e3e
pr-fix: update with correct double assertion of possible 'null'
stijnmoreels d56e4d1
pr-sug: update exception signature with message as least specific
stijnmoreels efff563
pr-sug: update exception signature with message as least specific
stijnmoreels 144705d
pr-sug: use diff setup for timeout/number of items
stijnmoreels 2676472
pr-sug: testing reconfigure
stijnmoreels 2e43b63
pr-sug: update simpler assertion
stijnmoreels be6b744
Update src/Invictus.Testing/LogicAppClient.cs
stijnmoreels 496c733
Update src/Invictus.Testing/LogicAppClient.cs
stijnmoreels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,59 @@ | ||
using Arcus.Testing.Logging; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit.Abstractions; | ||
|
||
namespace Invictus.Testing.Tests.Integration | ||
{ | ||
/// <summary> | ||
/// Provides set of reusable information required for the logic app integration tests. | ||
/// </summary> | ||
public abstract class IntegrationTest | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="IntegrationTest"/> class. | ||
/// </summary> | ||
protected IntegrationTest(ITestOutputHelper outputWriter) | ||
{ | ||
Logger = new XunitTestLogger(outputWriter); | ||
ResourceGroup = Configuration.GetAzureResourceGroup(); | ||
LogicAppName = Configuration.GetTestLogicAppName(); | ||
LogicAppMockingName = Configuration.GetTestMockingLogicAppName(); | ||
|
||
string subscriptionId = Configuration.GetAzureSubscriptionId(); | ||
string tenantId = Configuration.GetAzureTenantId(); | ||
string clientId = Configuration.GetAzureClientId(); | ||
string clientSecret = Configuration.GetAzureClientSecret(); | ||
Authentication = LogicAuthentication.UsingServicePrincipal(tenantId, subscriptionId, clientId, clientSecret); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the logger to write diagnostic messages during tests. | ||
/// </summary> | ||
protected ILogger Logger { get; } | ||
|
||
/// <summary> | ||
/// Gets the configuration available in the current integration test suite. | ||
/// </summary> | ||
protected TestConfig Configuration { get; } = TestConfig.Create(); | ||
|
||
/// <summary> | ||
/// Gets the resource group where the logic app resources on Azure are located. | ||
/// </summary> | ||
protected string ResourceGroup { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the logic app resource running on Azure to test stateless operations against. | ||
/// </summary> | ||
protected string LogicAppName { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the logic app resource running on Azure to test stateful operations against. | ||
/// </summary> | ||
protected string LogicAppMockingName { get; } | ||
|
||
/// <summary> | ||
/// Gets the authentication mechanism to authenticate with Azure. | ||
/// </summary> | ||
protected LogicAuthentication Authentication { get; } | ||
} | ||
} |
This file contains hidden or 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
263 changes: 263 additions & 0 deletions
263
src/Invictus.Testing.Tests.Integration/LogicAppClientTests.cs
This file contains hidden or 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,263 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Invictus.Testing.Model; | ||
using Invictus.Testing.Serialization; | ||
using Newtonsoft.Json.Linq; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Invictus.Testing.Tests.Integration | ||
{ | ||
public class LogicAppClientTests : IntegrationTest | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LogicAppClientTests"/> class. | ||
/// </summary> | ||
public LogicAppClientTests(ITestOutputHelper outputWriter) : base(outputWriter) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task GetLogicAppTriggerUrl_NoTriggerNameSpecified_Success() | ||
{ | ||
// Arrange | ||
using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppName, Authentication)) | ||
{ | ||
// Act | ||
LogicAppTriggerUrl logicAppTriggerUrl = await logicApp.GetTriggerUrlAsync(); | ||
|
||
// Assert | ||
Assert.NotNull(logicAppTriggerUrl.Value); | ||
Assert.Equal("POST", logicAppTriggerUrl.Method); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task GetLogicAppTriggerUrl_ByName_Success() | ||
{ | ||
using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppName, Authentication)) | ||
{ | ||
// Act | ||
LogicAppTriggerUrl logicAppTriggerUrl = await logicApp.GetTriggerUrlByNameAsync(triggerName: "manual"); | ||
|
||
// Assert | ||
Assert.NotNull(logicAppTriggerUrl.Value); | ||
Assert.Equal("POST", logicAppTriggerUrl.Method); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task TemporaryEnableSuccessStaticResultForAction_WithoutConsumerStaticResult_Success() | ||
{ | ||
// Arrange | ||
const string actionName = "HTTP"; | ||
string correlationId = $"correlationId-{Guid.NewGuid()}"; | ||
var headers = new Dictionary<string, string> | ||
{ | ||
{ "correlationId", correlationId }, | ||
}; | ||
|
||
// Act | ||
using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppMockingName, Authentication, Logger)) | ||
{ | ||
await using (await logicApp.TemporaryEnableAsync()) | ||
{ | ||
await using (await logicApp.TemporaryEnableSuccessStaticResultAsync(actionName)) | ||
{ | ||
// Act | ||
await logicApp.TriggerAsync(headers); | ||
LogicAppAction enabledAction = await PollForLogicAppActionAsync(correlationId, actionName); | ||
|
||
Assert.Equal(actionName, enabledAction.Name); | ||
Assert.Equal("200", enabledAction.Outputs.statusCode.ToString()); | ||
Assert.Equal("Succeeded", enabledAction.Status); | ||
} | ||
|
||
await logicApp.TriggerAsync(headers); | ||
LogicAppAction disabledAction = await PollForLogicAppActionAsync(correlationId, actionName); | ||
|
||
Assert.NotEmpty(disabledAction.Outputs.headers); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task TemporaryEnableStaticResultsForAction_WithSuccessStaticResult_Success() | ||
{ | ||
// Arrange | ||
const string actionName = "HTTP"; | ||
string correlationId = $"correlationId-{Guid.NewGuid()}"; | ||
var headers = new Dictionary<string, string> | ||
{ | ||
{ "correlationId", correlationId }, | ||
}; | ||
|
||
var definition = new StaticResultDefinition | ||
{ | ||
Outputs = new Outputs | ||
{ | ||
Headers = new Dictionary<string, string> { { "testheader", "testvalue" } }, | ||
StatusCode = "200", | ||
Body = JToken.Parse("{id : 12345, name : 'test body'}") | ||
}, | ||
Status = "Succeeded" | ||
}; | ||
|
||
// Act | ||
using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppMockingName, Authentication, Logger)) | ||
{ | ||
await using (await logicApp.TemporaryEnableAsync()) | ||
{ | ||
var definitions = new Dictionary<string, StaticResultDefinition> { [actionName] = definition }; | ||
await using (await logicApp.TemporaryEnableStaticResultsAsync(definitions)) | ||
{ | ||
// Act | ||
await logicApp.TriggerAsync(headers); | ||
LogicAppAction enabledAction = await PollForLogicAppActionAsync(correlationId, actionName); | ||
|
||
Assert.Equal("200", enabledAction.Outputs.statusCode.ToString()); | ||
Assert.Equal("testvalue", enabledAction.Outputs.headers["testheader"].ToString()); | ||
Assert.Contains("test body", enabledAction.Outputs.body.ToString()); | ||
} | ||
|
||
await logicApp.TriggerAsync(headers); | ||
LogicAppAction disabledAction = await PollForLogicAppActionAsync(correlationId, actionName); | ||
|
||
Assert.DoesNotContain("test body", disabledAction.Outputs.body.ToString()); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task TemporaryEnableStaticResultForAction_WithSuccessStaticResult_Success() | ||
{ | ||
// Arrange | ||
const string actionName = "HTTP"; | ||
string correlationId = $"correlationId-{Guid.NewGuid()}"; | ||
var headers = new Dictionary<string, string> | ||
{ | ||
{ "correlationId", correlationId }, | ||
}; | ||
|
||
var definition = new StaticResultDefinition | ||
{ | ||
Outputs = new Outputs | ||
{ | ||
Headers = new Dictionary<string, string> { { "testheader", "testvalue" } }, | ||
StatusCode = "200", | ||
Body = JToken.Parse("{id : 12345, name : 'test body'}") | ||
}, | ||
Status = "Succeeded" | ||
}; | ||
|
||
// Act | ||
using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppMockingName, Authentication)) | ||
{ | ||
await using (await logicApp.TemporaryEnableAsync()) | ||
{ | ||
await using (await logicApp.TemporaryEnableStaticResultAsync(actionName, definition)) | ||
{ | ||
// Act | ||
await logicApp.TriggerAsync(headers); | ||
LogicAppAction enabledAction = await PollForLogicAppActionAsync(correlationId, actionName); | ||
|
||
Assert.Equal("200", enabledAction.Outputs.statusCode.ToString()); | ||
Assert.Equal("testvalue", enabledAction.Outputs.headers["testheader"].ToString()); | ||
Assert.Contains("test body", enabledAction.Outputs.body.ToString()); | ||
} | ||
|
||
await logicApp.TriggerAsync(headers); | ||
LogicAppAction disabledAction = await PollForLogicAppActionAsync(correlationId, actionName); | ||
|
||
Assert.DoesNotContain("test body", disabledAction.Outputs.body.ToString()); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task TemporaryEnableLogicApp_Success() | ||
{ | ||
// Act | ||
using (var logicApp = await LogicAppClient.CreateAsync(ResourceGroup, LogicAppMockingName, Authentication, Logger)) | ||
{ | ||
await using (await logicApp.TemporaryEnableAsync()) | ||
{ | ||
// Assert | ||
LogicApp metadata = await logicApp.GetMetadataAsync(); | ||
Assert.Equal("Enabled", metadata.State); | ||
} | ||
{ | ||
LogicApp metadata = await logicApp.GetMetadataAsync(); | ||
Assert.Equal("Disabled", metadata.State); | ||
} | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
public async Task Constructor_WithBlankResourceGroup_Fails(string resourceGroup) | ||
{ | ||
await Assert.ThrowsAsync<ArgumentException>( | ||
() => LogicAppClient.CreateAsync(resourceGroup, LogicAppName, Authentication)); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
public async Task Constructor_WithBlankLogicApp_Fails(string logicApp) | ||
{ | ||
await Assert.ThrowsAsync<ArgumentException>( | ||
() => LogicAppClient.CreateAsync(ResourceGroup, logicApp, Authentication)); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
public async Task ConstructorWithLogger_WithBlankResourceGroup_Fails(string resourceGroup) | ||
{ | ||
await Assert.ThrowsAsync<ArgumentException>( | ||
() => LogicAppClient.CreateAsync(resourceGroup, LogicAppName, Authentication, Logger)); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
public async Task ConstructorWithLogger_WithBlankLogicApp_Fails(string logicApp) | ||
{ | ||
await Assert.ThrowsAsync<ArgumentException>( | ||
() => LogicAppClient.CreateAsync(ResourceGroup, logicApp, Authentication, Logger)); | ||
} | ||
|
||
[Fact] | ||
public async Task Constructor_WithNullAuthentication_Fails() | ||
{ | ||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => LogicAppClient.CreateAsync(ResourceGroup, LogicAppName, authentication: null)); | ||
} | ||
|
||
[Fact] | ||
public async Task ConstructorWithLogger_WithNullAuthentication_Fails() | ||
{ | ||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => LogicAppClient.CreateAsync(ResourceGroup, LogicAppName, authentication: null, logger: Logger)); | ||
} | ||
|
||
private async Task<LogicAppAction> PollForLogicAppActionAsync(string correlationId, string actionName) | ||
{ | ||
LogicAppRun logicAppRun = await LogicAppsProvider | ||
.LocatedAt(ResourceGroup, LogicAppMockingName, Authentication, Logger) | ||
.WithStartTime(DateTimeOffset.UtcNow.AddMinutes(-1)) | ||
.WithCorrelationId(correlationId) | ||
.PollForSingleLogicAppRunAsync(); | ||
|
||
Assert.True(logicAppRun.Actions.Count() != 0); | ||
LogicAppAction logicAppAction = logicAppRun.Actions.First(action => action.Name.Equals(actionName)); | ||
Assert.NotNull(logicAppAction); | ||
|
||
return logicAppAction; | ||
} | ||
} | ||
} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.