public void SingleAttributeProjectionTest()
        {
            Assert.Throws <ArgumentException>(() => _ = new SingleAttributeProjection(""));

            var p = new SingleAttributeProjection();

            Assert.That(p.FactoryId, Is.EqualTo(FactoryIds.ProjectionDsFactoryId));
            Assert.That(p.ClassId, Is.EqualTo(ProjectionDataSerializerHook.SingleAttribute));

            p = new SingleAttributeProjection("attribute");

            Assert.That(p.FactoryId, Is.EqualTo(FactoryIds.ProjectionDsFactoryId));
            Assert.That(p.ClassId, Is.EqualTo(ProjectionDataSerializerHook.SingleAttribute));

            Assert.Throws <ArgumentNullException>(() => p.WriteData(null));
            Assert.Throws <ArgumentNullException>(() => p.ReadData(null));

            using var output = new ByteArrayObjectDataOutput(256, null, Endianness.Unspecified);
            p.WriteData(output);

            using var input = new ByteArrayObjectDataInput(output.Buffer, null, Endianness.Unspecified);

            p = new SingleAttributeProjection();
            p.ReadData(input);

            Assert.That(p.AttributePath, Is.EqualTo("attribute"));
        }
Example #2
0
        public virtual void TestGetByteOrder()
        {
            var outLE = new ByteArrayObjectDataOutput(10, null, ByteOrder.LittleEndian);
            var outBE = new ByteArrayObjectDataOutput(10, null, ByteOrder.BigEndian);

            Assert.AreEqual(ByteOrder.LittleEndian, outLE.GetByteOrder());
            Assert.AreEqual(ByteOrder.BigEndian, outBE.GetByteOrder());
        }
