public void BaseTest()
        {
            Xtensive.Tuples.Tuple t1 = Xtensive.Tuples.Tuple.Create(1, "2");
            Xtensive.Tuples.Tuple t2 = Xtensive.Tuples.Tuple.Create(3, 4.0, "5");
            TestLog.Info("Originals: {0}, {1}", t1, t2);

            CombineTransform mt   = new CombineTransform(false, t1.Descriptor, t2.Descriptor);
            CombineTransform mtro = new CombineTransform(true, t1.Descriptor, t2.Descriptor);

            Xtensive.Tuples.Tuple wt1 = mt.Apply(TupleTransformType.TransformedTuple, t1, t2);
            TestLog.Info("Wrapper:   {0}", wt1);
            Xtensive.Tuples.Tuple ct1 = mt.Apply(TupleTransformType.Tuple, t1, t2);
            TestLog.Info("Copy:      {0}", ct1);
            Xtensive.Tuples.Tuple wt2 = mt.Apply(TupleTransformType.TransformedTuple, t1, t2);
            Xtensive.Tuples.Tuple ct2 = mt.Apply(TupleTransformType.Tuple, t1, t2);

            Assert.AreEqual(wt1, wt2);
            Assert.AreEqual(wt2, ct1);
            Assert.AreEqual(ct1, ct2);

            wt1.SetValue(2, 0);
            Assert.AreEqual(t2.GetValue(0), wt1.GetValue(2));
            Assert.AreEqual(wt1, wt2);
            Assert.AreNotEqual(wt2, ct1);
            Assert.AreEqual(ct1, ct2);

            ct1.SetValue(2, 0);
            Assert.AreEqual(t2.GetValue(0), ct1.GetValue(2));
            Assert.AreEqual(wt1, wt2);
            Assert.AreEqual(wt2, ct1);
            Assert.AreNotEqual(ct1, ct2);

            Xtensive.Tuples.Tuple wtro = mtro.Apply(TupleTransformType.TransformedTuple, t1, t2);
            AssertEx.Throws <NotSupportedException>(delegate {
                wtro.SetValue(2, 0);
            });

            CombineTransform mt3 = new CombineTransform(false, t1.Descriptor, t1.Descriptor, t1.Descriptor);

            Xtensive.Tuples.Tuple wt3 = mt3.Apply(TupleTransformType.TransformedTuple, t1, t1, t1);
            TestLog.Info("Wrapper:   {0}", wt3);
            Xtensive.Tuples.Tuple ct3 = mt3.Apply(TupleTransformType.Tuple, t1, t1, t1);
            TestLog.Info("Copy:      {0}", ct3);
            t1.SetValue(0, 0);
            Assert.AreEqual(wt3.GetValue(4), t1.GetValue(0));
            t1.SetValue(0, 1);

            CombineTransform mt4 = new CombineTransform(false, t1.Descriptor, t1.Descriptor, t1.Descriptor, t1.Descriptor);

            Xtensive.Tuples.Tuple wt4 = mt4.Apply(TupleTransformType.TransformedTuple, t1, t1, t1, t1);
            TestLog.Info("Wrapper:   {0}", wt4);
            Xtensive.Tuples.Tuple ct4 = mt4.Apply(TupleTransformType.Tuple, t1, t1, t1, t1);
            TestLog.Info("Copy:      {0}", ct4);
            t1.SetValue(0, 0);
            Assert.AreEqual(wt4.GetValue(6), t1.GetValue(0));
            t1.SetValue(0, 1);
        }
        private static void TestTuple(Xtensive.Tuples.Tuple tuple)
        {
            Assert.IsFalse(tuple.GetFieldState(0).IsAvailable());

            try {
                tuple.GetFieldState(0).IsNull();
                throw new AssertionException("Value is not available. No one knows if it is null or not.");
            } catch (InvalidOperationException) {
            }

            tuple.SetValue(0, 1);
            Assert.IsTrue(tuple.GetFieldState(0).IsAvailable());
            Assert.IsFalse(tuple.GetFieldState(0).IsNull());
            Assert.IsTrue(tuple.GetFieldState(0).HasValue());
            Assert.AreEqual(1, tuple.GetValue(0));
            Assert.AreEqual(1, tuple.GetValue <int>(0));
            Assert.AreEqual(new int?(1), tuple.GetValue <int?>(0));

            tuple.SetValue(0, null);
            Assert.IsTrue(tuple.GetFieldState(0).IsAvailable());
            Assert.IsTrue(tuple.GetFieldState(0).IsNull());
            Assert.IsFalse(tuple.GetFieldState(0).HasValue());
            Assert.AreEqual(null, tuple.GetValue(0));
            Assert.AreEqual(null, tuple.GetValue <int?>(0));

            tuple.SetValue <int?>(0, null);
            Assert.IsTrue(tuple.GetFieldState(0).IsAvailable());
            Assert.IsTrue(tuple.GetFieldState(0).IsNull());
            Assert.IsFalse(tuple.GetFieldState(0).HasValue());
            Assert.AreEqual(null, tuple.GetValue(0));
            Assert.AreEqual(null, tuple.GetValue <int?>(0));
            Assert.AreEqual(null, tuple.GetValueOrDefault(0));
            Assert.AreEqual(null, tuple.GetValueOrDefault <int?>(0));

            try {
                tuple.GetValue(1);
                throw new AssertionException("Value should not be available.");
            } catch (InvalidOperationException) {
            }

            try {
                tuple.GetValue <string>(2);
                throw new AssertionException("Value should not be available.");
            } catch (InvalidOperationException) {
            }

            try {
                tuple.GetValue <byte>(0);
                throw new AssertionException("Null reference or Invalid cast exception should be thrown.");
            }
            catch (NullReferenceException) {}
            catch (InvalidCastException) {}

            Assert.IsTrue(tuple.Equals(tuple));
        }
 private void GetValueTest(Xtensive.Tuples.Tuple t, int count, int index)
 {
     for (int i = 0; i < count; i++)
     {
         TupleFieldState state;
         t.GetValue(index, out state);
     }
 }
        private void GetAllValuesTest(Xtensive.Tuples.Tuple t, int count)
        {
            int fieldCount = t.Count;

            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < fieldCount; j++)
                {
                    TupleFieldState state;
                    t.GetValue(j, out state);
                }
            }
        }
        public void BaseTest()
        {
            Xtensive.Tuples.Tuple t = Xtensive.Tuples.Tuple.Create(1, "2", 3, 4.0);
            TestLog.Info("Original: {0}", t);

            SegmentTransform st   = new SegmentTransform(false, t.Descriptor, new Segment <int>(1, 2));
            SegmentTransform stro = new SegmentTransform(true, t.Descriptor, new Segment <int>(1, 2));

            Xtensive.Tuples.Tuple wt1 = st.Apply(TupleTransformType.TransformedTuple, t);
            TestLog.Info("Wrapper:  {0}", wt1);
            Xtensive.Tuples.Tuple ct1 = st.Apply(TupleTransformType.Tuple, t);
            TestLog.Info("Copy:     {0}", ct1);
            Xtensive.Tuples.Tuple wt2 = st.Apply(TupleTransformType.TransformedTuple, t);
            Xtensive.Tuples.Tuple ct2 = st.Apply(TupleTransformType.Tuple, t);

            Assert.AreEqual(wt1, wt2);
            Assert.AreEqual(wt2, ct1);
            Assert.AreEqual(ct1, ct2);

            wt1.SetValue(1, 1);
            Assert.AreEqual(t.GetValue(2), wt1.GetValue(1));
            Assert.AreEqual(wt1, wt2);
            Assert.AreNotEqual(wt2, ct1);
            Assert.AreEqual(ct1, ct2);

            ct1.SetValue(1, 1);
            Assert.AreEqual(t.GetValue(2), ct1.GetValue(1));
            Assert.AreEqual(wt1, wt2);
            Assert.AreEqual(wt2, ct1);
            Assert.AreNotEqual(ct1, ct2);

            Xtensive.Tuples.Tuple wtro = stro.Apply(TupleTransformType.TransformedTuple, t);
            AssertEx.Throws <NotSupportedException>(delegate {
                wtro.SetValue(1, 1);
            });
        }
 bool ManualEquals(Xtensive.Tuples.Tuple x, Xtensive.Tuples.Tuple y)
 {
     if (y != null)
     {
         TupleFieldState state;
         TupleFieldState state2;
         if (x == y)
         {
             return(true);
         }
         if (x.Descriptor != y.Descriptor)
         {
             return(false);
         }
         var flag = x.GetValue <int>(0, out state) == y.GetValue <int>(0, out state2);
         if ((state == state2) && ((state != TupleFieldState.Available) || flag))
         {
             return(true);
         }
     }
     return(false);
 }