public void BaseTest()
        {
            Assert.AreEqual("TupleComparer", advancedComparer.Implementation.GetType().Name);

            Xtensive.Tuples.Tuple tuple1 = Xtensive.Tuples.Tuple.Create(types1);
            Xtensive.Tuples.Tuple tuple2 = Xtensive.Tuples.Tuple.Create(types2);

            CheckComparisons(tuple1, tuple1, 0);
            CheckComparisons(tuple1, tuple2, -1);

            // Same length
            tuple1 = Xtensive.Tuples.Tuple.Create(types1);
            tuple2 = Xtensive.Tuples.Tuple.Create(types1);

            CheckComparisons(tuple1, tuple2, 0);

            tuple1.SetValue(1, "test"); // null-"test" null-null
            CheckComparisons(tuple1, tuple2, 1);

            tuple2.SetValue(1, "test"); // null-"test" null-"test"
            CheckComparisons(tuple1, tuple2, 0);

            tuple2.SetValue(1, null); // null-"test" null-null
            CheckComparisons(tuple1, tuple2, 1);

            tuple1.SetValue(0, 123); // 123-"test" null-null
            CheckComparisons(tuple1, tuple2, 1);

            tuple2.SetValue(0, 123); // 123-"test" 123-null
            CheckComparisons(tuple1, tuple2, 1);

            tuple2.SetValue(1, "test");
            tuple1.SetValue(1, null); // 123-null 123-"test"
            CheckComparisons(tuple1, tuple2, -1);
        }
        public void BaseTest()
        {
            Xtensive.Tuples.Tuple t = Xtensive.Tuples.Tuple.Create(1, "2", 3);
            TestLog.Info("Original: {0}", t);

            Xtensive.Tuples.Tuple rt = t.ToReadOnly(TupleTransformType.TransformedTuple);
            TestLog.Info("Wrapper:  {0}", rt);
            Assert.AreEqual(t, rt);
            t.SetValue(0, 2);
            Assert.AreEqual(t, rt);
            t.SetValue(0, 1);
            AssertEx.Throws <NotSupportedException>(delegate {
                rt.SetValue(0, 2);
            });

            Xtensive.Tuples.Tuple ct = t.ToReadOnly(TupleTransformType.Tuple);
            TestLog.Info("Copy:     {0}", ct);
            Assert.AreEqual(t, ct);
            t.SetValue(0, 2);
            Assert.AreNotEqual(t, ct);
            t.SetValue(0, 1);
            AssertEx.Throws <NotSupportedException>(delegate {
                ct.SetValue(0, 2);
            });
        }
        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));
        }
Esempio n. 5
0
        public void BasicTest()
        {
            Xtensive.Tuples.Tuple t = Xtensive.Tuples.Tuple.Create(TupleDescriptor.Create <string, int, string, TimeSpan, string, string>());
            t.SetValue(0, string.Empty);
            t.SetValue(2, "n\\a");
            t.SetValue(3, new TimeSpan());
            t.SetValue(4, null);
            t.SetValue(5, "null");

            var s  = t.Format();
            var tt = Xtensive.Tuples.Tuple.Parse(t.Descriptor, s);

            Assert.AreEqual(t, tt);
        }
        private static void InternalSetValue <T>(Xtensive.Tuples.Tuple tuple, int fieldIndex, Random random)
        {
            IInstanceGenerator <T> generator = InstanceGeneratorProvider.Default.GetInstanceGenerator <T>();
            T instance = generator.GetInstance(random);

            tuple.SetValue(fieldIndex, instance);
        }
        public void DebugTest()
        {
            Xtensive.Tuples.Tuple tuple1 = Xtensive.Tuples.Tuple.Create(types1);
            Xtensive.Tuples.Tuple tuple2 = Xtensive.Tuples.Tuple.Create(types2);

            tuple1.SetValue(1, "test"); // null-"test" null-null-null
            tuple2.SetValue(1, "test"); // null-"test" null-"test"-null
            CheckComparisons(tuple1, tuple2, -1);;
        }
        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);
            });
        }