Skip to content

Commit

Permalink
misc: Refactor all files to use file-scoped namespaces
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
nozzlegear committed May 10, 2024
1 parent a1c9640 commit 67dd349
Show file tree
Hide file tree
Showing 418 changed files with 16,256 additions and 16,639 deletions.
2 changes: 1 addition & 1 deletion ShopifySharp.Experimental/ShopifySharp.Experimental.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
<ItemGroup>
<ProjectReference Include="..\ShopifySharp\ShopifySharp.csproj" />
</ItemGroup>
</Project>
</Project>
39 changes: 19 additions & 20 deletions ShopifySharp.Extensions.DependencyInjection.Tests/TestExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
namespace ShopifySharp.Extensions.DependencyInjection.Tests
namespace ShopifySharp.Extensions.DependencyInjection.Tests;

public static class ObjectExtensions
{
public static class ObjectExtensions
private static readonly Dictionary<ServiceLifetime, bool> ServiceLifetimeInstanceValidation = new()
{
private static readonly Dictionary<ServiceLifetime, bool> ServiceLifetimeInstanceValidation = new()
{
{ ServiceLifetime.Scoped, true },
{ ServiceLifetime.Singleton, true },
{ ServiceLifetime.Transient, false }
};
{ ServiceLifetime.Scoped, true },
{ ServiceLifetime.Singleton, true },
{ ServiceLifetime.Transient, false }
};

public static bool ValidLifetimeInstance(this object actual, object expceted, ServiceLifetime serviceLifetime)
{
return ServiceLifetimeInstanceValidation.TryGetValue(serviceLifetime, out bool value) && value ? ReferenceEquals(actual, expceted) : !ReferenceEquals(actual, expceted);
}
public static bool ValidLifetimeInstance(this object actual, object expceted, ServiceLifetime serviceLifetime)
{
return ServiceLifetimeInstanceValidation.TryGetValue(serviceLifetime, out bool value) && value ? ReferenceEquals(actual, expceted) : !ReferenceEquals(actual, expceted);
}
}

