Skip to content

Commit

Permalink
Create AddressProcessingFixture.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
sachyco committed Jul 13, 2023
1 parent c13d984 commit c73001f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions source/Dgraph.tests/Transactions/AddressProcessingFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace Dgraph.tests.Others
{
public class AddressProcessingFixture
{
[Test]
public void TestProcessAddress()
{
var testData = new Dictionary<string, string>
{
{"https://example.us-east-1.aws.cloud.dgraph.io/graphql", "https://example.grpc.us-east-1.aws.cloud.dgraph.io"},
{"http://example.us-east-1.aws.cloud.dgraph.io/graphql", "https://example.grpc.us-east-1.aws.cloud.dgraph.io"},
{"example.us-east-1.aws.cloud.dgraph.io/graphql", "https://example.grpc.us-east-1.aws.cloud.dgraph.io"},
{"example.grpc.us-east-1.aws.cloud.dgraph.io", "https://example.grpc.us-east-1.aws.cloud.dgraph.io"},
{"https://example.us-west-1.aws.cloud.dgraph.io", "https://example.grpc.us-west-1.aws.cloud.dgraph.io"},
{"http://example.grpc.us-west-1.aws.cloud.dgraph.io", "https://example.grpc.us-west-1.aws.cloud.dgraph.io"},
{"example.us-west-1.aws.cloud.dgraph.io", "https://example.grpc.us-west-1.aws.cloud.dgraph.io"},
};

foreach (var testPair in testData)
{
var processedAddress = DgraphCloudChannel.ProcessAddress(testPair.Key);
Assert.AreEqual(testPair.Value, processedAddress);
}
}

[TestCase("https://invalid-example.com")]
[TestCase("http://invalid-example.io")]
[TestCase("invalid-example.io")]
[TestCase("example.invalid-domain.io")]
[TestCase("https://example.invalid-domain.io")]
[TestCase("http://example.invalid-domain.io")]
[TestCase("example.us-east-1.aws.invalid-domain.io")]
[TestCase("https://example.us-west-1.aws.invalid-domain.io/graphql")]
[TestCase("http://example.grpc.us-west-1.aws.invalid-domain.io/graphql")]
public void TestProcessAddress_ShouldFail(string invalidAddress)
{
Assert.Throws<ArgumentException>(() => DgraphCloudChannel.ProcessAddress(invalidAddress));
}
}
}

0 comments on commit c73001f

Please sign in to comment.