Skip to content

Commit

Permalink
chore: update test projects and examples (#34)
Browse files Browse the repository at this point in the history
Refactored unit tests, e2e tests, and examples to use the updated client
& transaction interfaces. Otherwise there are no functional changes or
additional tests added.
  • Loading branch information
sachyco committed Jul 24, 2023
1 parent 09440c6 commit 3ca1d18
Show file tree
Hide file tree
Showing 27 changed files with 259 additions and 313 deletions.
5 changes: 2 additions & 3 deletions examples/DgraphExample/DgraphExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.22.3" />
<PackageReference Include="Google.Protobuf" Version="3.23.2" />
<PackageReference Include="Grpc.Core" Version="2.46.6" />
<PackageReference Include="Grpc.Net.Client" Version="2.52.0" />
<PackageReference Include="Grpc.Net.Client" Version="2.53.0" />
<ProjectReference Include="..\..\source\Dgraph\Dgraph.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion examples/DgraphExample/ExecuteDQLQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace DgraphExample
{
class ExecuteDQL
{
public static async Task<string> Query(DgraphClient Client, string query)
public static async Task<string> Query(IDgraphClient Client, string query)
{
using (ITransaction transaction = Client.NewTransaction())
{
Expand Down
3 changes: 1 addition & 2 deletions examples/DgraphExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static async Task Main(string[] args)
// Connect to Dgraph Cloud.
var cloudUrl = "https://green-bird.grpc.us-east-1.aws.cloud.dgraph.io/graphql";
var APIKEY = "xxx=";
using var client = new DgraphClient(DgraphCloudChannel.Create(cloudUrl, APIKEY));
using var client = DgraphClient.Create(DgraphCloudChannel.Create(cloudUrl, APIKEY));

var version = await client.CheckVersion();

Expand All @@ -26,6 +26,5 @@ static async Task Main(string[] args)
Console.WriteLine(result);

}

}
}
30 changes: 15 additions & 15 deletions source/Dgraph.tests.e2e/Dgraph.tests.e2e.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Dgraph.tests.e2e</RootNamespace>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Net.Client" Version="2.52.0" />
<PackageReference Include="Assent" Version="1.4.1" />
<PackageReference Include="FluentAssertions" Version="5.10.2" />
<PackageReference Include="FluentResults" Version="1.4.0" />
<PackageReference Include="Grpc.Net.Client" Version="2.55.0" />
<PackageReference Include="Assent" Version="2.2.0" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="FluentResults" Version="3.15.2" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.2" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="7.0.8" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Dgraph\Dgraph.csproj" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Tests/Data/*" CopyToOutputDirectory="Always" />
Expand Down
3 changes: 1 addition & 2 deletions source/Dgraph.tests.e2e/Errors/DgraphDotNetTestFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

using System;
using FluentResults;

namespace Dgraph.tests.e2e.Errors
Expand All @@ -30,4 +29,4 @@ public DgraphDotNetTestFailure(string message, ResultBase failureReason) : base(
FailureReason = failureReason;
}
}
}
}
12 changes: 3 additions & 9 deletions source/Dgraph.tests.e2e/Orchestration/DgraphClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Threading.Tasks;
using Grpc.Core;

using Grpc.Net.Client;
using Serilog;

namespace Dgraph.tests.e2e.Orchestration
{
public class DgraphClientFactory
{

private bool printed;

public async Task<IDgraphClient> GetDgraphClient()
{

// FIXME: This is not what you'd want to do in a real app. Normally, there
// would be tls to the server. TO ADD - tests of running over https, and
// with a Dgraph tls client certificate, and in enterprise mode.
AppContext.SetSwitch(
"System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
var client = new DgraphClient(GrpcChannel.ForAddress("http://127.0.0.1:9080"));
var client = DgraphClient.Create(GrpcChannel.ForAddress("http://127.0.0.1:9080"));

if (!printed)
{
Expand All @@ -53,6 +48,5 @@ public async Task<IDgraphClient> GetDgraphClient()

return client;
}

}
}
}
4 changes: 0 additions & 4 deletions source/Dgraph.tests.e2e/Orchestration/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Dgraph.tests.e2e.Orchestration
{
Expand Down
7 changes: 2 additions & 5 deletions source/Dgraph.tests.e2e/Orchestration/TestFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;

using Dgraph.tests.e2e.Tests;
using Microsoft.Extensions.DependencyInjection;

Expand Down Expand Up @@ -68,4 +65,4 @@ public DgraphDotNetE2ETest FindTestByName(string name)
}
}
}
}
}
10 changes: 2 additions & 8 deletions source/Dgraph.tests.e2e/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

using Dgraph.tests.e2e.Errors;
using Dgraph.tests.e2e.Orchestration;
using Dgraph.tests.e2e.Tests;
Expand All @@ -29,7 +24,6 @@

namespace Dgraph.tests.e2e
{

[Command(Name = "Dgraph.net E2E test runner")]
[HelpOption("--help")]
class Program
Expand Down Expand Up @@ -163,4 +157,4 @@ private async Task<TestExecutor> Execute(IEnumerable<string> tests)
private void EnsureAllTestsRegistered() =>
TestFinder.FindTests(TestFinder.FindTestNames());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
abool: bool .
dgraph.drop.op: string .
dgraph.graphql.p_query: string @index(sha256) .
dgraph.graphql.schema: string .
dgraph.graphql.xid: string @index(exact) @upsert .
dgraph.type: [string] @index(exact) .
dob: datetime @index(year) .
friends: [uid] @reverse @count .
Expand All @@ -17,4 +20,9 @@ type Person {

type dgraph.graphql {
dgraph.graphql.schema
dgraph.graphql.xid
}

type dgraph.graphql.persisted_query {
dgraph.graphql.p_query
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
abool: bool .
car: uid @count .
carMake: string @index(hash) .
dgraph.drop.op: string .
dgraph.graphql.p_query: string @index(sha256) .
dgraph.graphql.schema: string .
dgraph.graphql.xid: string @index(exact) @upsert .
dgraph.type: [string] @index(exact) .
dob: datetime @index(day) .
friends: [uid] @reverse @count .
Expand All @@ -19,4 +22,9 @@ type Person {

type dgraph.graphql {
dgraph.graphql.schema
dgraph.graphql.xid
}

type dgraph.graphql.persisted_query {
dgraph.graphql.p_query
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
dgraph.drop.op: string .
dgraph.graphql.p_query: string @index(sha256) .
dgraph.graphql.schema: string .
dgraph.graphql.xid: string @index(exact) @upsert .
dgraph.type: [string] @index(exact) .
type dgraph.graphql {
dgraph.graphql.schema
dgraph.graphql.xid
}

type dgraph.graphql.persisted_query {
dgraph.graphql.p_query
}
13 changes: 9 additions & 4 deletions source/Dgraph.tests.e2e/Tests/DgraphDotNetE2ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
*/

using System.IO;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Assent.Namers;
using Dgraph.tests.e2e.Errors;
using Dgraph.tests.e2e.Orchestration;
using FluentResults;
using Microsoft.Extensions.FileProviders;
using Serilog;

namespace Dgraph.tests.e2e.Tests
{
Expand All @@ -39,7 +38,13 @@ public DgraphDotNetE2ETest(DgraphClientFactory clientFactory)
ClientFactory = clientFactory;

AssentConfiguration = new Assent.Configuration()
.UsingNamer(new SubdirectoryNamer("Approved"));
.UsingNamer(new SubdirectoryNamer("Approved"))
.UsingReporter((received, approved) =>
{
received = System.IO.File.ReadAllText(received);
approved = System.IO.File.ReadAllText(approved);
Log.Warning("Expected:\n{approved}\nReceived:\n{received}\n", approved, received);
});
// FIXME: .UsingSanitiser(...) might want to add this to remove versions etc
// FIXME: when I add this to a build pipeline it needs this turned off when running on the build server
// .SetInteractive(...);
Expand Down Expand Up @@ -95,4 +100,4 @@ protected void AssertResultIsSuccess(ResultBase result, string msg = null)
}

}
}
}
Loading

0 comments on commit 3ca1d18

Please sign in to comment.