|
| 1 | +// Copyright (C) 2021 Xtensive LLC. |
| 2 | +// This code is distributed under MIT license terms. |
| 3 | +// See the License.txt file in the project root for more information. |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Linq; |
| 8 | +using System.Reflection; |
| 9 | +using System.Text; |
| 10 | +using NUnit.Framework; |
| 11 | +using Xtensive.Tuples.Packed; |
| 12 | +using Xtensive.Orm.Tests; |
| 13 | + |
| 14 | +namespace Xtensive.Tuples |
| 15 | +{ |
| 16 | + [TestFixture] |
| 17 | + public sealed class DateTimeOffsetTupleTest |
| 18 | + { |
| 19 | + [Test] |
| 20 | + public void OnlyDateTimeOffsetFieldsTest() |
| 21 | + { |
| 22 | + var minLength = 30; |
| 23 | + var maxLength = 200; |
| 24 | + var iterationCount = 1000; |
| 25 | + var rnd = RandomManager.CreateRandom(); |
| 26 | + var generator = InstanceGeneratorProvider.Default.GetInstanceGenerator<DateTimeOffset>(); |
| 27 | + for (var i = 0; i < iterationCount; i++) { |
| 28 | + var count = rnd.Next(maxLength - minLength); |
| 29 | + |
| 30 | + var fields = new Type[count]; |
| 31 | + var data = new DateTimeOffset[count]; |
| 32 | + for (var j = 0; j < count; j++) { |
| 33 | + data[j] = generator.GetInstance(rnd); |
| 34 | + fields[j] = typeof(DateTimeOffset); |
| 35 | + } |
| 36 | + |
| 37 | + // Testing writes (untyped) |
| 38 | + var tuple1 = Tuple.Create(fields); |
| 39 | + Assert.That(tuple1, Is.InstanceOf<PackedTuple>()); |
| 40 | + for (var j = 0; j < count; j++) |
| 41 | + tuple1.SetValue(j, (object) data[j]); |
| 42 | + // Testing reads (untyped) |
| 43 | + for (var j = 0; j < count; j++) |
| 44 | + Assert.AreEqual(data[j], tuple1.GetValue(j)); |
| 45 | + |
| 46 | + // Testing writes (untyped) |
| 47 | + var tuple2 = Tuple.Create(fields); |
| 48 | + Assert.That(tuple2, Is.InstanceOf<PackedTuple>()); |
| 49 | + for (var j = 0; j < count; j++) |
| 50 | + tuple2.SetValue(j, data[j]); |
| 51 | + for (var j = 0; j < count; j++) |
| 52 | + Assert.AreEqual(data[j], tuple2.GetValue<DateTimeOffset>(j)); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments