예제 #1
0
        public void RootArrayWriteRead_1D_nullabledatetime()
        {
            using (var ms = new MemoryStream())
            {
                var s = new PODSlimSerializer();

                var originalData = new DateTime?[100];
                var sd           = DateTime.UtcNow;
                for (var i = 0; i < originalData.Length; i++)
                {
                    if ((i % 2) == 0)
                    {
                        originalData[i] = sd;
                        sd = sd.AddHours(i + (i * 0.01));
                    }
                }

                s.Serialize(ms, originalData);
                ms.Seek(0, SeekOrigin.Begin);

                var convertedData = s.Deserialize(ms) as DateTime?[];
                Aver.AreNotSameRef(originalData, convertedData);
                Aver.AreArraysEquivalent(originalData, convertedData);
            }
        }
예제 #2
0
        public void Test_InjectionTarget_Serialization()
        {
            using (var app = new AzosApplication(null, BASE_CONF))
            {
                const string DATA = "lalala!";

                var target = new InjectionTarget_Root();
                target.Data = DATA;

                app.DependencyInjector.InjectInto(target);
                target.AssertInjectionCorrectness(app);

                using (var ms = new MemoryStream())
                {
                    var ser = new SlimSerializer();
                    ser.Serialize(ms, target);
                    ms.Position = 0;

                    var target2 = ser.Deserialize(ms) as InjectionTarget_Root;
                    Aver.IsNotNull(target2);           //we deserialized the instance

                    Aver.AreEqual(DATA, target2.Data); //the Data member got deserialized ok
                    Aver.AreNotSameRef(target.Data, target2.Data);
                    Aver.AreNotSameRef(DATA, target2.Data);

                    target2.AssertAllInjectionsNull();       //but all injections are transitive, hence are null
                    app.DependencyInjector.InjectInto(target2);
                    target2.AssertInjectionCorrectness(app); //and are re-hydrated again after InjectInto() call
                }
            }
        }
예제 #3
0
        public void ValidationBatchException_Serialization()
        {
            var error1 = new AzosException("error1");
            var error2 = new ArgumentException("error2");

            var got = ValidationBatchException.Concatenate(error1, error2);

            Aver.IsNotNull(got);
            var ser = new SlimSerializer();
            var ms  = new MemoryStream();

            ser.Serialize(ms, got);
            ms.Position = 0;

            var deser = ser.Deserialize(ms) as ValidationBatchException;

            Aver.IsNotNull(deser);
            Aver.AreNotSameRef(got, deser);
            Aver.IsNotNull(deser.Batch);
            Aver.AreEqual(2, deser.Batch.Count);

            Aver.IsTrue(deser.Batch[0] is AzosException);
            Aver.IsTrue(deser.Batch[1] is ArgumentException);

            Aver.AreEqual("error1", deser.Batch[0].Message);
            Aver.AreEqual("error2", deser.Batch[1].Message);
        }
