├── .github └── workflows │ └── release.yml ├── .gitignore ├── .travis.yml ├── CSharpKdb.sln ├── Demos ├── FeedDemo │ ├── FeedDemo.csproj │ ├── Program.cs │ └── nlog.config ├── QueryResponseDemo │ ├── Program.cs │ ├── QueryResponseDemo.csproj │ └── nlog.config ├── SerializationDemo │ ├── Program.cs │ ├── SerializationDemo.csproj │ └── nlog.config └── SubscriberDemo │ ├── Program.cs │ ├── SubscriberDemo.csproj │ └── nlog.config ├── LICENSE ├── README.md ├── docs ├── README.md ├── gui.md └── img │ ├── image10.png │ ├── image11.png │ ├── image12.png │ ├── image13.png │ ├── image3.png │ ├── image4.png │ ├── image5.png │ ├── image6.png │ ├── image7.png │ ├── image8.png │ └── image9.png ├── kx.Benchmark.Test ├── Connection │ ├── ConnectionBooleanArraySerialisationTests.cs │ ├── ConnectionByteArraySerialisationTests.cs │ ├── ConnectionCharArraySerialisationTests.cs │ ├── ConnectionDateArraySerialisationTests.cs │ ├── ConnectionDateTimeArraySerialisationTests.cs │ ├── ConnectionDoubleArraySerialisationTests.cs │ ├── ConnectionFloatArraySerialisationTests.cs │ ├── ConnectionGuidArraySerialisationTests.cs │ ├── ConnectionIntArraySerialisationTests.cs │ ├── ConnectionKTimeSpanArraySerialisationTests.cs │ ├── ConnectionLongArraySerialisationTests.cs │ ├── ConnectionMinuteArraySerialisationTests.cs │ ├── ConnectionMonthArraySerialisationTests.cs │ ├── ConnectionObjectArraySerialisationTests.cs │ ├── ConnectionSecondArraySerialisationTests.cs │ ├── ConnectionShortArraySerialisationTests.cs │ ├── ConnectionStringArraySerialisationTests.cs │ └── ConnectionTimeSpanArraySerialisationTests.cs ├── Program.cs ├── ReadMe.md ├── kx.Benchmark.Test.csproj └── kx.Benchmark.Test.snk ├── kx.Test ├── Connection │ ├── ConnectionArrayTests.cs │ ├── ConnectionAsyncWriteTests.cs │ ├── ConnectionNullTests.cs │ ├── ConnectionSerialisationTests.cs │ ├── ConnectionSyncWriteTests.cs │ └── ConnectionTests.cs ├── ReadMe.md ├── Scripts │ └── GenerateLocalReport.ps1 ├── TestUtils │ ├── TestSerialisationHelper.cs │ ├── TestableFailingTcpServer.cs │ └── TestableTcpServer.cs ├── Types │ ├── DateTests.cs │ ├── DictTests.cs │ ├── FlipTests.cs │ ├── KTimespanTests.cs │ ├── MinuteTests.cs │ ├── MonthTests.cs │ └── SecondTests.cs ├── kx.Test.csproj └── kx.Test.snk ├── kx ├── KException.cs ├── c.cs ├── kx.csproj └── kx.snk └── tools ├── travis-ci-build.sh └── travis-ci-install-sonar.sh /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release to Nuget 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: Setup .NET Core 15 | uses: actions/setup-dotnet@v1 16 | with: 17 | dotnet-version: 3.1.101 18 | - name: Create NuGet Package 19 | run: dotnet pack ./kx.csproj -c Release /p:Version=${{ github.event.release.tag_name }} /p:PackageReleaseNotes="See https://github.com/KxSystems/csharpkdb/releases/tag/${{ github.event.release.tag_name }}" 20 | working-directory: ./kx 21 | - name: Archive NuGet Package 22 | uses: actions/upload-artifact@v1 23 | with: 24 | name: KxSystems.csharpkdb 25 | path: ./kx/bin/Release/CSharpKDB.${{ github.event.release.tag_name }}.nupkg 26 | - name: Archive NuGet Package 27 | uses: actions/upload-artifact@v1 28 | with: 29 | name: KxSystems.csharpkdb 30 | path: ./kx/bin/Release/CSharpKDB.${{ github.event.release.tag_name }}.nupkg 31 | - name: Publish Nuget Package 32 | run: dotnet nuget push **/*.nupkg --api-key ${{ secrets.nuget_api_key }} --source https://api.nuget.org/v3/index.json --no-symbols true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | */obj/* 2 | */bin/* 3 | */.vs/* 4 | *.vs/* 5 | *.vscode/* 6 | coverage.xml 7 | CodeCoverage/* 8 | */TestResults/* 9 | *coverage.opencover.xml* 10 | Demos/*/bin/* 11 | Demos/*/obj/* 12 | BenchmarkDotNet.Artifacts/* 13 | **/.DS_Store 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | mono: none 3 | dotnet: 3.1 4 | solution: ./CSharpKdb.sln 5 | 6 | addons: 7 | sonarcloud: 8 | organization: "kxsystems" 9 | 10 | before_install: 11 | - bash ./tools/travis-ci-install-sonar.sh 12 | 13 | script: 14 | - bash ./tools/travis-ci-build.sh 15 | -------------------------------------------------------------------------------- /CSharpKdb.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 16 3 | VisualStudioVersion = 16.0.30611.23 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "kx", "kx\kx.csproj", "{9325FAD0-FE05-480C-900B-8ED51599F686}" 6 | EndProject 7 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "kx.Test", "kx.Test\kx.Test.csproj", "{7F243343-0765-4284-BC74-48675C58DE33}" 8 | EndProject 9 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeedDemo", "Demos\FeedDemo\FeedDemo.csproj", "{028FB0C9-D59B-44B2-AF36-2AA39FFFD195}" 10 | EndProject 11 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Demos", "Demos", "{428A79B0-7807-4A06-B3FA-3D79901EB792}" 12 | EndProject 13 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerializationDemo", "Demos\SerializationDemo\SerializationDemo.csproj", "{0EF4A2F8-3404-4E7F-907F-363600A0E91E}" 14 | EndProject 15 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubscriberDemo", "Demos\SubscriberDemo\SubscriberDemo.csproj", "{B7893219-FD8E-4E65-871C-ADF9FC10B74F}" 16 | EndProject 17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QueryResponseDemo", "Demos\QueryResponseDemo\QueryResponseDemo.csproj", "{02703ADC-E3DD-4306-8BC3-6C0F1E48AA45}" 18 | EndProject 19 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "kx.Benchmark.Test", "kx.Benchmark.Test\kx.Benchmark.Test.csproj", "{B70916E5-6668-4216-BDEF-147C4D0FDDF1}" 20 | EndProject 21 | Global 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|Any CPU = Debug|Any CPU 24 | Release|Any CPU = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {9325FAD0-FE05-480C-900B-8ED51599F686}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {9325FAD0-FE05-480C-900B-8ED51599F686}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {9325FAD0-FE05-480C-900B-8ED51599F686}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {9325FAD0-FE05-480C-900B-8ED51599F686}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {7F243343-0765-4284-BC74-48675C58DE33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {7F243343-0765-4284-BC74-48675C58DE33}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {7F243343-0765-4284-BC74-48675C58DE33}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {7F243343-0765-4284-BC74-48675C58DE33}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {028FB0C9-D59B-44B2-AF36-2AA39FFFD195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {028FB0C9-D59B-44B2-AF36-2AA39FFFD195}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {028FB0C9-D59B-44B2-AF36-2AA39FFFD195}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {028FB0C9-D59B-44B2-AF36-2AA39FFFD195}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {0EF4A2F8-3404-4E7F-907F-363600A0E91E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {0EF4A2F8-3404-4E7F-907F-363600A0E91E}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {0EF4A2F8-3404-4E7F-907F-363600A0E91E}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {0EF4A2F8-3404-4E7F-907F-363600A0E91E}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {B7893219-FD8E-4E65-871C-ADF9FC10B74F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {B7893219-FD8E-4E65-871C-ADF9FC10B74F}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {B7893219-FD8E-4E65-871C-ADF9FC10B74F}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {B7893219-FD8E-4E65-871C-ADF9FC10B74F}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {02703ADC-E3DD-4306-8BC3-6C0F1E48AA45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 48 | {02703ADC-E3DD-4306-8BC3-6C0F1E48AA45}.Debug|Any CPU.Build.0 = Debug|Any CPU 49 | {02703ADC-E3DD-4306-8BC3-6C0F1E48AA45}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {02703ADC-E3DD-4306-8BC3-6C0F1E48AA45}.Release|Any CPU.Build.0 = Release|Any CPU 51 | {B70916E5-6668-4216-BDEF-147C4D0FDDF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 52 | {B70916E5-6668-4216-BDEF-147C4D0FDDF1}.Debug|Any CPU.Build.0 = Debug|Any CPU 53 | {B70916E5-6668-4216-BDEF-147C4D0FDDF1}.Release|Any CPU.ActiveCfg = Release|Any CPU 54 | {B70916E5-6668-4216-BDEF-147C4D0FDDF1}.Release|Any CPU.Build.0 = Release|Any CPU 55 | EndGlobalSection 56 | GlobalSection(SolutionProperties) = preSolution 57 | HideSolutionNode = FALSE 58 | EndGlobalSection 59 | GlobalSection(NestedProjects) = preSolution 60 | {028FB0C9-D59B-44B2-AF36-2AA39FFFD195} = {428A79B0-7807-4A06-B3FA-3D79901EB792} 61 | {0EF4A2F8-3404-4E7F-907F-363600A0E91E} = {428A79B0-7807-4A06-B3FA-3D79901EB792} 62 | {B7893219-FD8E-4E65-871C-ADF9FC10B74F} = {428A79B0-7807-4A06-B3FA-3D79901EB792} 63 | {02703ADC-E3DD-4306-8BC3-6C0F1E48AA45} = {428A79B0-7807-4A06-B3FA-3D79901EB792} 64 | EndGlobalSection 65 | GlobalSection(ExtensibilityGlobals) = postSolution 66 | SolutionGuid = {55298CD4-27D4-4D00-9143-8A2275B50149} 67 | EndGlobalSection 68 | EndGlobal 69 | -------------------------------------------------------------------------------- /Demos/FeedDemo/FeedDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 1701;1702;1591 10 | true 11 | 12 | 13 | 14 | 1701;1702;1591 15 | true 16 | 17 | 18 | 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | Always 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Demos/FeedDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.Cryptography; 3 | using kx; 4 | using NLog; 5 | 6 | namespace FeedDemo 7 | { 8 | static class Program 9 | { 10 | private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); 11 | 12 | private const string QFunc = ".u.upd"; 13 | private const string TableName = "mytable"; 14 | 15 | static void Main() 16 | { 17 | string host = "localhost"; 18 | int port = 5001; 19 | string usernamePassword = $"{Environment.UserName}:mypassword"; 20 | 21 | c connection = null; 22 | try 23 | { 24 | connection = new c(host, port, usernamePassword); 25 | 26 | //Example of 10 single row inserts to a table 27 | InsertRows(connection); 28 | 29 | //Example of bulk inserts to a table to improve throughput 30 | BulkInsertRows(connection); 31 | 32 | } 33 | catch (Exception ex) 34 | { 35 | Logger.Error($"Error occurred running Feed-Demo. \r\n{ex}"); 36 | } 37 | finally 38 | { 39 | if (connection != null) 40 | { 41 | connection.Close(); 42 | } 43 | } 44 | } 45 | 46 | private static void InsertRows(c connection) 47 | { 48 | // Single row insert - not as efficient as bulk insert 49 | Logger.Info("Populating '{0}' table on kdb server with 10 rows...", TableName); 50 | 51 | for(int i = 0; i < 10; i++) 52 | { 53 | // Assumes a remote schema of mytable:([]time:`timespan$();sym:`symbol$();price:`float$();size:`long$()) 54 | object[] row = new object[] 55 | { 56 | new c.KTimespan(100), 57 | "SYMBOL", 58 | 93.5, 59 | 300L 60 | }; 61 | 62 | connection.ks(QFunc, TableName, row); 63 | } 64 | 65 | Logger.Info("Successfully inserted 10 rows to {0}", TableName); 66 | } 67 | 68 | private static void BulkInsertRows(c connection) 69 | { 70 | // Bulk row insert - more efficient 71 | string[] syms = new[] { "ABC", "DEF", "GHI", "JKL" }; 72 | 73 | c.KTimespan[] times = CreateTestArray(i => new c.KTimespan(i), 10); 74 | string[] symbols = CreateTestArray(i => syms[RandomNumberGenerator.GetInt32(syms.Length)], 10); 75 | double[] prices = CreateTestArray(i => i * 1.1, 10); 76 | long[] sizes = CreateTestArray(i => (long)(i * 100), 10); 77 | 78 | Logger.Info("Bulk populating '{0}' table on kdb server without using column names", TableName); 79 | 80 | connection.ks(QFunc, TableName, new object[] { times, symbols, prices, sizes }); 81 | 82 | Logger.Info("Bulk populating '{0}' table on kdb server using column names", TableName); 83 | 84 | connection.ks(QFunc, TableName, new c.Flip(new c.Dict(new string[] { "time", "sym", "price", "size" }, new object[] { times, symbols, prices, sizes }))); 85 | 86 | //block until all messages are processed 87 | connection.k(string.Empty); 88 | } 89 | 90 | private static T[] CreateTestArray(Func elementBuilder, int arraySize) 91 | { 92 | T[] array = new T[arraySize]; 93 | 94 | for (int i = 0; i < arraySize; i++) 95 | { 96 | array[i] = elementBuilder(i); 97 | } 98 | return array; 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Demos/FeedDemo/nlog.config: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | 8 | 9 | 10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /Demos/QueryResponseDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using kx; 3 | using NLog; 4 | 5 | namespace QueryResponseDemo 6 | { 7 | static class Program 8 | { 9 | private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); 10 | 11 | static void Main() 12 | { 13 | string host = "localhost"; 14 | int port = 5001; 15 | string usernamePassword = $"{Environment.UserName}:mypassword"; 16 | 17 | c connection = null; 18 | try 19 | { 20 | Logger.Info($"Connecting to {host}:{port}"); 21 | connection = new c(host, port, usernamePassword); 22 | 23 | connection.ksAsync("2+3"); 24 | 25 | object result = connection.k("2+3"); 26 | Logger.Info($"Result of 2+3:{result}"); 27 | 28 | result = connection.k("type",true); 29 | Logger.Info($"q type for c# bool:{result}"); 30 | 31 | result = connection.k("type",Guid.NewGuid()); 32 | Logger.Info($"q type for c# Guid:{result}"); 33 | 34 | result = connection.k("type",(byte)1); 35 | Logger.Info($"q type for c# byte:{result}"); 36 | 37 | result = connection.k("type",(short)1); 38 | Logger.Info($"q type for c# short:{result}"); 39 | 40 | result = connection.k("type",22); 41 | Logger.Info($"q type for c# int:{result}"); 42 | 43 | result = connection.k("type",22L); 44 | Logger.Info($"q type for c# long:{result}"); 45 | 46 | result = connection.k("type",22.2F); 47 | Logger.Info($"q type for c# float:{result}"); 48 | 49 | result = connection.k("type",22.2D); 50 | Logger.Info($"q type for c# double:{result}"); 51 | 52 | result = connection.k("type",'a'); 53 | Logger.Info($"q type for c# char:{result}"); 54 | 55 | result = connection.k("type","hello"); 56 | Logger.Info($"q type for c# string:{result}"); 57 | 58 | result = connection.k("type",new System.DateTime(1999, 1, 13, 3, 57, 32, 11)); 59 | Logger.Info($"q type for c# DateTime:{result}"); 60 | 61 | result = connection.k("type",new c.Month(1)); 62 | Logger.Info($"q type for c# c.Month:{result}"); 63 | 64 | result = connection.k("type",new c.Date(1)); 65 | Logger.Info($"q type for c# c.Date:{result}"); 66 | 67 | result = connection.k("type",new c.KTimespan(1)); 68 | Logger.Info($"q type for c# c.KTimespan:{result}"); 69 | 70 | result = connection.k("type",new c.Minute(1)); 71 | Logger.Info($"q type for c# c.Minute:{result}"); 72 | 73 | result = connection.k("type",new c.Second(1)); 74 | Logger.Info($"q type for c# c.Second:{result}"); 75 | 76 | result = connection.k("type",new TimeSpan(1)); 77 | Logger.Info($"q type for c# TimeSpan:{result}"); 78 | 79 | result = connection.k("type","hello".ToCharArray()); 80 | Logger.Info($"q type for c# character array:{result}"); 81 | } 82 | catch(Exception ex) 83 | { 84 | Logger.Error($"Error occurred running QueryResponse-Demo. \r\n{ex}"); 85 | } 86 | finally 87 | { 88 | if(connection != null) 89 | { 90 | connection.Close(); 91 | connection.Dispose(); 92 | } 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Demos/QueryResponseDemo/QueryResponseDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 1701;1702;1591 10 | true 11 | 12 | 13 | 14 | 1701;1702;1591 15 | true 16 | 17 | 18 | 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | Always 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Demos/QueryResponseDemo/nlog.config: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | 8 | 9 | 10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /Demos/SerializationDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using kx; 3 | using NLog; 4 | 5 | namespace SerializationDemo 6 | { 7 | static class Program 8 | { 9 | private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); 10 | 11 | static void Main() 12 | { 13 | string host = "localhost"; 14 | int port = 5001; 15 | string usernamePassword = $"{Environment.UserName}:mypassword"; 16 | 17 | c connection = null; 18 | 19 | int[] input = CreateTestArray(i => i % 10, 50000); 20 | 21 | try 22 | { 23 | connection = new c(host, port, usernamePassword); 24 | 25 | int[] deserialisedResult = 26 | connection.Deserialize(connection.Serialize(1, input)) as int[]; 27 | 28 | Logger.Info("{0}", System.Linq.Enumerable.SequenceEqual(input, deserialisedResult)); 29 | } 30 | catch (Exception ex) 31 | { 32 | Logger.Error($"Error occurred running Serialization-Demo. \r\n{ex}"); 33 | } 34 | finally 35 | { 36 | if (connection != null) 37 | { 38 | connection.Close(); 39 | } 40 | } 41 | } 42 | 43 | private static T[] CreateTestArray(Func elementBuilder, int arraySize) 44 | { 45 | T[] array = new T[arraySize]; 46 | 47 | for (int i = 0; i < arraySize; i++) 48 | { 49 | array[i] = elementBuilder(i); 50 | } 51 | return array; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Demos/SerializationDemo/SerializationDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 1701;1702;1591 10 | true 11 | 12 | 13 | 14 | 1701;1702;1591 15 | true 16 | 17 | 18 | 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | Always 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Demos/SerializationDemo/nlog.config: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | 8 | 9 | 10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /Demos/SubscriberDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using kx; 4 | using NLog; 5 | 6 | namespace SubscriberDemo 7 | { 8 | static class Program 9 | { 10 | private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); 11 | 12 | static void Main() 13 | { 14 | string host = "localhost"; 15 | int port = 5001; 16 | string usernamePassword = $"{Environment.UserName}:mypassword"; 17 | 18 | c connection = null; 19 | try 20 | { 21 | connection = new c(host, port, usernamePassword); 22 | 23 | //open subscription 24 | connection.ks(".u.sub", "mytable", "MSFT"); 25 | 26 | bool subscribing = true; 27 | 28 | //start processing subscriptions until user exit or error 29 | Task.Factory.StartNew(() => 30 | { 31 | Logger.Info("Processing subscription results. Press any key to exit"); 32 | while (subscribing) 33 | { 34 | try 35 | { 36 | Logger.Info($"Received subscription result:{connection.k()}"); 37 | } 38 | catch (Exception) 39 | { 40 | Logger.Error("Error occurred processing Subscription. Exiting Subscription-Demo"); 41 | subscribing = false; 42 | } 43 | } 44 | }); 45 | 46 | Console.ReadLine(); 47 | subscribing = false; 48 | 49 | } 50 | catch (Exception ex) 51 | { 52 | Logger.Error($"Error occurred running Subscription-Demo. \r\n{ex}"); 53 | } 54 | finally 55 | { 56 | if (connection != null) 57 | { 58 | connection.Close(); 59 | } 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Demos/SubscriberDemo/SubscriberDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 1701;1702;1591 10 | true 11 | 12 | 13 | 14 | 1701;1702;1591 15 | true 16 | 17 | 18 | 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | Always 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Demos/SubscriberDemo/nlog.config: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | 8 | 9 | 10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C# KDB 2 | 3 | [![Travis](https://img.shields.io/travis/com/kxsystems/csharpkdb/main)](https://travis-ci.com/github/KxSystems/csharpkdb) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=KxSystems_csharpkdb&metric=coverage)](https://sonarcloud.io/dashboard?id=KxSystems_csharpkdb) 4 | 5 | 6 | 7 | *The C# KDB library provides functionality for .NET applications to interface with a kdb+ process.* 8 | 9 | The library is compiled on .NET Standard 2.0 and supports running applications on 10 | 11 | - .NET Core 2.0 - 3.1 12 | - .NET Framework 4.6.1 - 4.8 13 | 14 | See https://dotnet.microsoft.com/platform/dotnet-standard for further details 15 | 16 | **Documentation** in :open_file_folder: [`docs`](docs) 17 | 18 | ## Client integration 19 | 20 | ### NuGet releases 21 | 22 | Latest release version can be downloaded from [NuGet](https://www.nuget.org/packages/CSharpKDB/). 23 | 24 | Client-applications can search and install "CSharpKDB" package either via 25 | 26 | - [Visual Studio](https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio) 27 | 28 | - [Package Manager Console](https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-powershell) 29 | 30 | Example 31 | ```powershell 32 | 33 | PM> Find-Package CSharpKDB 34 | 35 | Id Versions Description 36 | -- -------- ----------- 37 | CSharpKDB "Provides functionality for .NET applications to interface with a kdb+ process. " 38 | Time Elapsed: 00:00:00.8274076 39 | 40 | PM> Install-Package CSharpKDB 41 | Restoring packages for ... 42 | Installing NuGet package CSharpKDB .... 43 | ``` 44 | 45 | 46 | 47 | ## `c.cs` 48 | 49 | The main entry point for client applications is the `kx.c.cs` class. 50 | 51 | Example: 52 | ```csharp 53 | public static void Main(string[]args) 54 | { 55 | //establish connection 56 | c connection = null; 57 | try 58 | { 59 | connection = new c("localhost", 5001); 60 | connection.ReceiveTimeout = 1000; 61 | connection.e = System.Text.Encoding.UTF8; 62 | 63 | Console.WriteLine("Unicode " + connection.k("`$\"c\"$0x52616e627920426ac3b6726b6c756e64204142")); 64 | 65 | //insert some data-rows 66 | object [] x = new object[] 67 | { 68 | DateTime.Now.TimeOfDay, 69 | "xx", 70 | (double)93.5, 71 | 300, 72 | }; 73 | 74 | for (int i = 0; i < 1000; ++i) 75 | { 76 | connection.k("insert", "trade", x); 77 | } 78 | 79 | //read data 80 | Flip result = c.td(connection.k("select sum price by sym from trade")); 81 | 82 | Console.WriteLine("cols: " + c.n(result.x)); 83 | Console.WriteLine("rows: "+ c.n(result.y[0])); 84 | } 85 | finally 86 | { 87 | //finally close connection 88 | connection.Close(); 89 | } 90 | } 91 | 92 | ``` 93 | 94 | ## Examples 95 | 96 | Supplied with the code is a series of code examples. The following describes each with an example of how to run from command prompt. Note minimum [.NET Core SDK and Runtime](https://dotnet.microsoft.com/download) should be installed. 97 | 98 | ### QueryResponse demo 99 | 100 | Instructs the remote kdb+ process to execute q code (kdb+ native language) and receives the result. 101 | The same principle can be used to execute q functions. Example of a sync request: 102 | 103 | #### Prerequisite 104 | 105 | A kdb+ server running on port 5001 on your machine i.e. `q -p 5001` 106 | 107 | #### Run commands 108 | ``` bat 109 | REM Need to ensure nuget dependencies have been loaded 110 | dotnet restore .\CSharpKdb.sln 111 | 112 | REM Build Release version of Demo application 113 | dotnet msbuild Demos\QueryResponseDemo\QueryResponseDemo.csproj /p:Configuration="Release" 114 | 115 | REM Run demo application 116 | dotnet .\Demos\QueryResponseDemo\bin\Release\netcoreapp3.1\QueryResponseDemo.dll 117 | ``` 118 | 119 | ### Serialization demo 120 | 121 | Example of code that can be used to serialize/dezerialize a C# type (array of ints) to kdb+ format. 122 | 123 | #### Prerequisite 124 | 125 | A kdb+ server running on port 5001 on your machine i.e. `q -p 5001` 126 | 127 | #### Run commands 128 | ``` bat 129 | REM Need to ensure nuget dependencies have been loaded 130 | dotnet restore .\CSharpKdb.sln 131 | 132 | REM Build Release version of Demo application 133 | dotnet msbuild Demos\SerializationDemo\SerializationDemo.csproj /p:Configuration="Release" 134 | 135 | REM Run demo application 136 | dotnet .\Demos\SerializationDemo\bin\Release\netcoreapp3.1\SerializationDemo.dll 137 | ``` 138 | 139 | ### Feed demo 140 | 141 | Example of creating an update function remotely (to capture table inserts), along with table creation and population of the table. 142 | Table population has an example of single row inserts (lower latency) and bulk inserts (better throughput and resource utilization). 143 | 144 | #### Prerequisite 145 | 146 | A kdb+ server running on port 5001 on your machine i.e. `q -p 5001`. 147 | 148 | This example depends on a `.u.upd` function being defined and a table named `mytable` pre-existing, you may wish to run the following within the kdb+ server (in normal environments, these table and function definitions should be pre-created by your kdb+ admin). 149 | 150 | ```q 151 | q).u.upd:{[tbl;row] insert[tbl](row)} 152 | q)mytable:([]time:`timespan$();sym:`symbol$();price:`float$();size:`long$()) 153 | ``` 154 | 155 | #### Run commands 156 | ``` bat 157 | REM Need to ensure nuget dependencies have been loaded 158 | dotnet restore .\CSharpKdb.sln 159 | 160 | REM Build Release version of Demo application 161 | dotnet msbuild Demos\FeedDemo\FeedDemo.csproj /p:Configuration="Release" 162 | 163 | REM Run demo application 164 | dotnet .\Demos\FeedDemo\bin\Release\netcoreapp3.1\FeedDemo.dll 165 | ``` 166 | 167 | ### Subscriber demo 168 | Example app that subscribes to real-time updates from a table that is maintained in kdb+. 169 | 170 | #### Prerequisite 171 | 172 | A kdb+ server running on port 5001 on your machine. The instance must have the `.u.sub` function defined. An example of `.u.sub` can be found in [KxSystems/kdb-tick](https://github.com/KxSystems/kdb-tick), an example tickerplant. 173 | 174 | This example will subscribe to updates to a table called 'mytable', filtering on the sym column for any updates using the symbol 'MSFT'. 175 | 176 | Once the kdb-tick example is downloaded, create a file called `sym.q` in the `tick` folder with the following contents 177 | ``` 178 | mytable:([]time:`timespan$(); sym:`g#`symbol$(); price:`float$(); size:`int$(); side:`char$()) 179 | ``` 180 | 181 | #### Run command 182 | 183 | Create a kdb+ process which operates as a tickerplant by running `q tick.q -p 5001 -t 0` (listening on port 5001, with real-time updates). 184 | 185 | Run the C# subscriber example: 186 | 187 | ``` bat 188 | REM Need to ensure nuget dependencies have been loaded 189 | dotnet restore .\CSharpKdb.sln 190 | 191 | REM Build Release version of Demo application 192 | dotnet msbuild Demos\SubscriberDemo\SubscriberDemo.csproj /p:Configuration="Release" 193 | 194 | REM Run demo application 195 | dotnet .\Demos\SubscriberDemo\bin\Release\netcoreapp3.1\SubscriberDemo.dll 196 | ``` 197 | 198 | Once the subscriber has connected to the tickerplant, the following can be run in the tickerplant to see that a client has connected and subscribing to the relevant data 199 | ```q 200 | q).u.w 201 | mytable| 8i `MSFT 202 | ``` 203 | 204 | Run the following in the tickerplant to emulate an application publishing data to the tickerplant, via its in-build .u.upd function. 205 | ```q 206 | q).u.upd[`mytable;(.z.n;`MSFT;35.65;100;`B)] 207 | ``` 208 | As this is data for the table 'mytable', subscribed clients matching the criteria will be informed in real-time. The C# client will therefore be notified of the data for processing or enrichment. 209 | 210 | ## Change record 211 | 212 | - 2020-11-16 : Issue 2# : Reformat code 213 | - 2017-05-23 : Identify string[] as type 11 214 | - 2017-04-18 : Added ssl/tls support 215 | - 2014-01-29 : Make method n public 216 | - 2013-12-19 : qn did not detect null guid 217 | - 2013-12-10 : Remove retry logic on authentication fail. For kdb+2.5 and prior, 218 | 219 | Use 220 | ```csharp 221 | B = new byte[1+u.Length]; 222 | Connect(h,p); 223 | s=this.GetStream(); 224 | J=0;w(u); 225 | s.Write(B,0,J); 226 | if(1!=s.Read(B,0,1))... 227 | ``` 228 | 229 | - 2013.09.16 : za represents -0Wd, not 0Nd 230 | - 2013.08.20 : null val for TimeStamp -> nj 231 | - 2012.06.07 : Fixed scoping of GUID 232 | - 2012.05.29 : For use with kdb+v3.0, changed handshake and added Guid. boolean v6->vt tracks type capability. 233 | - 2012.01.26 : Refactored clamp into clampDT, for Date.DateTime() 234 | - 2012.01.25 : rz() clamp datetime to valid range 235 | - 2010.11.17 : Block sending new timetypes to version of kdb+ prior to v2.6 (use prior release of c.cs for older kdb+ versions) 236 | 237 | Max buffer size (default 64kB) used for reading is now a parameter to the c constructor Date, Month, Minute, Second, KTimeSpan are now serializable, implement IComparable and have default constructors for xml serialization. 238 | 239 | Added NULL(Type t) 240 | 241 | - 2010/08.05 : Added KException for exceptions due to server error, authentication fail and func decode 242 | - 2010/01.14 : Exposed static var e (Encoding) as public 243 | - 2010/01.12 : Added support for unicode encoding, defaults to ASCII 244 | - 2010/01.11 : Added null checks for qn for UDTs Date,Month,Minute,Second,KTimespan 245 | - 2010/01.04 : Added new time types (timespan->KTimespan,timestamp->DateTime), drop writing kdb+ datetime 246 | - 2009/10.19 : Limit reads to blocks of 64kB to reduce load on kernel memory 247 | - 2007/09.26 : 0Wz to MaxValue 248 | - 2006/10.05 : Truncate string at null 249 | - 2006/09.29 : NULL c.Date class(sync with c.java) 250 | 251 | SSL/TLS: To use self-signed certificates add them to the Local Computer Trusted Root Certification Authorities 252 | 253 | 254 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # C# interface to kdb+ 2 | 3 | 4 | The C\# interface to kdb+ is implemented in the `c` class, which implements the protocol to interact with a kdb+ server. 5 | The interface closely resembles that for [interfacing with Java](https://github.com/javakdb). 6 | 7 | ## Connecting to kdb+ 8 | 9 | ### Connecting using TCP 10 | 11 | Instances may be constructed with one of the following constructors: 12 | 13 | signature | notes 14 | ---------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------ 15 | `public c(string host, int port, string usernameAndPassword)` | Throws `Exception("access")` if access is denied by the q server. The username and password should be of the format username:password 16 | `public c(string host, int port)` | Throws `Exception("access")` if access is denied by the q server. Uses `Environment.!UserName` as the login name and password 17 | 18 | It is important to close the `c` object explicitly, via the `Close` method, when we are finished with the connection to a kdb+ server. 19 | 20 | The class provides a number of other features explored in the following sections. 21 | 22 | ### Connecting using UDS (Unix Domain Sockets) 23 | 24 | As an alternative to the standard TCP connection, kdb+ can use UDS. See [here](https://code.kx.com/q/basics/listening-port/#unix-domain-socket) for details. 25 | 26 | UDS requires support on the underlying Operating System and the client/server residing on same machine. 27 | 28 | Example of client connection when kdb+ listening on 5001: 29 | 30 | ```c# 31 | connection = new c("/tmp/kx.5001","username:password"); 32 | ``` 33 | 34 | ## Maximum Message Size 35 | 36 | The maximum transmissible message size is 2GB due to a limitation with the maximum array size in C\#, therefore [capability 3](https://code.kx.com/q/basics/ipc/#handshake) will be used within the kdb+ handshake. 37 | 38 | ## Utility class for q types 39 | 40 | Within the `c` class are a number of utility classes provided which match the available types in q that do not map directly to standard classes such as Integer. 41 | In general these classes have all their fields declared with public access, and several provide custom `toString()` methods to decode the data payload. 42 | 43 | | class | members | methods | notes | 44 | |--------|----------------------------|----------------------------------|-----------------------------------------------------------------------------------------------------------| 45 | | Dict | object x; object y | `int find(string[] x, string y)` | | 46 | | Flip | string\[\] x, object\[\] y | `public object at(string s)` | | 47 | | Month | int i | `string ToString()` | Provides `ToString()` to decode the i field | 48 | | Minute | int i | `string ToString()` | Provides `ToString()` to decode the i field | 49 | | Second | int i | `string ToString()` | Provides `ToString()` to decode the i field | 50 | | Date | int i | `string ToString()` | Provides `ToString()` to decode the i field. Provides constructors which decode from int, long and DateTime | 51 | 52 | 53 | ## Creating null values 54 | 55 | For each type character, we can get a reference to a null q value by indexing into the NU Object array using the `NULL` utility method. 56 | Note that the q null values are not the same as C\#’s null. 57 | 58 | An example of creating an object array containing two null q integers: 59 | 60 | ```c# 61 | #!text/x-c++src 62 | object[] twoNullIntegers = {NULL('i'), NULL('i')}; 63 | ``` 64 | 65 | The q null values are mapped to C\# values according to the following table: 66 | 67 | q type | q null accessor | C\# null 68 | ----------|-------------|---------------------------- 69 | Boolean | `NULL('b')` | `false` 70 | Guid | `NULL('g')` | `Guid.Empty` 71 | Byte | `NULL('x')` | `(byte)0` 72 | Short | `NULL('h')` | `Int16.MinValue` 73 | Integer | `NULL('i')` | `Int32.MinValue` 74 | Long | `NULL('j')` | `Int64.MinValue` 75 | Float | `NULL('e')` | `(Single)Double.NaN` 76 | Double | `NULL('f')` | `Double.NaN` 77 | Character | `NULL('c')` | `' '` 78 | Symbol | `NULL('s')` | `""` 79 | Timestamp | `NULL('p')` | `System.DateTime(0)` 80 | Month | `NULL('m')` | `c.Month(Int32.MinValue)` 81 | Date | `NULL('d')` | `c.Date(Int32.MinValue)` 82 | DateTime | `NULL('z')` | `(depreciated in favour of Timestamp)` 83 | TimeSpan | `NULL('n')` | `c.KTimespan(Int64.MinValue)` 84 | Minute | `NULL('u')` | `c.Minute(Int32.MinValue)` 85 | Second | `NULL('v')` | `c.Second(Int32.MinValue)` 86 | Time | `NULL('t')` | `TimeSpan(Int64.MinValue)` 87 | 88 | We can check whether a given Object x is a q null using the `c` utility method: 89 | 90 | ```c# 91 | #!text/x-c++src 92 | public static bool qn(object x); 93 | ``` 94 | 95 | 96 | ## Q types of C\# objects 97 | 98 | The following sections list the mapping of C\# types to [q data types](https://code.kx.com/q/basics/datatypes/). 99 | 100 | The datetime datatype (15) is deprecated in favour of the 8-byte timestamp datatype (12). 101 | If such compatibility is required, this can be handled by various methods such as casting the resulting timestamp to a datetime on the server side. 102 | 103 | The default return value for all other objects is 0. 104 | 105 | ### Atoms 106 | 107 | For reference, internally, types are mapped as follows for atoms: 108 | 109 | | C\# object type | q type | q type number | 110 | |-----------------|--------| ---------------| 111 | | bool | bool | -1 | 112 | | Guid | guid | -2 | 113 | | byte | byte | -4 | 114 | | short | short | -5 | 115 | | int | int | -6 | 116 | | long | long | -7 | 117 | | float | real | -8 | 118 | | double | float | -9 | 119 | | char | char | -10 | 120 | | string | symbol | -11 | 121 | | DateTime | timestamp | -12 | 122 | | c.Month | month | -13 | 123 | | c.Date | date | -14 | 124 | | (depreciated in favour of C# DateTime mapping to timestamp) | datetime | -15 | 125 | | c.KTimespan | timespan | -16 | 126 | | c.Minute | minute | -17 | 127 | | c.Second | second | -18 | 128 | | TimeSpan | time | -19 | 129 | 130 | ### Vectors 131 | 132 | C\# object type | q type number 133 | ----------------|-------------- 134 | object\[\] | 0 135 | bool\[\] | 1 136 | byte\[\] | 4 137 | short\[\] | 5 138 | int\[\] | 6 139 | long\[\] | 7 140 | float\[\] | 8 141 | double\[\] | 9 142 | char\[\] | 10 143 | String\[\] | 11 144 | DateTime\[\] | 12 145 | c.Month\[\] | 13 146 | c.Date\[\] | 14 147 | (depreciated in favour of DateTime) | 15 148 | c.KTimeSpan\[\] | 16 149 | c.Minute\[\] | 17 150 | c.Second\[\] | 18 151 | TimeSpan\[\] | 19 152 | 153 | ### Complex Data 154 | 155 | C\# object type | q type | q type number 156 | ----------------|--------|-------------- 157 | Flip | table | 98 158 | Dict | dictionary | 99 159 | 160 | 161 | ## Interacting with kdb+ via an open `c` instance 162 | 163 | Interacting with the kdb+ server is very simple. 164 | You must make a basic choice between sending a message to the server where you expect no answer, 165 | or will check later for an answer. 166 | 167 | In the first case, where we will not wait for a response, use the `ks` method on a `c` instance: 168 | 169 | ```c# 170 | public void ks(String s) 171 | public void ks(String s,Object x) 172 | public void ks(String s,Object x,Object y) 173 | ``` 174 | 175 | Alternatively, should we expect an immediate response, use the `k` method: 176 | 177 | ```c# 178 | public object k(object x) 179 | public object k(string s) 180 | public object k(string s,object x) 181 | public object k(string s,object x,object y) 182 | public object k(string s,object x,object y,object z) 183 | ``` 184 | 185 | The parameters to methods `k` and `ks`, and its result, are arbitrarily-nested arrays (Integer, Double, int\[\], DateTime, etc). 186 | If you need to pass more than 3 arguments, you should put them in list(s). 187 | 188 | As a special case of the `k` method, we may receive a message from the server without sending any message as an argument: 189 | 190 | ```c# 191 | public object k() 192 | ``` 193 | 194 | 195 | ## Accessing items of arrays 196 | 197 | We can access elements using the `at` method: 198 | 199 | ```c# 200 | public static object at(object x,int i) // Returns the object at x\[i\] or null 201 | ``` 202 | 203 | and set them with `set`: 204 | 205 | ```c# 206 | public static void set(object x,int i,object y) // Set x\[i\] to y, or the appropriate q null value if y is null 207 | ``` 208 | 209 | 210 | ## Bulk transfers 211 | 212 | A kdb+tick feed handler can send one record at a time, like this 213 | 214 | ```c# 215 | #!text/x-c++src 216 | Object[] row = {"ibm", new Double(93.5), new Integer(300)}; 217 | c.ks(".u.upd", "trade", row); 218 | ``` 219 | 220 | or send many records at a time: 221 | 222 | ```c# 223 | #!text/x-c++src 224 | int n = 100; 225 | Object[] rows = {new String[n], new double[n], new int[n]}; 226 | for(int i=0; i0?",":"")+flip.x[column]); 267 | System.Console.WriteLine(); 268 | for(int row=0;row0?",":"")+c.at(flip.y[column],row)); // c.at extracts the cell from column,row. 271 | System.Console.WriteLine(); 272 | } 273 | c.Close(); 274 | } 275 | } 276 | ``` 277 | 278 | 279 | ### Simple insert 280 | 281 | This connects to a q process, creates a table to insert into, and then inserts a single row to that table. 282 | 283 | ```c# 284 | using System; 285 | using System.IO; 286 | using System.Net.Sockets; 287 | using kx; 288 | public class Insert{ 289 | public static void Main(string[]args){ 290 | c c=new c("localhost",5001,"username:password"); 291 | c.ks("mytrade:([]time:();sym:();price:();size:())"); // create an empty dummy table which we will insert into 292 | object[]x=new object[4]; 293 | x[0]=DateTime.Now.TimeOfDay; 294 | x[1]="abc"; 295 | x[2]=(double)93.5; 296 | x[3]=300; 297 | c.k("insert","mytrade",x); 298 | c.Close(); 299 | } 300 | } 301 | ``` 302 | 303 | 304 | ### Simple bulk insert 305 | 306 | This connects to a q process, creates a table to insert into, and then inserts 1024 rows to that table. 307 | 308 | ```c# 309 | using System; 310 | using System.IO; 311 | using System.Net.Sockets; 312 | using kx; 313 | public class BulkInsert{ 314 | public static void Main(string[]args){ 315 | Random rnd=new Random(); 316 | string[] syms=new string[]{"abc","def","ghi","jki"}; 317 | c c=new c("localhost",5001,"username:password"); 318 | c.ks("mytrade:([]time:();sym:();price:();size:())"); 319 | object[]x=new object[4]; 320 | System.TimeSpan[] time=new System.TimeSpan[1024]; 321 | string[]sym=new string[1024]; 322 | double[]price=new double[1024]; 323 | int[]size=new int[1024]; 324 | for(int i=0;i<1024;i++){ 325 | time[i]=DateTime.Now.TimeOfDay; 326 | sym[i]=syms[rnd.Next(0,syms.Length)]; 327 | price[i]=(double)rnd.Next(0,200); 328 | size[i]=100*rnd.Next(1,10); 329 | } 330 | x[0]=time; 331 | x[1]=sym; 332 | x[2]=price; 333 | x[3]=size; 334 | c.k("insert","mytrade",x); 335 | c.Close(); 336 | } 337 | } 338 | ``` 339 | 340 | 341 | ### Simple subscriber 342 | 343 | This code subscribes to a ticker plant, and prints updates to the console as they are received. 344 | 345 | ```c# 346 | using System; 347 | using System.IO; 348 | using System.Net.Sockets; 349 | using kx; 350 | 351 | public class Subscriber{ 352 | public static void Main(string[]args){ 353 | c c=null; 354 | try{ 355 | c=new c("localhost",5001,"username:password"); 356 | c.k("sub[`trade;`MSFT.O`IBM.N]"); 357 | while(true){ 358 | object result=c.k(); 359 | c.Flip flip=c.td(result); 360 | int nRows=c.n(flip.y[0]); 361 | int nColumns=c.n(flip.x); 362 | for(int row=0;row0?",":"")+c.at(flip.y[column],row)); 365 | System.Console.WriteLine(); 366 | } 367 | } 368 | } 369 | finally{ 370 | if(c!=null)c.Close(); 371 | } 372 | } 373 | } 374 | ``` 375 | 376 | -------------------------------------------------------------------------------- /docs/img/image10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image10.png -------------------------------------------------------------------------------- /docs/img/image11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image11.png -------------------------------------------------------------------------------- /docs/img/image12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image12.png -------------------------------------------------------------------------------- /docs/img/image13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image13.png -------------------------------------------------------------------------------- /docs/img/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image3.png -------------------------------------------------------------------------------- /docs/img/image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image4.png -------------------------------------------------------------------------------- /docs/img/image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image5.png -------------------------------------------------------------------------------- /docs/img/image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image6.png -------------------------------------------------------------------------------- /docs/img/image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image7.png -------------------------------------------------------------------------------- /docs/img/image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image8.png -------------------------------------------------------------------------------- /docs/img/image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/docs/img/image9.png -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionBooleanArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionBooleanArraySerialisationTests 11 | { 12 | private bool[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesBooleanArrayInput() 19 | { 20 | bool[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | bool[] result = connection.Deserialize(serialisedData) as bool[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesBooleanArrayInputWithZipEnabled() 34 | { 35 | bool[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | bool[] result = connection.Deserialize(serialisedData) as bool[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new bool[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = i % 2 == 0; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionByteArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionByteArraySerialisationTests 11 | { 12 | private byte[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesByteArrayInput() 19 | { 20 | byte[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | byte[] result = connection.Deserialize(serialisedData) as byte[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesByteArrayInputWithZipEnabled() 34 | { 35 | byte[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | byte[] result = connection.Deserialize(serialisedData) as byte[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new byte[Number]; 53 | for(int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = 0x20; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionCharArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using BenchmarkDotNet.Attributes; 4 | using NUnit.Framework; 5 | 6 | namespace kx.Benchmark.Test.Connection 7 | { 8 | [MemoryDiagnoser] 9 | [MedianColumn] 10 | [MaxColumn] 11 | public class ConnectionCharArraySerialisationTests 12 | { 13 | private char[] _data; 14 | 15 | [Params(1000, 10000, 100000, 500000)] 16 | public int Number { get; set; } 17 | 18 | [Benchmark] 19 | public void ConnectionSerialisesAndDeserialisesCharArrayInput() 20 | { 21 | char[] expected = _data; 22 | 23 | using (var connection = new c(3)) 24 | { 25 | byte[] serialisedData = connection.Serialize(1, expected); 26 | 27 | char[] result = connection.Deserialize(serialisedData) as char[]; 28 | 29 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 30 | } 31 | } 32 | 33 | [Benchmark] 34 | public void ConnectionSerialisesAndDeserialisesCharArrayInputWithZipEnabled() 35 | { 36 | char[] expected = _data; 37 | 38 | using (var connection = new c(3)) 39 | { 40 | connection.IsZipEnabled = true; 41 | 42 | byte[] serialisedData = connection.Serialize(1, expected); 43 | 44 | char[] result = connection.Deserialize(serialisedData) as char[]; 45 | 46 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 47 | } 48 | } 49 | 50 | [GlobalSetup] 51 | public void Setup() 52 | { 53 | _data = new char[Number]; 54 | for (int i = 0; i < _data.Length; i++) 55 | { 56 | _data[i] = (char)Math.Abs(new Random(i).Next(0, 127)); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionDateArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using BenchmarkDotNet.Attributes; 4 | using NUnit.Framework; 5 | 6 | namespace kx.Benchmark.Test.Connection 7 | { 8 | [MemoryDiagnoser] 9 | [MedianColumn] 10 | [MaxColumn] 11 | public class ConnectionDateArraySerialisationTests 12 | { 13 | private c.Date[] _data; 14 | 15 | [Params(1000, 10000, 100000, 500000)] 16 | public int Number { get; set; } 17 | 18 | [Benchmark] 19 | public void ConnectionSerialisesAndDeserialisesDateArrayInput() 20 | { 21 | c.Date[] expected = _data; 22 | 23 | using (var connection = new c(3)) 24 | { 25 | byte[] serialisedData = connection.Serialize(1, expected); 26 | 27 | c.Date[] result = connection.Deserialize(serialisedData) as c.Date[]; 28 | 29 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 30 | } 31 | } 32 | 33 | [Benchmark] 34 | public void ConnectionSerialisesAndDeserialisesDateArrayInputWithZipEnabled() 35 | { 36 | c.Date[] expected = _data; 37 | 38 | using (var connection = new c(3)) 39 | { 40 | connection.IsZipEnabled = true; 41 | 42 | byte[] serialisedData = connection.Serialize(1, expected); 43 | 44 | c.Date[] result = connection.Deserialize(serialisedData) as c.Date[]; 45 | 46 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 47 | } 48 | } 49 | 50 | [GlobalSetup] 51 | public void Setup() 52 | { 53 | DateTime dt = new DateTime(2020, 11, 11, 0, 0, 0, DateTimeKind.Utc); 54 | _data = new c.Date[Number]; 55 | for (int i = 0; i < _data.Length; i++) 56 | { 57 | _data[i] = new c.Date(dt.AddSeconds(i)); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionDateTimeArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using BenchmarkDotNet.Attributes; 4 | using NUnit.Framework; 5 | 6 | namespace kx.Benchmark.Test.Connection 7 | { 8 | [MemoryDiagnoser] 9 | [MedianColumn] 10 | [MaxColumn] 11 | public class ConnectionDateTimeArraySerialisationTests 12 | { 13 | private DateTime[] _data; 14 | 15 | [Params(1000, 10000, 100000, 500000)] 16 | public int Number { get; set; } 17 | 18 | [Benchmark] 19 | public void ConnectionSerialisesAndDeserialisesDateTimeArrayInput() 20 | { 21 | DateTime[] expected = _data; 22 | 23 | using (var connection = new c(3)) 24 | { 25 | byte[] serialisedData = connection.Serialize(1, expected); 26 | 27 | DateTime[] result = connection.Deserialize(serialisedData) as DateTime[]; 28 | 29 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 30 | } 31 | } 32 | 33 | [Benchmark] 34 | public void ConnectionSerialisesAndDeserialisesDateTimeArrayInputWithZipEnabled() 35 | { 36 | DateTime[] expected = _data; 37 | 38 | using (var connection = new c(3)) 39 | { 40 | connection.IsZipEnabled = true; 41 | 42 | byte[] serialisedData = connection.Serialize(1, expected); 43 | 44 | DateTime[] result = connection.Deserialize(serialisedData) as DateTime[]; 45 | 46 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 47 | } 48 | } 49 | 50 | [GlobalSetup] 51 | public void Setup() 52 | { 53 | DateTime dt = new DateTime(2020, 11, 11, 0, 0, 0, DateTimeKind.Utc); 54 | _data = new DateTime[Number]; 55 | for (int i = 0; i < _data.Length; i++) 56 | { 57 | _data[i] = dt.AddSeconds(i); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionDoubleArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionDoubleArraySerialisationTests 11 | { 12 | private double[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesDoubleArrayInput() 19 | { 20 | double[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | double[] result = connection.Deserialize(serialisedData) as double[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesDoubleArrayInputWithZipEnabled() 34 | { 35 | double[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | double[] result = connection.Deserialize(serialisedData) as double[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new double[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = (double)i / 2; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionFloatArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionFloatArraySerialisationTests 11 | { 12 | private float[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesFloatArrayInput() 19 | { 20 | float[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | float[] result = connection.Deserialize(serialisedData) as float[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesFloatArrayInputWithZipEnabled() 34 | { 35 | float[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | float[] result = connection.Deserialize(serialisedData) as float[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new float[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = (float)i / 2; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionGuidArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using BenchmarkDotNet.Attributes; 4 | using NUnit.Framework; 5 | 6 | namespace kx.Benchmark.Test.Connection 7 | { 8 | [MemoryDiagnoser] 9 | [MedianColumn] 10 | [MaxColumn] 11 | public class ConnectionGuidArraySerialisationTests 12 | { 13 | private Guid[] _data; 14 | 15 | [Params(1000, 10000, 100000, 500000)] 16 | public int Number { get; set; } 17 | 18 | [Benchmark] 19 | public void ConnectionSerialisesAndDeserialisesGuidArrayInput() 20 | { 21 | Guid[] expected = _data; 22 | 23 | using (var connection = new c(3)) 24 | { 25 | byte[] serialisedData = connection.Serialize(1, expected); 26 | 27 | Guid[] result = connection.Deserialize(serialisedData) as Guid[]; 28 | 29 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 30 | } 31 | } 32 | 33 | [Benchmark] 34 | public void ConnectionSerialisesAndDeserialisesGuidArrayInputWithZipEnabled() 35 | { 36 | Guid[] expected = _data; 37 | 38 | using (var connection = new c(3)) 39 | { 40 | connection.IsZipEnabled = true; 41 | 42 | byte[] serialisedData = connection.Serialize(1, expected); 43 | 44 | Guid[] result = connection.Deserialize(serialisedData) as Guid[]; 45 | 46 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 47 | } 48 | } 49 | 50 | [GlobalSetup] 51 | public void Setup() 52 | { 53 | _data = new Guid[Number]; 54 | for (int i = 0; i < _data.Length; i++) 55 | { 56 | _data[i] = Guid.NewGuid(); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionIntArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionIntArraySerialisationTests 11 | { 12 | private int[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesIntArrayInput() 19 | { 20 | int[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | int[] result = connection.Deserialize(serialisedData) as int[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesIntArrayInputWithZipEnabled() 34 | { 35 | int[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | int[] result = connection.Deserialize(serialisedData) as int[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new int[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = i; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionKTimeSpanArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionKTimeSpanArraySerialisationTests 11 | { 12 | private c.KTimespan[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesKTimeSpanArrayInput() 19 | { 20 | c.KTimespan[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | c.KTimespan[] result = connection.Deserialize(serialisedData) as c.KTimespan[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesKTimeSpanArrayInputWithZipEnabled() 34 | { 35 | c.KTimespan[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | c.KTimespan[] result = connection.Deserialize(serialisedData) as c.KTimespan[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new c.KTimespan[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = new c.KTimespan(i); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionLongArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionLongArraySerialisationTests 11 | { 12 | private long[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesLongArrayInput() 19 | { 20 | long[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | long[] result = connection.Deserialize(serialisedData) as long[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesLongArrayInputWithZipEnabled() 34 | { 35 | long[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | long[] result = connection.Deserialize(serialisedData) as long[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new long[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = i; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionMinuteArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionMinuteArraySerialisationTests 11 | { 12 | private c.Minute[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesMinuteArrayInput() 19 | { 20 | c.Minute[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | c.Minute[] result = connection.Deserialize(serialisedData) as c.Minute[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesMinuteArrayInputWithZipEnabled() 34 | { 35 | c.Minute[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | c.Minute[] result = connection.Deserialize(serialisedData) as c.Minute[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new c.Minute[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = new c.Minute(i); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionMonthArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionMonthArraySerialisationTests 11 | { 12 | private c.Month[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesMonthArrayInput() 19 | { 20 | c.Month[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | c.Month[] result = connection.Deserialize(serialisedData) as c.Month[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesMonthArrayInputWithZipEnabled() 34 | { 35 | c.Month[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | c.Month[] result = connection.Deserialize(serialisedData) as c.Month[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new c.Month[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = new c.Month(i); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionObjectArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionObjectArraySerialisationTests 11 | { 12 | private object[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesObjectArrayInput() 19 | { 20 | object[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | object[] result = connection.Deserialize(serialisedData) as object[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesObjectArrayInputWithZipEnabled() 34 | { 35 | object[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | object[] result = connection.Deserialize(serialisedData) as object[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new object[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = string.Format("Hello_{0}", i); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionSecondArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionSecondArraySerialisationTests 11 | { 12 | private c.Second[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesSecondArrayInput() 19 | { 20 | c.Second[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | c.Second[] result = connection.Deserialize(serialisedData) as c.Second[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesSecondArrayInputWithZipEnabled() 34 | { 35 | c.Second[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | c.Second[] result = connection.Deserialize(serialisedData) as c.Second[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new c.Second[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = new c.Second(i); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionShortArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using BenchmarkDotNet.Attributes; 4 | using NUnit.Framework; 5 | 6 | namespace kx.Benchmark.Test.Connection 7 | { 8 | [MemoryDiagnoser] 9 | [MedianColumn] 10 | [MaxColumn] 11 | public class ConnectionShortArraySerialisationTests 12 | { 13 | private short[] _data; 14 | 15 | [Params(1000, 10000, 100000, 500000)] 16 | public int Number { get; set; } 17 | 18 | [Benchmark] 19 | public void ConnectionSerialisesAndDeserialisesByteArrayInput() 20 | { 21 | short[] expected = _data; 22 | 23 | using (var connection = new c(3)) 24 | { 25 | byte[] serialisedData = connection.Serialize(1, expected); 26 | 27 | short[] result = connection.Deserialize(serialisedData) as short[]; 28 | 29 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 30 | } 31 | } 32 | 33 | [Benchmark] 34 | public void ConnectionSerialisesAndDeserialisesByteArrayInputWithZipEnabled() 35 | { 36 | short[] expected = _data; 37 | 38 | using (var connection = new c(3)) 39 | { 40 | connection.IsZipEnabled = true; 41 | 42 | byte[] serialisedData = connection.Serialize(1, expected); 43 | 44 | short[] result = connection.Deserialize(serialisedData) as short[]; 45 | 46 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 47 | } 48 | } 49 | 50 | [GlobalSetup] 51 | public void Setup() 52 | { 53 | Random random = new Random(); 54 | 55 | _data = new short[Number]; 56 | for (int i = 0; i < _data.Length; i++) 57 | { 58 | _data[i] = (short)random.Next(short.MinValue, short.MaxValue); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionStringArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using BenchmarkDotNet.Attributes; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Benchmark.Test.Connection 6 | { 7 | [MemoryDiagnoser] 8 | [MedianColumn] 9 | [MaxColumn] 10 | public class ConnectionStringArraySerialisationTests 11 | { 12 | private string[] _data; 13 | 14 | [Params(1000, 10000, 100000, 500000)] 15 | public int Number { get; set; } 16 | 17 | [Benchmark] 18 | public void ConnectionSerialisesAndDeserialisesStringArrayInput() 19 | { 20 | string[] expected = _data; 21 | 22 | using (var connection = new c(3)) 23 | { 24 | byte[] serialisedData = connection.Serialize(1, expected); 25 | 26 | string[] result = connection.Deserialize(serialisedData) as string[]; 27 | 28 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void ConnectionSerialisesAndDeserialisesStringArrayInputWithZipEnabled() 34 | { 35 | string[] expected = _data; 36 | 37 | using (var connection = new c(3)) 38 | { 39 | connection.IsZipEnabled = true; 40 | 41 | byte[] serialisedData = connection.Serialize(1, expected); 42 | 43 | string[] result = connection.Deserialize(serialisedData) as string[]; 44 | 45 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 46 | } 47 | } 48 | 49 | [GlobalSetup] 50 | public void Setup() 51 | { 52 | _data = new string[Number]; 53 | for (int i = 0; i < _data.Length; i++) 54 | { 55 | _data[i] = string.Format("Hello_{0}", i); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Connection/ConnectionTimeSpanArraySerialisationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using BenchmarkDotNet.Attributes; 4 | using NUnit.Framework; 5 | 6 | namespace kx.Benchmark.Test.Connection 7 | { 8 | [MemoryDiagnoser] 9 | [MedianColumn] 10 | [MaxColumn] 11 | public class ConnectionTimeSpanArraySerialisationTests 12 | { 13 | private TimeSpan[] _data; 14 | 15 | [Params(1000, 10000, 100000, 500000)] 16 | public int Number { get; set; } 17 | 18 | [Benchmark] 19 | public void ConnectionSerialisesAndDeserialisesTimeSpanArrayInput() 20 | { 21 | TimeSpan[] expected = _data; 22 | 23 | using (var connection = new c(3)) 24 | { 25 | byte[] serialisedData = connection.Serialize(1, expected); 26 | 27 | TimeSpan[] result = connection.Deserialize(serialisedData) as TimeSpan[]; 28 | 29 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 30 | } 31 | } 32 | 33 | [Benchmark] 34 | public void ConnectionSerialisesAndDeserialisesTimeSpanArrayInputWithZipEnabled() 35 | { 36 | TimeSpan[] expected = _data; 37 | 38 | using (var connection = new c(3)) 39 | { 40 | connection.IsZipEnabled = true; 41 | 42 | byte[] serialisedData = connection.Serialize(1, expected); 43 | 44 | TimeSpan[] result = connection.Deserialize(serialisedData) as TimeSpan[]; 45 | 46 | Assert.IsTrue(Enumerable.SequenceEqual(expected, result)); 47 | } 48 | } 49 | 50 | [GlobalSetup] 51 | public void Setup() 52 | { 53 | _data = new TimeSpan[Number]; 54 | 55 | for (int i = 0; i < _data.Length; i++) 56 | { 57 | _data[i] = new TimeSpan(new Random(i).Next(1, 2000) * 10000); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/Program.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Running; 2 | 3 | namespace kx.Benchmark.Test 4 | { 5 | static class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var switcher = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly); 10 | switcher.Run(args); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/ReadMe.md: -------------------------------------------------------------------------------- 1 | # kx.Benchmark.Test 2 | 3 | The kx.Benchmark.Test.csproj is a test library that leverage the BenchmarkDotNet framework 4 | to run performance-tests. 5 | 6 | For further details see 7 | https://benchmarkdotnet.org/articles/overview.html 8 | 9 | Developers can run the tests 10 | - via command-line 11 | 12 | ## Run via dotnet command-line 13 | 14 | Recommendation is to run Benchmarks using the dotnet command-line with other processes stopped to avoid resource contentation. 15 | 16 | Open command-prompt at top level solution folder 17 | 18 | 1) Restore any requried nuget packages 19 | 20 | ``` bat 21 | dotnet restore .\CSharpKdb.sln 22 | ``` 23 | 24 | 2) Build the kx.Benchmark.Test project 25 | Note : Build should be done against optimised Release build for accuracy 26 | 27 | ``` bat 28 | dotnet msbuild /t:"kx_Benchmark_Test" /p:Configuration=Release /p:Platform="Any CPU" .\CSharpKdb.sln 29 | ``` 30 | 31 | 3) Run benchmark tests using a specified filter 32 | 33 | *i)* Run all benchmarks 34 | 35 | ``` bat 36 | dotnet .\kx.Benchmark.Test\bin\Release\netcoreapp3.1\kx.Benchmark.Test.dll -f '*' 37 | ``` 38 | 39 | *ii)* Run an individual benchmark 40 | 41 | ``` bat 42 | dotnet .\kx.Benchmark.Test\bin\Release\netcoreapp3.1\kx.Benchmark.Test.dll 43 | ``` 44 | 45 | 4) Provided tests complete successfully you should see the following output and a BenchmarkDotNet.Artifacts folder containing the report files. 46 | 47 | ``` cmd 48 | // * Summary * 49 | 50 | BenchmarkDotNet=v0.12.0, OS=Windows 10.0.19041 51 | Intel Core i7-6500U CPU 2.50GHz (Skylake), 1 CPU, 4 logical and 2 physical cores 52 | .NET Core SDK=5.0.100 53 | [Host] : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203), X64 RyuJIT 54 | DefaultJob : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203), X64 RyuJIT 55 | 56 | 57 | | Method | Number | Mean | Error | StdDev | Median | Max | Gen 0 | Gen 1 | Gen 2 | Allocated | 58 | |-------------------------------------------------- |------- |------------:|-----------:|-----------:|------------:|------------:|---------:|---------:|---------:|-----------:| 59 | | ConnectionSerialisesAndDeserialisesByteArrayInput | 1000 | 71.78 us | 1.191 us | 1.114 us | 71.59 us | 74.32 us | 1.7090 | - | - | 3.64 KB | 60 | | ConnectionSerialisesAndDeserialisesByteArrayInput | 10000 | 202.72 us | 1.135 us | 1.061 us | 202.67 us | 205.13 us | 14.6484 | - | - | 30.01 KB | 61 | | ConnectionSerialisesAndDeserialisesByteArrayInput | 100000 | 1,616.86 us | 32.536 us | 36.164 us | 1,601.41 us | 1,721.33 us | 91.7969 | 91.7969 | 91.7969 | 293.68 KB | 62 | | ConnectionSerialisesAndDeserialisesByteArrayInput | 500000 | 7,409.03 us | 144.813 us | 177.843 us | 7,327.12 us | 7,770.63 us | 335.9375 | 335.9375 | 335.9375 | 1465.54 KB | 63 | 64 | // * Legends * 65 | Number : Value of the 'Number' parameter 66 | Mean : Arithmetic mean of all measurements 67 | Error : Half of 99.9% confidence interval 68 | StdDev : Standard deviation of all measurements 69 | Median : Value separating the higher half of all measurements (50th percentile) 70 | Max : Maximum 71 | Gen 0 : GC Generation 0 collects per 1000 operations 72 | Gen 1 : GC Generation 1 collects per 1000 operations 73 | Gen 2 : GC Generation 2 collects per 1000 operations 74 | Allocated : Allocated memory per single operation (managed only, inclusive, 1KB = 1024B) 75 | 1 us : 1 Microsecond (0.000001 sec) 76 | 77 | // * Diagnostic Output - MemoryDiagnoser * 78 | 79 | 80 | // ***** BenchmarkRunner: End ***** 81 | // ** Remained 0 benchmark(s) to run ** 82 | Run time: 00:01:38 (98.06 sec), executed benchmarks: 4 83 | 84 | Global total time: 00:01:50 (110.53 sec), executed benchmarks: 4 85 | // * Artifacts cleanup * 86 | ``` 87 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/kx.Benchmark.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | kx.Benchmark.Test.Program 7 | true 8 | kx.Benchmark.Test.snk 9 | 10 | 11 | 12 | true 13 | 1701;1702;1591 14 | 15 | 16 | 17 | 1701;1702;1591 18 | true 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /kx.Benchmark.Test/kx.Benchmark.Test.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/kx.Benchmark.Test/kx.Benchmark.Test.snk -------------------------------------------------------------------------------- /kx.Test/Connection/ConnectionArrayTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using kx.Test.TestUtils; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Test.Connection 6 | { 7 | [TestFixture] 8 | public class ConnectionArrayTests 9 | { 10 | [Test] 11 | public void ConnectionReturnsExpectedLengthForDict() 12 | { 13 | const int expected = 1; 14 | 15 | c.Dict dict = new c.Dict(new[] { "Key_1" }, new object[] { "Value_1" }); 16 | 17 | int count = c.n(dict); 18 | 19 | Assert.AreEqual(expected, count); 20 | } 21 | 22 | [Test] 23 | public void ConnectionReturnsExpectedLengthForFlip() 24 | { 25 | const int expected = 1; 26 | 27 | c.Flip flip = new c.Flip(new c.Dict(new[] { "Key_1" }, new object[] { new object[] { "Value_1" } })); 28 | 29 | int count = c.n(flip); 30 | 31 | Assert.AreEqual(expected, count); 32 | } 33 | 34 | [Test] 35 | public void ConnectionReturnsExpectedLengthForCharArray() 36 | { 37 | const int expected = 8; 38 | 39 | char[] array = "Aardvark".ToCharArray(); 40 | 41 | int count = c.n(array); 42 | 43 | Assert.AreEqual(expected, count); 44 | } 45 | 46 | [Test] 47 | public void ConnectionReturnsExpectedLengthForObjectArray() 48 | { 49 | const int expected = 1; 50 | 51 | object[] array = new[] { "Aardvark" }; 52 | 53 | int count = c.n(array); 54 | 55 | Assert.AreEqual(expected, count); 56 | } 57 | 58 | [Test] 59 | public void ConnectionThrowsIfLengthForNull() 60 | { 61 | Assert.Throws(() => c.n(null)); 62 | } 63 | 64 | [Test] 65 | public void ConnectionAtThrowsIfXIsNull() 66 | { 67 | Assert.Throws(() => c.at(null, 0)); 68 | } 69 | 70 | [Test] 71 | public void ConnectionAtReturnsExpectedObjectFromArrayIndex() 72 | { 73 | const string expected = "foo"; 74 | 75 | object result = c.at(new object[] { "foo", "bar" }, 0); 76 | 77 | Assert.IsNotNull(result); 78 | Assert.AreEqual(expected, result); 79 | } 80 | 81 | [Test] 82 | public void ConnectionAtReturnsNullIfObjectFromArrayIndexIsNull() 83 | { 84 | object result = c.at(new object[] { null, "bar" }, 0); 85 | 86 | Assert.IsNull(result); 87 | } 88 | 89 | [Test] 90 | public void ConnectionAtReturnsNullIfObjectFromArrayIndexIsQNull() 91 | { 92 | object result = c.at(new object[] { string.Empty, "bar" }, 0); 93 | 94 | Assert.IsNull(result); 95 | } 96 | 97 | [Test] 98 | public void ConnectionTdThrowsIfXIsNull() 99 | { 100 | Assert.Throws(() => c.td(null)); 101 | } 102 | 103 | [Test] 104 | public void ConnectionTableReturnsExpectedTableIfObjectIsFlip() 105 | { 106 | c.Flip flip = new c.Flip(new c.Dict(new[] { "Key_1" }, new object[] { new object[] { "Value_1" } })); 107 | 108 | object result = c.td(flip); 109 | 110 | Assert.IsNotNull(result); 111 | Assert.IsTrue(result is c.Flip); 112 | } 113 | 114 | [Test] 115 | public void ConnectionTableReturnsExpectedTableIfObjectIsDict() 116 | { 117 | c.Dict dict = new c.Dict 118 | ( 119 | new c.Flip(new c.Dict(new[] { "Key_1" }, new object[] { new object[] { "Value_1" } })), 120 | new c.Flip(new c.Dict(new[] { "Key_1" }, new object[] { new object[] { "Value_1" } })) 121 | ); 122 | 123 | object result = c.td(dict); 124 | 125 | Assert.IsNotNull(result); 126 | Assert.IsTrue(result is c.Flip); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /kx.Test/Connection/ConnectionAsyncWriteTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System; 7 | using Moq; 8 | using NUnit.Framework; 9 | 10 | namespace kx.Test.Connection 11 | { 12 | [TestFixture] 13 | public class ConnectionAsyncWriteTests 14 | { 15 | [Test] 16 | public void ConnectionWritesExpectedObjectParameterToClientStreamAsynchronously() 17 | { 18 | object expected = "param1"; 19 | 20 | List bytesWritten = new List(); 21 | 22 | Mock testStream = CreateTestStream(bytesWritten); 23 | 24 | using (var connection = new c(testStream.Object)) 25 | { 26 | connection.ks(expected); 27 | 28 | object result = connection.Deserialize(bytesWritten.ToArray()); 29 | 30 | Assert.AreEqual(expected, result); 31 | } 32 | } 33 | 34 | [Test] 35 | public void ConnectionWritesThrowsWithSingleParamIfSIsNull() 36 | { 37 | using (MemoryStream s = new MemoryStream()) 38 | { 39 | using (var connection = new c(s)) 40 | { 41 | Assert.ThrowsAsync(() => connection.ksAsync(null)); 42 | } 43 | } 44 | } 45 | 46 | [Test] 47 | public void ConnectionWritesThrowsWith2ParamsIfSIsNull() 48 | { 49 | object expected = "param"; 50 | 51 | using (MemoryStream s = new MemoryStream()) 52 | { 53 | using (var connection = new c(s)) 54 | { 55 | Assert.ThrowsAsync(() => connection.ksAsync(null,expected)); 56 | } 57 | } 58 | } 59 | 60 | [Test] 61 | public void ConnectionWritesThrowsWith3ParamsIfSIsNull() 62 | { 63 | object expected = "param"; 64 | 65 | using (MemoryStream s = new MemoryStream()) 66 | { 67 | using (var connection = new c(s)) 68 | { 69 | Assert.ThrowsAsync(() => connection.ksAsync(null,expected,expected)); 70 | } 71 | } 72 | } 73 | 74 | [Test] 75 | public async Task ConnectionWritesExpectedObjectParameterToClientStreamAsync() 76 | { 77 | object expected = "param1"; 78 | 79 | using (MemoryStream s = new MemoryStream()) 80 | { 81 | using (var connection = new c(s)) 82 | { 83 | await connection.ksAsync(expected); 84 | 85 | object result = connection.Deserialize(s.GetBuffer()); 86 | 87 | Assert.AreEqual(expected, result); 88 | } 89 | } 90 | } 91 | 92 | [Test] 93 | public void ConnectionWritesThrowsIfSIsNull() 94 | { 95 | List bytesWritten = new List(); 96 | 97 | Mock testStream = CreateTestStream(bytesWritten); 98 | 99 | using (var connection = new c(testStream.Object)) 100 | { 101 | Assert.Throws(() => connection.ks((string)null)); 102 | } 103 | } 104 | 105 | [Test] 106 | public void ConnectionWritesWith2ParamsThrowsIfSIsNull() 107 | { 108 | object expected = "param"; 109 | 110 | List bytesWritten = new List(); 111 | 112 | Mock testStream = CreateTestStream(bytesWritten); 113 | 114 | using (var connection = new c(testStream.Object)) 115 | { 116 | Assert.Throws(() => connection.ks(null,expected)); 117 | } 118 | } 119 | 120 | [Test] 121 | public void ConnectionWritesWith3ParamsThrowsIfSIsNull() 122 | { 123 | object expected = "param"; 124 | 125 | List bytesWritten = new List(); 126 | 127 | Mock testStream = CreateTestStream(bytesWritten); 128 | 129 | using (var connection = new c(testStream.Object)) 130 | { 131 | Assert.Throws(() => connection.ks(null,expected,expected)); 132 | } 133 | } 134 | 135 | [Test] 136 | public void ConnectionWritesExpectedStringExpressionToClientStreamAsynchronously() 137 | { 138 | const string expected = "test_expression"; 139 | 140 | List bytesWritten = new List(); 141 | 142 | Mock testStream = CreateTestStream(bytesWritten); 143 | 144 | using (var connection = new c(testStream.Object)) 145 | { 146 | connection.ks(expected); 147 | 148 | object result = connection.Deserialize(bytesWritten.ToArray()); 149 | 150 | Assert.AreEqual(expected, result); 151 | } 152 | } 153 | 154 | [Test] 155 | public async Task ConnectionWritesExpectedStringExpressionToClientStreamAsync() 156 | { 157 | const string expected = "test_expression"; 158 | 159 | using (MemoryStream s = new MemoryStream()) 160 | { 161 | using (var connection = new c(s)) 162 | { 163 | await connection.ksAsync(expected); 164 | 165 | object result = connection.Deserialize(s.GetBuffer()); 166 | 167 | Assert.AreEqual(expected, result); 168 | } 169 | } 170 | } 171 | 172 | [Test] 173 | public void ConnectionWritesExpectedStringExpressionAndParameterToClientStreamAsynchronously() 174 | { 175 | const string expression = "test_expression"; 176 | object parameter1 = 1; 177 | 178 | List bytesWritten = new List(); 179 | 180 | Mock testStream = CreateTestStream(bytesWritten); 181 | 182 | using (var connection = new c(testStream.Object)) 183 | { 184 | connection.ks(expression, parameter1); 185 | 186 | object[] result = connection.Deserialize(bytesWritten.ToArray()) as object[]; 187 | 188 | Assert.IsNotNull(result); 189 | Assert.AreEqual(2, result.Length); 190 | Assert.AreEqual(expression, new string(result[0] as char[])); 191 | Assert.AreEqual(parameter1, result[1]); 192 | } 193 | } 194 | 195 | [Test] 196 | public async Task ConnectionWritesExpectedStringExpressionAndParameterToClientStreamAsync() 197 | { 198 | const string expression = "test_expression"; 199 | object parameter1 = 1; 200 | 201 | using (MemoryStream s = new MemoryStream()) 202 | { 203 | using (var connection = new c(s)) 204 | { 205 | await connection.ksAsync(expression, parameter1); 206 | 207 | object[] result = connection.Deserialize(s.GetBuffer()) as object[]; 208 | 209 | Assert.IsNotNull(result); 210 | Assert.AreEqual(2, result.Length); 211 | Assert.AreEqual(expression, new string(result[0] as char[])); 212 | Assert.AreEqual(parameter1, result[1]); 213 | } 214 | } 215 | } 216 | 217 | [Test] 218 | public void ConnectionWritesExpectedStringExpressionAndParametersToClientStreamAsynchronously() 219 | { 220 | const string expression = "test_expression"; 221 | object parameter1 = 1; 222 | object parameter2 = 2; 223 | 224 | List bytesWritten = new List(); 225 | 226 | Mock testStream = CreateTestStream(bytesWritten); 227 | 228 | using (var connection = new c(testStream.Object)) 229 | { 230 | connection.ks(expression, parameter1, parameter2); 231 | 232 | object[] result = connection.Deserialize(bytesWritten.ToArray()) as object[]; 233 | 234 | Assert.IsNotNull(result); 235 | Assert.AreEqual(3, result.Length); 236 | Assert.AreEqual(expression, new string(result[0] as char[])); 237 | Assert.AreEqual(parameter1, result[1]); 238 | Assert.AreEqual(parameter2, result[2]); 239 | } 240 | } 241 | 242 | [Test] 243 | public async Task ConnectionWritesExpectedStringExpressionAndParametersToClientStreamAsync() 244 | { 245 | const string expression = "test_expression"; 246 | object parameter1 = 1; 247 | object parameter2 = 2; 248 | 249 | using (MemoryStream s = new MemoryStream()) 250 | { 251 | using (var connection = new c(s)) 252 | { 253 | await connection.ksAsync(expression, parameter1, parameter2); 254 | 255 | object[] result = connection.Deserialize(s.GetBuffer()) as object[]; 256 | 257 | Assert.IsNotNull(result); 258 | Assert.AreEqual(3, result.Length); 259 | Assert.AreEqual(expression, new string(result[0] as char[])); 260 | Assert.AreEqual(parameter1, result[1]); 261 | Assert.AreEqual(parameter2, result[2]); 262 | } 263 | } 264 | } 265 | 266 | private Mock CreateTestStream(List bytesWritten) 267 | { 268 | Mock testStream = new Mock(); 269 | 270 | //record bytes written to test-stream. 271 | testStream.Setup(s => s.Write(It.IsAny(), It.IsAny(), It.IsAny())) 272 | .Callback((a, b, c) => 273 | { 274 | var content = a 275 | .Skip(b) 276 | .Take(c) 277 | .ToArray(); 278 | 279 | bytesWritten.AddRange(content); 280 | }); 281 | 282 | 283 | return testStream; 284 | } 285 | } 286 | } -------------------------------------------------------------------------------- /kx.Test/Connection/ConnectionSyncWriteTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | using System; 5 | using Moq; 6 | using NUnit.Framework; 7 | 8 | namespace kx.Test.Connection 9 | { 10 | [TestFixture] 11 | public class ConnectionSyncWriteTests 12 | { 13 | [Test] 14 | public void ConnectionWritesThrowsIfSingleParamSIsNull() 15 | { 16 | List bytesWritten = new List(); 17 | 18 | Mock testStream = CreateTestStream(bytesWritten); 19 | 20 | using (var connection = new c(testStream.Object)) 21 | { 22 | Assert.Throws(() => connection.k(null)); 23 | } 24 | } 25 | 26 | [Test] 27 | public void ConnectionWritesThrowsIf2ParamSIsNull() 28 | { 29 | object expected = "param"; 30 | 31 | List bytesWritten = new List(); 32 | 33 | Mock testStream = CreateTestStream(bytesWritten); 34 | 35 | using (var connection = new c(testStream.Object)) 36 | { 37 | Assert.Throws(() => connection.k(null,expected)); 38 | } 39 | } 40 | 41 | [Test] 42 | public void ConnectionWritesThrowsIf3ParamSIsNull() 43 | { 44 | object expected = "param"; 45 | 46 | List bytesWritten = new List(); 47 | 48 | Mock testStream = CreateTestStream(bytesWritten); 49 | 50 | using (var connection = new c(testStream.Object)) 51 | { 52 | Assert.Throws(() => connection.k(null,expected,expected)); 53 | } 54 | } 55 | 56 | [Test] 57 | public void ConnectionWritesThrowsIf4ParamSIsNull() 58 | { 59 | object expected = "param"; 60 | 61 | List bytesWritten = new List(); 62 | 63 | Mock testStream = CreateTestStream(bytesWritten); 64 | 65 | using (var connection = new c(testStream.Object)) 66 | { 67 | Assert.Throws(() => connection.k(null,expected,expected,expected)); 68 | } 69 | } 70 | 71 | [Test] 72 | public void ConnectionWritesExpectedObjectParameterToClientStreamSynchronously() 73 | { 74 | object expected = "param1"; 75 | 76 | List bytesWritten = new List(); 77 | 78 | Mock testStream = CreateTestStream(bytesWritten); 79 | 80 | using (var connection = new c(testStream.Object)) 81 | { 82 | connection.k(expected); 83 | 84 | object result = connection.Deserialize(bytesWritten.ToArray()); 85 | 86 | Assert.AreEqual(expected, result); 87 | } 88 | } 89 | 90 | [Test] 91 | public void ConnectionWritesExpectedStringExpressionToClientStreamSynchronously() 92 | { 93 | const string expression = "test_expression"; 94 | 95 | List bytesWritten = new List(); 96 | 97 | Mock testStream = CreateTestStream(bytesWritten); 98 | 99 | using (var connection = new c(testStream.Object)) 100 | { 101 | connection.k(expression); 102 | 103 | object result = connection.Deserialize(bytesWritten.ToArray()); 104 | 105 | Assert.AreEqual(expression, result); 106 | } 107 | } 108 | 109 | [Test] 110 | public void ConnectionWritesExpectedStringExpressionAndObjectParameterToClientStreamSynchronously() 111 | { 112 | const string expression = "test_expression"; 113 | object parameter1 = 1; 114 | 115 | List bytesWritten = new List(); 116 | 117 | Mock testStream = CreateTestStream(bytesWritten); 118 | 119 | using (var connection = new c(testStream.Object)) 120 | { 121 | connection.k(expression, parameter1); 122 | 123 | object[] result = connection.Deserialize(bytesWritten.ToArray()) as object[]; 124 | 125 | Assert.IsNotNull(result); 126 | Assert.AreEqual(2, result.Length); 127 | Assert.AreEqual(expression, new string(result[0] as char[])); 128 | Assert.AreEqual(parameter1, result[1]); 129 | } 130 | } 131 | 132 | [Test] 133 | public void ConnectionWritesExpectedStringExpressionAndTwoObjectParametersToClientStreamSynchronously() 134 | { 135 | const string expression = "test_expression"; 136 | object parameter1 = 1; 137 | object parameter2 = 2; 138 | 139 | List bytesWritten = new List(); 140 | 141 | Mock testStream = CreateTestStream(bytesWritten); 142 | 143 | using (var connection = new c(testStream.Object)) 144 | { 145 | connection.k(expression, parameter1, parameter2); 146 | 147 | object[] result = connection.Deserialize(bytesWritten.ToArray()) as object[]; 148 | 149 | Assert.IsNotNull(result); 150 | Assert.AreEqual(3, result.Length); 151 | Assert.AreEqual(expression, new string(result[0] as char[])); 152 | Assert.AreEqual(parameter1, result[1]); 153 | Assert.AreEqual(parameter2, result[2]); 154 | } 155 | } 156 | 157 | [Test] 158 | public void ConnectionWritesExpectedStringExpressionAndThreeObjectParametersToClientStreamSynchronously() 159 | { 160 | const string expression = "test_expression"; 161 | object parameter1 = 1; 162 | object parameter2 = 2; 163 | object parameter3 = 3; 164 | 165 | List bytesWritten = new List(); 166 | 167 | Mock testStream = CreateTestStream(bytesWritten); 168 | 169 | using (var connection = new c(testStream.Object)) 170 | { 171 | connection.k(expression, parameter1, parameter2, parameter3); 172 | 173 | object[] result = connection.Deserialize(bytesWritten.ToArray()) as object[]; 174 | 175 | Assert.IsNotNull(result); 176 | Assert.AreEqual(4, result.Length); 177 | Assert.AreEqual(expression, new string(result[0] as char[])); 178 | Assert.AreEqual(parameter1, result[1]); 179 | Assert.AreEqual(parameter2, result[2]); 180 | Assert.AreEqual(parameter3, result[3]); 181 | } 182 | } 183 | 184 | private Mock CreateTestStream(List bytesWritten) 185 | { 186 | Mock testStream = new Mock(); 187 | 188 | //simulate sync response read 189 | testStream.Setup(s => s.Read(It.IsAny(), It.IsAny(), It.IsAny())) 190 | .Returns((a, b, c) => 191 | { 192 | //simulate header read 193 | if (a.Length == 8) 194 | { 195 | a[0] = 1; 196 | a[1] = 2; 197 | a[2] = 0; 198 | a[3] = 0; 199 | a[4] = 10; 200 | } 201 | //simulate empty string response 202 | if (a.Length == 2) 203 | { 204 | a[0] = 245; 205 | } 206 | return a.Length; 207 | }); 208 | 209 | //record bytes written to test-stream. 210 | testStream.Setup(s => s.Write(It.IsAny(), It.IsAny(), It.IsAny())) 211 | .Callback((a, b, c) => 212 | { 213 | var content = a 214 | .Skip(b) 215 | .Take(c) 216 | .ToArray(); 217 | 218 | bytesWritten.AddRange(content); 219 | }); 220 | 221 | return testStream; 222 | } 223 | } 224 | } -------------------------------------------------------------------------------- /kx.Test/Connection/ConnectionTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using kx.Test.TestUtils; 3 | using NUnit.Framework; 4 | 5 | namespace kx.Test.Connection 6 | { 7 | [TestFixture] 8 | public class ConnectionTests 9 | { 10 | [Test] 11 | public void ConnectionInitialises() 12 | { 13 | using (var server = new TestableTcpServer()) 14 | using (var c = new c("localhost", server.TestPort)) 15 | { 16 | Assert.IsNotNull(c); 17 | } 18 | } 19 | 20 | [Test] 21 | public void ConnectionThrowsIfHostIsNull() 22 | { 23 | Assert.Throws(() => new c(null as string, 8080)); 24 | } 25 | 26 | [Test] 27 | public void ConnectionThrowsIfPortIsLessThanRange() 28 | { 29 | Assert.Throws(() => new c("localhost", System.Net.IPEndPoint.MinPort - 1)); 30 | } 31 | 32 | [Test] 33 | public void ConnectionThrowsIfPortIsMoreThanRange() 34 | { 35 | Assert.Throws(() => new c("localhost", System.Net.IPEndPoint.MaxPort + 1)); 36 | } 37 | 38 | [Test] 39 | public void ConnectionThrowsIfUserPassWordIsNull() 40 | { 41 | Assert.Throws(() => new c("localhost", 8080, null)); 42 | } 43 | 44 | [Test] 45 | public void ConnectionThrowsIfAuthenticationDoesNotPass() 46 | { 47 | 48 | using (var server = new TestableFailingTcpServer()) 49 | { 50 | Assert.Throws(() => new c("localhost", server.TestPort)); 51 | } 52 | } 53 | 54 | [Test] 55 | public void ConnectionThrowsSerialisableExpectionIfAuthenticationDoesNotPass() 56 | { 57 | KException error = null; 58 | c connection = null; 59 | 60 | using (var server = new TestableFailingTcpServer()) 61 | { 62 | try 63 | { 64 | connection = new c("localhost", server.TestPort); 65 | } 66 | catch (KException ex) 67 | { 68 | error = TestSerialisationHelper.SerialiseAndDeserialiseException(ex); 69 | } 70 | 71 | Assert.IsNull(connection); 72 | Assert.IsNotNull(error); 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /kx.Test/ReadMe.md: -------------------------------------------------------------------------------- 1 | # kx.Test 2 | 3 | The kx.Test.csproj is a test library that leverages the NUnit framework 4 | to run unit-tests. 5 | 6 | Developers can run the tests either 7 | - via Visual Studio Test Explorer 8 | - via the .\kx.Test\Scripts\GenerateLocalReport.ps1 PowerShell script 9 | 10 | ## Run via Visual Studio 11 | 12 | Instructions for running via Visual Studio can be found at 13 | https://docs.microsoft.com/en-us/visualstudio/test/run-unit-tests-with-test-explorer?view=vs-2019 14 | 15 | ## Run via PowerShell 16 | 17 | 1) Running the tests through the PowerShell script not only runs the unit-tests but creates 18 | a local test coverage report for developers to inspect. 19 | 20 | *i)* First ensure that the kx.Test is built 21 | in this example we have built it in Debug 22 | 23 | *ii)* Open PowerShell ISE and navigate to the top-level folder of the local repository 24 | Should contain CSharpKdb.sln file and the various project sub-folders 25 | 26 | *iii)* Run the following command in PowerShell 27 | ```powershell 28 | .\kx.Test\Scripts\GenerateLocalReport.ps1 -TargetAssembly:kx -TargetTestProj:.\kx.Test\kx.Test.csproj -BuildConfiguration:Debug 29 | ``` 30 | 31 | *iv)* Provided the tests complete successfully you should the following output 32 | ```powershell 33 | Starting test execution, please wait... 34 | 35 | A total of 1 test files matched the specified pattern. 36 | 37 | Test Run Successful. 38 | Total tests: 363 39 | Passed: 363 40 | Total time: 7.2434 Seconds 41 | ................ 42 | ``` 43 | 44 | *v)* Additionally if you look in top-level folder of the local repository you should see a local CodeCoverage folder has been created 45 | 46 | *vi)* If you open the CodeCoverage folder you will find an index.html file. Open this file with Chrome to see the local code coverage report. 47 | 48 | 2) Also you can use the PowerShell script to run the tests multiple times in succession to confirm the tests are stable 49 | For example to run the tests 15 times simply use a for loop in PowerShell ISE 50 | 51 | ```powershell 52 | for($i = 0; $i -lt 15; $i++){ 53 | .\kx.Test\Scripts\GenerateLocalReport.ps1 -TargetAssembly:kx -TargetTestProj:.\kx.Test\kx.Test.csproj -BuildConfiguration:Debug 54 | } 55 | ``` 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /kx.Test/Scripts/GenerateLocalReport.ps1: -------------------------------------------------------------------------------- 1 | Param 2 | ( 3 | [Parameter(Mandatory=$True, Position=1)] 4 | [string] $TargetAssembly, 5 | 6 | [Parameter(Mandatory=$True, Position=2)] 7 | [string] $TargetTestProj, 8 | 9 | [Parameter(Mandatory=$True, Position=3)] 10 | [string] $BuildConfiguration 11 | ) 12 | 13 | $nugetPackagesPath = "C:\Users\$($env:USERNAME)\.nuget\packages" 14 | 15 | $openCover = "$($nugetPackagesPath)\opencover\4.7.922\tools\OpenCover.Console.exe" 16 | $reportGenerator = "$($nugetPackagesPath)\reportgenerator\4.7.1\tools\net47\ReportGenerator.exe" 17 | 18 | ## OpenCover to consume results of executing tests 19 | &$openCover -target:'C:\Program Files\dotnet\dotnet.exe' -targetargs:"test $TargetTestProj --no-build --no-restore -p:Configuration=$BuildConfiguration" -output:Coverage.xml -register:user -oldStyle -filter:"+[$TargetAssembly]*" 20 | 21 | ## Generate Test Coverage report from OpenCover coverage.xml file 22 | &$reportGenerator -reports:Coverage.xml -targetdir:CodeCoverage 23 | 24 | 25 | -------------------------------------------------------------------------------- /kx.Test/TestUtils/TestSerialisationHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.Serialization.Formatters.Binary; 4 | 5 | namespace kx.Test.TestUtils 6 | { 7 | /// 8 | /// A helper class for testing serialisation and de-serialisation logic 9 | /// in unit-tests 10 | /// 11 | internal static class TestSerialisationHelper 12 | { 13 | /// 14 | /// Performs binary serialisation and de-serialisation on a specified exception. 15 | /// 16 | /// The type of exception being tested. 17 | /// The exception to be serialised and de-serialised. 18 | /// 19 | /// A de-serialised instance of the exception passed. All serialisable members should match the original. 20 | /// 21 | /// 22 | /// This is primarily intended to confirm custom exceptions within the DeltaApiCore 23 | /// library comply to ISerialization pattern. 24 | /// 25 | /// See https://stackoverflow.com/questions/94488/what-is-the-correct-way-to-make-a-custom-net-exception-serializable 26 | /// 27 | public static T SerialiseAndDeserialiseException(T exception) 28 | where T : Exception 29 | { 30 | BinaryFormatter binaryFormatter = new BinaryFormatter(); 31 | 32 | using (var stream = new MemoryStream()) 33 | { 34 | binaryFormatter.Serialize(stream, exception); 35 | 36 | stream.Seek(0, 0); 37 | 38 | return (T)binaryFormatter.Deserialize(stream); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /kx.Test/TestUtils/TestableFailingTcpServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | using System.Threading.Tasks; 5 | 6 | namespace kx.Test.TestUtils 7 | { 8 | /// 9 | /// A wrapper over a TCP Listener to simulate a running KDB+ environment for 10 | /// which client log-in will fail. 11 | /// 12 | internal sealed class TestableFailingTcpServer : IDisposable 13 | { 14 | private readonly TcpListener _server; 15 | 16 | /// 17 | /// Initialises a new default instance of . 18 | /// 19 | public TestableFailingTcpServer() 20 | { 21 | _server = new TcpListener(IPAddress.Loopback, 0); 22 | _server.Start(); 23 | 24 | //kick off task to simulate successful log-off 25 | Task.Factory.StartNew(() => 26 | { 27 | //block until client has established connection 28 | if (!_server.Pending()) 29 | { 30 | System.Threading.Thread.Sleep(10); 31 | } 32 | 33 | //now get the stream from the client 34 | var client = _server.AcceptTcpClient(); 35 | var stream = client.GetStream(); 36 | 37 | byte[] buffer = new byte[client.ReceiveBufferSize]; 38 | 39 | // read incoming stream 40 | stream.Read(buffer, 0, client.ReceiveBufferSize); 41 | 42 | //simulate connection being rejected 43 | client.Close(); 44 | }); 45 | } 46 | 47 | 48 | /// 49 | /// Gets the port this class is connected to for testing. 50 | /// 51 | public int TestPort 52 | { 53 | get 54 | { 55 | return ((IPEndPoint)_server.LocalEndpoint).Port; 56 | } 57 | } 58 | 59 | #region IDisposable Members 60 | public void Dispose() 61 | { 62 | if (_server != null) 63 | { 64 | _server.Stop(); 65 | } 66 | } 67 | #endregion IDisposable Members 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /kx.Test/TestUtils/TestableTcpServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | using System.Threading.Tasks; 5 | 6 | namespace kx.Test.TestUtils 7 | { 8 | /// 9 | /// A wrapper over a TCP Listener to simulate a running KDB+ environment for which 10 | /// client log-in will succeed. 11 | /// 12 | internal sealed class TestableTcpServer : IDisposable 13 | { 14 | private readonly TcpListener _server; 15 | 16 | /// 17 | /// Initialises a new default instance of . 18 | /// 19 | public TestableTcpServer() 20 | { 21 | _server = new TcpListener(IPAddress.Loopback, 0); 22 | _server.Start(); 23 | 24 | //kick off task to simulate successful log-on 25 | Task.Factory.StartNew(() => 26 | { 27 | //block until client has established connection 28 | if (!_server.Pending()) 29 | { 30 | System.Threading.Thread.Sleep(10); 31 | } 32 | 33 | //now get the stream from the client 34 | var client = _server.AcceptTcpClient(); 35 | var stream = client.GetStream(); 36 | 37 | byte[] buffer = new byte[client.ReceiveBufferSize]; 38 | 39 | // read incoming stream 40 | stream.Read(buffer, 0, client.ReceiveBufferSize); 41 | 42 | //simulate authentication succeeding 43 | stream.Write(buffer, 0, 1); 44 | }); 45 | } 46 | 47 | /// 48 | /// Gets the port this class is connected to for testing. 49 | /// 50 | public int TestPort 51 | { 52 | get 53 | { 54 | return ((IPEndPoint)_server.LocalEndpoint).Port; 55 | } 56 | } 57 | 58 | #region IDisposable Members 59 | public void Dispose() 60 | { 61 | if (_server != null) 62 | { 63 | _server.Stop(); 64 | } 65 | } 66 | #endregion IDisposable Members 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /kx.Test/Types/DictTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace kx.Test.Types 5 | { 6 | [TestFixture] 7 | public class DictTests 8 | { 9 | [Test] 10 | public void DictInitialises() 11 | { 12 | var dict = new c.Dict(new string[] { "Key_1" }, new object[] { "Value_1" }); 13 | 14 | Assert.IsNotNull(dict); 15 | } 16 | 17 | [Test] 18 | public void DictThrowsIfKeysIsNull() 19 | { 20 | Assert.Throws(() => 21 | new c.Dict(null, new object[] { "Value_1" })); 22 | } 23 | 24 | [Test] 25 | public void DictThrowsIfValuesIsNull() 26 | { 27 | Assert.Throws(() => 28 | new c.Dict(new string[] { "Key_1" }, null)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /kx.Test/Types/FlipTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace kx.Test.Types 5 | { 6 | [TestFixture] 7 | public class FlipTests 8 | { 9 | [Test] 10 | public void FlipInitialises() 11 | { 12 | var flip = new c.Flip(new c.Dict(new string[] { "Key_1" }, new object[] { "Value_1" })); 13 | 14 | Assert.IsNotNull(flip); 15 | } 16 | 17 | [Test] 18 | public void FlipThrowsIfDictIsNull() 19 | { 20 | Assert.Throws(() => new c.Flip(null as c.Dict)); 21 | } 22 | 23 | [Test] 24 | public void FlipAtReturnsValueForColumnName() 25 | { 26 | var flip = new c.Flip(new c.Dict(new string[] { "Key_1" }, new object[] { "Value_1" })); 27 | 28 | object result = flip.at("Key_1"); 29 | 30 | Assert.IsNotNull(result); 31 | Assert.AreEqual("Value_1", result); 32 | } 33 | 34 | [Test] 35 | public void FlipAtThrowsIfColumnNameIfNotFound() 36 | { 37 | var flip = new c.Flip(new c.Dict(new string[] { "Key_1" }, new object[] { "Value_1" })); 38 | 39 | Assert.Throws(() => flip.at("Aardvark")); 40 | } 41 | 42 | [Test] 43 | public void FlipAtThrowsIfColumnNameIfNull() 44 | { 45 | var flip = new c.Flip(new c.Dict(new string[] { "Key_1" }, new object[] { "Value_1" })); 46 | 47 | Assert.Throws(() => flip.at(null)); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /kx.Test/Types/KTimespanTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using NUnit.Framework; 3 | 4 | namespace kx.Test.Types 5 | { 6 | [TestFixture] 7 | public class KTimespanTests 8 | { 9 | [Test] 10 | public void KTimespanInitialisesWithInt64() 11 | { 12 | c.KTimespan kTimespan = new c.KTimespan(1); 13 | 14 | Assert.IsNotNull(kTimespan); 15 | } 16 | 17 | [Test] 18 | public void KTimespanToStringReturnsExpectedString() 19 | { 20 | const string expected = "00:00:00.0000047"; 21 | 22 | c.KTimespan kTimespan = new c.KTimespan(4700); 23 | 24 | Assert.AreEqual(expected, kTimespan.ToString()); 25 | } 26 | 27 | [Test] 28 | public void KTimespanToStringReturnsExpectedStringForMinInt64() 29 | { 30 | const string expected = ""; 31 | 32 | c.KTimespan kTimespan = new c.KTimespan(long.MinValue); 33 | 34 | Assert.AreEqual(expected, kTimespan.ToString()); 35 | } 36 | 37 | [Test] 38 | public void KTimespanGetHashCodeReturnsExpectedHash() 39 | { 40 | const int expected = 47; 41 | 42 | c.KTimespan kTimespan = new c.KTimespan(4700); 43 | 44 | Assert.AreEqual(expected, kTimespan.GetHashCode()); 45 | } 46 | 47 | [Test] 48 | public void KTimespanEqualsReturnsFalseIfOtherIsNull() 49 | { 50 | c.KTimespan kTimespan = new c.KTimespan(4700); 51 | c.KTimespan other = null; 52 | 53 | Assert.IsFalse(kTimespan.Equals(other)); 54 | } 55 | 56 | [Test] 57 | public void KTimespanEqualsReturnsFalseIfOtherIsNotTypeOfKTimespan() 58 | { 59 | c.KTimespan kTimespan = new c.KTimespan(4700); 60 | Task other = new Task(() => { }); 61 | 62 | Assert.IsFalse(kTimespan.Equals(other)); 63 | } 64 | 65 | [Test] 66 | public void KTimespanEqualsReturnsTrueIfOtherIsSameReference() 67 | { 68 | c.KTimespan kTimespan = new c.KTimespan(4700); 69 | c.KTimespan other = kTimespan; 70 | 71 | Assert.IsTrue(kTimespan.Equals(other)); 72 | } 73 | 74 | [Test] 75 | public void KTimespanEqualsReturnsTrueIfOtherIsSameValue() 76 | { 77 | c.KTimespan kTimespan = new c.KTimespan(4700); 78 | c.KTimespan other = new c.KTimespan(4700); 79 | 80 | Assert.IsTrue(kTimespan.Equals(other)); 81 | } 82 | 83 | [Test] 84 | public void KTimespanEqualsReturnsFalseIfOtherIsDifferentValue() 85 | { 86 | c.KTimespan kTimespan = new c.KTimespan(4700); 87 | c.KTimespan other = new c.KTimespan(4500); 88 | 89 | Assert.IsFalse(kTimespan.Equals(other)); 90 | } 91 | [Test] 92 | public void KTimespanCompareToReturnsOneIfOtherIsNull() 93 | { 94 | const int expected = 1; 95 | 96 | c.KTimespan kTimespan = new c.KTimespan(4700); 97 | c.KTimespan other = null; 98 | 99 | Assert.AreEqual(expected, kTimespan.CompareTo(other)); 100 | } 101 | 102 | [Test] 103 | public void KTimespanCompareToReturnsOneIfOtherIsNotTypeOfKTimespan() 104 | { 105 | const int expected = 1; 106 | 107 | c.KTimespan kTimespan = new c.KTimespan(4700); 108 | Task other = new Task(() => { }); 109 | 110 | Assert.AreEqual(expected, kTimespan.CompareTo(other)); 111 | } 112 | 113 | [Test] 114 | public void KTimespanCompareToReturnsOneIfOtherIsLessThanValue() 115 | { 116 | const int expected = 1; 117 | 118 | c.KTimespan kTimespan = new c.KTimespan(4700); 119 | c.KTimespan other = new c.KTimespan(4600); 120 | 121 | Assert.AreEqual(expected, kTimespan.CompareTo(other)); 122 | } 123 | 124 | [Test] 125 | public void KTimespanCompareToReturnsZeroIfOtherIsSameReference() 126 | { 127 | const int expected = 0; 128 | 129 | c.KTimespan kTimespan = new c.KTimespan(4700); 130 | c.KTimespan other = kTimespan; 131 | 132 | Assert.AreEqual(expected, kTimespan.CompareTo(other)); 133 | } 134 | 135 | [Test] 136 | public void KTimespanCompareToReturnsZeroIfOtherIsSameValue() 137 | { 138 | const int expected = 0; 139 | 140 | c.KTimespan kTimespan = new c.KTimespan(4700); 141 | c.KTimespan other = new c.KTimespan(4700); 142 | 143 | Assert.AreEqual(expected, kTimespan.CompareTo(other)); 144 | } 145 | 146 | [Test] 147 | public void KTimespanCompareToReturnsMinusOneIfOtherIsMoreThanValue() 148 | { 149 | const int expected = -1; 150 | 151 | c.KTimespan kTimespan = new c.KTimespan(4700); 152 | c.KTimespan other = new c.KTimespan(4800); 153 | 154 | Assert.AreEqual(expected, kTimespan.CompareTo(other)); 155 | } 156 | [Test] 157 | public void KTimespanEqualsOperatorReturnsTrueIfLeftAndRightAreSameValue() 158 | { 159 | c.KTimespan left = new c.KTimespan(4700); 160 | c.KTimespan right = new c.KTimespan(4700); 161 | 162 | Assert.IsTrue(left == right); 163 | } 164 | 165 | [Test] 166 | public void KTimespanEqualsOperatorReturnsTrueIfLeftAndRightAreSameReference() 167 | { 168 | c.KTimespan left = new c.KTimespan(4700); 169 | c.KTimespan right = left; 170 | 171 | Assert.IsTrue(left == right); 172 | } 173 | 174 | [Test] 175 | public void KTimespanEqualsOperatorReturnsFalseIfLeftAndRightAreNotSameValue() 176 | { 177 | c.KTimespan left = new c.KTimespan(4700); 178 | c.KTimespan right = new c.KTimespan(4600); 179 | 180 | Assert.IsFalse(left == right); 181 | } 182 | 183 | [Test] 184 | public void KTimespanEqualsOperatorReturnsTrueIfLeftAndRightAreNull() 185 | { 186 | c.KTimespan left = null; 187 | c.KTimespan right = null; 188 | 189 | Assert.IsTrue(left == right); 190 | } 191 | 192 | [Test] 193 | public void KTimespanEqualsOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 194 | { 195 | c.KTimespan left = null; 196 | c.KTimespan right = new c.KTimespan(4700); 197 | 198 | Assert.IsFalse(left == right); 199 | } 200 | 201 | [Test] 202 | public void KTimespanEqualsOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 203 | { 204 | c.KTimespan left = new c.KTimespan(4700); 205 | c.KTimespan right = null; 206 | 207 | Assert.IsFalse(left == right); 208 | } 209 | 210 | [Test] 211 | public void KTimespanNotEqualsOperatorReturnsFalseIfLeftAndRightAreSameValue() 212 | { 213 | c.KTimespan left = new c.KTimespan(4700); 214 | c.KTimespan right = new c.KTimespan(4700); 215 | 216 | Assert.IsFalse(left != right); 217 | } 218 | 219 | [Test] 220 | public void KTimespanNotEqualsOperatorReturnsFalseIfLeftAndRightAreSameReference() 221 | { 222 | c.KTimespan left = new c.KTimespan(4700); 223 | c.KTimespan right = left; 224 | 225 | Assert.IsFalse(left != right); 226 | } 227 | 228 | [Test] 229 | public void KTimespanNotEqualsOperatorReturnsTrueIfLeftAndRightAreNotSameValue() 230 | { 231 | c.KTimespan left = new c.KTimespan(4700); 232 | c.KTimespan right = new c.KTimespan(4600); 233 | 234 | Assert.IsTrue(left != right); 235 | } 236 | 237 | [Test] 238 | public void KTimespanNotEqualsOperatorReturnsFalseIfLeftAndRightAreNull() 239 | { 240 | c.KTimespan left = null; 241 | c.KTimespan right = null; 242 | 243 | Assert.IsFalse(left != right); 244 | } 245 | 246 | [Test] 247 | public void KTimespanNotEqualsOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 248 | { 249 | c.KTimespan left = null; 250 | c.KTimespan right = new c.KTimespan(4700); 251 | 252 | Assert.IsTrue(left != right); 253 | } 254 | 255 | [Test] 256 | public void KTimespanNotEqualsOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 257 | { 258 | c.KTimespan left = new c.KTimespan(4700); 259 | c.KTimespan right = null; 260 | 261 | Assert.IsTrue(left != right); 262 | } 263 | 264 | [Test] 265 | public void KTimespanLessThanOperatorReturnsFalseIfLeftIsGreaterThanRight() 266 | { 267 | c.KTimespan left = new c.KTimespan(4700); 268 | c.KTimespan right = new c.KTimespan(4600); 269 | 270 | Assert.IsFalse(left < right); 271 | } 272 | 273 | [Test] 274 | public void KTimespanLessThanOperatorReturnsFalseIfLeftIsSameValueAsRight() 275 | { 276 | c.KTimespan left = new c.KTimespan(4700); 277 | c.KTimespan right = new c.KTimespan(4700); 278 | 279 | Assert.IsFalse(left < right); 280 | } 281 | 282 | [Test] 283 | public void KTimespanLessThanOperatorReturnsFalseIfLeftIsSameReferenceAsRight() 284 | { 285 | c.KTimespan left = new c.KTimespan(4700); 286 | c.KTimespan right = left; 287 | 288 | Assert.IsFalse(left < right); 289 | } 290 | 291 | [Test] 292 | public void KTimespanLessThanOperatorReturnsTrueIfLeftIsLessThanRight() 293 | { 294 | c.KTimespan left = new c.KTimespan(4700); 295 | c.KTimespan right = new c.KTimespan(4800); 296 | 297 | Assert.IsTrue(left < right); 298 | } 299 | 300 | [Test] 301 | public void KTimespanLessThanOperatorReturnsFalseIfLeftAndRightAreNull() 302 | { 303 | c.KTimespan left = null; 304 | c.KTimespan right = null; 305 | 306 | Assert.IsFalse(left < right); 307 | } 308 | 309 | [Test] 310 | public void KTimespanLessThanOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 311 | { 312 | c.KTimespan left = null; 313 | c.KTimespan right = new c.KTimespan(4600); 314 | 315 | Assert.IsTrue(left < right); 316 | } 317 | 318 | [Test] 319 | public void KTimespanLessThanOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 320 | { 321 | c.KTimespan left = new c.KTimespan(4700); 322 | c.KTimespan right = null; 323 | 324 | Assert.IsFalse(left < right); 325 | } 326 | 327 | [Test] 328 | public void KTimespanGreaterThanOperatorReturnsTrueIfLeftIsGreaterThanRight() 329 | { 330 | c.KTimespan left = new c.KTimespan(4700); 331 | c.KTimespan right = new c.KTimespan(4600); 332 | 333 | Assert.IsTrue(left > right); 334 | } 335 | 336 | [Test] 337 | public void KTimespanGreaterThanOperatorReturnsFalseIfLeftIsSameValueAsRight() 338 | { 339 | c.KTimespan left = new c.KTimespan(4700); 340 | c.KTimespan right = new c.KTimespan(4700); 341 | 342 | Assert.IsFalse(left > right); 343 | } 344 | 345 | [Test] 346 | public void KTimespanGreaterThanOperatorReturnsFalseIfLeftIsSameReferenceAsRight() 347 | { 348 | c.KTimespan left = new c.KTimespan(4700); 349 | c.KTimespan right = left; 350 | 351 | Assert.IsFalse(left > right); 352 | } 353 | 354 | [Test] 355 | public void KTimespanGreaterThanOperatorReturnsFalseIfLeftIsLessThanRight() 356 | { 357 | c.KTimespan left = new c.KTimespan(4700); 358 | c.KTimespan right = new c.KTimespan(4800); 359 | 360 | Assert.IsFalse(left > right); 361 | } 362 | 363 | [Test] 364 | public void KTimespanGreaterThanOperatorReturnsFalseIfLeftAndRightAreNull() 365 | { 366 | c.KTimespan left = null; 367 | c.KTimespan right = null; 368 | 369 | Assert.IsFalse(left > right); 370 | } 371 | 372 | [Test] 373 | public void KTimespanGreaterThanOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 374 | { 375 | c.KTimespan left = null; 376 | c.KTimespan right = new c.KTimespan(4600); 377 | 378 | Assert.IsFalse(left > right); 379 | } 380 | 381 | [Test] 382 | public void KTimespanGreaterThanOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 383 | { 384 | c.KTimespan left = new c.KTimespan(4700); 385 | c.KTimespan right = null; 386 | 387 | Assert.IsTrue(left > right); 388 | } 389 | 390 | [Test] 391 | public void KTimespanLessThanOrEqualOperatorReturnsFalseIfLeftIsGreaterThanRight() 392 | { 393 | c.KTimespan left = new c.KTimespan(4700); 394 | c.KTimespan right = new c.KTimespan(4600); 395 | 396 | Assert.IsFalse(left <= right); 397 | } 398 | 399 | [Test] 400 | public void KTimespanLessThanOrEqualOperatorReturnsTrueIfLeftIsSameValueAsRight() 401 | { 402 | c.KTimespan left = new c.KTimespan(4700); 403 | c.KTimespan right = new c.KTimespan(4700); 404 | 405 | Assert.IsTrue(left <= right); 406 | } 407 | 408 | [Test] 409 | public void KTimespanLessThanOrEqualOperatorReturnsTrueIfLeftIsSameReferenceAsRight() 410 | { 411 | c.KTimespan left = new c.KTimespan(4700); 412 | c.KTimespan right = left; 413 | 414 | Assert.IsTrue(left <= right); 415 | } 416 | 417 | [Test] 418 | public void KTimespanLessThanOrEqualOperatorReturnsTrueIfLeftIsLessThanRight() 419 | { 420 | c.KTimespan left = new c.KTimespan(4700); 421 | c.KTimespan right = new c.KTimespan(4800); 422 | 423 | Assert.IsTrue(left <= right); 424 | } 425 | 426 | [Test] 427 | public void KTimespanLessThanOrEqualOperatorReturnsTrueIfLeftAndRightAreNull() 428 | { 429 | c.KTimespan left = null; 430 | c.KTimespan right = null; 431 | 432 | Assert.IsTrue(left <= right); 433 | } 434 | 435 | [Test] 436 | public void KTimespanLessThanOrEqualOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 437 | { 438 | c.KTimespan left = null; 439 | c.KTimespan right = new c.KTimespan(4600); 440 | 441 | Assert.IsTrue(left <= right); 442 | } 443 | 444 | [Test] 445 | public void KTimespanLessThanOrEqualOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 446 | { 447 | c.KTimespan left = new c.KTimespan(4700); 448 | c.KTimespan right = null; 449 | 450 | Assert.IsFalse(left <= right); 451 | } 452 | 453 | [Test] 454 | public void KTimespanGreaterThanOrEqualOperatorReturnsTrueIfLeftIsGreaterThanRight() 455 | { 456 | c.KTimespan left = new c.KTimespan(4700); 457 | c.KTimespan right = new c.KTimespan(4600); 458 | 459 | Assert.IsTrue(left >= right); 460 | } 461 | 462 | [Test] 463 | public void KTimespanGreaterThanOrEqualOperatorReturnsTrueIfLeftIsSameValueAsRight() 464 | { 465 | c.KTimespan left = new c.KTimespan(4700); 466 | c.KTimespan right = new c.KTimespan(4700); 467 | 468 | Assert.IsTrue(left >= right); 469 | } 470 | 471 | [Test] 472 | public void KTimespanGreaterThanOrEqualOperatorReturnsTrueIfLeftIsSameReferenceAsRight() 473 | { 474 | c.KTimespan left = new c.KTimespan(4700); 475 | c.KTimespan right = left; 476 | 477 | Assert.IsTrue(left >= right); 478 | } 479 | 480 | [Test] 481 | public void KTimespanGreaterThanOrEqualOperatorReturnsFalseIfLeftIsLessThanRight() 482 | { 483 | c.KTimespan left = new c.KTimespan(4700); 484 | c.KTimespan right = new c.KTimespan(4800); 485 | 486 | Assert.IsFalse(left >= right); 487 | } 488 | 489 | [Test] 490 | public void KTimespanGreaterThanOrEqualOperatorReturnsTrueIfLeftAndRightAreNull() 491 | { 492 | c.KTimespan left = null; 493 | c.KTimespan right = null; 494 | 495 | Assert.IsTrue(left >= right); 496 | } 497 | 498 | [Test] 499 | public void KTimespanGreaterThanOrEqualOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 500 | { 501 | c.KTimespan left = null; 502 | c.KTimespan right = new c.KTimespan(4600); 503 | 504 | Assert.IsFalse(left >= right); 505 | } 506 | 507 | [Test] 508 | public void KTimespanGreaterThanOrEqualOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 509 | { 510 | c.KTimespan left = new c.KTimespan(4700); 511 | c.KTimespan right = null; 512 | 513 | Assert.IsTrue(left >= right); 514 | } 515 | } 516 | } 517 | -------------------------------------------------------------------------------- /kx.Test/Types/MinuteTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using NUnit.Framework; 3 | 4 | namespace kx.Test.Types 5 | { 6 | [TestFixture] 7 | public class MinuteTests 8 | { 9 | [Test] 10 | public void MinuteInitialisesWithInt32() 11 | { 12 | c.Minute minute = new c.Minute(1); 13 | 14 | Assert.IsNotNull(minute); 15 | } 16 | 17 | [Test] 18 | public void MinuteToStringReturnsExpectedString() 19 | { 20 | const string expected = "00:47"; 21 | 22 | c.Minute minute = new c.Minute(47); 23 | 24 | Assert.AreEqual(expected, minute.ToString()); 25 | } 26 | 27 | [Test] 28 | public void MinuteToStringReturnsExpectedStringForMinInt32() 29 | { 30 | const string expected = ""; 31 | 32 | c.Minute minute = new c.Minute(int.MinValue); 33 | 34 | Assert.AreEqual(expected, minute.ToString()); 35 | } 36 | 37 | [Test] 38 | public void MinuteGetHashCodeReturnsExpectedHash() 39 | { 40 | const int expected = 47; 41 | 42 | c.Minute minute = new c.Minute(expected); 43 | 44 | Assert.AreEqual(expected, minute.GetHashCode()); 45 | } 46 | 47 | [Test] 48 | public void MinuteEqualsReturnsFalseIfOtherIsNull() 49 | { 50 | c.Minute minute = new c.Minute(47); 51 | c.Minute other = null; 52 | 53 | Assert.IsFalse(minute.Equals(other)); 54 | } 55 | 56 | [Test] 57 | public void MinuteEqualsReturnsFalseIfOtherIsNotTypeOfMinute() 58 | { 59 | c.Minute minute = new c.Minute(47); 60 | Task other = new Task(() => { }); 61 | 62 | Assert.IsFalse(minute.Equals(other)); 63 | } 64 | 65 | [Test] 66 | public void MinuteEqualsReturnsTrueIfOtherIsSameReference() 67 | { 68 | c.Minute minute = new c.Minute(47); 69 | c.Minute other = minute; 70 | 71 | Assert.IsTrue(minute.Equals(other)); 72 | } 73 | 74 | [Test] 75 | public void MinuteEqualsReturnsTrueIfOtherIsSameValue() 76 | { 77 | c.Minute minute = new c.Minute(47); 78 | c.Minute other = new c.Minute(47); 79 | 80 | Assert.IsTrue(minute.Equals(other)); 81 | } 82 | 83 | [Test] 84 | public void MinuteEqualsReturnsFalseIfOtherIsDifferentValue() 85 | { 86 | c.Minute minute = new c.Minute(47); 87 | c.Minute other = new c.Minute(45); 88 | 89 | Assert.IsFalse(minute.Equals(other)); 90 | } 91 | [Test] 92 | public void MinuteCompareToReturnsOneIfOtherIsNull() 93 | { 94 | const int expected = 1; 95 | 96 | c.Minute minute = new c.Minute(47); 97 | c.Minute other = null; 98 | 99 | Assert.AreEqual(expected, minute.CompareTo(other)); 100 | } 101 | 102 | [Test] 103 | public void MinuteCompareToReturnsOneIfOtherIsNotTypeOfMinute() 104 | { 105 | const int expected = 1; 106 | 107 | c.Minute minute = new c.Minute(47); 108 | Task other = new Task(() => { }); 109 | 110 | Assert.AreEqual(expected, minute.CompareTo(other)); 111 | } 112 | 113 | [Test] 114 | public void MinuteCompareToReturnsOneIfOtherIsLessThanValue() 115 | { 116 | const int expected = 1; 117 | 118 | c.Minute minute = new c.Minute(47); 119 | c.Minute other = new c.Minute(46); 120 | 121 | Assert.AreEqual(expected, minute.CompareTo(other)); 122 | } 123 | 124 | [Test] 125 | public void MinuteCompareToReturnsZeroIfOtherIsSameReference() 126 | { 127 | const int expected = 0; 128 | 129 | c.Minute minute = new c.Minute(47); 130 | c.Minute other = minute; 131 | 132 | Assert.AreEqual(expected, minute.CompareTo(other)); 133 | } 134 | 135 | [Test] 136 | public void MinuteCompareToReturnsZeroIfOtherIsSameValue() 137 | { 138 | const int expected = 0; 139 | 140 | c.Minute minute = new c.Minute(47); 141 | c.Minute other = new c.Minute(47); 142 | 143 | Assert.AreEqual(expected, minute.CompareTo(other)); 144 | } 145 | 146 | [Test] 147 | public void MinuteCompareToReturnsMinusOneIfOtherIsMoreThanValue() 148 | { 149 | const int expected = -1; 150 | 151 | c.Minute minute = new c.Minute(47); 152 | c.Minute other = new c.Minute(48); 153 | 154 | Assert.AreEqual(expected, minute.CompareTo(other)); 155 | } 156 | [Test] 157 | public void MinuteEqualsOperatorReturnsTrueIfLeftAndRightAreSameValue() 158 | { 159 | c.Minute left = new c.Minute(47); 160 | c.Minute right = new c.Minute(47); 161 | 162 | Assert.IsTrue(left == right); 163 | } 164 | 165 | [Test] 166 | public void MinuteEqualsOperatorReturnsTrueIfLeftAndRightAreSameReference() 167 | { 168 | c.Minute left = new c.Minute(47); 169 | c.Minute right = left; 170 | 171 | Assert.IsTrue(left == right); 172 | } 173 | 174 | [Test] 175 | public void MinuteEqualsOperatorReturnsFalseIfLeftAndRightAreNotSameValue() 176 | { 177 | c.Minute left = new c.Minute(47); 178 | c.Minute right = new c.Minute(46); 179 | 180 | Assert.IsFalse(left == right); 181 | } 182 | 183 | [Test] 184 | public void MinuteEqualsOperatorReturnsTrueIfLeftAndRightAreNull() 185 | { 186 | c.Minute left = null; 187 | c.Minute right = null; 188 | 189 | Assert.IsTrue(left == right); 190 | } 191 | 192 | [Test] 193 | public void MinuteEqualsOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 194 | { 195 | c.Minute left = null; 196 | c.Minute right = new c.Minute(47); 197 | 198 | Assert.IsFalse(left == right); 199 | } 200 | 201 | [Test] 202 | public void MinuteEqualsOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 203 | { 204 | c.Minute left = new c.Minute(47); 205 | c.Minute right = null; 206 | 207 | Assert.IsFalse(left == right); 208 | } 209 | 210 | [Test] 211 | public void MinuteNotEqualsOperatorReturnsFalseIfLeftAndRightAreSameValue() 212 | { 213 | c.Minute left = new c.Minute(47); 214 | c.Minute right = new c.Minute(47); 215 | 216 | Assert.IsFalse(left != right); 217 | } 218 | 219 | [Test] 220 | public void MinuteNotEqualsOperatorReturnsFalseIfLeftAndRightAreSameReference() 221 | { 222 | c.Minute left = new c.Minute(47); 223 | c.Minute right = left; 224 | 225 | Assert.IsFalse(left != right); 226 | } 227 | 228 | [Test] 229 | public void MinuteNotEqualsOperatorReturnsTrueIfLeftAndRightAreNotSameValue() 230 | { 231 | c.Minute left = new c.Minute(47); 232 | c.Minute right = new c.Minute(46); 233 | 234 | Assert.IsTrue(left != right); 235 | } 236 | 237 | [Test] 238 | public void MinuteNotEqualsOperatorReturnsFalseIfLeftAndRightAreNull() 239 | { 240 | c.Minute left = null; 241 | c.Minute right = null; 242 | 243 | Assert.IsFalse(left != right); 244 | } 245 | 246 | [Test] 247 | public void MinuteNotEqualsOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 248 | { 249 | c.Minute left = null; 250 | c.Minute right = new c.Minute(47); 251 | 252 | Assert.IsTrue(left != right); 253 | } 254 | 255 | [Test] 256 | public void MinuteNotEqualsOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 257 | { 258 | c.Minute left = new c.Minute(47); 259 | c.Minute right = null; 260 | 261 | Assert.IsTrue(left != right); 262 | } 263 | 264 | [Test] 265 | public void MinuteLessThanOperatorReturnsFalseIfLeftIsGreaterThanRight() 266 | { 267 | c.Minute left = new c.Minute(47); 268 | c.Minute right = new c.Minute(46); 269 | 270 | Assert.IsFalse(left < right); 271 | } 272 | 273 | [Test] 274 | public void MinuteLessThanOperatorReturnsFalseIfLeftIsSameValueAsRight() 275 | { 276 | c.Minute left = new c.Minute(47); 277 | c.Minute right = new c.Minute(47); 278 | 279 | Assert.IsFalse(left < right); 280 | } 281 | 282 | [Test] 283 | public void MinuteLessThanOperatorReturnsFalseIfLeftIsSameReferenceAsRight() 284 | { 285 | c.Minute left = new c.Minute(47); 286 | c.Minute right = left; 287 | 288 | Assert.IsFalse(left < right); 289 | } 290 | 291 | [Test] 292 | public void MinuteLessThanOperatorReturnsTrueIfLeftIsLessThanRight() 293 | { 294 | c.Minute left = new c.Minute(47); 295 | c.Minute right = new c.Minute(48); 296 | 297 | Assert.IsTrue(left < right); 298 | } 299 | 300 | [Test] 301 | public void MinuteLessThanOperatorReturnsFalseIfLeftAndRightAreNull() 302 | { 303 | c.Minute left = null; 304 | c.Minute right = null; 305 | 306 | Assert.IsFalse(left < right); 307 | } 308 | 309 | [Test] 310 | public void MinuteLessThanOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 311 | { 312 | c.Minute left = null; 313 | c.Minute right = new c.Minute(46); 314 | 315 | Assert.IsTrue(left < right); 316 | } 317 | 318 | [Test] 319 | public void MinuteLessThanOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 320 | { 321 | c.Minute left = new c.Minute(47); 322 | c.Minute right = null; 323 | 324 | Assert.IsFalse(left < right); 325 | } 326 | 327 | [Test] 328 | public void MinuteGreaterThanOperatorReturnsTrueIfLeftIsGreaterThanRight() 329 | { 330 | c.Minute left = new c.Minute(47); 331 | c.Minute right = new c.Minute(46); 332 | 333 | Assert.IsTrue(left > right); 334 | } 335 | 336 | [Test] 337 | public void MinuteGreaterThanOperatorReturnsFalseIfLeftIsSameValueAsRight() 338 | { 339 | c.Minute left = new c.Minute(47); 340 | c.Minute right = new c.Minute(47); 341 | 342 | Assert.IsFalse(left > right); 343 | } 344 | 345 | [Test] 346 | public void MinuteGreaterThanOperatorReturnsFalseIfLeftIsSameReferenceAsRight() 347 | { 348 | c.Minute left = new c.Minute(47); 349 | c.Minute right = left; 350 | 351 | Assert.IsFalse(left > right); 352 | } 353 | 354 | [Test] 355 | public void MinuteGreaterThanOperatorReturnsFalseIfLeftIsLessThanRight() 356 | { 357 | c.Minute left = new c.Minute(47); 358 | c.Minute right = new c.Minute(48); 359 | 360 | Assert.IsFalse(left > right); 361 | } 362 | 363 | [Test] 364 | public void MinuteGreaterThanOperatorReturnsFalseIfLeftAndRightAreNull() 365 | { 366 | c.Minute left = null; 367 | c.Minute right = null; 368 | 369 | Assert.IsFalse(left > right); 370 | } 371 | 372 | [Test] 373 | public void MinuteGreaterThanOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 374 | { 375 | c.Minute left = null; 376 | c.Minute right = new c.Minute(46); 377 | 378 | Assert.IsFalse(left > right); 379 | } 380 | 381 | [Test] 382 | public void MinuteGreaterThanOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 383 | { 384 | c.Minute left = new c.Minute(47); 385 | c.Minute right = null; 386 | 387 | Assert.IsTrue(left > right); 388 | } 389 | 390 | [Test] 391 | public void MinuteLessThanOrEqualOperatorReturnsFalseIfLeftIsGreaterThanRight() 392 | { 393 | c.Minute left = new c.Minute(47); 394 | c.Minute right = new c.Minute(46); 395 | 396 | Assert.IsFalse(left <= right); 397 | } 398 | 399 | [Test] 400 | public void MinuteLessThanOrEqualOperatorReturnsTrueIfLeftIsSameValueAsRight() 401 | { 402 | c.Minute left = new c.Minute(47); 403 | c.Minute right = new c.Minute(47); 404 | 405 | Assert.IsTrue(left <= right); 406 | } 407 | 408 | [Test] 409 | public void MinuteLessThanOrEqualOperatorReturnsTrueIfLeftIsSameReferenceAsRight() 410 | { 411 | c.Minute left = new c.Minute(47); 412 | c.Minute right = left; 413 | 414 | Assert.IsTrue(left <= right); 415 | } 416 | 417 | [Test] 418 | public void MinuteLessThanOrEqualOperatorReturnsTrueIfLeftIsLessThanRight() 419 | { 420 | c.Minute left = new c.Minute(47); 421 | c.Minute right = new c.Minute(48); 422 | 423 | Assert.IsTrue(left <= right); 424 | } 425 | 426 | [Test] 427 | public void MinuteLessThanOrEqualOperatorReturnsTrueIfLeftAndRightAreNull() 428 | { 429 | c.Minute left = null; 430 | c.Minute right = null; 431 | 432 | Assert.IsTrue(left <= right); 433 | } 434 | 435 | [Test] 436 | public void MinuteLessThanOrEqualOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 437 | { 438 | c.Minute left = null; 439 | c.Minute right = new c.Minute(46); 440 | 441 | Assert.IsTrue(left <= right); 442 | } 443 | 444 | [Test] 445 | public void MinuteLessThanOrEqualOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 446 | { 447 | c.Minute left = new c.Minute(47); 448 | c.Minute right = null; 449 | 450 | Assert.IsFalse(left <= right); 451 | } 452 | 453 | [Test] 454 | public void MinuteGreaterThanOrEqualOperatorReturnsTrueIfLeftIsGreaterThanRight() 455 | { 456 | c.Minute left = new c.Minute(47); 457 | c.Minute right = new c.Minute(46); 458 | 459 | Assert.IsTrue(left >= right); 460 | } 461 | 462 | [Test] 463 | public void MinuteGreaterThanOrEqualOperatorReturnsTrueIfLeftIsSameValueAsRight() 464 | { 465 | c.Minute left = new c.Minute(47); 466 | c.Minute right = new c.Minute(47); 467 | 468 | Assert.IsTrue(left >= right); 469 | } 470 | 471 | [Test] 472 | public void MinuteGreaterThanOrEqualOperatorReturnsTrueIfLeftIsSameReferenceAsRight() 473 | { 474 | c.Minute left = new c.Minute(47); 475 | c.Minute right = left; 476 | 477 | Assert.IsTrue(left >= right); 478 | } 479 | 480 | [Test] 481 | public void MinuteGreaterThanOrEqualOperatorReturnsFalseIfLeftIsLessThanRight() 482 | { 483 | c.Minute left = new c.Minute(47); 484 | c.Minute right = new c.Minute(48); 485 | 486 | Assert.IsFalse(left >= right); 487 | } 488 | 489 | [Test] 490 | public void MinuteGreaterThanOrEqualOperatorReturnsTrueIfLeftAndRightAreNull() 491 | { 492 | c.Minute left = null; 493 | c.Minute right = null; 494 | 495 | Assert.IsTrue(left >= right); 496 | } 497 | 498 | [Test] 499 | public void MinuteGreaterThanOrEqualOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 500 | { 501 | c.Minute left = null; 502 | c.Minute right = new c.Minute(46); 503 | 504 | Assert.IsFalse(left >= right); 505 | } 506 | 507 | [Test] 508 | public void MinuteGreaterThanOrEqualOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 509 | { 510 | c.Minute left = new c.Minute(47); 511 | c.Minute right = null; 512 | 513 | Assert.IsTrue(left >= right); 514 | } 515 | } 516 | } 517 | -------------------------------------------------------------------------------- /kx.Test/Types/MonthTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using NUnit.Framework; 3 | 4 | namespace kx.Test.Types 5 | { 6 | [TestFixture] 7 | public class MonthTests 8 | { 9 | [Test] 10 | public void MonthInitialisesWithInt32() 11 | { 12 | c.Month month = new c.Month(1); 13 | 14 | Assert.IsNotNull(month); 15 | } 16 | 17 | [Test] 18 | public void MonthToStringReturnsExpectedString() 19 | { 20 | const string expected = "2003-12"; 21 | 22 | c.Month month = new c.Month(47); 23 | 24 | Assert.AreEqual(expected, month.ToString()); 25 | } 26 | 27 | [Test] 28 | public void MonthToStringReturnsExpectedStringForMinInt32() 29 | { 30 | const string expected = ""; 31 | 32 | c.Month month = new c.Month(int.MinValue); 33 | 34 | Assert.AreEqual(expected, month.ToString()); 35 | } 36 | 37 | [Test] 38 | public void MonthGetHashCodeReturnsExpectedHash() 39 | { 40 | const int expected = 47; 41 | 42 | c.Month month = new c.Month(expected); 43 | 44 | Assert.AreEqual(expected, month.GetHashCode()); 45 | } 46 | 47 | [Test] 48 | public void MonthEqualsReturnsFalseIfOtherIsNull() 49 | { 50 | c.Month month = new c.Month(47); 51 | c.Month other = null; 52 | 53 | Assert.IsFalse(month.Equals(other)); 54 | } 55 | 56 | [Test] 57 | public void MonthEqualsReturnsFalseIfOtherIsNotTypeOfMonth() 58 | { 59 | c.Month month = new c.Month(47); 60 | Task other = new Task(() => { }); 61 | 62 | Assert.IsFalse(month.Equals(other)); 63 | } 64 | 65 | [Test] 66 | public void MonthEqualsReturnsTrueIfOtherIsSameReference() 67 | { 68 | c.Month month = new c.Month(47); 69 | c.Month other = month; 70 | 71 | Assert.IsTrue(month.Equals(other)); 72 | } 73 | 74 | [Test] 75 | public void MonthEqualsReturnsTrueIfOtherIsSameValue() 76 | { 77 | c.Month month = new c.Month(47); 78 | c.Month other = new c.Month(47); 79 | 80 | Assert.IsTrue(month.Equals(other)); 81 | } 82 | 83 | [Test] 84 | public void MonthEqualsReturnsFalseIfOtherIsDifferentValue() 85 | { 86 | c.Month month = new c.Month(47); 87 | c.Month other = new c.Month(45); 88 | 89 | Assert.IsFalse(month.Equals(other)); 90 | } 91 | 92 | [Test] 93 | public void MonthCompareToReturnsOneIfOtherIsNull() 94 | { 95 | const int expected = 1; 96 | 97 | c.Month month = new c.Month(47); 98 | c.Month other = null; 99 | 100 | Assert.AreEqual(expected, month.CompareTo(other)); 101 | } 102 | 103 | [Test] 104 | public void MonthCompareToReturnsOneIfOtherIsNotTypeOfMonth() 105 | { 106 | const int expected = 1; 107 | 108 | c.Month month = new c.Month(47); 109 | Task other = new Task(() => { }); 110 | 111 | Assert.AreEqual(expected, month.CompareTo(other)); 112 | } 113 | 114 | [Test] 115 | public void MonthCompareToReturnsOneIfOtherIsLessThanValue() 116 | { 117 | const int expected = 1; 118 | 119 | c.Month month = new c.Month(47); 120 | c.Month other = new c.Month(46); 121 | 122 | Assert.AreEqual(expected, month.CompareTo(other)); 123 | } 124 | 125 | [Test] 126 | public void MonthCompareToReturnsZeroIfOtherIsSameReference() 127 | { 128 | const int expected = 0; 129 | 130 | c.Month month = new c.Month(47); 131 | c.Month other = month; 132 | 133 | Assert.AreEqual(expected, month.CompareTo(other)); 134 | } 135 | 136 | [Test] 137 | public void MonthCompareToReturnsZeroIfOtherIsSameValue() 138 | { 139 | const int expected = 0; 140 | 141 | c.Month month = new c.Month(47); 142 | c.Month other = new c.Month(47); 143 | 144 | Assert.AreEqual(expected, month.CompareTo(other)); 145 | } 146 | 147 | [Test] 148 | public void MonthCompareToReturnsMinusOneIfOtherIsMoreThanValue() 149 | { 150 | const int expected = -1; 151 | 152 | c.Month month = new c.Month(47); 153 | c.Month other = new c.Month(48); 154 | 155 | Assert.AreEqual(expected, month.CompareTo(other)); 156 | } 157 | [Test] 158 | public void MonthEqualsOperatorReturnsTrueIfLeftAndRightAreSameValue() 159 | { 160 | c.Month left = new c.Month(47); 161 | c.Month right = new c.Month(47); 162 | 163 | Assert.IsTrue(left == right); 164 | } 165 | 166 | [Test] 167 | public void MonthEqualsOperatorReturnsTrueIfLeftAndRightAreSameReference() 168 | { 169 | c.Month left = new c.Month(47); 170 | c.Month right = left; 171 | 172 | Assert.IsTrue(left == right); 173 | } 174 | 175 | [Test] 176 | public void MonthEqualsOperatorReturnsFalseIfLeftAndRightAreNotSameValue() 177 | { 178 | c.Month left = new c.Month(47); 179 | c.Month right = new c.Month(46); 180 | 181 | Assert.IsFalse(left == right); 182 | } 183 | 184 | [Test] 185 | public void MonthEqualsOperatorReturnsTrueIfLeftAndRightAreNull() 186 | { 187 | c.Month left = null; 188 | c.Month right = null; 189 | 190 | Assert.IsTrue(left == right); 191 | } 192 | 193 | [Test] 194 | public void MonthEqualsOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 195 | { 196 | c.Month left = null; 197 | c.Month right = new c.Month(47); 198 | 199 | Assert.IsFalse(left == right); 200 | } 201 | 202 | [Test] 203 | public void MonthEqualsOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 204 | { 205 | c.Month left = new c.Month(47); 206 | c.Month right = null; 207 | 208 | Assert.IsFalse(left == right); 209 | } 210 | 211 | [Test] 212 | public void MonthNotEqualsOperatorReturnsFalseIfLeftAndRightAreSameValue() 213 | { 214 | c.Month left = new c.Month(47); 215 | c.Month right = new c.Month(47); 216 | 217 | Assert.IsFalse(left != right); 218 | } 219 | 220 | [Test] 221 | public void MonthNotEqualsOperatorReturnsFalseIfLeftAndRightAreSameReference() 222 | { 223 | c.Month left = new c.Month(47); 224 | c.Month right = left; 225 | 226 | Assert.IsFalse(left != right); 227 | } 228 | 229 | [Test] 230 | public void MonthNotEqualsOperatorReturnsTrueIfLeftAndRightAreNotSameValue() 231 | { 232 | c.Month left = new c.Month(47); 233 | c.Month right = new c.Month(46); 234 | 235 | Assert.IsTrue(left != right); 236 | } 237 | 238 | [Test] 239 | public void MonthNotEqualsOperatorReturnsFalseIfLeftAndRightAreNull() 240 | { 241 | c.Month left = null; 242 | c.Month right = null; 243 | 244 | Assert.IsFalse(left != right); 245 | } 246 | 247 | [Test] 248 | public void MonthNotEqualsOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 249 | { 250 | c.Month left = null; 251 | c.Month right = new c.Month(47); 252 | 253 | Assert.IsTrue(left != right); 254 | } 255 | 256 | [Test] 257 | public void MonthNotEqualsOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 258 | { 259 | c.Month left = new c.Month(47); 260 | c.Month right = null; 261 | 262 | Assert.IsTrue(left != right); 263 | } 264 | 265 | [Test] 266 | public void MonthLessThanOperatorReturnsFalseIfLeftIsGreaterThanRight() 267 | { 268 | c.Month left = new c.Month(47); 269 | c.Month right = new c.Month(46); 270 | 271 | Assert.IsFalse(left < right); 272 | } 273 | 274 | [Test] 275 | public void MonthLessThanOperatorReturnsFalseIfLeftIsSameValueAsRight() 276 | { 277 | c.Month left = new c.Month(47); 278 | c.Month right = new c.Month(47); 279 | 280 | Assert.IsFalse(left < right); 281 | } 282 | 283 | [Test] 284 | public void MonthLessThanOperatorReturnsFalseIfLeftIsSameReferenceAsRight() 285 | { 286 | c.Month left = new c.Month(47); 287 | c.Month right = left; 288 | 289 | Assert.IsFalse(left < right); 290 | } 291 | 292 | [Test] 293 | public void MonthLessThanOperatorReturnsTrueIfLeftIsLessThanRight() 294 | { 295 | c.Month left = new c.Month(47); 296 | c.Month right = new c.Month(48); 297 | 298 | Assert.IsTrue(left < right); 299 | } 300 | 301 | [Test] 302 | public void MonthLessThanOperatorReturnsFalseIfLeftAndRightAreNull() 303 | { 304 | c.Month left = null; 305 | c.Month right = null; 306 | 307 | Assert.IsFalse(left < right); 308 | } 309 | 310 | [Test] 311 | public void MonthLessThanOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 312 | { 313 | c.Month left = null; 314 | c.Month right = new c.Month(46); 315 | 316 | Assert.IsTrue(left < right); 317 | } 318 | 319 | [Test] 320 | public void MonthLessThanOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 321 | { 322 | c.Month left = new c.Month(47); 323 | c.Month right = null; 324 | 325 | Assert.IsFalse(left < right); 326 | } 327 | 328 | [Test] 329 | public void MonthGreaterThanOperatorReturnsTrueIfLeftIsGreaterThanRight() 330 | { 331 | c.Month left = new c.Month(47); 332 | c.Month right = new c.Month(46); 333 | 334 | Assert.IsTrue(left > right); 335 | } 336 | 337 | [Test] 338 | public void MonthGreaterThanOperatorReturnsFalseIfLeftIsSameValueAsRight() 339 | { 340 | c.Month left = new c.Month(47); 341 | c.Month right = new c.Month(47); 342 | 343 | Assert.IsFalse(left > right); 344 | } 345 | 346 | [Test] 347 | public void MonthGreaterThanOperatorReturnsFalseIfLeftIsSameReferenceAsRight() 348 | { 349 | c.Month left = new c.Month(47); 350 | c.Month right = left; 351 | 352 | Assert.IsFalse(left > right); 353 | } 354 | 355 | [Test] 356 | public void MonthGreaterThanOperatorReturnsFalseIfLeftIsLessThanRight() 357 | { 358 | c.Month left = new c.Month(47); 359 | c.Month right = new c.Month(48); 360 | 361 | Assert.IsFalse(left > right); 362 | } 363 | 364 | [Test] 365 | public void MonthGreaterThanOperatorReturnsFalseIfLeftAndRightAreNull() 366 | { 367 | c.Month left = null; 368 | c.Month right = null; 369 | 370 | Assert.IsFalse(left > right); 371 | } 372 | 373 | [Test] 374 | public void MonthGreaterThanOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 375 | { 376 | c.Month left = null; 377 | c.Month right = new c.Month(46); 378 | 379 | Assert.IsFalse(left > right); 380 | } 381 | 382 | [Test] 383 | public void MonthGreaterThanOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 384 | { 385 | c.Month left = new c.Month(47); 386 | c.Month right = null; 387 | 388 | Assert.IsTrue(left > right); 389 | } 390 | 391 | [Test] 392 | public void MonthLessThanOrEqualOperatorReturnsFalseIfLeftIsGreaterThanRight() 393 | { 394 | c.Month left = new c.Month(47); 395 | c.Month right = new c.Month(46); 396 | 397 | Assert.IsFalse(left <= right); 398 | } 399 | 400 | [Test] 401 | public void MonthLessThanOrEqualOperatorReturnsTrueIfLeftIsSameValueAsRight() 402 | { 403 | c.Month left = new c.Month(47); 404 | c.Month right = new c.Month(47); 405 | 406 | Assert.IsTrue(left <= right); 407 | } 408 | 409 | [Test] 410 | public void MonthLessThanOrEqualOperatorReturnsTrueIfLeftIsSameReferenceAsRight() 411 | { 412 | c.Month left = new c.Month(47); 413 | c.Month right = left; 414 | 415 | Assert.IsTrue(left <= right); 416 | } 417 | 418 | [Test] 419 | public void MonthLessThanOrEqualOperatorReturnsTrueIfLeftIsLessThanRight() 420 | { 421 | c.Month left = new c.Month(47); 422 | c.Month right = new c.Month(48); 423 | 424 | Assert.IsTrue(left <= right); 425 | } 426 | 427 | [Test] 428 | public void MonthLessThanOrEqualOperatorReturnsTrueIfLeftAndRightAreNull() 429 | { 430 | c.Month left = null; 431 | c.Month right = null; 432 | 433 | Assert.IsTrue(left <= right); 434 | } 435 | 436 | [Test] 437 | public void MonthLessThanOrEqualOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 438 | { 439 | c.Month left = null; 440 | c.Month right = new c.Month(46); 441 | 442 | Assert.IsTrue(left <= right); 443 | } 444 | 445 | [Test] 446 | public void MonthLessThanOrEqualOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 447 | { 448 | c.Month left = new c.Month(47); 449 | c.Month right = null; 450 | 451 | Assert.IsFalse(left <= right); 452 | } 453 | 454 | [Test] 455 | public void MonthGreaterThanOrEqualOperatorReturnsTrueIfLeftIsGreaterThanRight() 456 | { 457 | c.Month left = new c.Month(47); 458 | c.Month right = new c.Month(46); 459 | 460 | Assert.IsTrue(left >= right); 461 | } 462 | 463 | [Test] 464 | public void MonthGreaterThanOrEqualOperatorReturnsTrueIfLeftIsSameValueAsRight() 465 | { 466 | c.Month left = new c.Month(47); 467 | c.Month right = new c.Month(47); 468 | 469 | Assert.IsTrue(left >= right); 470 | } 471 | 472 | [Test] 473 | public void MonthGreaterThanOrEqualOperatorReturnsTrueIfLeftIsSameReferenceAsRight() 474 | { 475 | c.Month left = new c.Month(47); 476 | c.Month right = left; 477 | 478 | Assert.IsTrue(left >= right); 479 | } 480 | 481 | [Test] 482 | public void MonthGreaterThanOrEqualOperatorReturnsFalseIfLeftIsLessThanRight() 483 | { 484 | c.Month left = new c.Month(47); 485 | c.Month right = new c.Month(48); 486 | 487 | Assert.IsFalse(left >= right); 488 | } 489 | 490 | [Test] 491 | public void MonthGreaterThanOrEqualOperatorReturnsTrueIfLeftAndRightAreNull() 492 | { 493 | c.Month left = null; 494 | c.Month right = null; 495 | 496 | Assert.IsTrue(left >= right); 497 | } 498 | 499 | [Test] 500 | public void MonthGreaterThanOrEqualOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 501 | { 502 | c.Month left = null; 503 | c.Month right = new c.Month(46); 504 | 505 | Assert.IsFalse(left >= right); 506 | } 507 | 508 | [Test] 509 | public void MonthGreaterThanOrEqualOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 510 | { 511 | c.Month left = new c.Month(47); 512 | c.Month right = null; 513 | 514 | Assert.IsTrue(left >= right); 515 | } 516 | } 517 | } 518 | -------------------------------------------------------------------------------- /kx.Test/Types/SecondTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using NUnit.Framework; 3 | 4 | namespace kx.Test.Types 5 | { 6 | [TestFixture] 7 | public class SecondTests 8 | { 9 | [Test] 10 | public void SecondInitialisesWithInt32() 11 | { 12 | c.Second second = new c.Second(1); 13 | 14 | Assert.IsNotNull(second); 15 | } 16 | 17 | [Test] 18 | public void SecondToStringReturnsExpectedString() 19 | { 20 | const string expected = "00:00:47"; 21 | 22 | c.Second second = new c.Second(47); 23 | 24 | Assert.AreEqual(expected, second.ToString()); 25 | } 26 | 27 | [Test] 28 | public void SecondToStringReturnsExpectedStringForMinInt32() 29 | { 30 | const string expected = ""; 31 | 32 | c.Second second = new c.Second(int.MinValue); 33 | 34 | Assert.AreEqual(expected, second.ToString()); 35 | } 36 | 37 | [Test] 38 | public void SecondGetHashCodeReturnsExpectedHash() 39 | { 40 | const int expected = 47; 41 | 42 | c.Second second = new c.Second(expected); 43 | 44 | Assert.AreEqual(expected, second.GetHashCode()); 45 | } 46 | [Test] 47 | public void SecondEqualsReturnsFalseIfOtherIsNull() 48 | { 49 | c.Second second = new c.Second(47); 50 | c.Second other = null; 51 | 52 | Assert.IsFalse(second.Equals(other)); 53 | } 54 | 55 | [Test] 56 | public void SecondEqualsReturnsFalseIfOtherIsNotTypeOfSecond() 57 | { 58 | c.Second second = new c.Second(47); 59 | Task other = new Task(() => { }); 60 | 61 | Assert.IsFalse(second.Equals(other)); 62 | } 63 | 64 | [Test] 65 | public void SecondEqualsReturnsTrueIfOtherIsSameReference() 66 | { 67 | c.Second second = new c.Second(47); 68 | c.Second other = second; 69 | 70 | Assert.IsTrue(second.Equals(other)); 71 | } 72 | 73 | [Test] 74 | public void SecondEqualsReturnsTrueIfOtherIsSameValue() 75 | { 76 | c.Second second = new c.Second(47); 77 | c.Second other = new c.Second(47); 78 | 79 | Assert.IsTrue(second.Equals(other)); 80 | } 81 | 82 | [Test] 83 | public void SecondEqualsReturnsFalseIfOtherIsDifferentValue() 84 | { 85 | c.Second second = new c.Second(47); 86 | c.Second other = new c.Second(45); 87 | 88 | Assert.IsFalse(second.Equals(other)); 89 | } 90 | [Test] 91 | public void SecondCompareToReturnsOneIfOtherIsNull() 92 | { 93 | const int expected = 1; 94 | 95 | c.Second second = new c.Second(47); 96 | c.Second other = null; 97 | 98 | Assert.AreEqual(expected, second.CompareTo(other)); 99 | } 100 | 101 | [Test] 102 | public void SecondCompareToReturnsOneIfOtherIsNotTypeOfSecond() 103 | { 104 | const int expected = 1; 105 | 106 | c.Second second = new c.Second(47); 107 | Task other = new Task(() => { }); 108 | 109 | Assert.AreEqual(expected, second.CompareTo(other)); 110 | } 111 | 112 | [Test] 113 | public void SecondCompareToReturnsOneIfOtherIsLessThanValue() 114 | { 115 | const int expected = 1; 116 | 117 | c.Second second = new c.Second(47); 118 | c.Second other = new c.Second(46); 119 | 120 | Assert.AreEqual(expected, second.CompareTo(other)); 121 | } 122 | 123 | [Test] 124 | public void SecondCompareToReturnsZeroIfOtherIsSameReference() 125 | { 126 | const int expected = 0; 127 | 128 | c.Second second = new c.Second(47); 129 | c.Second other = second; 130 | 131 | Assert.AreEqual(expected, second.CompareTo(other)); 132 | } 133 | 134 | [Test] 135 | public void SecondCompareToReturnsZeroIfOtherIsSameValue() 136 | { 137 | const int expected = 0; 138 | 139 | c.Second second = new c.Second(47); 140 | c.Second other = new c.Second(47); 141 | 142 | Assert.AreEqual(expected, second.CompareTo(other)); 143 | } 144 | 145 | [Test] 146 | public void SecondCompareToReturnsMinusOneIfOtherIsMoreThanValue() 147 | { 148 | const int expected = -1; 149 | 150 | c.Second second = new c.Second(47); 151 | c.Second other = new c.Second(48); 152 | 153 | Assert.AreEqual(expected, second.CompareTo(other)); 154 | } 155 | [Test] 156 | public void SecondEqualsOperatorReturnsTrueIfLeftAndRightAreSameValue() 157 | { 158 | c.Second left = new c.Second(47); 159 | c.Second right = new c.Second(47); 160 | 161 | Assert.IsTrue(left == right); 162 | } 163 | 164 | [Test] 165 | public void SecondEqualsOperatorReturnsTrueIfLeftAndRightAreSameReference() 166 | { 167 | c.Second left = new c.Second(47); 168 | c.Second right = left; 169 | 170 | Assert.IsTrue(left == right); 171 | } 172 | 173 | [Test] 174 | public void SecondEqualsOperatorReturnsFalseIfLeftAndRightAreNotSameValue() 175 | { 176 | c.Second left = new c.Second(47); 177 | c.Second right = new c.Second(46); 178 | 179 | Assert.IsFalse(left == right); 180 | } 181 | 182 | [Test] 183 | public void SecondEqualsOperatorReturnsTrueIfLeftAndRightAreNull() 184 | { 185 | c.Second left = null; 186 | c.Second right = null; 187 | 188 | Assert.IsTrue(left == right); 189 | } 190 | 191 | [Test] 192 | public void SecondEqualsOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 193 | { 194 | c.Second left = null; 195 | c.Second right = new c.Second(47); 196 | 197 | Assert.IsFalse(left == right); 198 | } 199 | 200 | [Test] 201 | public void SecondEqualsOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 202 | { 203 | c.Second left = new c.Second(47); 204 | c.Second right = null; 205 | 206 | Assert.IsFalse(left == right); 207 | } 208 | 209 | [Test] 210 | public void SecondNotEqualsOperatorReturnsFalseIfLeftAndRightAreSameValue() 211 | { 212 | c.Second left = new c.Second(47); 213 | c.Second right = new c.Second(47); 214 | 215 | Assert.IsFalse(left != right); 216 | } 217 | 218 | [Test] 219 | public void SecondNotEqualsOperatorReturnsFalseIfLeftAndRightAreSameReference() 220 | { 221 | c.Second left = new c.Second(47); 222 | c.Second right = left; 223 | 224 | Assert.IsFalse(left != right); 225 | } 226 | 227 | [Test] 228 | public void SecondNotEqualsOperatorReturnsTrueIfLeftAndRightAreNotSameValue() 229 | { 230 | c.Second left = new c.Second(47); 231 | c.Second right = new c.Second(46); 232 | 233 | Assert.IsTrue(left != right); 234 | } 235 | 236 | [Test] 237 | public void SecondNotEqualsOperatorReturnsFalseIfLeftAndRightAreNull() 238 | { 239 | c.Second left = null; 240 | c.Second right = null; 241 | 242 | Assert.IsFalse(left != right); 243 | } 244 | 245 | [Test] 246 | public void SecondNotEqualsOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 247 | { 248 | c.Second left = null; 249 | c.Second right = new c.Second(47); 250 | 251 | Assert.IsTrue(left != right); 252 | } 253 | 254 | [Test] 255 | public void SecondNotEqualsOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 256 | { 257 | c.Second left = new c.Second(47); 258 | c.Second right = null; 259 | 260 | Assert.IsTrue(left != right); 261 | } 262 | 263 | [Test] 264 | public void SecondLessThanOperatorReturnsFalseIfLeftIsGreaterThanRight() 265 | { 266 | c.Second left = new c.Second(47); 267 | c.Second right = new c.Second(46); 268 | 269 | Assert.IsFalse(left < right); 270 | } 271 | 272 | [Test] 273 | public void SecondLessThanOperatorReturnsFalseIfLeftIsSameValueAsRight() 274 | { 275 | c.Second left = new c.Second(47); 276 | c.Second right = new c.Second(47); 277 | 278 | Assert.IsFalse(left < right); 279 | } 280 | 281 | [Test] 282 | public void SecondLessThanOperatorReturnsFalseIfLeftIsSameReferenceAsRight() 283 | { 284 | c.Second left = new c.Second(47); 285 | c.Second right = left; 286 | 287 | Assert.IsFalse(left < right); 288 | } 289 | 290 | [Test] 291 | public void SecondLessThanOperatorReturnsTrueIfLeftIsLessThanRight() 292 | { 293 | c.Second left = new c.Second(47); 294 | c.Second right = new c.Second(48); 295 | 296 | Assert.IsTrue(left < right); 297 | } 298 | 299 | [Test] 300 | public void SecondLessThanOperatorReturnsFalseIfLeftAndRightAreNull() 301 | { 302 | c.Second left = null; 303 | c.Second right = null; 304 | 305 | Assert.IsFalse(left < right); 306 | } 307 | 308 | [Test] 309 | public void SecondLessThanOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 310 | { 311 | c.Second left = null; 312 | c.Second right = new c.Second(46); 313 | 314 | Assert.IsTrue(left < right); 315 | } 316 | 317 | [Test] 318 | public void SecondLessThanOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 319 | { 320 | c.Second left = new c.Second(47); 321 | c.Second right = null; 322 | 323 | Assert.IsFalse(left < right); 324 | } 325 | 326 | [Test] 327 | public void SecondGreaterThanOperatorReturnsTrueIfLeftIsGreaterThanRight() 328 | { 329 | c.Second left = new c.Second(47); 330 | c.Second right = new c.Second(46); 331 | 332 | Assert.IsTrue(left > right); 333 | } 334 | 335 | [Test] 336 | public void SecondGreaterThanOperatorReturnsFalseIfLeftIsSameValueAsRight() 337 | { 338 | c.Second left = new c.Second(47); 339 | c.Second right = new c.Second(47); 340 | 341 | Assert.IsFalse(left > right); 342 | } 343 | 344 | [Test] 345 | public void SecondGreaterThanOperatorReturnsFalseIfLeftIsSameReferenceAsRight() 346 | { 347 | c.Second left = new c.Second(47); 348 | c.Second right = left; 349 | 350 | Assert.IsFalse(left > right); 351 | } 352 | 353 | [Test] 354 | public void SecondGreaterThanOperatorReturnsFalseIfLeftIsLessThanRight() 355 | { 356 | c.Second left = new c.Second(47); 357 | c.Second right = new c.Second(48); 358 | 359 | Assert.IsFalse(left > right); 360 | } 361 | 362 | [Test] 363 | public void SecondGreaterThanOperatorReturnsFalseIfLeftAndRightAreNull() 364 | { 365 | c.Second left = null; 366 | c.Second right = null; 367 | 368 | Assert.IsFalse(left > right); 369 | } 370 | 371 | [Test] 372 | public void SecondGreaterThanOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 373 | { 374 | c.Second left = null; 375 | c.Second right = new c.Second(46); 376 | 377 | Assert.IsFalse(left > right); 378 | } 379 | 380 | [Test] 381 | public void SecondGreaterThanOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 382 | { 383 | c.Second left = new c.Second(47); 384 | c.Second right = null; 385 | 386 | Assert.IsTrue(left > right); 387 | } 388 | 389 | [Test] 390 | public void SecondLessThanOrEqualOperatorReturnsFalseIfLeftIsGreaterThanRight() 391 | { 392 | c.Second left = new c.Second(47); 393 | c.Second right = new c.Second(46); 394 | 395 | Assert.IsFalse(left <= right); 396 | } 397 | 398 | [Test] 399 | public void SecondLessThanOrEqualOperatorReturnsTrueIfLeftIsSameValueAsRight() 400 | { 401 | c.Second left = new c.Second(47); 402 | c.Second right = new c.Second(47); 403 | 404 | Assert.IsTrue(left <= right); 405 | } 406 | 407 | [Test] 408 | public void SecondLessThanOrEqualOperatorReturnsTrueIfLeftIsSameReferenceAsRight() 409 | { 410 | c.Second left = new c.Second(47); 411 | c.Second right = left; 412 | 413 | Assert.IsTrue(left <= right); 414 | } 415 | 416 | [Test] 417 | public void SecondLessThanOrEqualOperatorReturnsTrueIfLeftIsLessThanRight() 418 | { 419 | c.Second left = new c.Second(47); 420 | c.Second right = new c.Second(48); 421 | 422 | Assert.IsTrue(left <= right); 423 | } 424 | 425 | [Test] 426 | public void SecondLessThanOrEqualOperatorReturnsTrueIfLeftAndRightAreNull() 427 | { 428 | c.Second left = null; 429 | c.Second right = null; 430 | 431 | Assert.IsTrue(left <= right); 432 | } 433 | 434 | [Test] 435 | public void SecondLessThanOrEqualOperatorReturnsTrueIfLeftIsNullAndRightIsNotNull() 436 | { 437 | c.Second left = null; 438 | c.Second right = new c.Second(46); 439 | 440 | Assert.IsTrue(left <= right); 441 | } 442 | 443 | [Test] 444 | public void SecondLessThanOrEqualOperatorReturnsFalseIfLeftIsNotNullAndRightIsNull() 445 | { 446 | c.Second left = new c.Second(47); 447 | c.Second right = null; 448 | 449 | Assert.IsFalse(left <= right); 450 | } 451 | 452 | [Test] 453 | public void SecondGreaterThanOrEqualOperatorReturnsTrueIfLeftIsGreaterThanRight() 454 | { 455 | c.Second left = new c.Second(47); 456 | c.Second right = new c.Second(46); 457 | 458 | Assert.IsTrue(left >= right); 459 | } 460 | 461 | [Test] 462 | public void SecondGreaterThanOrEqualOperatorReturnsTrueIfLeftIsSameValueAsRight() 463 | { 464 | c.Second left = new c.Second(47); 465 | c.Second right = new c.Second(47); 466 | 467 | Assert.IsTrue(left >= right); 468 | } 469 | 470 | [Test] 471 | public void SecondGreaterThanOrEqualOperatorReturnsTrueIfLeftIsSameReferenceAsRight() 472 | { 473 | c.Second left = new c.Second(47); 474 | c.Second right = left; 475 | 476 | Assert.IsTrue(left >= right); 477 | } 478 | 479 | [Test] 480 | public void SecondGreaterThanOrEqualOperatorReturnsFalseIfLeftIsLessThanRight() 481 | { 482 | c.Second left = new c.Second(47); 483 | c.Second right = new c.Second(48); 484 | 485 | Assert.IsFalse(left >= right); 486 | } 487 | 488 | [Test] 489 | public void SecondGreaterThanOrEqualOperatorReturnsTrueIfLeftAndRightAreNull() 490 | { 491 | c.Second left = null; 492 | c.Second right = null; 493 | 494 | Assert.IsTrue(left >= right); 495 | } 496 | 497 | [Test] 498 | public void SecondGreaterThanOrEqualOperatorReturnsFalseIfLeftIsNullAndRightIsNotNull() 499 | { 500 | c.Second left = null; 501 | c.Second right = new c.Second(46); 502 | 503 | Assert.IsFalse(left >= right); 504 | } 505 | 506 | [Test] 507 | public void SecondGreaterThanOrEqualOperatorReturnsTrueIfLeftIsNotNullAndRightIsNull() 508 | { 509 | c.Second left = new c.Second(47); 510 | c.Second right = null; 511 | 512 | Assert.IsTrue(left >= right); 513 | } 514 | } 515 | } 516 | -------------------------------------------------------------------------------- /kx.Test/kx.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | true 9 | 10 | kx.Test.snk 11 | 12 | 13 | 14 | true 15 | 1701;1702;1591 16 | 17 | 18 | 19 | true 20 | 1701;1702;1591 21 | 22 | 23 | 24 | 25 | all 26 | runtime; build; native; contentfiles; analyzers; buildtransitive 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /kx.Test/kx.Test.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/kx.Test/kx.Test.snk -------------------------------------------------------------------------------- /kx/KException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace kx 5 | { 6 | /// 7 | /// An exception that is thrown when in an error occurs in the class. 8 | /// 9 | [Serializable] 10 | public class KException : Exception 11 | { 12 | /// 13 | /// Initialises a new default instance of . 14 | /// 15 | public KException() 16 | : base() 17 | { 18 | } 19 | 20 | /// 21 | /// Initialises a new instance of with a specified 22 | /// error message. 23 | /// 24 | /// The error message that explains the reason for this exception. 25 | public KException(string message) 26 | : base(message) 27 | { 28 | } 29 | 30 | /// 31 | /// Initialises a new instance of with a specified 32 | /// error message and the excception that is the cause of this exception. 33 | /// 34 | /// The error message that explains the reason for this exception. 35 | /// The exception that is the cause of the current exception. 36 | public KException(string message, Exception innerException) 37 | : base(message, innerException) 38 | { 39 | } 40 | 41 | /// 42 | /// Initialises a new instance of with serialised data. 43 | /// 44 | /// The that holds the serialised data of the exception. 45 | /// The that contains contextual information about the source or destination. 46 | protected KException(SerializationInfo info, StreamingContext context) 47 | : base(info, context) 48 | { 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /kx/kx.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | CSharpKDB 6 | CSharpKDB 7 | Provides functionality for .NET applications to interface with a KDB+ process. 8 | KX Systems 9 | KX Systems 10 | Copyright © KX Systems 11 | https://github.com/KxSystems/csharpkdb 12 | https://github.com/KxSystems/csharpkdb 13 | true 14 | kx.snk 15 | 16 | 17 | 18 | <_Parameter1>kx.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100bd7513fb38413667269a66c3c6733bacc8985829183f8dfa03b1d2c6ebc573603ad5a1cee1d0b925a9b4cfc54923f852ca33db2bf0ace4842e8c05b014802192d4057ab58d461bd49d3a71ae310631f47e2222caaa2c7da377656b4953e082a920d4f4585291222ad2cd46ee61b7fafa7062d003844e1ac8ca6d2603ad2792c2 19 | 20 | 21 | 22 | 23 | <_Parameter1>kx.Benchmark.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dd2d944d77ec2cffdd50c7a1b4e241a5b69a393753eff2d34ad56e94e8bc7cba4a07f28980e4eff8f258b5f12cbc40589bcf6422f1a7c7e182959a93ee965179ba773a18aacc607e1180ae4bd847f6630b39a3f981c46205344fe523863a5892c2ddf0d672aaf3e9253a53b7ce62e0bae3db9f9e999b981fa2a8467f3f5642ca 24 | 25 | 26 | 27 | 28 | bin\Release 29 | bin\Release\netstandard2.0\kx.xml 30 | 31 | 32 | 33 | bin\Debug\ 34 | bin\Debug\netstandard2.0\kx.xml 35 | 36 | 37 | 38 | 39 | all 40 | runtime; build; native; contentfiles; analyzers; buildtransitive 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /kx/kx.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KxSystems/csharpkdb/142a14a46da68b144cbe9fe0b38023610d6edc78/kx/kx.snk -------------------------------------------------------------------------------- /tools/travis-ci-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Only Run SonarScanner if it is not a pull_request 3 | if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then 4 | echo "Executing MSBuild DLL begin command..." 5 | dotnet ./tools/sonar/SonarScanner.MSBuild.dll begin /o:"kxsystems" /k:"KxSystems_csharpkdb" /d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx" /d:sonar.cs.opencover.reportsPaths="*/coverage.opencover.xml" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.verbose=false /d:sonar.login=${SONAR_TOKEN} 6 | fi 7 | 8 | # Run Release build 9 | echo "Running build..." 10 | dotnet build /p:Configuration=Release ./CSharpKdb.sln 11 | 12 | # Run Tests, Coverlet to record result and code-coverage 13 | echo "Running tests..." 14 | dotnet test /p:Configuration=Release --no-build ./kx.Test/kx.Test.csproj --logger:trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover 15 | 16 | if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then 17 | echo "Executing MSBuild DLL end command..." 18 | dotnet ./tools/sonar/SonarScanner.MSBuild.dll end /d:sonar.login=${SONAR_TOKEN} 19 | fi -------------------------------------------------------------------------------- /tools/travis-ci-install-sonar.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/bin/sh 3 | if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then 4 | java -version 5 | echo "Sonar requires updated Java for Ubuntu 16.04.7, updating repos" 6 | sudo apt-get update 7 | sudo apt-get install -y software-properties-common 8 | sudo add-apt-repository -y ppa:linuxuprising/java 9 | sudo apt-get update 10 | echo "Set properties to agree to Java17 license prompts" 11 | echo oracle-java17-installer shared/accepted-oracle-license-v1-3 select true | sudo /usr/bin/debconf-set-selections 12 | echo "Install Java17" 13 | sudo apt install -y oracle-java17-installer --install-recommends 14 | sudo apt install oracle-java17-set-default 15 | java -version 16 | fi 17 | echo "Starting sonar install..." 18 | wget -O sonar.zip https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.0.4.24009/sonar-scanner-msbuild-5.0.4.24009-netcoreapp3.0.zip 19 | echo "Unzipping..." 20 | unzip -qq sonar.zip -d tools/sonar 21 | echo "Displaying file structure..." 22 | find . 23 | ls -l tools/sonar 24 | echo "Changing permissions..." 25 | chmod +x tools/sonar/sonar-scanner-4.4.0.2170/bin/sonar-scanner 26 | --------------------------------------------------------------------------------