Skip to content

Commit 709a083

Browse files
committed
Test for TypeHelper.IsValueTuple()
1 parent e171fe7 commit 709a083

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

Orm/Xtensive.Orm.Tests.Core/Reflection/TypeHelperTest.cs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2007-2022 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alex Yakunin
55
// Created: 2007.12.17
66

@@ -14,6 +14,7 @@
1414
using Xtensive.Core;
1515
using Xtensive.Reflection;
1616
using Xtensive.Orm.Tests;
17+
using System.Linq;
1718

1819
namespace Xtensive.Orm.Tests.Core.Reflection
1920
{
@@ -480,5 +481,47 @@ public void GenericIsNullableTest()
480481
Assert.IsFalse(TypeHelper.IsNullable<int>());
481482
Assert.IsFalse(TypeHelper.IsNullable<string>());
482483
}
484+
485+
[Test]
486+
public void IsValueTupleTest()
487+
{
488+
var tupleTypes = new[] {
489+
typeof (ValueTuple<int>),
490+
typeof (ValueTuple<int, int>),
491+
typeof (ValueTuple<int, int, int>),
492+
typeof (ValueTuple<int, int, int, int>),
493+
typeof (ValueTuple<int, int, int, int, int>),
494+
typeof (ValueTuple<int, int, int, int, int, int>),
495+
typeof (ValueTuple<int, int, int, int, int, int, int>),
496+
typeof (ValueTuple<int, int, int, int, int, int, int, int>)
497+
};
498+
499+
var otherTypes = new[] {
500+
typeof (string),
501+
typeof (char),
502+
typeof (bool),
503+
typeof (DateTime),
504+
typeof (TimeSpan),
505+
typeof (Guid),
506+
typeof (TypeCode),
507+
typeof (byte[]),
508+
typeof (Key),
509+
this.GetType()
510+
};
511+
512+
var startingToken = tupleTypes[0].MetadataToken;
513+
514+
Assert.That(
515+
tupleTypes.Select(t => t.MetadataToken - startingToken).SequenceEqual(Enumerable.Range(0, tupleTypes.Length)),
516+
Is.True);
517+
518+
foreach (var type in tupleTypes) {
519+
Assert.IsTrue(type.IsValueTuple());
520+
}
521+
522+
foreach (var type in otherTypes) {
523+
Assert.IsFalse(type.IsValueTuple());
524+
}
525+
}
483526
}
484527
}

Orm/Xtensive.Orm/Reflection/TypeHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2007-2020 Xtensive LLC.
1+
// Copyright (C) 2007-2022 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Nick Svetlov

0 commit comments

Comments
 (0)