예제 #4
0
        public void SerDeser_FamilyRow_4_EmptyArray()
        {
            var row1 = new FamilyRow
            {
                ID = new GDID(1, 345), Name = "Lalala", RegisteredToVote = true,

                Father = new SimplePersonRow
                {
                    Age = 123, Bool1 = true, ID = new GDID(12, 234), Name = "Jacques Jabakz", Salary = 143098, Str1 = "Tryten", Date = new DateTime(1980, 08, 12, 13, 45, 11)
                },
                Mother = new SimplePersonRow
                {
                    Age = 245, Bool1 = false, ID = new GDID(2, 12), Name = "Katya Zhaba", Salary = 180000, Str1 = "Snake", Str2 = "Borra", Date = new DateTime(1911, 01, 01, 14, 11, 07)
                },
                Brothers = new SimplePersonRow[0],
            };

            var writer = SlimFormat.Instance.GetWritingStreamer();
            var reader = SlimFormat.Instance.GetReadingStreamer();

            using (var ms = new MemoryStream())
            {
                writer.BindStream(ms);
                ArowSerializer.Serialize(row1, writer);
                writer.UnbindStream();

                ms.Position = 0;

                var row2 = new FamilyRow();
                reader.BindStream(ms);
                ArowSerializer.Deserialize(row2, reader);
                reader.UnbindStream();

                Aver.AreNotSameRef(row1, row2);
                Aver.AreEqual(row1.ID, row2.ID);
                Aver.AreEqual(row1.Name, row2.Name);
                Aver.AreEqual(row1.RegisteredToVote, row2.RegisteredToVote);
                Aver.IsNotNull(row2.Father);
                Aver.AreEqual(row1.Father.ID, row2.Father.ID);
                Aver.AreEqual(row1.Father.Age, row2.Father.Age);
                Aver.AreEqual(row1.Father.Str1, row2.Father.Str1);

                Aver.AreEqual(row1.Father.Date, row2.Father.Date);
                Aver.IsNull(row2.Father.Str2);

                Aver.IsNotNull(row2.Mother);
                Aver.AreEqual(row1.Mother.ID, row2.Mother.ID);
                Aver.AreEqual(row1.Mother.Age, row2.Mother.Age);
                Aver.AreEqual(row1.Mother.Str1, row2.Mother.Str1);
                Aver.IsNotNull(row2.Mother.Str2);
                Aver.AreEqual(row1.Mother.Str2, row2.Mother.Str2);
                Aver.AreEqual(row1.Mother.Date, row2.Mother.Date);

                Aver.IsNotNull(row2.Brothers);
                Aver.AreEqual(0, row2.Brothers.Length);
                Aver.IsNull(row2.Sisters);
                Aver.IsNull(row2.Advisers);
            }
        }
예제 #5
0
        public void ManyToMany()
        {
            var cfg = @"
app
{
  web-settings
  {
    content-type-mappings
    {
        map
        {
          extensions='f1,f2'
          content-type='custom/xyz'
          binary=true
        }

        map
        {
          extensions='f3'
          content-type='custom/xyz'
          binary=false
          name{eng{n='F3' d='F3 file'}}
        }
    }
  }
}
".AsLaconicConfig();

            using (var app = new AzosApplication(null, cfg))
            {
                var maps = app.GetContentTypeMappings();
                Aver.IsNotNull(maps);

                var map1 = maps.MapFileExtension("f1");
                var map2 = maps.MapFileExtension("f2");
                var map3 = maps.MapFileExtension("f3");
                Aver.IsNotNull(map1);
                Aver.IsNotNull(map2);
                Aver.IsNotNull(map3);

                Aver.AreSameRef(map1, map2);
                Aver.AreNotSameRef(map2, map3);

                Aver.IsFalse(map1.IsGeneric);
                Aver.IsFalse(map3.IsGeneric);
                Aver.IsTrue(map1.IsBinary);
                Aver.IsFalse(map3.IsBinary);
                Aver.AreEqual("custom/xyz", map1.ContentType);
                Aver.AreEqual("custom/xyz", map3.ContentType);

                Aver.IsNull(map1.Name["eng"].Description);
                Aver.AreEqual("F3 file", map3.Name["eng"].Description);

                var mappings = maps.MapContentType("custom/xyz").ToArray();
                Aver.AreEqual(2, mappings.Length);
                Aver.AreSameRef(map1, mappings[0]);
                Aver.AreSameRef(map3, mappings[1]);
            }
        }
예제 #6
0
        public void AppendToNewArray_2()
        {
            var existing = new int[] { 1, 2, 3 };
            var got      = existing.AppendToNew();

            Aver.IsNotNull(got);
            Aver.AreNotSameRef(existing, got);
        }
