Ejemplo n.º 1
0
        public void GetValueTyped()
        {
            FudgeMsg msg       = StandardFudgeMessages.CreateMessageAllNames(fudgeContext);
            long     longValue = ((long)int.MaxValue) + 5;

            Assert.Equal(longValue, msg.GetValue <long>("long"));
            Assert.Equal(5, msg.GetValue <long>("byte"));
        }
Ejemplo n.º 2
0
        public void LookupByNameSingleValue()
        {
            FudgeMsg            msg    = StandardFudgeMessages.CreateMessageAllNames(fudgeContext);
            IFudgeField         field  = null;
            IList <IFudgeField> fields = null;

            field = msg.GetByName("boolean");
            Assert.NotNull(field);
            Assert.Equal(PrimitiveFieldTypes.BooleanType, field.Type);
            Assert.Equal(true, field.Value);
            Assert.Equal("boolean", field.Name);
            Assert.Null(field.Ordinal);

            field = msg.GetByName("Boolean");
            Assert.NotNull(field);
            Assert.Equal(PrimitiveFieldTypes.BooleanType, field.Type);
            Assert.Equal((object)false, field.Value);
            Assert.Equal("Boolean", field.Name);
            Assert.Null(field.Ordinal);

            fields = msg.GetAllByName("boolean");
            Assert.NotNull(fields);
            Assert.Equal(1, fields.Count);
            field = fields[0];
            Assert.NotNull(field);
            Assert.Equal(PrimitiveFieldTypes.BooleanType, field.Type);
            Assert.Equal(true, field.Value);
            Assert.Equal("boolean", field.Name);
            Assert.Null(field.Ordinal);

            // Check the indicator type specially
            Assert.Same(IndicatorType.Instance, msg.GetValue("indicator"));
        }
        public void CheckSecondaryTypes()
        {
            var msg = new FudgeMsg(context);
            var dt = new DateTime(1987, 1, 13, 8, 6, 5);
            var dto = new DateTimeOffset(1822, 7, 20, 13, 2, 15, new TimeSpan(-2, 0, 0));

            msg.Add("dt", dt);
            msg.Add("dto", dto);

            Assert.Same(DateTimeFieldType.Instance, msg.GetByName("dt").Type);
            Assert.IsType<FudgeDateTime>(msg.GetByName("dt").Value);
            Assert.Same(DateTimeFieldType.Instance, msg.GetByName("dto").Type);
            Assert.IsType<FudgeDateTime>(msg.GetByName("dto").Value);

            Assert.Equal(dt, msg.GetValue<DateTime>("dt"));
            Assert.Equal(dto, msg.GetValue<DateTime>("dto"));
        }
Ejemplo n.º 4
0
        public void AddingFieldContainerCopiesFields()
        {
            var msg = new FudgeMsg();

            // Add a normal sub-message (shouldn't copy)
            IFudgeFieldContainer sub1 = new FudgeMsg(new Field("age", 37));
            msg.Add("sub1", sub1);
            Assert.Same(sub1, msg.GetValue("sub1"));

            // Add a sub-message that isn't a FudgeMsg (should copy)
            IFudgeFieldContainer sub2 = (IFudgeFieldContainer)new Field("dummy", new Field("colour", "blue")).Value;
            Assert.IsNotType<FudgeMsg>(sub2);       // Just making sure
            msg.Add("sub2", sub2);
            Assert.NotSame(sub2, msg.GetValue("sub2"));
            Assert.IsType<FudgeMsg>(msg.GetValue("sub2"));
            Assert.Equal("blue", msg.GetMessage("sub2").GetString("colour"));
        }
        public void CheckSecondaryTypes()
        {
            var msg = new FudgeMsg(context);
            var dt  = new DateTime(1987, 1, 13, 8, 6, 5);
            var dto = new DateTimeOffset(1822, 7, 20, 13, 2, 15, new TimeSpan(-2, 0, 0));

            msg.Add("dt", dt);
            msg.Add("dto", dto);

            Assert.Same(DateTimeFieldType.Instance, msg.GetByName("dt").Type);
            Assert.IsType <FudgeDateTime>(msg.GetByName("dt").Value);
            Assert.Same(DateTimeFieldType.Instance, msg.GetByName("dto").Type);
            Assert.IsType <FudgeDateTime>(msg.GetByName("dto").Value);

            Assert.Equal(dt, msg.GetValue <DateTime>("dt"));
            Assert.Equal(dto, msg.GetValue <DateTime>("dto"));
        }
Ejemplo n.º 6
0
        public void AddingFieldContainerCopiesFields()
        {
            var msg = new FudgeMsg();

            // Add a normal sub-message (shouldn't copy)
            IFudgeFieldContainer sub1 = new FudgeMsg(new Field("age", 37));

            msg.Add("sub1", sub1);
            Assert.Same(sub1, msg.GetValue("sub1"));

            // Add a sub-message that isn't a FudgeMsg (should copy)
            IFudgeFieldContainer sub2 = (IFudgeFieldContainer) new Field("dummy", new Field("colour", "blue")).Value;

            Assert.IsNotType <FudgeMsg>(sub2);       // Just making sure
            msg.Add("sub2", sub2);
            Assert.NotSame(sub2, msg.GetValue("sub2"));
            Assert.IsType <FudgeMsg>(msg.GetValue("sub2"));
            Assert.Equal("blue", msg.GetMessage("sub2").GetString("colour"));
        }
        public void Minimsation()
        {
            var msg = new FudgeMsg(context);
            var dt = new DateTime(1990, 2, 1);
            var fdt = new FudgeDateTime(1990, 2, 1, 0, 0, 0, 0, FudgeDateTimePrecision.Day);

            msg.Add("dt", dt);
            msg.Add("fdt", fdt);
            Assert.Same(DateFieldType.Instance, msg.GetByName("dt").Type);
            Assert.IsType<FudgeDate>(msg.GetByName("dt").Value);
            Assert.Same(DateFieldType.Instance, msg.GetByName("fdt").Type);
            Assert.IsType<FudgeDate>(msg.GetByName("fdt").Value);

            Assert.Equal(dt, msg.GetValue<DateTime>("dt"));
            Assert.Equal(fdt, msg.GetValue<FudgeDateTime>("fdt"));

            // Error cases
            FudgeFieldType type = null;
            Assert.Equal(null, DateTimeFieldType.Instance.Minimize(null, ref type));
            Assert.Throws<ArgumentException>(() => DateTimeFieldType.Instance.Minimize("fred", ref type));
        }
        public void Minimsation()
        {
            var msg = new FudgeMsg(context);
            var dt  = new DateTime(1990, 2, 1);
            var fdt = new FudgeDateTime(1990, 2, 1, 0, 0, 0, 0, FudgeDateTimePrecision.Day);

            msg.Add("dt", dt);
            msg.Add("fdt", fdt);
            Assert.Same(DateFieldType.Instance, msg.GetByName("dt").Type);
            Assert.IsType <FudgeDate>(msg.GetByName("dt").Value);
            Assert.Same(DateFieldType.Instance, msg.GetByName("fdt").Type);
            Assert.IsType <FudgeDate>(msg.GetByName("fdt").Value);

            Assert.Equal(dt, msg.GetValue <DateTime>("dt"));
            Assert.Equal(fdt, msg.GetValue <FudgeDateTime>("fdt"));

            // Error cases
            FudgeFieldType type = null;

            Assert.Equal(null, DateTimeFieldType.Instance.Minimize(null, ref type));
            Assert.Throws <ArgumentException>(() => DateTimeFieldType.Instance.Minimize("fred", ref type));
        }