Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 6db7339

Browse files
committed
Update TestsConsole to have test methods
1 parent 2183e6e commit 6db7339

File tree

3 files changed

+64
-41
lines changed

3 files changed

+64
-41
lines changed
Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,70 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Threading.Tasks;
42

53
namespace ServiceStack.Text.TestsConsole
64
{
7-
public class T
5+
public struct T
86
{
9-
public Guid X { get; set; }
10-
public char Y { get; set; }
7+
public int PropValue { get; set; }
8+
public string PropRef { get; set; }
9+
10+
public int FieldValue;
11+
public string FieldRef;
1112
}
1213

1314
class Program
1415
{
1516
static void Main(string[] args)
1617
{
17-
var violations = 0;
18-
const int count = 1000 * 1000;
19-
var json = new List<string>();
20-
var serializer = new JsonSerializer<T>();
21-
for (int i = 0; i < count; i++)
22-
{
23-
var t = new T
24-
{
25-
X = Guid.NewGuid(),
26-
Y = i % 2 == 0 ? 'C' : 'P',
27-
};
28-
json.Add(serializer.SerializeToString(t));
29-
}
30-
31-
var tasks = new List<Task>();
32-
var tasksCount = args.Length > 0 ? int.Parse(args[0]) : 3;
33-
for (int jj = 0; jj < tasksCount; jj++)
34-
{
35-
int j = jj;
36-
tasks.Add(Task.Run(() => {
37-
for (int i = 0; i < count; i++)
38-
{
39-
string s = json[i];
40-
var t = serializer.DeserializeFromString(s);
41-
if (t.Y != (i % 2 == 0 ? 'C' : 'P'))
42-
{
43-
violations++;
44-
Console.WriteLine("Constraint violation index {0} thread {1} expected: {2} received: {3} json: {4}",
45-
i, j, i % 2 == 0 ? 'C' : 'P', t.Y, s);
46-
}
47-
}
48-
}));
49-
}
50-
tasks.ForEach(task => task.Wait());
51-
52-
Console.WriteLine($"There were {violations} viloations, running {tasksCount} Tasks");
18+
var t = new T { PropValue = 1, PropRef = "foo", FieldValue = 2, FieldRef = "bar" };
19+
20+
//var i1 = GetPropInt(t);
21+
//var s1 = GetPropString(t);
22+
23+
//var i2 = GetFieldInt(t);
24+
//var s2 = GetFieldString(t);
25+
26+
//$"PropValue: ${i1}, PropRef: ${s1}".Print();
27+
//$"FieldValue: ${i2}, FieldRef: ${s2}".Print();
28+
29+
var tuple = ((int i, string s))new ValueTuple<int,string>(1,"foo");
30+
31+
var oTuple = (object) tuple;
32+
var value = GetValueTupleItem2(oTuple);
33+
34+
value.PrintDump();
35+
}
36+
37+
static object GetPropInt(object instance)
38+
{
39+
var t = (T)instance;
40+
return t.PropValue;
41+
}
42+
43+
static object GetPropString(object instance)
44+
{
45+
var t = (T)instance;
46+
return t.PropRef;
47+
}
48+
49+
static object GetFieldInt(object instance)
50+
{
51+
var t = (T)instance;
52+
return t.FieldValue;
53+
}
54+
55+
static object GetFieldString(object instance)
56+
{
57+
return ((T)instance).FieldRef;
58+
}
59+
60+
static object GetValueTupleItem1(object instance)
61+
{
62+
return ((ValueTuple<int, string>)instance).Item1;
63+
}
64+
65+
static object GetValueTupleItem2(object instance)
66+
{
67+
return ((ValueTuple<int, string>)instance).Item2;
5368
}
5469
}
5570
}

tests/ServiceStack.Text.TestsConsole/ServiceStack.Text.TestsConsole.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
</Reference>
4545
<Reference Include="System" />
4646
<Reference Include="System.Core" />
47+
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
48+
<HintPath>..\..\src\packages\System.ValueTuple.4.4.0-preview1-25305-02\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
49+
</Reference>
4750
<Reference Include="System.Xml.Linq" />
4851
<Reference Include="System.Data.DataSetExtensions" />
4952
<Reference Include="Microsoft.CSharp" />
@@ -57,6 +60,7 @@
5760
</ItemGroup>
5861
<ItemGroup>
5962
<None Include="App.config" />
63+
<None Include="packages.config" />
6064
</ItemGroup>
6165
<ItemGroup>
6266
<ProjectReference Include="..\..\src\ServiceStack.Text\ServiceStack.Text.csproj">
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="System.ValueTuple" version="4.4.0-preview1-25305-02" targetFramework="net45" />
4+
</packages>

0 commit comments

Comments
 (0)