Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Feature - redesign library with first cycle of refactoring #27

Merged
Merged
Show file tree
Hide file tree
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 May 25, 2020
844c398
pr-fix: finish renaming
stijnmoreels May 25, 2020
92ea233
pr-fix: use string as output result
stijnmoreels May 25, 2020
12b9757
pr-sug: test temp enabling logic app
stijnmoreels Jun 5, 2020
7636afc
pr-sug: split 'GetLogicAppTriggerUrlAsync' to better alternative
stijnmoreels Jun 5, 2020
f7e159c
pr-sug: use Arcus guidelines for test's names
stijnmoreels Jun 9, 2020
d62a856
pr-sug: use date time offset
stijnmoreels Jun 9, 2020
8d8227c
pr-sug: use single or default
stijnmoreels Jun 9, 2020
b91a0fc
pr-sug: remove magic number of runs
stijnmoreels Jun 9, 2020
19c7252
pr-sug: increase timeout to 40s
stijnmoreels Jun 9, 2020
761f560
pr-sug: add explicit test cases for logic apps provider
stijnmoreels Jun 9, 2020
afa75e6
pr-sug: add extra information to the trigger exception
stijnmoreels Jun 9, 2020
f33684d
pr-sug: use '...Async' suffix on all asynchronous methods
stijnmoreels Jun 9, 2020
3944b54
pr-sug: update without booleans in result type
stijnmoreels Jun 9, 2020
947d947
pr-sug: add arg checks
stijnmoreels Jun 9, 2020
f406630
pr-sug: add test for temp success static result
stijnmoreels Jun 9, 2020
b932c9a
pr-sug: update with any derived exception assertion
stijnmoreels Jun 9, 2020
e3e0bc4
pr-sug: using datetime offset
stijnmoreels Jun 10, 2020
233217b
pr-sug: rename to 'LogicAppConverter'
stijnmoreels Jun 10, 2020
11484af
pr-sug: use private disabling func.
stijnmoreels Jun 10, 2020
68ec399
pr-sug: move tenant ID before subscription ID in logic app auth.
stijnmoreels Jun 10, 2020
6b25c73
pr-sug: rename to include 'minimum...' in number of logic app runs to…
stijnmoreels Jun 11, 2020
bcb3e9e
pr-sug: add tests for creating/assigning info in custom exceptions
stijnmoreels Jun 12, 2020
d106d4b
pr-sug: add tests for logic app converter
stijnmoreels Jun 12, 2020
c104e3e
pr-fix: update with correct double assertion of possible 'null'
stijnmoreels Jun 12, 2020
d56e4d1
pr-sug: update exception signature with message as least specific
stijnmoreels Jun 12, 2020
efff563
pr-sug: update exception signature with message as least specific
stijnmoreels Jun 12, 2020
144705d
pr-sug: use diff setup for timeout/number of items
stijnmoreels Jun 15, 2020
2676472
pr-sug: testing reconfigure
stijnmoreels Jun 15, 2020
2e43b63
pr-sug: update simpler assertion
stijnmoreels Jun 15, 2020
be6b744
Update src/Invictus.Testing/LogicAppClient.cs
stijnmoreels Jun 15, 2020
496c733
Update src/Invictus.Testing/LogicAppClient.cs
stijnmoreels Jun 15, 2020
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
59 changes: 59 additions & 0 deletions src/Invictus.Testing.Tests.Integration/IntegrationTest.cs
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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="29.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
263 changes: 263 additions & 0 deletions src/Invictus.Testing.Tests.Integration/LogicAppClientTests.cs
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;
}
}
}
Loading