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

Commit fb6ebcf

Browse files
committed
Add getter tests to TypeFieldsTests
1 parent 625ac19 commit fb6ebcf

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

src/ServiceStack.Text/TypeFields.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static TypeFields Get(Type type)
7878
return instance;
7979
}
8080

81-
public Type Type;
81+
public Type Type { get; protected set; }
8282

8383
public readonly Dictionary<string, PropertyGetterDelegate> PublicGetters =
8484
new Dictionary<string, PropertyGetterDelegate>(PclExport.Instance.InvariantComparerIgnoreCase);

tests/ServiceStack.Text.Tests/TypeFieldReflectorTests.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using NUnit.Framework;
2+
3+
namespace ServiceStack.Text.Tests
4+
{
5+
public class TypeFieldsTests
6+
{
7+
(string s, int i, long l, double d) CreateValueTuple() =>
8+
("foo", 1, 2, 3.3);
9+
10+
[Test]
11+
public void Can_cache_ValueTuple_field_accessors()
12+
{
13+
var typeFields = TypeFields.Get(typeof((string s, int i, long l, double d)));
14+
15+
var oTuple = (object)CreateValueTuple();
16+
17+
typeFields.GetPublicSetterRef("Item1")(ref oTuple, "bar");
18+
typeFields.GetPublicSetterRef("Item2")(ref oTuple, 10);
19+
typeFields.GetPublicSetterRef("Item3")(ref oTuple, 20L);
20+
typeFields.GetPublicSetterRef("Item4")(ref oTuple, 4.4d);
21+
22+
Assert.That(typeFields.GetPublicGetter("Item1")(oTuple), Is.EqualTo("bar"));
23+
Assert.That(typeFields.GetPublicGetter("Item2")(oTuple), Is.EqualTo(10));
24+
Assert.That(typeFields.GetPublicGetter("Item3")(oTuple), Is.EqualTo(20));
25+
Assert.That(typeFields.GetPublicGetter("Item4")(oTuple), Is.EqualTo(4.4));
26+
27+
var tuple = ((string s, int i, long l, double d))oTuple;
28+
29+
Assert.That(tuple.s, Is.EqualTo("bar"));
30+
Assert.That(tuple.i, Is.EqualTo(10));
31+
Assert.That(tuple.l, Is.EqualTo(20));
32+
Assert.That(tuple.d, Is.EqualTo(4.4));
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)