Example #3
0
        private T AssertPredicate <T>(T predicate, int classId)
            where T : IPredicate
        {
            Assert.That(predicate.FactoryId, Is.EqualTo(FactoryIds.PredicateFactoryId));
            Assert.That(predicate.ClassId, Is.EqualTo(classId));

            Assert.Throws <ArgumentNullException>(() => predicate.WriteData(null));
            Assert.Throws <ArgumentNullException>(() => predicate.ReadData(null));

            using var output = new ByteArrayObjectDataOutput(1024, _serializationService, Endianness.Unspecified);
            predicate.WriteData(output);

            T p = default;

            if (typeof(T) != typeof(PagingPredicate) && typeof(T) != typeof(PartitionPredicate))
            {
                using var input = new ByteArrayObjectDataInput(output.Buffer, _serializationService, Endianness.Unspecified);
                p = (T)Activator.CreateInstance(typeof(T));
                p.ReadData(input);

                Assert.That(predicate.Equals(p));
                Assert.That(predicate.Equals(predicate));
                Assert.That(predicate.Equals(null), Is.False);

                Assert.That(Equals(predicate, p));
                Assert.That(Equals(predicate, predicate));
                Assert.That(Equals(predicate, null), Is.False);

                var        type = typeof(T);
                MethodInfo staticEquals;
                do
                {
                    staticEquals = type.GetMethod("Equals", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
                    type         = type.BaseType;
                } while (staticEquals == null && type != typeof(object));
                Assert.That(staticEquals, Is.Not.Null);

                Assert.That((bool)staticEquals.Invoke(null, new object[] { predicate, p }));
                Assert.That((bool)staticEquals.Invoke(null, new object[] { predicate, predicate }));
                Assert.That((bool)staticEquals.Invoke(null, new object[] { predicate, null }), Is.False);

                var data = _serializationService.ToData(predicate);
                p = _serializationService.ToObject <T>(data);
                Assert.That(predicate.Equals(p));
            }

            _ = predicate.GetHashCode();

            Console.WriteLine($"{typeof(T)}: {predicate}");

            return(p);
        }
        private void AssertAggregator <TAggregator>(TAggregator aggregator, int classId)
            where TAggregator : IAggregator
        {
            Assert.That(aggregator.FactoryId, Is.EqualTo(FactoryIds.AggregatorDsFactoryId));
            Assert.That(aggregator.ClassId, Is.EqualTo(classId));

            Assert.Throws <ArgumentException>(() => _ = Aggregator.Count(""));
            Assert.Throws <ArgumentException>(() => _ = Aggregator.Count(null));

            Assert.Throws <ArgumentNullException>(() => aggregator.WriteData(null));
            Assert.Throws <ArgumentNullException>(() => aggregator.ReadData(null));

            using var output = new ByteArrayObjectDataOutput(1024, _serializationService, Endianness.Unspecified);
            aggregator.WriteData(output);

            using var input = new ByteArrayObjectDataInput(output.Buffer, _serializationService, Endianness.Unspecified);
            var a = (TAggregator)Activator.CreateInstance(typeof(TAggregator));

            a.ReadData(input);

            Assert.That(a.AttributePath, Is.EqualTo(aggregator.AttributePath));

            var data = _serializationService.ToData(aggregator);

            IAggregator x = null;

            if (typeof(TAggregator).IsGenericType)
            {
                // doh - cannot deserialize generic types?

                if (typeof(TAggregator).GetGenericTypeDefinition() == typeof(MaxAggregator <>))
                {
                    x = _serializationService.ToObject <MaxAggregator <object> >(data);
                }
                else if (typeof(TAggregator).GetGenericTypeDefinition() == typeof(MinAggregator <>))
                {
                    x = _serializationService.ToObject <MinAggregator <object> >(data);
                }
                else
                {
                    Assert.Fail("Unsupported generic aggregator type.");
                }
            }
            else
            {
                x = _serializationService.ToObject <TAggregator>(data);
            }

            Assert.That(x.AttributePath, Is.EqualTo(aggregator.AttributePath));
        }
Example #5
0
        public void PartitionPredicate()
        {
            AssertPredicate(new PartitionPredicate(), PredicateDataSerializerHook.PartitionPredicate);
            AssertPredicate(new PartitionPredicate("key", Predicate.True()), PredicateDataSerializerHook.PartitionPredicate);

            var partition = new PartitionPredicate("key", Predicate.True());

            Assert.That(partition.FactoryId, Is.EqualTo(FactoryIds.PredicateFactoryId));
            Assert.That(partition.ClassId, Is.EqualTo(PredicateDataSerializerHook.PartitionPredicate));

            Assert.Throws <ArgumentNullException>(() => partition.WriteData(null));
            Assert.Throws <ArgumentNullException>(() => partition.ReadData(null));

            using var output = new ByteArrayObjectDataOutput(1024, _serializationService, Endianness.Unspecified);
            partition.WriteData(output);
            using var input = new ByteArrayObjectDataInput(output.Buffer, _serializationService, Endianness.Unspecified);
            var p = new PartitionPredicate();

            p.ReadData(input);

            Assert.That(p.PartitionKey, Is.EqualTo(partition.PartitionKey));
            Assert.That(p.Target, Is.EqualTo(partition.Target));
        }
 public virtual void TestEnsureAvailable()
 {
     _output = new ByteArrayObjectDataOutput(0, null, Endianness.BigEndian);
     _output.Validate(0, 5);
     Assert.AreEqual(10, _output.Buffer.Length);
 }
 public virtual void Before()
 {
     _output = new ByteArrayObjectDataOutput(10, null, Endianness.BigEndian);
 }
Example #8
0
        public void ComparerTest()
        {
            var comparer = new PredicateComparer(1, IterationType.Value);

            Assert.Throws <ArgumentNullException>(() => comparer.WriteData(null));
            Assert.Throws <ArgumentNullException>(() => comparer.ReadData(null));

            using var output = new ByteArrayObjectDataOutput(1024, _serializationService, Endianness.Unspecified);
            comparer.WriteData(output);
            var c = new PredicateComparer();

            using var input = new ByteArrayObjectDataInput(output.Buffer, _serializationService, Endianness.Unspecified);
            c.ReadData(input);

            Assert.That(c.Type, Is.EqualTo(comparer.Type));
            Assert.That(c.IterationType, Is.EqualTo(comparer.IterationType));

            // entry

            Assert.That(new PredicateComparer(0, IterationType.Key).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo("key1".CompareTo("key2")));

            Assert.That(new PredicateComparer(1, IterationType.Key).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo("key2".CompareTo("key1")));

            Assert.That(new PredicateComparer(2, IterationType.Key).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo(0));

            Assert.That(new PredicateComparer(2, IterationType.Key).Compare(("key1", "value1"), ("key2x", "value2")),
                        Is.EqualTo("key1".Length.CompareTo("key2x".Length)));

            Assert.That(new PredicateComparer(3, IterationType.Key).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo(0));

            Assert.That(new PredicateComparer(3, IterationType.Key).Compare(("key1", "value1"), ("key2x", "value2")),
                        Is.EqualTo(0));

            // uh?

            Assert.That(new PredicateComparer(0, (IterationType)666).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo("key1".CompareTo("key2")));

            Assert.That(new PredicateComparer(1, (IterationType)666).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo("key2".CompareTo("key1")));

            Assert.That(new PredicateComparer(2, (IterationType)666).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo(0));

            Assert.That(new PredicateComparer(2, (IterationType)666).Compare(("key1", "value1"), ("key2x", "value2")),
                        Is.EqualTo("key1".Length.CompareTo("key2x".Length)));

            Assert.That(new PredicateComparer(3, (IterationType)666).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo(0));

            Assert.That(new PredicateComparer(3, (IterationType)666).Compare(("key1", "value1"), ("key2x", "value2")),
                        Is.EqualTo(0));

            // value

            Assert.That(new PredicateComparer(0, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo("value1".CompareTo("value2")));

            Assert.That(new PredicateComparer(1, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo("value2".CompareTo("value1")));

            Assert.That(new PredicateComparer(2, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo(0));

            Assert.That(new PredicateComparer(2, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2x")),
                        Is.EqualTo("value1".Length.CompareTo("value2x".Length)));

            Assert.That(new PredicateComparer(3, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo(0));

            Assert.That(new PredicateComparer(3, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2x")),
                        Is.EqualTo(0));

            // entry

            Assert.That(new PredicateComparer(0, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo("key1:::value1".CompareTo("key2:::value2")));

            Assert.That(new PredicateComparer(1, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo("key2:::value2".CompareTo("key1:::value1")));

            Assert.That(new PredicateComparer(2, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo(0));

            Assert.That(new PredicateComparer(2, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2x")),
                        Is.EqualTo("key1:::value1".Length.CompareTo("key2:::value2x".Length)));

            Assert.That(new PredicateComparer(3, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2")),
                        Is.EqualTo(0));

            Assert.That(new PredicateComparer(3, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2x")),
                        Is.EqualTo(0));

            Assert.That(new PredicateComparer(0, IterationType.Entry).Compare(("abc", "defghi"), ("abcdef", "ghi")),
                        Is.EqualTo("abc:::defghi".CompareTo("abcdef:::ghi")));

            // NOTE
            // the behavior for non-supported types and iteration types is ... weird
        }