public static class ServiceProviderExtensions
public static class ServiceProviderExtensions
{
public static TestServiceLifetime<T> GetServiceInstances<T>(this ServiceProvider? serviceProvider) where T : class
{
public static TestServiceLifetime<T> GetServiceInstances<T>(this ServiceProvider? serviceProvider) where T : class
{
var service1 = serviceProvider?.GetService<T>();
var service2 = serviceProvider?.GetService<T>();
var service1 = serviceProvider?.GetService<T>();
var service2 = serviceProvider?.GetService<T>();

return new TestServiceLifetime<T>(service1, service2);
}
return new TestServiceLifetime<T>(service1, service2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
<ItemGroup>
<PackageReference Include="microsoft.extensions.dependencyinjection" Version="8.0.0" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/Checkout_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Xunit;

namespace ShopifySharp.Tests;
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/CustomerAddress_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/DateTime_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/DiscountCode_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/FulfillmentRequest_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down
65 changes: 32 additions & 33 deletions ShopifySharp.Tests/GenerateGraphQLSchema_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,43 @@
using Wish.GraphQLSchemaGenerator;
using Xunit;

namespace ShopifySharp.Tests
namespace ShopifySharp.Tests;

[Trait("Category", "GraphQL")]
public class GenerateGraphQLSchema_Test
{
[Trait("Category", "GraphQL")]
public class GenerateGraphQLSchema_Test
[Fact(Skip = "This test should be run manually to re-generate the GraphQL types whenever the API version is upgraded")]
public async Task GenerateGraphQLTypes()
{
[Fact(Skip = "This test should be run manually to re-generate the GraphQL types whenever the API version is upgraded")]
public async Task GenerateGraphQLTypes()
var scalarNameToTypeName = new Dictionary<string, string>
{
{ "UnsignedInt64", "ulong" },
{ "Money", "decimal" },
{ "Decimal", "decimal" },
{ "DateTime", "DateTime" },//GraphQL datetimes are always UTC
{ "Date", "DateOnly" },
{ "UtcOffset", "TimeSpan" },
{ "URL", "string" },
{ "HTML", "string" },
{ "JSON", "string" },
{ "FormattedString", "string" },
{ "ARN", "string" },
{ "StorefrontID", "string" },
{ "Color", "string" },
};
string csharpCode = await new GraphQLTypeGenerator().GenerateTypesAsync("ShopifySharp.GraphQL", scalarNameToTypeName, async query =>
{
var scalarNameToTypeName = new Dictionary<string, string>
{
{ "UnsignedInt64", "ulong" },
{ "Money", "decimal" },
{ "Decimal", "decimal" },
{ "DateTime", "DateTime" },//GraphQL datetimes are always UTC
{ "Date", "DateOnly" },
{ "UtcOffset", "TimeSpan" },
{ "URL", "string" },
{ "HTML", "string" },
{ "JSON", "string" },
{ "FormattedString", "string" },
{ "ARN", "string" },
{ "StorefrontID", "string" },
{ "Color", "string" },
};
string csharpCode = await new GraphQLTypeGenerator().GenerateTypesAsync("ShopifySharp.GraphQL", scalarNameToTypeName, async query =>
{
var res = await new GraphService(Utils.MyShopifyUrl, Utils.AccessToken).PostAsync(query);
var doc = JsonDocument.Parse(res.ToString());
return doc;
});
var res = await new GraphService(Utils.MyShopifyUrl, Utils.AccessToken).PostAsync(query);
var doc = JsonDocument.Parse(res.ToString());
return doc;
});

var strCode = new StringBuilder()
.AppendLine("#if NET6_0_OR_GREATER")
.AppendLine(csharpCode)
.AppendLine("#endif");
var strCode = new StringBuilder()
.AppendLine("#if NET6_0_OR_GREATER")
.AppendLine(csharpCode)
.AppendLine("#endif");

File.WriteAllText(@"../../../../ShopifySharp/Entities/GraphQL/GraphQLSchema.generated.cs", strCode.ToString());
}
File.WriteAllText(@"../../../../ShopifySharp/Entities/GraphQL/GraphQLSchema.generated.cs", strCode.ToString());
}
}
#endif
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/GiftCard_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down
107 changes: 53 additions & 54 deletions ShopifySharp.Tests/Graph_SendTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
using ShopifySharp.GraphQL;
using Xunit;

namespace ShopifySharp.Tests
namespace ShopifySharp.Tests;

[Trait("Category", "Graph")]
public class Graph_SendTests
{
[Trait("Category", "Graph")]
public class Graph_SendTests
[Fact]
public async Task GetOrders()
{
[Fact]
public async Task GetOrders()
foreach (var policy in new IRequestExecutionPolicy[]
{
new DefaultRequestExecutionPolicy(),
new RetryExecutionPolicy(),
new LeakyBucketExecutionPolicy()
})
{
foreach (var policy in new IRequestExecutionPolicy[]
{
new DefaultRequestExecutionPolicy(),
new RetryExecutionPolicy(),
new LeakyBucketExecutionPolicy()
})
{
var svc = new GraphService(Utils.MyShopifyUrl, Utils.AccessToken);
svc.SetExecutionPolicy(policy);
var res = await svc.SendAsync<OrderConnection>(@"
var svc = new GraphService(Utils.MyShopifyUrl, Utils.AccessToken);
svc.SetExecutionPolicy(policy);
var res = await svc.SendAsync<OrderConnection>(@"
{
orders(first:10)
{
Expand All @@ -43,33 +43,33 @@ public async Task GetOrders()
}
}
");
var orders = res.nodes;
Assert.True(orders.Count() > 0);
var o = orders.First();
Assert.True(o.name != null);
Assert.True(o.lineItems.nodes.First().quantity != null);
var commentEventEmbed = o as ICommentEventEmbed;
Assert.NotNull(commentEventEmbed);
Assert.NotNull(commentEventEmbed.AsOrder());
Assert.Null(commentEventEmbed.AsCustomer());
}
var orders = res.nodes;
Assert.True(orders.Count() > 0);
var o = orders.First();
Assert.True(o.name != null);
Assert.True(o.lineItems.nodes.First().quantity != null);
var commentEventEmbed = o as ICommentEventEmbed;
Assert.NotNull(commentEventEmbed);
Assert.NotNull(commentEventEmbed.AsOrder());
Assert.Null(commentEventEmbed.AsCustomer());
}
}

[Fact]
public async Task GetOrdersWithVariables()
[Fact]
public async Task GetOrdersWithVariables()
{
foreach (var policy in new IRequestExecutionPolicy[]
{
new DefaultRequestExecutionPolicy(),
new RetryExecutionPolicy(),
new LeakyBucketExecutionPolicy()
})
{
foreach (var policy in new IRequestExecutionPolicy[]
{
new DefaultRequestExecutionPolicy(),
new RetryExecutionPolicy(),
new LeakyBucketExecutionPolicy()
})
var svc = new GraphService(Utils.MyShopifyUrl, Utils.AccessToken);
svc.SetExecutionPolicy(policy);
var res = await svc.SendAsync<OrderConnection>(new GraphRequest
{
var svc = new GraphService(Utils.MyShopifyUrl, Utils.AccessToken);
svc.SetExecutionPolicy(policy);
var res = await svc.SendAsync<OrderConnection>(new GraphRequest
{
query =
query =
@"
query ($firstOrders: Int!, $firstLineItems: Int!)
{
Expand All @@ -92,22 +92,21 @@ public async Task GetOrdersWithVariables()
}
}
}",
variables = new
{
firstOrders = 10,
firstLineItems = 20
}
});
var orders = res.nodes;
Assert.True(orders.Count() > 0);
var o = orders.First();
Assert.True(o.name != null);
Assert.True(o.lineItems.nodes.First().quantity != null);
var commentEventEmbed = o as ICommentEventEmbed;
Assert.NotNull(commentEventEmbed);
Assert.NotNull(commentEventEmbed.AsOrder());
Assert.Null(commentEventEmbed.AsCustomer());
}
variables = new
{
firstOrders = 10,
firstLineItems = 20
}
});
var orders = res.nodes;
Assert.True(orders.Count() > 0);
var o = orders.First();
Assert.True(o.name != null);
Assert.True(o.lineItems.nodes.First().quantity != null);
var commentEventEmbed = o as ICommentEventEmbed;
Assert.NotNull(commentEventEmbed);
Assert.NotNull(commentEventEmbed.AsOrder());
Assert.Null(commentEventEmbed.AsCustomer());
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions ShopifySharp.Tests/LeakyBucket_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using ShopifySharp.Infrastructure.Policies.LeakyBucketPolicy;
using Xunit;

Expand Down Expand Up @@ -124,7 +126,7 @@ public async Task BlockedMultipleCallsCompleteAfterEnoughTime()
Assert.False(task3.IsCompleted);

Assert.Equal(1, b.ComputedCurrentlyAvailable);

await PassSeconds(1);
Assert.True(task1.IsCompleted);
Assert.False(task2.IsCompleted);
Expand Down Expand Up @@ -163,4 +165,4 @@ private async Task PassSeconds(int seconds)
now = now.AddSeconds(seconds);
await Task.Delay(TimeSpan.FromSeconds(seconds * 1.2));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using JetBrains.Annotations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/SalesChannel/CollectionListing_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/SalesChannel/ProductListing_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/ShopifySharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/TenderTransaction_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Threading.Tasks;
using ShopifySharp.Filters;
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/User_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using ShopifySharp.Filters;
using Xunit;
Expand Down
Loading

0 comments on commit 67dd349

Please sign in to comment.