Skip to content

Commit

Permalink
Clean app plugin registration and all speckle plugin verisons (#123)
Browse files Browse the repository at this point in the history
* Clean app plugin registration and all speckle plugin verisons

* fix naming
  • Loading branch information
adamhathcock authored Sep 20, 2024
1 parent 198f1a2 commit d73bf36
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/Speckle.Sdk/Api/GraphQL/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private static HttpClient CreateHttpClient(ISpeckleApplication application, ISpe
{
var httpClient = speckleHttp.CreateHttpClient(timeoutSeconds: 30, authorizationToken: account.token);

httpClient.DefaultRequestHeaders.Add("apollographql-client-name", application.ApplicationVersion);
httpClient.DefaultRequestHeaders.Add("apollographql-client-name", application.ApplicationAndVersion);
httpClient.DefaultRequestHeaders.Add(
"apollographql-client-version",
Assembly.GetExecutingAssembly().GetName().Version?.ToString()
Expand Down
2 changes: 1 addition & 1 deletion src/Speckle.Sdk/Credentials/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ private static void TryLockAccountAddFlow(ISpeckleApplication application, TimeS
}
}

var lockId = application.ApplicationVersion + "@" + DateTime.Now.Add(timespan).ToString("o");
var lockId = application.ApplicationAndVersion + "@" + DateTime.Now.Add(timespan).ToString("o");

// using the lock release time as an id and value
// for ease of deletion and retrieval
Expand Down
19 changes: 5 additions & 14 deletions src/Speckle.Sdk/ServiceRegistration.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Speckle.InterfaceGenerator;
using Speckle.Sdk.Host;
using Speckle.Sdk.Logging;

namespace Speckle.Sdk;

[GenerateAutoInterface]
public class SpeckleApplication : ISpeckleApplication
{
public string Application { get; init; }
public string Version { get; init; }
public string Slug { get; init; }

public string ApplicationVersion => $"{Application} {Version}";
}

public static class ServiceRegistration
{
public static IServiceCollection AddSpeckleSdk(
this IServiceCollection serviceCollection,
HostApplication application,
HostAppVersion version
HostAppVersion version,
string speckleVersion
)
{
serviceCollection.AddLogging();
Expand All @@ -31,8 +21,9 @@ HostAppVersion version
serviceCollection.AddSingleton<ISpeckleApplication>(
new SpeckleApplication
{
Application = name,
Version = HostApplications.GetVersion(version),
HostApplication = name,
SpeckleVersion = speckleVersion,
HostApplicationVersion = HostApplications.GetVersion(version),
Slug = application.Slug
}
);
Expand Down
14 changes: 14 additions & 0 deletions src/Speckle.Sdk/SpeckleApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Speckle.InterfaceGenerator;

namespace Speckle.Sdk;

[GenerateAutoInterface]
public class SpeckleApplication : ISpeckleApplication
{
public string HostApplication { get; init; }
public string HostApplicationVersion { get; init; }
public string Slug { get; init; }
public string SpeckleVersion { get; init; }

public string ApplicationAndVersion => $"{HostApplication} {HostApplicationVersion}";
}
4 changes: 1 addition & 3 deletions tests/Speckle.Sdk.Tests.Integration/Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ static Fixtures()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(IgnoreTest).Assembly);
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
ServiceProvider = serviceCollection.BuildServiceProvider();
ServiceProvider = TestServiceSetup.GetServiceProvider();
}

public static Client Unauthed =>
Expand Down
4 changes: 1 addition & 3 deletions tests/Speckle.Sdk.Tests.Integration/GraphQLCLient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public async Task Setup()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(DataChunk).Assembly);
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
_account = await Fixtures.SeedUser();
_client = serviceProvider.GetRequiredService<IClientFactory>().Create(_account);
Expand Down
4 changes: 1 addition & 3 deletions tests/Speckle.Sdk.Tests.Integration/MemoryTransportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public void Setup()
CleanData();
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, Assembly.GetExecutingAssembly());
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Speckle.Sdk.Tests.Integration/TestServiceSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using Speckle.Sdk.Host;

namespace Speckle.Sdk.Tests.Integration;

public static class TestServiceSetup
{
public static IServiceProvider GetServiceProvider()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023, "Test");
return serviceCollection.BuildServiceProvider();
}
}
2 changes: 1 addition & 1 deletion tests/Speckle.Sdk.Tests.Performance/TestDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class TestDataHelper : IDisposable
public TestDataHelper()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023, "Test");
ServiceProvider = serviceCollection.BuildServiceProvider();
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Speckle.Sdk.Tests.Unit/Api/GraphQLClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public sealed class GraphQLClientTests : IDisposable
[OneTimeSetUp]
public void Setup()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_client = serviceProvider
.GetRequiredService<IClientFactory>()
.Create(
Expand Down
4 changes: 1 addition & 3 deletions tests/Speckle.Sdk.Tests.Unit/Api/Operations/ClosureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public void Setup()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(TableLegFixture).Assembly);
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ private static void Reset()
public async Task GlobalSetup()
{
Reset();
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
_testCaseTransport = new MemoryTransport();
foreach (var b in s_testObjects)
Expand All @@ -67,9 +65,7 @@ public async Task GlobalSetup()
public void Setup()
{
Reset();
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public void Setup()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(DataChunk).Assembly);
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public void Setup()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(Point).Assembly);
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public void Setup()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(DataChunk).Assembly, typeof(ColorMock).Assembly);
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public static IEnumerable<TestCaseData> MigrationTestCase()
public void TestServerMigration(IList<Account> accounts, string requestedUrl, IList<Account> expectedSequence)
{
AddAccounts(accounts);
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();

var result = serviceProvider.GetRequiredService<IAccountManager>().GetAccounts(requestedUrl).ToList();

Expand Down
4 changes: 1 addition & 3 deletions tests/Speckle.Sdk.Tests.Unit/Credentials/Accounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public static void SetUp()
[SetUp]
public void Setup2()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_accountManager = serviceProvider.GetRequiredService<IAccountManager>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public void Setup()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(Point).Assembly);
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public void Setup()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(StringValueMock).Assembly);
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public void Setup()
{
Reset();

var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023);
var serviceProvider = serviceCollection.BuildServiceProvider();
var serviceProvider = TestServiceSetup.GetServiceProvider();
_operations = serviceProvider.GetRequiredService<IOperations>();
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Speckle.Sdk.Tests.Unit/TestServiceSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using Speckle.Sdk.Host;

namespace Speckle.Sdk.Tests.Unit;

public static class TestServiceSetup
{
public static IServiceProvider GetServiceProvider()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023, "Test");
return serviceCollection.BuildServiceProvider();
}
}

0 comments on commit d73bf36

Please sign in to comment.