diff --git a/.gitignore b/.gitignore
index 2b7e4fb..5e7e65a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -576,3 +576,5 @@ FodyWeavers.xsd
# Additional files built by Visual Studio
# End of https://www.toptal.com/developers/gitignore/api/dotnetcore,linux,visualstudiocode,rider,visualstudio,windows,macos
+
+appsettings.json
\ No newline at end of file
diff --git a/SpeckleAutomateDotnetExample/SpeckleAutomateDotnetExample.csproj b/SpeckleAutomateDotnetExample/SpeckleAutomateDotnetExample.csproj
index 0449b76..787f804 100644
--- a/SpeckleAutomateDotnetExample/SpeckleAutomateDotnetExample.csproj
+++ b/SpeckleAutomateDotnetExample/SpeckleAutomateDotnetExample.csproj
@@ -8,7 +8,8 @@
-
-
+
+
+
diff --git a/TestAutomateFunction/AutomationContextTest.cs b/TestAutomateFunction/AutomationContextTest.cs
index 525b457..beea937 100644
--- a/TestAutomateFunction/AutomationContextTest.cs
+++ b/TestAutomateFunction/AutomationContextTest.cs
@@ -1,91 +1,24 @@
-# nullable enable
namespace TestAutomateFunction;
-using Speckle.Automate.Sdk.Schema;
using Speckle.Automate.Sdk;
+using Speckle.Automate.Sdk.Test;
using Speckle.Core.Api;
using Speckle.Core.Credentials;
-using Speckle.Core.Models;
-using Speckle.Core.Transports;
-using Utils = TestAutomateUtils;
[TestFixture]
public sealed class AutomationContextTest : IDisposable
{
- private async Task AutomationRunData(Base testObject)
- {
- string projectId = await client.StreamCreate(new() { name = "Automate function e2e test" });
- const string branchName = "main";
-
- Branch model = await client.BranchGet(projectId, branchName, 1);
- string modelId = model.id;
-
- string rootObjId = await Operations.Send(
- testObject,
- new List { new ServerTransport(client.Account, projectId) }
- );
-
- string versionId = await client.CommitCreate(
- new()
- {
- streamId = projectId,
- objectId = rootObjId,
- branchName = model.name
- }
- );
-
- var automationName = TestAutomateUtils.RandomString(10);
- var automationId = TestAutomateUtils.RandomString(10);
- var automationRevisionId = TestAutomateUtils.RandomString(10);
-
- await TestAutomateUtils.RegisterNewAutomation(projectId, modelId, client, automationId, automationName, automationRevisionId);
-
- var automationRunId = TestAutomateUtils.RandomString(10);
- var functionId = TestAutomateUtils.RandomString(10);
- var functionName = "Automation name " + TestAutomateUtils.RandomString(10);
- var functionRelease = TestAutomateUtils.RandomString(10);
-
- return new AutomationRunData
- {
- ProjectId = projectId,
- ModelId = modelId,
- BranchName = branchName,
- VersionId = versionId,
- SpeckleServerUrl = client.ServerUrl,
- AutomationId = automationId,
- AutomationRevisionId = automationRevisionId,
- AutomationRunId = automationRunId,
- FunctionId = functionId,
- FunctionName = functionName,
- FunctionRelease = functionRelease,
- };
- }
private Client client;
private Account account;
- private string GetSpeckleToken()
- {
- var envVarName = "SPECKLE_TOKEN";
- var token = Environment.GetEnvironmentVariable(envVarName);
- if (token is null)
- {
- throw new Exception($"Cannot run tests without a {envVarName} environment variable");
- }
-
- return token;
- }
-
- private string GetSpeckleServerUrl() =>
- Environment.GetEnvironmentVariable("SPECKLE_SERVER_ULR") ?? "http://127.0.0.1:3000";
-
[OneTimeSetUp]
public void Setup()
{
account = new Account
{
- token = GetSpeckleToken(),
- serverInfo = new ServerInfo { url = GetSpeckleServerUrl()}
+ token = TestAutomateEnvironment.GetSpeckleToken(),
+ serverInfo = new ServerInfo { url = TestAutomateEnvironment.GetSpeckleServerUrl().ToString() }
};
client = new Client(account);
}
@@ -93,12 +26,18 @@ public sealed class AutomationContextTest : IDisposable
[Test]
public async Task TestFunctionRun()
{
- var automationRunData = await AutomationRunData(TestAutomateUtils.TestObject());
+ var inputs = new FunctionInputs
+ {
+ SpeckleTypeToCount = "Base",
+ SpeckleTypeTargetCount = 1
+ };
+
+ var automationRunData = await TestAutomateUtils.CreateTestRun(client);
var automationContext = await AutomationRunner.RunFunction(
AutomateFunction.Run,
automationRunData,
account.token,
- new FunctionInputs { SpeckleTypeToCount = "Base" }
+ inputs
);
Assert.That(automationContext.RunStatus, Is.EqualTo("SUCCEEDED"));
@@ -107,5 +46,6 @@ public sealed class AutomationContextTest : IDisposable
public void Dispose()
{
client.Dispose();
+ TestAutomateEnvironment.Clear();
}
}
diff --git a/TestAutomateFunction/TestAutomateFunction.csproj b/TestAutomateFunction/TestAutomateFunction.csproj
index efc5480..10b7954 100644
--- a/TestAutomateFunction/TestAutomateFunction.csproj
+++ b/TestAutomateFunction/TestAutomateFunction.csproj
@@ -14,12 +14,16 @@
-
-
+
+
+ PreserveNewest
+
+
+
diff --git a/TestAutomateFunction/TestAutomateUtils.cs b/TestAutomateFunction/TestAutomateUtils.cs
deleted file mode 100644
index d5bcf25..0000000
--- a/TestAutomateFunction/TestAutomateUtils.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-using GraphQL;
-using Speckle.Core.Api;
-using Speckle.Core.Models;
-
-namespace TestAutomateFunction;
-
-public static class TestAutomateUtils
-{
- [SuppressMessage("Security", "CA5394:Do not use insecure randomness")]
- public static string RandomString(int length)
- {
- Random rand = new();
- const string pool = "abcdefghijklmnopqrstuvwxyz0123456789";
- var chars = Enumerable.Range(0, length).Select(_ => pool[rand.Next(0, pool.Length)]);
- return new string(chars.ToArray());
- }
-
- public static Base TestObject()
- {
- Base rootObject = new() { ["foo"] = "bar" };
- return rootObject;
- }
-
- public static async Task RegisterNewAutomation(
- string projectId,
- string modelId,
- Client speckleClient,
- string automationId,
- string automationName,
- string automationRevisionId
- )
- {
- GraphQLRequest query =
- new(
- query: """
- mutation CreateAutomation(
- $projectId: String!
- $modelId: String!
- $automationName: String!
- $automationId: String!
- $automationRevisionId: String!
- ) {
- automationMutations {
- create(
- input: {
- projectId: $projectId
- modelId: $modelId
- automationName: $automationName
- automationId: $automationId
- automationRevisionId: $automationRevisionId
- }
- )
- }
- }
- """,
- variables: new
- {
- projectId,
- modelId,
- automationName,
- automationId,
- automationRevisionId,
- }
- );
-
- await speckleClient.ExecuteGraphQLRequest