예제 #7
0
        private void averDataAreEqual(TypicalData data, TypicalData got)
        {
            Aver.IsNotNull(got);
            Aver.AreNotSameRef(data, got);

            Aver.AreEqual(data.Guid, got.Guid);
            Aver.AreEqual(data.True, got.True);
            Aver.AreEqual(data.False, got.False);
            Aver.AreEqual(data.CharMin, got.CharMin);
            Aver.AreEqual(data.CharMax, got.CharMax);
            Aver.AreEqual(data.SByteMin, got.SByteMin);
            Aver.AreEqual(data.SByteMax, got.SByteMax);
            Aver.AreEqual(data.ByteMin, got.ByteMin);
            Aver.AreEqual(data.ByteMax, got.ByteMax);
            Aver.AreEqual(data.Int16Min, got.Int16Min);
            Aver.AreEqual(data.Int16Max, got.Int16Max);
            Aver.AreEqual(data.UInt16Min, got.UInt16Min);
            Aver.AreEqual(data.UInt16Max, got.UInt16Max);
            Aver.AreEqual(data.Int32Min, got.Int32Min);
            Aver.AreEqual(data.Int32Max, got.Int32Max);
            Aver.AreEqual(data.UInt32Min, got.UInt32Min);
            Aver.AreEqual(data.UInt32Max, got.UInt32Max);
            Aver.AreEqual(data.Int64Min, got.Int64Min);
            Aver.AreEqual(data.Int64Max, got.Int64Max);
            Aver.AreEqual(data.UInt64Min, got.UInt64Min);
            Aver.AreEqual(data.UInt64Max, got.UInt64Max);
            Aver.AreEqual(data.SingleEps, got.SingleEps);
            Aver.AreEqual(data.SingleMin, got.SingleMin);
            Aver.AreEqual(data.SingleMax, got.SingleMax);
            Aver.AreEqual(data.SingleNaN, got.SingleNaN);
            Aver.AreEqual(data.SinglePosInf, got.SinglePosInf);
            Aver.AreEqual(data.SingleNegInf, got.SingleNegInf);
            Aver.AreEqual(data.DoubleEps, got.DoubleEps);
            Aver.AreEqual(data.DoubleMin, got.DoubleMin);
            Aver.AreEqual(data.DoubleMax, got.DoubleMax);
            Aver.AreEqual(data.DoubleNaN, got.DoubleNaN);
            Aver.AreEqual(data.DoublePosInf, got.DoublePosInf);
            Aver.AreEqual(data.DoubleNegInf, got.DoubleNegInf);
            Aver.AreEqual(data.DecimalMin, got.DecimalMin);
            Aver.AreEqual(data.DecimalMax, got.DecimalMax);
            Aver.AreEqual(data.DecimalZero, got.DecimalZero);
            Aver.AreEqual(data.DecimalOne, got.DecimalOne);
            Aver.AreEqual(data.DecimalMOne, got.DecimalMOne);
            Aver.AreEqual(data.DateTimeMin, got.DateTimeMin);
            Aver.AreEqual(data.DateTimeMax, got.DateTimeMax);
            Aver.AreEqual(data.DateTimeNow, got.DateTimeNow);
            Aver.AreEqual(data.DateTimeUtc, got.DateTimeUtc);
            Aver.AreEqual(data.TimeSpanMin, got.TimeSpanMin);
            Aver.AreEqual(data.TimeSpanMax, got.TimeSpanMax);
            Aver.AreEqual(data.StringEmpty, got.StringEmpty);
            Aver.AreEqual(data.StringNull, got.StringNull);
            Aver.AreEqual(data.String, got.String);
        }
예제 #8
0
        public void AppendToNewArray_3()
        {
            var existing = new int[] { 1, 2, 3 };
            var got      = existing.AppendToNew(-5);

            Aver.IsNotNull(got);
            Aver.AreNotSameRef(existing, got);
            Aver.AreEqual(4, got.Length);
            Aver.AreEqual(1, got[0]);
            Aver.AreEqual(2, got[1]);
            Aver.AreEqual(3, got[2]);
            Aver.AreEqual(-5, got[3]);
        }
예제 #9
0
        public void T12_DictComparerComplex()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var cmpr = new Comparer1();

                var c1 = new C13();
                var c2 = new C13();

                var dict1 = new Dictionary <int, C13>(cmpr);
                dict1[1] = c1;
                dict1[2] = c1;
                dict1[3] = c2;
                var dict2 = new Dictionary <int, C13>(cmpr);
                dict2[1] = c2;
                dict2[2] = c1;

                var dIn = new List <S3>();
                dIn.Add(new S3()
                {
                    FDict = dict1
                });
                dIn.Add(new S3()
                {
                    FDict = dict1
                });
                dIn.Add(new S3()
                {
                    FDict = dict2
                });

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (List <S3>)s.Deserialize(ms);

                Aver.AreSameRef(dOut[0].FDict, dOut[1].FDict);
                Aver.AreNotSameRef(dOut[0].FDict, dOut[2].FDict);

                Aver.AreSameRef(dOut[0].FDict[1], dOut[0].FDict[2]);
                Aver.AreNotSameRef(dOut[0].FDict[1], dOut[0].FDict[3]);

                Aver.AreSameRef(dOut[0].FDict[1], dOut[2].FDict[2]);
                Aver.AreSameRef(dOut[0].FDict[3], dOut[2].FDict[1]);
            }
        }
