From 614ced34e43d8838c0d8179d8476ba019ff5c968 Mon Sep 17 00:00:00 2001 From: MaleDong Date: Mon, 30 Jul 2018 10:48:30 +0800 Subject: [PATCH] [Update] Refactor codes according to RocherHong's changes 1) Considering using xUnit for UnitTest, remove my unit tests. 2) Remove useless `async`, because `async` is just the wrapper of `Task`. 3) Modify unit tests to be sure that the values MUST BE equal to each other when the IP is the same. --- binding/c#/BenchmarkTest/App.config | 34 ---- .../BenchmarkTest/BenchTests/BenchTestBase.cs | 21 --- .../BenchTests/NormalBenchmarkTests.cs | 46 ------ .../IP2Region.Test.NetFxBenchmark.csproj | 154 ------------------ binding/c#/BenchmarkTest/Program.cs | 13 -- .../BenchmarkTest/Properties/AssemblyInfo.cs | 35 ---- binding/c#/BenchmarkTest/packages.config | 54 ------ binding/c#/IP2Region.Test.xUnit/SearchTest.cs | 46 ++++++ binding/c#/IP2Region.Test.xUnit/UnitTest1.cs | 36 ---- binding/c#/IP2Region/DBSearcher.cs | 12 +- binding/c#/UnitTests/ExceptionTest.cs | 50 ------ binding/c#/UnitTests/NormalAsyncTest.cs | 148 ----------------- binding/c#/UnitTests/NormalSyncTest.cs | 146 ----------------- .../c#/UnitTests/Properties/AssemblyInfo.cs | 19 --- binding/c#/UnitTests/UnitTests.csproj | 76 --------- binding/c#/UnitTests/packages.config | 5 - 16 files changed, 52 insertions(+), 843 deletions(-) delete mode 100644 binding/c#/BenchmarkTest/App.config delete mode 100644 binding/c#/BenchmarkTest/BenchTests/BenchTestBase.cs delete mode 100644 binding/c#/BenchmarkTest/BenchTests/NormalBenchmarkTests.cs delete mode 100644 binding/c#/BenchmarkTest/IP2Region.Test.NetFxBenchmark.csproj delete mode 100644 binding/c#/BenchmarkTest/Program.cs delete mode 100644 binding/c#/BenchmarkTest/Properties/AssemblyInfo.cs delete mode 100644 binding/c#/BenchmarkTest/packages.config create mode 100644 binding/c#/IP2Region.Test.xUnit/SearchTest.cs delete mode 100644 binding/c#/IP2Region.Test.xUnit/UnitTest1.cs delete mode 100644 binding/c#/UnitTests/ExceptionTest.cs delete mode 100644 binding/c#/UnitTests/NormalAsyncTest.cs delete mode 100644 binding/c#/UnitTests/NormalSyncTest.cs delete mode 100644 binding/c#/UnitTests/Properties/AssemblyInfo.cs delete mode 100644 binding/c#/UnitTests/UnitTests.csproj delete mode 100644 binding/c#/UnitTests/packages.config diff --git a/binding/c#/BenchmarkTest/App.config b/binding/c#/BenchmarkTest/App.config deleted file mode 100644 index 1ab3951..0000000 --- a/binding/c#/BenchmarkTest/App.config +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/binding/c#/BenchmarkTest/BenchTests/BenchTestBase.cs b/binding/c#/BenchmarkTest/BenchTests/BenchTestBase.cs deleted file mode 100644 index 835aed6..0000000 --- a/binding/c#/BenchmarkTest/BenchTests/BenchTestBase.cs +++ /dev/null @@ -1,21 +0,0 @@ -using BenchmarkDotNet.Attributes; -using IP2Region; - -namespace BenchmarkTest.BenchTests -{ - public class BenchTestBase - { - protected DbSearcher _dbSearcher = null; - - [GlobalSetup] - public void Init() - { - _dbSearcher = new DbSearcher("../../../../../data/ip2region.db"); - } - [GlobalCleanup] - public void Clearup() - { - _dbSearcher.Dispose(); - } - } -} diff --git a/binding/c#/BenchmarkTest/BenchTests/NormalBenchmarkTests.cs b/binding/c#/BenchmarkTest/BenchTests/NormalBenchmarkTests.cs deleted file mode 100644 index f3e4fec..0000000 --- a/binding/c#/BenchmarkTest/BenchTests/NormalBenchmarkTests.cs +++ /dev/null @@ -1,46 +0,0 @@ -using BenchmarkDotNet.Attributes; -using System.Threading.Tasks; - -namespace BenchmarkTest.BenchTests -{ - public class NormalBenchmarkTests : BenchTestBase - { - [Params("0.0.0.0", "210.109.255.230", "192.168.0.1", "255.255.255.255", "183.196.233.159", - "77.49.66.88", "210.248.255.231", "10.10.10.10", "197.84.60.202", "35.193.251.120", - "20.108.91.101", "120.196.148.137", "249.255.250.200", "112.65.1.130")] - public string validIp = null; - - [Benchmark] - public void TestSyncSpeedForMemorySearch() - { - _dbSearcher.MemorySearch(validIp); - } - [Benchmark] - public async Task TestAsyncSpeedForMemorySearch() - { - await _dbSearcher.MemorySearchAsync(validIp); - } - - [Benchmark] - public void TestSyncSpeedForBinarySearch() - { - _dbSearcher.BinarySearch(validIp); - } - [Benchmark] - public async Task TestAsyncBinarySearch() - { - await _dbSearcher.BinarySearchAsync(validIp); - } - - [Benchmark] - public void TestSyncSpeedForBTreeSearch() - { - _dbSearcher.BtreeSearch(validIp); - } - [Benchmark] - public async Task TestAsyncSpeedForBTreeSearch() - { - await _dbSearcher.BtreeSearchAsync(validIp); - } - } -} diff --git a/binding/c#/BenchmarkTest/IP2Region.Test.NetFxBenchmark.csproj b/binding/c#/BenchmarkTest/IP2Region.Test.NetFxBenchmark.csproj deleted file mode 100644 index 3145a23..0000000 --- a/binding/c#/BenchmarkTest/IP2Region.Test.NetFxBenchmark.csproj +++ /dev/null @@ -1,154 +0,0 @@ - - - - - Debug - AnyCPU - {053EA51E-2246-4FCB-A106-9B53E70FDC3F} - Exe - BenchmarkTest - BenchmarkTest - v4.6 - 512 - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\BenchmarkDotNet.0.10.14\lib\net46\BenchmarkDotNet.dll - - - ..\packages\BenchmarkDotNet.Core.0.10.14\lib\net46\BenchmarkDotNet.Core.dll - - - ..\packages\BenchmarkDotNet.Toolchains.Roslyn.0.10.14\lib\net46\BenchmarkDotNet.Toolchains.Roslyn.dll - - - ..\packages\Microsoft.CodeAnalysis.Common.2.6.1\lib\netstandard1.3\Microsoft.CodeAnalysis.dll - - - ..\packages\Microsoft.CodeAnalysis.CSharp.2.6.1\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll - - - ..\packages\Microsoft.DotNet.InternalAbstractions.1.0.0\lib\net451\Microsoft.DotNet.InternalAbstractions.dll - - - ..\packages\Microsoft.DotNet.PlatformAbstractions.1.1.1\lib\net451\Microsoft.DotNet.PlatformAbstractions.dll - - - ..\packages\Microsoft.Win32.Registry.4.3.0\lib\net46\Microsoft.Win32.Registry.dll - - - - ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - - - - ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll - - - - - - ..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll - - - ..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll - - - ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll - - - ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll - - - ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll - - - - - - ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll - - - ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net46\System.Security.Cryptography.Algorithms.dll - - - ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll - - - ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll - - - ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll - - - ..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll - - - ..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll - - - ..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll - - - ..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll - - - - - ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll - - - ..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll - - - ..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll - - - ..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll - - - - - - - - - - - - - - - - - - - {4c6032ee-43a5-4d5c-88f8-c411069e49e0} - IP2Region - - - - \ No newline at end of file diff --git a/binding/c#/BenchmarkTest/Program.cs b/binding/c#/BenchmarkTest/Program.cs deleted file mode 100644 index 44da3d1..0000000 --- a/binding/c#/BenchmarkTest/Program.cs +++ /dev/null @@ -1,13 +0,0 @@ -using BenchmarkDotNet.Running; -using BenchmarkTest.BenchTests; - -namespace BenchmarkTest -{ - public class Program - { - public static void Main(string[] args) - { - BenchmarkRunner.Run(); - } - } -} diff --git a/binding/c#/BenchmarkTest/Properties/AssemblyInfo.cs b/binding/c#/BenchmarkTest/Properties/AssemblyInfo.cs deleted file mode 100644 index 6f7bdff..0000000 --- a/binding/c#/BenchmarkTest/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// 有关程序集的一般信息由以下 -// 控制。更改这些特性值可修改 -// 与程序集关联的信息。 -[assembly: AssemblyTitle("BenchmarkTest")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("BenchmarkTest")] -[assembly: AssemblyCopyright("Copyright © 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 会使此程序集中的类型 -//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 -//请将此类型的 ComVisible 特性设置为 true。 -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID -[assembly: Guid("053ea51e-2246-4fcb-a106-9b53e70fdc3f")] - -// 程序集的版本信息由下列四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 -// 方法是按如下所示使用“*”: : -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/binding/c#/BenchmarkTest/packages.config b/binding/c#/BenchmarkTest/packages.config deleted file mode 100644 index 165b5a3..0000000 --- a/binding/c#/BenchmarkTest/packages.config +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/binding/c#/IP2Region.Test.xUnit/SearchTest.cs b/binding/c#/IP2Region.Test.xUnit/SearchTest.cs new file mode 100644 index 0000000..1215765 --- /dev/null +++ b/binding/c#/IP2Region.Test.xUnit/SearchTest.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using Xunit; + +namespace IP2Region.Test.xUnit +{ + public class SearchTest + { + private readonly DbSearcher _search; + public SearchTest() + { + _search = new DbSearcher(Environment.CurrentDirectory + @"\DB\ip2region.db"); + } + [Fact] + public void Search_Test() + { + string memResult = _search.MemorySearch("183.192.62.65").Region; + string binarySearchResult = _search.BinarySearch("183.192.62.65").Region; + string binaryTreeSearchResult = _search.BtreeSearch("183.192.62.65").Region; + + Assert.NotNull(memResult); + Assert.NotNull(binarySearchResult); + Assert.NotNull(binaryTreeSearchResult); + + Assert.Equal(memResult, binarySearchResult); + Assert.Equal(binaryTreeSearchResult, memResult); + } + + [Fact] + public async Task SearchAsync_Test() + { + var memResult = await _search.MemorySearchAsync("183.192.62.65"); + var binarySearchResult = await _search.BinarySearchAsync("183.192.62.65"); + var bTreeSearchResult = await _search.BtreeSearchAsync("183.192.62.65"); + + Assert.NotNull(memResult.Region); + Assert.NotNull(binarySearchResult.Region); + Assert.NotNull(bTreeSearchResult.Region); + + Assert.Equal(memResult.Region, binarySearchResult.Region); + Assert.Equal(bTreeSearchResult.Region, memResult.Region); + } + + + } +} diff --git a/binding/c#/IP2Region.Test.xUnit/UnitTest1.cs b/binding/c#/IP2Region.Test.xUnit/UnitTest1.cs deleted file mode 100644 index 09a6f9b..0000000 --- a/binding/c#/IP2Region.Test.xUnit/UnitTest1.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Threading.Tasks; -using Xunit; - -namespace IP2Region.Test.xUnit -{ - public class UnitTest1 - { - private readonly DbSearcher _search; - public UnitTest1() - { - _search = new DbSearcher(Environment.CurrentDirectory + @"\DB\ip2region.db"); - } - [Fact] - public void Search_Test() - { - - Assert.NotNull(_search.MemorySearch("183.192.62.65").Region); - Assert.NotNull(_search.MemorySearchAsync("183.192.62.65").Result.Region); - Assert.NotNull(_search.BinarySearch("183.192.62.65").Region); - Assert.NotNull(_search.BinarySearchAsync("183.192.62.65").Result.Region); - Assert.NotNull(_search.BtreeSearch("183.192.62.65").Region); - Assert.NotNull(_search.BtreeSearchAsync("183.192.62.65").Result.Region); - - } - - [Fact] - public async Task SearchAsync_Test() - { - var result = await _search.MemorySearchAsync("183.192.62.65"); - Assert.NotNull(result.Region); - } - - - } -} diff --git a/binding/c#/IP2Region/DBSearcher.cs b/binding/c#/IP2Region/DBSearcher.cs index aaae79b..b99dba8 100644 --- a/binding/c#/IP2Region/DBSearcher.cs +++ b/binding/c#/IP2Region/DBSearcher.cs @@ -360,23 +360,23 @@ namespace IP2Region /// /// Get the region throught the ip address with memory binary search algorithm. /// - public async Task MemorySearchAsync(string ip) + public Task MemorySearchAsync(string ip) { return Task.FromResult(MemorySearch(ip)); } /// /// Get the region throught the ip address with b-tree search algorithm. /// - public async Task BtreeSearchAsync(string ip) + public Task BtreeSearchAsync(string ip) { return Task.FromResult(BtreeSearch(ip)); - } + } /// /// Get the region throught the ip address with binary search algorithm. /// - public async Task BinarySearchAsync(string ip) + public Task BinarySearchAsync(string ip) { - return Task.FromResult(BinarySearch(ip)); + return Task.FromResult(BinarySearch(ip)); } #endregion @@ -397,4 +397,4 @@ namespace IP2Region } } -} +} diff --git a/binding/c#/UnitTests/ExceptionTest.cs b/binding/c#/UnitTests/ExceptionTest.cs deleted file mode 100644 index 1eb9552..0000000 --- a/binding/c#/UnitTests/ExceptionTest.cs +++ /dev/null @@ -1,50 +0,0 @@ -using IP2Region; -using IP2Region.Models; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace UnitTests -{ - /// - /// This test class is mainly used to test your exception types. - /// It should throw exceptions of differnt kinds of types on certain occations. - /// - [TestClass] - public class ExceptionTest - { - /// - /// Path error should throw "DbMakerConfigException" - /// - [TestMethod] - [ExpectedException(typeof(DbMakerConfigException))] - public void TestDbMakerConfigException() - { - using (var _dbSearcher = new DbSearcher(new DbConfig(255), "../../../../../data/ip2region.db")) { } - } - /// - /// Invalid IP should throw "IPInValidException" - /// - [TestMethod] - public void TestInvalidIP() - { - using (var _dbSearcher = new DbSearcher("../../../../../data/ip2region.db")) - { - var invalidIps = new string[] { "256.255.1.1", "-1.0.0.0", "192.168.4", "x.y.z" }; - var counter = 0; - - foreach (var item in invalidIps) - { - try - { - _dbSearcher.MemorySearch(item); - } - catch (IPInValidException) - { - counter++; - } - } - - Assert.AreEqual(counter, 4); - } - } - } -} diff --git a/binding/c#/UnitTests/NormalAsyncTest.cs b/binding/c#/UnitTests/NormalAsyncTest.cs deleted file mode 100644 index 4155d06..0000000 --- a/binding/c#/UnitTests/NormalAsyncTest.cs +++ /dev/null @@ -1,148 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using IP2Region; -using System.Threading.Tasks; - -namespace UnitTests -{ - /// - /// This class is used to test with normal IPs (Chinese, Foreign and Special). - /// Use async functions for testing. - /// - [TestClass] - public class NormalAsyncTest - { - private static DbSearcher _dbSearcher = null; - - [ClassInitialize] - public static void Init(TestContext context) - { - _dbSearcher = new DbSearcher("../../../../../data/ip2region.db"); - } - - [ClassCleanup] - public static void ClearUp() - { - _dbSearcher.Dispose(); - } - - #region Normal Valid Chinese IP Test Cases - [TestMethod] - [TestCategory("Async Chinese Ip Test")] - public async Task AsyncBinarySearchTestForChinese() - { - const int cityId = 2163; - const string region = "中国|0|广东省|深圳市|鹏博士"; - - var result = await _dbSearcher.AsyncBinarySearch("101.105.35.57"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - [TestMethod] - [TestCategory("Async Chinese Ip Test")] - public async Task AsyncBtreeSearchTestForChinese() - { - const int cityId = 2163; - const string region = "中国|0|广东省|深圳市|鹏博士"; - - var result = await _dbSearcher.AsyncBtreeSearch("101.105.35.57"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - [TestMethod] - [TestCategory("Async Chinese Ip Test")] - public async Task AsyncMemorySearchTestForChinese() - { - const int cityId = 2163; - const string region = "中国|0|广东省|深圳市|鹏博士"; - - var result = await _dbSearcher.AsyncMemorySearch("101.105.35.57"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - #endregion - - #region Normal Valid Foreign IP Test Cases - [TestMethod] - [TestCategory("Async Foreign Ip Test")] - public async Task AsyncBinarySearchTestForForeign() - { - const int cityId = 71; - const string region = "荷兰|0|0|0|0"; - - var result = await _dbSearcher.AsyncBinarySearch("86.84.21.60"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - [TestMethod] - [TestCategory("Async Foreign Ip Test")] - public async Task AsyncBtreeSearchTestForForeign() - { - const int cityId = 71; - const string region = "荷兰|0|0|0|0"; - - var result = await _dbSearcher.AsyncBtreeSearch("86.84.21.60"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - [TestMethod] - [TestCategory("Async Foreign Ip Test")] - public async Task AsyncMemorySearchTestForForeign() - { - const int cityId = 71; - const string region = "荷兰|0|0|0|0"; - - var result = await _dbSearcher.AsyncMemorySearch("86.84.21.60"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - #endregion - - #region Normal Valid Special Ip Test Cases - [TestMethod] - [TestCategory("Async Special Ip Test")] - public async Task AsyncBinarySearchTestForSpecial() - { - const int cityId = 0; - const string region = "0|0|0|内网IP|内网IP"; - string[] specialIps = new string[] { "255.255.255.255", "0.0.0.0" }; - - foreach (var item in specialIps) - { - var result = await _dbSearcher.AsyncBinarySearch(item); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - } - [TestMethod] - [TestCategory("Async Special Ip Test")] - public async Task AsyncBtreeSearchTestForSpecial() - { - const int cityId = 0; - const string region = "0|0|0|内网IP|内网IP"; - string[] specialIps = new string[] { "255.255.255.255", "0.0.0.0" }; - - foreach (var item in specialIps) - { - var result = await _dbSearcher.AsyncBtreeSearch(item); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - } - [TestMethod] - [TestCategory("Async Special Ip Test")] - public async Task AsyncMemorySearchTestForSpecial() - { - const int cityId = 0; - const string region = "0|0|0|内网IP|内网IP"; - string[] specialIps = new string[] { "255.255.255.255", "0.0.0.0" }; - - foreach (var item in specialIps) - { - var result = await _dbSearcher.AsyncMemorySearch(item); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - } - #endregion - } -} diff --git a/binding/c#/UnitTests/NormalSyncTest.cs b/binding/c#/UnitTests/NormalSyncTest.cs deleted file mode 100644 index 628e585..0000000 --- a/binding/c#/UnitTests/NormalSyncTest.cs +++ /dev/null @@ -1,146 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using IP2Region; -namespace UnitTests -{ - /// - /// This class is used to test with normal IPs (Chinese, Foreign and Special). - /// Use sync functions for testing. - /// - [TestClass] - public class NormalSyncTest - { - private static DbSearcher _dbSearcher = null; - - [ClassInitialize] - public static void Init(TestContext context) - { - _dbSearcher = new DbSearcher("../../../../../data/ip2region.db"); - } - - [ClassCleanup] - public static void ClearUp() - { - _dbSearcher.Dispose(); - } - - #region Normal Valid Chinese IP Test Cases - [TestMethod] - [TestCategory("Chinese Ip Test")] - public void BinarySearchTestForChinese() - { - const int cityId = 2163; - const string region = "中国|0|广东省|深圳市|鹏博士"; - - var result = _dbSearcher.BinarySearch("101.105.35.57"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - [TestMethod] - [TestCategory("Chinese Ip Test")] - public void BtreeSearchTestForChinese() - { - const int cityId = 2163; - const string region = "中国|0|广东省|深圳市|鹏博士"; - - var result = _dbSearcher.BtreeSearch("101.105.35.57"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - [TestMethod] - [TestCategory("Chinese Ip Test")] - public void MemorySearchTestForChinese() - { - const int cityId = 2163; - const string region = "中国|0|广东省|深圳市|鹏博士"; - - var result = _dbSearcher.MemorySearch("101.105.35.57"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - #endregion - - #region Normal Valid Foreign IP Test Cases - [TestMethod] - [TestCategory("Foreign Ip Test")] - public void BinarySearchTestForForeign() - { - const int cityId = 71; - const string region = "荷兰|0|0|0|0"; - - var result = _dbSearcher.BinarySearch("86.84.21.60"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - [TestMethod] - [TestCategory("Foreign Ip Test")] - public void BtreeSearchTestForForeign() - { - const int cityId = 71; - const string region = "荷兰|0|0|0|0"; - - var result = _dbSearcher.BtreeSearch("86.84.21.60"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - [TestMethod] - [TestCategory("Foreign Ip Test")] - public void MemorySearchTestForForeign() - { - const int cityId = 71; - const string region = "荷兰|0|0|0|0"; - - var result = _dbSearcher.MemorySearch("86.84.21.60"); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - #endregion - - #region Normal Valid Special Ip Test Cases - [TestMethod] - [TestCategory("Special Ip Test")] - public void BinarySearchTestForSpecial() - { - const int cityId = 0; - const string region = "0|0|0|内网IP|内网IP"; - string[] specialIps = new string[] { "255.255.255.255", "0.0.0.0" }; - - foreach (var item in specialIps) - { - var result = _dbSearcher.BinarySearch(item); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - } - [TestMethod] - [TestCategory("Special Ip Test")] - public void BtreeSearchTestForSpecial() - { - const int cityId = 0; - const string region = "0|0|0|内网IP|内网IP"; - string[] specialIps = new string[] { "255.255.255.255", "0.0.0.0" }; - - foreach (var item in specialIps) - { - var result = _dbSearcher.BtreeSearch(item); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - } - [TestMethod] - [TestCategory("Special Ip Test")] - public void MemorySearchTestForSpecial() - { - const int cityId = 0; - const string region = "0|0|0|内网IP|内网IP"; - string[] specialIps = new string[] { "255.255.255.255", "0.0.0.0" }; - - foreach (var item in specialIps) - { - var result = _dbSearcher.MemorySearch(item); - Assert.AreEqual(result.CityID, cityId); - Assert.AreEqual(result.Region, region); - } - } - #endregion - } -} diff --git a/binding/c#/UnitTests/Properties/AssemblyInfo.cs b/binding/c#/UnitTests/Properties/AssemblyInfo.cs deleted file mode 100644 index 4ecebe1..0000000 --- a/binding/c#/UnitTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("UnitTests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("UnitTests")] -[assembly: AssemblyCopyright("Copyright © 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("38abc99f-cc14-47e3-9eeb-06c67d5ac33f")] - -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/binding/c#/UnitTests/UnitTests.csproj b/binding/c#/UnitTests/UnitTests.csproj deleted file mode 100644 index 4527142..0000000 --- a/binding/c#/UnitTests/UnitTests.csproj +++ /dev/null @@ -1,76 +0,0 @@ - - - - - Debug - AnyCPU - {38ABC99F-CC14-47E3-9EEB-06C67D5AC33F} - Library - Properties - UnitTests - UnitTests - v4.6 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - - - ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - - - - - - - - - - - - - - - {4c6032ee-43a5-4d5c-88f8-c411069e49e0} - IP2Region - - - - - - - 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - - - - - \ No newline at end of file diff --git a/binding/c#/UnitTests/packages.config b/binding/c#/UnitTests/packages.config deleted file mode 100644 index 31240c1..0000000 --- a/binding/c#/UnitTests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file