-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from dtm-labs/feat/nstd2.0
feat: support netstandard2.0
- Loading branch information
Showing
9 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using DtmCommon; | ||
using System; | ||
using Xunit; | ||
|
||
namespace Dtmgrpc.Tests | ||
{ | ||
public class BranchIDGenTests | ||
{ | ||
[Fact] | ||
public void TestNewSubBranchID() | ||
{ | ||
var b = new BranchIDGen(""); | ||
|
||
// 01,...,09 | ||
for (int i = 0; i < 9; i++) | ||
{ | ||
var n = b.NewSubBranchID(); | ||
Assert.Equal($"0{i + 1}", n); | ||
} | ||
|
||
// 10~98 | ||
for (int i = 9; i < 99; i++) | ||
{ | ||
var n = b.NewSubBranchID(); | ||
Assert.Equal($"{i + 1}", n); | ||
} | ||
|
||
// 99~ | ||
Assert.Throws<ArgumentException>(() => b.NewSubBranchID()); | ||
} | ||
|
||
[Fact] | ||
public void NewSubBranchID_With_BranchId_Should_Succeed() | ||
{ | ||
var b = new BranchIDGen("ss"); | ||
var n = b.NewSubBranchID(); | ||
Assert.Equal($"ss01", n); | ||
} | ||
|
||
[Fact] | ||
public void NewSubBranchID_With_BranchId_Should_Throw_Exception() | ||
{ | ||
var b = new BranchIDGen("sssssssssssssssssssss"); | ||
Assert.Throws<ArgumentException>(() => b.NewSubBranchID()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using DtmCommon; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace Dtmgrpc.Tests | ||
{ | ||
public class ServiceCollectionExtensionsTests | ||
{ | ||
[Fact] | ||
public void AddDtmGrpc_With_Action_Should_Succeed() | ||
{ | ||
var dtmUrl = "http://localhost:36789"; | ||
|
||
var services = new ServiceCollection(); | ||
services.AddDtmGrpc(x => | ||
{ | ||
x.DtmUrl = dtmUrl; | ||
x.DtmGrpcUrl = dtmUrl; | ||
x.DtmTimeout = 8000; | ||
x.BranchTimeout = 8000; | ||
}); | ||
|
||
var provider = services.BuildServiceProvider(); | ||
|
||
var dtmOptionsAccs = provider.GetService<IOptions<DtmOptions>>(); | ||
var dtmOptions = dtmOptionsAccs.Value; | ||
Assert.Equal(dtmUrl, dtmOptions.DtmGrpcUrl); | ||
|
||
var dtmClient = provider.GetRequiredService<IDtmgRPCClient>(); | ||
Assert.NotNull(dtmClient); | ||
} | ||
|
||
[Fact] | ||
public void AddDtmGrpc_Without_Action_Should_Throw_Exception() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
Assert.Throws<System.ArgumentNullException>(() => services.AddDtmGrpc(null)); | ||
} | ||
|
||
[Fact] | ||
public void AddDtmGrpc_With_IConfiguration_Should_Succeed() | ||
{ | ||
var dtmUrl = "http://localhost:36790"; | ||
|
||
var dict = new Dictionary<string, string> | ||
{ | ||
{ "dtm:DtmUrl", dtmUrl }, | ||
{ "dtm:DtmGrpcUrl", dtmUrl }, | ||
{ "dtm:DtmTimeout", "1000" }, | ||
{ "dtm:BranchTimeout", "8000" }, | ||
}; | ||
|
||
var config = new ConfigurationBuilder().AddInMemoryCollection(dict).Build(); | ||
|
||
var services = new ServiceCollection(); | ||
services.AddDtmGrpc(config, "dtm"); | ||
|
||
var provider = services.BuildServiceProvider(); | ||
|
||
var dtmOptionsAccs = provider.GetService<IOptions<DtmOptions>>(); | ||
var dtmOptions = dtmOptionsAccs.Value; | ||
Assert.Equal(dtmUrl, dtmOptions.DtmUrl); | ||
Assert.Equal(dtmUrl, dtmOptions.DtmGrpcUrl); | ||
|
||
var dtmClient = provider.GetRequiredService<IDtmgRPCClient>(); | ||
Assert.NotNull(dtmClient); | ||
} | ||
|
||
[Fact] | ||
public void AddDtmGrpc_With_IConfiguration_And_Empty_Option_Should_Succeed() | ||
{ | ||
var dtmUrl = "http://localhost:36790"; | ||
|
||
var dict = new Dictionary<string, string> | ||
{ | ||
{ "dtmx:DtmGrpcUrl", dtmUrl }, | ||
}; | ||
|
||
var config = new ConfigurationBuilder().AddInMemoryCollection(dict).Build(); | ||
|
||
var services = new ServiceCollection(); | ||
services.AddDtmGrpc(config, "dtm"); | ||
|
||
var provider = services.BuildServiceProvider(); | ||
|
||
var dtmOptionsAccs = provider.GetService<IOptions<DtmOptions>>(); | ||
var dtmOptions = dtmOptionsAccs.Value; | ||
Assert.NotEqual(dtmUrl, dtmOptions.DtmUrl); | ||
} | ||
} | ||
} |