예제 #10
0
        public void RootArrayWriteRead_5D()
        {
            using (var ms = new MemoryStream())
            {
                var s = new PODSlimSerializer();

                var originalData = new int[10, 4, 6, 2, 2];

                s.Serialize(ms, originalData);
                ms.Seek(0, SeekOrigin.Begin);

                var convertedData = s.Deserialize(ms) as int[, , , , ];
                Aver.AreNotSameRef(originalData, convertedData);
                Aver.AreArraysEquivalent(originalData, convertedData);
            }
        }
예제 #11
0
        public void ValueInterning()
        {
            var x = Atom.Encode("abc");
            var y = Atom.Encode("abc");
            var z = new Atom(x.ID);

            Aver.AreEqual(x, y);
            Aver.AreEqual(x, z);

            Aver.AreEqual("abc", x.Value);
            Aver.AreEqual("abc", y.Value);
            Aver.AreEqual("abc", z.Value);

            Aver.AreNotSameRef("abc", x.Value);
            Aver.AreSameRef(x.Value, y.Value);
            Aver.AreSameRef(x.Value, z.Value);
        }
예제 #12
0
        public void SerDeser_FamilyRow_2_OneFieldRef()
        {
            var row1 = new FamilyRow
            {
                ID = new GDID(1, 345), Name = "Lalala", RegisteredToVote = true,

                Father = new SimplePersonRow
                {
                    Age = 123, Bool1 = true, ID = new GDID(12, 234), Name = "Jacques Jabakz", Salary = 143098, Str1 = "Tryten", Date = new DateTime(1980, 08, 12, 13, 45, 11)
                }
            };

            var writer = SlimFormat.Instance.GetWritingStreamer();
            var reader = SlimFormat.Instance.GetReadingStreamer();

            using (var ms = new MemoryStream())
            {
                writer.BindStream(ms);
                ArowSerializer.Serialize(row1, writer);
                writer.UnbindStream();

                ms.Position = 0;

                var row2 = new FamilyRow();
                reader.BindStream(ms);
                ArowSerializer.Deserialize(row2, reader);
                reader.UnbindStream();

                Aver.AreNotSameRef(row1, row2);
                Aver.AreEqual(row1.ID, row2.ID);
                Aver.AreEqual(row1.Name, row2.Name);
                Aver.AreEqual(row1.RegisteredToVote, row2.RegisteredToVote);
                Aver.IsNotNull(row2.Father);
                Aver.AreEqual(row1.Father.ID, row2.Father.ID);
                Aver.AreEqual(row1.Father.Age, row2.Father.Age);
                Aver.AreEqual(row1.Father.Str1, row2.Father.Str1);

                Aver.AreEqual(row1.Father.Date, row2.Father.Date);
                Aver.IsNull(row2.Father.Str2);

                Aver.IsNull(row2.Mother);
            }
        }
예제 #13
0
        private void averWrappedExceptionEquality(WrappedExceptionData d1, WrappedExceptionData d2)
        {
            Aver.IsNotNull(d1);
            Aver.IsNotNull(d2);
            Aver.AreNotSameRef(d1, d2);

            Aver.AreEqual(d1.Message, d2.Message);
            Aver.AreEqual(d1.Code, d2.Code);
            Aver.AreEqual(d1.Source, d2.Source);
            Aver.AreEqual(d1.TypeName, d2.TypeName);
            Aver.AreEqual(d1.ApplicationName, d2.ApplicationName);
            Aver.AreEqual(d1.StackTrace, d2.StackTrace);
            Aver.AreEqual(d1.WrappedData, d2.WrappedData);

            if (d1.InnerException != null)
            {
                averWrappedExceptionEquality(d1.InnerException, d2.InnerException);
            }
        }
예제 #14
0
        private void testMsgEquWoError(NFX.Log.Message msg, NFX.Log.Message got)
        {
            Aver.IsNotNull(got);
            Aver.AreNotSameRef(msg, got);

            Aver.AreEqual(msg.Guid, got.Guid);
            Aver.AreEqual(msg.RelatedTo, got.RelatedTo);
            Aver.AreEqual(msg.Host, got.Host);
            Aver.AreEqual(msg.TimeStamp, got.TimeStamp);

            Aver.IsTrue(msg.Type == got.Type);
            Aver.AreEqual(msg.Channel, got.Channel);
            Aver.AreEqual(msg.From, got.From);
            Aver.AreEqual(msg.Topic, got.Topic);
            Aver.AreEqual(msg.Text, got.Text);
            Aver.AreEqual(msg.Source, got.Source);
            Aver.AreEqual(msg.Parameters, got.Parameters);
            Aver.AreEqual(msg.ArchiveDimensions, got.ArchiveDimensions);
        }
예제 #15
0
        private void averWrappedExceptionEquality(WrappedExceptionData d1, WrappedExceptionData d2)
        {
            Aver.IsNotNull(d1);
            Aver.IsNotNull(d2);
            Aver.AreNotSameRef(d1, d2);

            Aver.AreEqual(d1.Message, d2.Message);
            Aver.AreEqual(d1.Code, d2.Code);
            Aver.AreEqual(d1.Source, d2.Source);
            Aver.AreEqual(d1.TypeName, d2.TypeName);
            Aver.AreEqual(d1.AppName, d2.AppName);
            Aver.AreEqual(d1.AppId, d2.AppId);
            Aver.AreEqual(d1.StackTrace, d2.StackTrace);
            Aver.AreEqual(d1.ExternalStatus.ToJson(), d2.ExternalStatus.ToJson());

            if (d1.InnerException != null)
            {
                averWrappedExceptionEquality(d1.InnerException, d2.InnerException);
            }
        }
예제 #16
0
        public void TypedDoc_1()
        {
            var schema = Schema.GetForTypedDoc <Doc1>();
            var a      = schema["Field1"][null];

            Aver.IsTrue(a.HasValueList);
            var vl1 = a.ParseValueList();
            var vl2 = a.ParseValueList();
            var vl3 = a.ParseValueList(true);
            var vl4 = a.ParseValueList(true);

            Aver.AreSameRef(vl1, vl2);
            Aver.AreNotSameRef(vl1, vl3);
            Aver.AreSameRef(vl3, vl4);
            Aver.AreEqual(4, vl1.Count);

            Aver.AreEqual("apple", vl1["a"].AsString());
            Aver.AreEqual("banana", vl1["b"].AsString());
            Aver.AreEqual("cherry", vl1["c"].AsString());
            Aver.AreEqual("dynamo", vl1["d"].AsString());
            Aver.AreEqual("dynamo", vl1["D"].AsString());//case insensitive
        }
예제 #17
0
        public void Test_FullCycle()
        {
            var d = new Tezt
            {
                C1 = "{r: {a:1, b:2}}",
                C2 = "{r: {a:-1, b:-2}}"
            };

            var json = JsonWriter.Write(d, JsonWritingOptions.PrettyPrintRowsAsMap);

            json.See();

            var got = JsonReader.ToDoc <Tezt>(json);

            var n1 = got.C1.Node;

            Aver.AreEqual(1, got.C1.Node.Of("a").ValueAsInt());
            Aver.AreEqual(2, got.C1.Node.Of("b").ValueAsInt());
            Aver.AreSameRef(n1, got.C1.Node);

            got.C1.Content = "{r: {a:10, b:20}}";
            var n2 = got.C1.Node;

            Aver.AreNotSameRef(n1, n2);
            Aver.AreSameRef(n2, got.C1.Node);

            got.C1.Node = "r{z=900}".AsLaconicConfig();
            var n3 = got.C1.Node;

            Aver.AreNotSameRef(n2, n3);
            Aver.AreEqual(900, got.C1.Node.Of("z").ValueAsInt());

            Aver.AreEqual(-1, got.C2.Node.Of("a").ValueAsInt());
            Aver.AreEqual(-2, got.C2.Node.Of("b").ValueAsInt());

            got.See();
        }