コード例 #1
0
        public void T_07_ArraysListsAndMaps()
        {
            var row = new RowC
            {
                Map = new JSONDataMap {
                    { "Name", "Xerson" }, { "Age", 123 }
                },
                List = new List <object> {
                    1, true, "YEZ!", -123.01m
                },
                ObjectArray = new object[] { 123, -12, 789d, new GDID(0, 1223), null, new object[] { 54.67d, "alpIna" } },
                MapArray    = new JSONDataMap[] { new JSONDataMap {
                                                      { "a", 1 }, { "b", true }
                                                  }, new JSONDataMap {
                                                      { "kosmos", 234.12 }, { "b", null }
                                                  } },
                MapList = new List <JSONDataMap> {
                    new JSONDataMap {
                        { "abc", 0 }, { "buba", new GDID(2, 1223) }
                    }, new JSONDataMap {
                        { "nothing", null }
                    }
                }
            };

            var rc = new DataDocConverter();

            var doc = rc.DataDocToBSONDocument(row, "A");

            Console.WriteLine(doc.ToString());

            var row2 = new RowC();

            rc.BSONDocumentToDataDoc(doc, row2, "A");

            Aver.AreEqual(2, row2.Map.Count);
            Aver.AreObjectsEqual("Xerson", row2.Map["Name"]);
            Aver.AreObjectsEqual(123, row2.Map["Age"]);

            Aver.AreEqual(4, row2.List.Count);
            Aver.AreObjectsEqual(1, row2.List[0]);
            Aver.AreObjectsEqual(true, row2.List[1]);
            Aver.AreObjectsEqual("YEZ!", row2.List[2]);
            Aver.AreObjectsEqual((long)-123010m, row2.List[3]); //notice that "decimalness" is lost, because reading back into list<object>

            Aver.AreEqual(6, row2.ObjectArray.Length);
            Aver.AreObjectsEqual(123, row2.ObjectArray[0]);
            Aver.AreObjectsEqual(-12, row2.ObjectArray[1]);
            Aver.AreObjectsEqual(789d, row2.ObjectArray[2]);
            Aver.IsTrue((new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0xc7 }).SequenceEqual((byte[])(row2.ObjectArray[3])));//notice that GDID is lost, it got turned into int because reading back in object[], so no type conversion happens
            Aver.IsNull(row2.ObjectArray[4]);
            var arr = (object[])row2.ObjectArray[5];

            Aver.IsNotNull(arr);
            Aver.AreObjectsEqual(54.67d, arr[0]);
            Aver.AreObjectsEqual("alpIna", arr[1]);

            Aver.AreEqual(2, row2.MapArray.Length);
            Aver.AreObjectsEqual(1, row2.MapArray[0]["a"]);
            Aver.AreObjectsEqual(true, row2.MapArray[0]["b"]);
            Aver.AreObjectsEqual(234.12, row2.MapArray[1]["kosmos"]);
            Aver.AreObjectsEqual(null, row2.MapArray[1]["b"]);

            Aver.AreEqual(2, row2.MapList.Count);
            Aver.AreEqual(2, row2.MapList[0].Count);
            Aver.AreObjectsEqual(0, row2.MapList[0]["abc"]);
            Aver.IsTrue((new byte[] { 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0x04, 0xc7 }).SequenceEqual((byte[])(row2.MapList[0]["buba"])));//"GDIDness" is lost
            Aver.AreEqual(1, row2.MapList[1].Count);
            Aver.IsNull(row2.MapList[1]["nothing"]);
        }
コード例 #2
0
        public void T_01_Equals()
        {
            var BIN = new byte[] { 0x00, 0x79, 0x14 };

            var row = new RowA
            {
                String1  = "Mudaker",
                String2  = null,
                Date1    = new DateTime(1980, 07, 12, 10, 13, 27, DateTimeKind.Utc),
                Date2    = null,
                Bool1    = true,
                Bool2    = null,
                Guid1    = new Guid("{9195F7DB-FE21-4BB2-B006-2496F4E24D14}"),
                Guid2    = null,
                Gdid1    = new GDID(0, 12345),
                Gdid2    = null,
                Float1   = 127.0123f,
                Float2   = null,
                Double1  = 122345.012d,
                Double2  = null,
                Decimal1 = 1234567.098M,
                Decimal2 = null,
                Amount1  = new Amount("din", 123.11M),
                Amount2  = null,
                Bytes1   = BIN,
                Bytes2   = null,

                Byte1   = 23,
                SByte1  = -3,
                Short1  = -32761,
                UShort1 = 65535,
                Int1    = 4324,
                Uint1   = 42345,
                Long1   = 993,
                ULong1  = 8829383762,
                ETest1  = ETest.Two,
                EFlags1 = EFlags.First | EFlags.Third,

                Byte2   = null,
                SByte2  = null,
                Short2  = null,
                UShort2 = null,
                Int2    = null,
                Uint2   = null,
                Long2   = null,
                ULong2  = null,
                ETest2  = null,
                EFlags2 = null
            };

            var rc = new DataDocConverter();

            var docOriginal = rc.DataDocToBSONDocument(row, "A");
            var doc         = fullCopy(docOriginal);

            Console.WriteLine(doc.ToString());

            Aver.IsTrue(BIN.SequenceEqual(((BSONBinaryElement)doc["Bytes1"]).Value.Data));
            //Aver.IsTrue(doc["Bytes2"] is global::MongoDB.Bson.BsonNull);

            var row2 = new RowA();

            rc.BSONDocumentToDataDoc(doc, row2, "A");

            Aver.IsTrue(row.Equals(row2));
            Aver.IsTrue(BIN.SequenceEqual(row2.Bytes1));
            Aver.IsNull(row2.Bytes2);
            Aver.IsFalse(object.ReferenceEquals(BIN, row2.Bytes1));
        }
コード例 #3
0
        public void T06()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer(SlimFormat.Instance);

                var root = new ObjectA[3];

                root[0] = null;

                root[1] = new ObjectA();
                root[2] = new ObjectB();

                root[1].AField   = 2345;
                root[1].Another1 = new ObjectA {
                    AField = 27892
                };
                root[1].Another2 = new ObjectB {
                    AField = -278, BField = -12, Another1 = root[1]
                };

                root[2].AField            = 2345;
                ((ObjectB)root[2]).BField = 900333;
                root[2].Another1          = new ObjectA {
                    AField = 8000000
                };
                root[2].Another2 = new ObjectB {
                    AField = -278, BField = -1532, Another1 = root[2]
                };
                root[2].Another9 = root[1];

                s.Serialize(ms, root);

                ms.Position = 0;


                var deser = s.Deserialize(ms) as ObjectA[];

                Aver.IsNotNull(deser);
                Aver.IsTrue(deser.GetType() == typeof(ObjectA[]));
                Aver.AreEqual(3, deser.Length);
                Aver.IsNull(deser[0]);
                Aver.IsNotNull(deser[1]);
                Aver.IsNotNull(deser[2]);


                Aver.AreEqual(2345, deser[1].AField);
                Aver.IsNotNull(deser[1].Another1);
                Aver.IsTrue(deser[1].Another1.GetType() == typeof(ObjectA));
                Aver.AreEqual(27892, deser[1].Another1.AField);

                Aver.IsNotNull(deser[1].Another2);
                Aver.AreEqual(-278, deser[1].Another2.AField);

                Aver.IsTrue(deser[1].Another2.GetType() == typeof(ObjectB));
                Aver.AreEqual(-12, ((ObjectB)deser[1].Another2).BField);

                Aver.IsNotNull(deser[1].Another2.Another1);
                Aver.IsTrue(object.ReferenceEquals(deser[1], deser[1].Another2.Another1));
                Aver.IsTrue(deser[1].Another2.GetType() == typeof(ObjectB));

                Aver.IsNull(deser[1].Another3);
                Aver.IsNull(deser[1].Another4);
                Aver.IsNull(deser[1].Another5);
                Aver.IsNull(deser[1].Another6);
                Aver.IsNull(deser[1].Another7);
                Aver.IsNull(deser[1].Another8);
                Aver.IsNull(deser[1].Another9);
                Aver.IsNull(deser[1].Another10);



                Aver.AreEqual(2345, deser[2].AField);
                Aver.AreEqual(900333, ((ObjectB)deser[2]).BField);
                Aver.IsNotNull(deser[2].Another1);
                Aver.IsTrue(deser[2].Another1.GetType() == typeof(ObjectA));
                Aver.AreEqual(8000000, deser[2].Another1.AField);

                Aver.IsNotNull(deser[2].Another2);
                Aver.AreEqual(-278, deser[2].Another2.AField);

                Aver.IsTrue(deser[2].Another2.GetType() == typeof(ObjectB));
                Aver.AreEqual(-1532, ((ObjectB)deser[2].Another2).BField);

                Aver.IsNotNull(deser[2].Another2.Another1);
                Aver.IsTrue(object.ReferenceEquals(deser[2], deser[2].Another2.Another1));
                Aver.IsTrue(deser[2].Another2.GetType() == typeof(ObjectB));

                Aver.IsNull(deser[2].Another3);
                Aver.IsNull(deser[2].Another4);
                Aver.IsNull(deser[2].Another5);
                Aver.IsNull(deser[2].Another6);
                Aver.IsNull(deser[2].Another7);
                Aver.IsNull(deser[2].Another8);
                Aver.IsNotNull(deser[2].Another9);
                Aver.IsNull(deser[2].Another10);

                Aver.IsTrue(object.ReferenceEquals(deser[1], deser[2].Another9));
            }
        }
コード例 #4
0
 public void ValidationBatchException_Concat_01()
 {
     Aver.IsNull(ValidationBatchException.Concatenate(null, null));
 }
コード例 #5
0
        public void T_02_Update_Parallel()
        {
            const int CNT = 11973;
            var       BIN = new byte[] { 0x00, 0x79, 0x14 };

            using (var client = new MongoClient(NOPApplication.Instance, "My Test"))
            {
                var db = client.DefaultLocalServer["db1"];

                db["t1"].Drop();

                var t1 = db["t1"];

                var rows = new TestRow[CNT];

                var rc = new DataDocConverter();

                var sw = new Stopwatch();

                sw.Start();

                Parallel.For(0, CNT, i =>
                {
                    var row = new TestRow()
                    {
                        _id = i,

                        String1  = "Mudaker",
                        String2  = null,
                        Date1    = new DateTime(1980, 07, 12, 10, 13, 27, DateTimeKind.Utc),
                        Date2    = null,
                        Bool1    = true,
                        Bool2    = null,
                        Guid1    = new Guid("{9195F7DB-FE21-4BB2-B006-2496F4E24D14}"),
                        Guid2    = null,
                        Gdid1    = new GDID(0, 12345),
                        Gdid2    = null,
                        Float1   = 127.0123f,
                        Float2   = null,
                        Double1  = 122345.012d,
                        Double2  = null,
                        Decimal1 = 1234567.098M,
                        Decimal2 = null,
                        Amount1  = new Amount("din", 123.11M),
                        Amount2  = null,
                        Bytes1   = BIN,
                        Bytes2   = null,

                        Byte1   = 23,
                        SByte1  = -3,
                        Short1  = -32761,
                        UShort1 = 65535,
                        Int1    = 4324,
                        Uint1   = 42345,
                        Long1   = 993,
                        ULong1  = 8829383762,
                        ETest1  = ETest.Two,
                        EFlags1 = EFlags.First | EFlags.Third,

                        Byte2   = null,
                        SByte2  = null,
                        Short2  = null,
                        UShort2 = null,
                        Int2    = null,
                        Uint2   = null,
                        Long2   = null,
                        ULong2  = null,
                        ETest2  = null,
                        EFlags2 = null
                    };

                    rows[i] = row;

                    var doc = rc.DataDocToBSONDocument(row, "A");
                    Aver.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);
                });
                sw.Stop();
                Console.WriteLine("{0:N0} row inserted in {1:N3} sec on {2:N0} ops/sec", CNT, sw.Elapsed.TotalSeconds, CNT / sw.Elapsed.TotalSeconds);

                sw.Restart();
                Parallel.For(0, CNT, i => {
                    var row     = rows[i];
                    row.String1 = "makaka" + i.ToString();
                    row.Int1    = 9789 + (i * 100);

                    var doc = rc.DataDocToBSONDocument(row, "A");

                    var r = t1.Save(doc);
                    Aver.AreEqual(1, r.TotalDocumentsAffected);
                    Aver.AreEqual(1, r.TotalDocumentsUpdatedAffected);
                    Aver.IsNull(r.WriteErrors);
                });
                sw.Stop();
                Console.WriteLine("{0:N0} row updated in {1:N3} sec on {2:N0} ops/sec", CNT, sw.Elapsed.TotalSeconds, CNT / sw.Elapsed.TotalSeconds);

                sw.Restart();
                var RCNT = CNT * 3;
                Parallel.For(0, RCNT, i => {
                    var j   = i % CNT;
                    var got = db["t1"].FindOne(Query.ID_EQ_Int32(j));
                    Aver.IsNotNull(got);

                    var row1 = new TestRow();
                    rc.BSONDocumentToDataDoc(got, row1, "A");

                    Aver.AreObjectsEqual(rows[j], row1);
                });
                sw.Stop();
                Console.WriteLine("{0:N0} row red in {1:N3} sec on {2:N0} ops/sec", RCNT, sw.Elapsed.TotalSeconds, RCNT / sw.Elapsed.TotalSeconds);
            }
        }
コード例 #6
0
ファイル: GoogleDriveTests.cs プロジェクト: zhabis/nfx
        public void GoogleDrive_Parallel_CreateWriteReadFile_Async()
        {
            using (CreateApplication())
            {
                var fs = GetFileSystem();

                var tasks = new List <Task>();

                System.Threading.Tasks.Parallel.For(PARALLEL_FROM, PARALLEL_TO,
                                                    (i) =>
                {
                    var fn = FN_PARALLEL_MASK.Args(i);

                    var session = StartSession(fs);

                    FileSystemDirectory dir = null;
                    FileSystemFile file     = null;

                    var t = session.GetItemAsync(ROOT)
                            .OnOk(item =>
                    {
                        dir = item as FileSystemDirectory;
                        return(dir.CreateFileAsync(fn));
                    }).OnOk(f => {
                        Console.WriteLine("file '{0}' created", f.Name);
                        file = f;
                        return(file.WriteAllTextAsync("Hello, {0}".Args(i)));
                    })
                            .OnOkOrError(_ => {
                        Console.WriteLine("text written into '{0}'", file.Name);
                        if (file != null && !file.Disposed)
                        {
                            file.Dispose();
                            Console.WriteLine("file '{0}' disposed", file.Name);
                        }
                    })
                            .OnOk(() => session.GetItemAsync(fs.CombinePaths(ROOT, fn)))
                            .OnOk(item => {
                        file = item as FileSystemFile;
                        Console.WriteLine("file {0} got", file.Name);
                        return(file.ReadAllTextAsync());
                    })
                            .OnOk(txt => {
                        Console.WriteLine("file '{0}' red {1}", file.Name, txt);
                        Aver.AreEqual("Hello, {0}".Args(i), txt);
                        return(file.DeleteAsync());
                    })
                            .OnOkOrError(_ => {
                        Console.WriteLine("file '{0}' deleted", file.Name);
                        if (file != null && !file.Disposed)
                        {
                            file.Dispose();
                            Console.WriteLine("file '{0}' disposed", file.Name);
                        }
                    })
                            .OnOk(() => session.GetItemAsync(fs.CombinePaths(ROOT, fn)))
                            .OnOk(item => { Aver.IsNull(item); })
                            .OnOkOrError(_ => { if (!session.Disposed)
                                                {
                                                    session.Dispose();
                                                }
                                         });

                    tasks.Add(t);
                });//Parallel.For

                Console.WriteLine("all tasks created");

                Task.WaitAll(tasks.ToArray());

                Aver.AreEqual(0, fs.Sessions.Count());//checking item registation via .ctor/.dctor

                Console.WriteLine("done");
            }
        }
コード例 #7
0
ファイル: CappedQueueTests.cs プロジェクト: azist/azos
        public void BasicQueueFunctions()
        {
            var sut = new CappedQueue <MyItem>(i => i == null ? 0 : i.Name == null ? 0 : i.Name.Length);

            Aver.IsTrue(sut.TryEnqueue(new MyItem {
                Name = "Cat"
            }));
            Aver.AreEqual(1, sut.Count);
            Aver.IsTrue(sut.TryEnqueue(new MyItem {
                Name = "Dog"
            }));
            Aver.AreEqual(2, sut.Count);
            Aver.IsTrue(sut.TryEnqueue(null));
            Aver.AreEqual(3, sut.Count);
            Aver.IsTrue(sut.TryEnqueue(new MyItem {
                Name = "Bird"
            }));
            Aver.AreEqual(4, sut.Count);

            Aver.AreEqual(4, ((IEnumerable <MyItem>)sut).Count());

            Aver.AreEqual(4, sut.EnqueuedCount);
            Aver.AreEqual(3 + 3 + 4, sut.EnqueuedSize);

            //1st time
            Aver.IsTrue(sut.TryPeek(out var got));
            Aver.IsNotNull(got);
            Aver.AreEqual("Cat", got.Name);

            //2nd time peek
            Aver.IsTrue(sut.TryPeek(out got));
            Aver.IsNotNull(got);
            Aver.AreEqual("Cat", got.Name);

            //3rd time dequeue
            Aver.IsTrue(sut.TryDequeue(out got));
            Aver.IsNotNull(got);
            Aver.AreEqual("Cat", got.Name);

            Aver.AreEqual(3, sut.EnqueuedCount);
            Aver.AreEqual(3 + 4, sut.EnqueuedSize);

            //4th time peek
            Aver.IsTrue(sut.TryPeek(out got));
            Aver.IsNotNull(got);
            Aver.AreEqual("Dog", got.Name);

            //5th time dequeue
            Aver.IsTrue(sut.TryDequeue(out got));
            Aver.IsNotNull(got);
            Aver.AreEqual("Dog", got.Name);

            Aver.AreEqual(2, sut.EnqueuedCount);
            Aver.AreEqual(4, sut.EnqueuedSize);

            //6th time dequeue
            Aver.IsTrue(sut.TryDequeue(out got));
            Aver.IsNull(got);

            Aver.AreEqual(1, sut.EnqueuedCount);
            Aver.AreEqual(4, sut.EnqueuedSize);

            //7th time dequeue the last
            Aver.IsTrue(sut.TryDequeue(out got));
            Aver.IsNotNull(got);
            Aver.AreEqual("Bird", got.Name);

            Aver.AreEqual(0, sut.EnqueuedCount);
            Aver.AreEqual(0, sut.EnqueuedSize);

            Aver.IsFalse(sut.TryPeek(out got));
            Aver.IsFalse(sut.TryDequeue(out got));
        }
コード例 #8
0
        public void AddThenEnumerateAll(int COUNT)
        {
            using (var cache = PileCacheTestCore.MakeDurableCache())
            {
                var tA = cache.GetOrCreateTable <Guid>("A");

                var dict = new Dictionary <Guid, string>();

                for (var i = 0; i < COUNT; i++)
                {
                    var key   = Guid.NewGuid();
                    var value = "this is a value of " + key;
                    dict.Add(key, value);

                    var pr = tA.Put(key, value);
                    Aver.IsTrue(PutResult.Inserted == pr);
                }

                Aver.AreEqual(COUNT, dict.Count);
                Aver.AreEqual(COUNT, tA.Count);

                foreach (var kvp in  dict)
                {
                    Aver.IsTrue(tA.ContainsKey(kvp.Key));
                    Aver.AreEqual(kvp.Value, tA.Get(kvp.Key) as string);
                }

                var hs = new HashSet <Guid>();

                var cnt = 0;
                foreach (var entry in tA.AsEnumerable(false))//no materialization
                {
                    var value = dict[entry.Key];

                    Aver.IsTrue(hs.Add(entry.Key));//ensure no duplication in enumerator

                    Aver.IsNull(entry.Value);
                    Aver.AreEqual(value, tA.Get(entry.Key) as string);
                    cnt++;
                }

                Aver.AreEqual(dict.Count, cnt);//ensure the same# of elements

                hs  = new HashSet <Guid>();
                cnt = 0;
                foreach (var entry in tA.AsEnumerable(true))//with materialization
                {
                    var value = dict[entry.Key];

                    Aver.IsTrue(hs.Add(entry.Key));//ensure no duplication in enumerator

                    Aver.AreEqual(value, entry.Value as string);
                    cnt++;
                }
                Aver.AreEqual(dict.Count, cnt);//ensure the same# of elements

                //------- Manual enumerator -------
                var enumerator = tA.AsEnumerable(false).GetEnumerator();
                cnt = 0;
                hs  = new HashSet <Guid>();
                while (enumerator.MoveNext())
                {
                    var value = dict[enumerator.Current.Key];

                    Aver.IsTrue(hs.Add(enumerator.Current.Key));//ensure no duplication in enumerator

                    Aver.IsNull(enumerator.Current.Value);
                    Aver.AreEqual(value, tA.Get(enumerator.Current.Key) as string);
                    cnt++;
                }

                Aver.AreEqual(dict.Count, cnt);//ensure the same# of elements

                //Reset enumerator
                enumerator.Reset();//<-----------------------------
                cnt = 0;
                hs  = new HashSet <Guid>();
                while (enumerator.MoveNext())
                {
                    var value = dict[enumerator.Current.Key];

                    Aver.IsTrue(hs.Add(enumerator.Current.Key));//ensure no duplication in enumerator

                    Aver.IsNull(enumerator.Current.Value);
                    Aver.AreEqual(value, tA.Get(enumerator.Current.Key) as string);
                    cnt++;
                }

                Aver.AreEqual(dict.Count, cnt);//ensure the same# of elements
            }
        }
コード例 #9
0
        public void Object_8()
        {
            var got = JZ.DeserializeFromJson("null", true);

            Aver.IsNull(got);
        }
コード例 #10
0
        public void NullableGUID_3()
        {
            object obj = "sfsadfsd fsdafsd CF04F818-6194-48C3-B618-8965ACA4D229";

            Aver.IsNull(obj.AsNullableGUID());
        }
コード例 #11
0
ファイル: ARow.cs プロジェクト: zhabis/nfx
        public void SerDeser_FamilyRow_7_ArraysAndList()
        {
            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 [] { new SimplePersonRow {
                                        Age = 111
                                    }, new SimplePersonRow {
                                        Age = 222
                                    }, new SimplePersonRow {
                                        Age = 333
                                    } },
                Sisters = new [] { new SimplePersonRow {
                                       Age = 12
                                   }, new SimplePersonRow {
                                       Age = 13
                                   } },
                Advisers = new List <SimplePersonRow> {
                    new SimplePersonRow {
                        Age = 101, Name = "Kaznatchei"
                    }, new SimplePersonRow {
                        Age = 102
                    }
                }
            };

            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(3, row2.Brothers.Length);
                Aver.AreEqual(111, row2.Brothers[0].Age);
                Aver.AreEqual(222, row2.Brothers[1].Age);
                Aver.AreEqual(333, row2.Brothers[2].Age);
                Aver.IsNotNull(row2.Sisters);
                Aver.AreEqual(2, row2.Sisters.Length);
                Aver.AreEqual(12, row2.Sisters[0].Age);
                Aver.AreEqual(13, row2.Sisters[1].Age);
                Aver.IsNotNull(row2.Advisers);

                Aver.AreEqual(2, row2.Advisers.Count);
                Aver.AreEqual(101, row2.Advisers[0].Age);
                Aver.AreEqual("Kaznatchei", row2.Advisers[0].Name);
                Aver.AreEqual(102, row2.Advisers[1].Age);
            }
        }
コード例 #12
0
ファイル: BasicTests.cs プロジェクト: wangchengqun/azos
        public void CreateByConfigurationOwnDaemonWithTwoSinks()
        {
            var conf = @"
log
{
  name='YourFriendLogger'
  write-interval-ms=0

  sink
  {
    name='CatchAll'
    order=100
    type='Azos.Log.Sinks.MemoryBufferSink, Azos'
  }

  sink
  {
    name='Problems'
    min-level=Warning
    order=0
    type='Azos.Log.Sinks.MemoryBufferSink, Azos'
  }
}".AsLaconicConfig();

            using (var logger = FactoryUtils.MakeAndConfigureComponent <LogDaemon>(NOPApplication.Instance, conf, typeof(LogDaemon)))
            {
                Aver.AreEqual("YourFriendLogger", logger.Name);                   //name got set
                Aver.AreEqual(LogDaemon.MIN_INTERVAL_MSEC, logger.WriteInterval); //got set the minimum flush period from config
                Aver.AreEqual(2, logger.Sinks.Count);

                logger.Start();
                Aver.IsTrue(logger.Running);

                var s0 = logger.Sinks["Problems"] as MemoryBufferSink;
                var s1 = logger.Sinks["CatchAll"] as MemoryBufferSink;//catchall order =100

                Aver.IsNotNull(s0);
                Aver.IsNotNull(s1);
                Aver.AreSameRef(s0, logger.Sinks[0]);
                Aver.AreSameRef(s1, logger.Sinks[1]);

                Aver.IsNull(logger.Sinks["TheOneWhich isNotthere"]);
                Aver.IsNull(logger.Sinks[324234]);

                logger.Write(new Message {
                    Type = MessageType.Info, Text = "This was info"
                });
                logger.Write(new Message {
                    Type = MessageType.Debug, Text = "Now debug"
                });
                logger.Write(new Message {
                    Type = MessageType.Error, Text = "And now error"
                });

                Thread.Sleep(DAEMON_FLUSH_WAIT_MS);//make sure async flush happens

                Aver.AreEqual(3, s1.Buffered.Count());
                Aver.AreEqual(1, s0.Buffered.Count());

                Aver.AreEqual("And now error", s0.Buffered.FirstOrDefault().Text);
                Aver.AreEqual("This was info", s1.Buffered.FirstOrDefault().Text);
                Aver.AreEqual("Now debug", s1.Buffered.Skip(1).FirstOrDefault().Text);
                Aver.AreEqual("And now error", s1.Buffered.Skip(2).FirstOrDefault().Text);
            }
        }
コード例 #13
0
ファイル: NetGateTests.cs プロジェクト: wangchengqun/azos
        public void DefaultDeny()
        {
            using (var gate = new NetGate(NOPApplication.Instance))
            {
                gate.Configure(CONFIG_DEFAULT_DENY.AsLaconicConfig());
                gate.Start();

                Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "123.0.0.1"
                }));

                Rule rule;

                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "170.12.14.12"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("AdminAccess", rule.Name);

                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "170.12.14.13"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("AdminAccess", rule.Name);

                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "14.2.1.12"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("Workgroups", rule.Name);

                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "14.2.1.46"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("Workgroups", rule.Name);


                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "14.2.1.18"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("Workgroups", rule.Name);

                Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "14.2.2.18"
                }, out rule));
                Aver.IsNull(rule);

                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "3.118.2.12"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("Workgroups", rule.Name);

                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "3.118.2.13"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("Workgroups", rule.Name);

                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "3.118.2.14"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("Workgroups", rule.Name);


                Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "3.118.2.15"
                }, out rule));
                Aver.IsNull(rule);


                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "77.123.1.14"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("Workgroups", rule.Name);

                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "45.2.2.12"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("Workgroups", rule.Name);


                Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic {
                    FromAddress = "45.2.2.75"
                }, out rule));
                Aver.IsNotNull(rule);
                Aver.AreEqual("Workgroups", rule.Name);
            }
        }
コード例 #14
0
        public void Employees1()
        {
            var cnt  = 100;
            var list = new List <Employee>();

            for (var i = 0; i < cnt; i++)
            {
                list.Add(makeEmployee(new GDID(0, 1, (ulong)i)));
            }

            using (var ds = makeDataStore())
            {
                list.ForEach(e => ds.Insert(e));

                var fetchQry  = new Query <Employee>("CRUD.Queries.Employee.FetchAll");
                var employees = ds.LoadEnumerable(fetchQry);

                Aver.AreEqual(list.Count(), employees.Count());
                Employee row;
                foreach (var emp in list)
                {
                    row = employees.FirstOrDefault(e => e.GDID == emp.GDID);
                    Aver.IsNotNull(row);
                    Aver.IsTrue(emp.Equals(row));
                }

                var deleteQry = new Query <Employee>("CRUD.Queries.Employee.DeleteBySalaryMax")
                {
                    new Query.Param("pSalary", 200.50M)
                };
                ds.Execute(deleteQry);

                var rest = list.Where(e => e.Salary < 200.50M);
                employees = ds.LoadEnumerable(fetchQry);
                Aver.AreEqual(rest.Count(), employees.Count());
                foreach (var emp in rest)
                {
                    row = employees.FirstOrDefault(e => e.GDID == emp.GDID);
                    Aver.IsNotNull(row);
                    Aver.IsTrue(emp.Equals(row));
                }

                // try load deleted
                var fetchByGDIDQry = new Query <Employee>("CRUD.Queries.Employee.FetchByGDID")
                {
                    new Query.Param("pGDID", list.First(e => e.Salary > 210).GDID)
                };
                row = ds.LoadDoc(fetchByGDIDQry);
                Aver.IsNull(row);

                fetchByGDIDQry = new Query <Employee>("CRUD.Queries.Employee.FetchByGDID")
                {
                    new Query.Param("pGDID", rest.First().GDID)
                };

                row = ds.LoadDoc(fetchByGDIDQry);
                Aver.IsNotNull(row);
                Aver.IsTrue(rest.First().Equals(row));
                var code = Guid.NewGuid();
                row.Code = code;
                ds.Update(row);

                row = ds.LoadDoc(fetchByGDIDQry);
                Aver.IsNotNull(row);
                Aver.AreObjectsEqual(code, row.Code);
            }
        }
コード例 #15
0
        public void T_02_Update()
        {
            var BIN = new byte[] { 0x00, 0x79, 0x14 };

            using (var client = new MongoClient(NOPApplication.Instance, "My Test"))
            {
                var db = client.DefaultLocalServer["db1"];

                db["t1"].Drop();

                var t1 = db["t1"];

                var row = new TestRow()
                {
                    _id = 1,

                    String1  = "Mudaker",
                    String2  = null,
                    Date1    = new DateTime(1980, 07, 12, 10, 13, 27, DateTimeKind.Utc),
                    Date2    = null,
                    Bool1    = true,
                    Bool2    = null,
                    Guid1    = new Guid("{9195F7DB-FE21-4BB2-B006-2496F4E24D14}"),
                    Guid2    = null,
                    Gdid1    = new GDID(0, 12345),
                    Gdid2    = null,
                    Float1   = 127.0123f,
                    Float2   = null,
                    Double1  = 122345.012d,
                    Double2  = null,
                    Decimal1 = 1234567.098M,
                    Decimal2 = null,
                    Amount1  = new Amount("din", 123.11M),
                    Amount2  = null,
                    Bytes1   = BIN,
                    Bytes2   = null,

                    Byte1   = 23,
                    SByte1  = -3,
                    Short1  = -32761,
                    UShort1 = 65535,
                    Int1    = 4324,
                    Uint1   = 42345,
                    Long1   = 993,
                    ULong1  = 8829383762,
                    ETest1  = ETest.Two,
                    EFlags1 = EFlags.First | EFlags.Third,

                    Byte2   = null,
                    SByte2  = null,
                    Short2  = null,
                    UShort2 = null,
                    Int2    = null,
                    Uint2   = null,
                    Long2   = null,
                    ULong2  = null,
                    ETest2  = null,
                    EFlags2 = null
                };

                var rc  = new DataDocConverter();
                var doc = rc.DataDocToBSONDocument(row, "A");
                Aver.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

                row.String1 = "makaka";
                row.Int1    = 9789;

                doc = rc.DataDocToBSONDocument(row, "A");

                var r = t1.Save(doc);
                Aver.AreEqual(1, r.TotalDocumentsAffected);
                Aver.AreEqual(1, r.TotalDocumentsUpdatedAffected);
                Aver.IsNull(r.WriteErrors);

                var got = db["t1"].FindOne(Query.ID_EQ_Int32(1));
                Aver.IsNotNull(got);

                var row1 = new TestRow();
                rc.BSONDocumentToDataDoc(got, row1, "A");

                Aver.AreObjectsEqual(row, row1);
            }
        }
コード例 #16
0
        public void AllUsingConfigAttr()
        {
            var obj = new tezt();

            ConfigAttribute.Apply(obj, root);

            Aver.IsTrue(TztEnum.B == obj.venum1);
            Aver.AreEqual(123, obj.vint1);
            Aver.AreEqual(-123, obj.vint2);
            Aver.AreEqual(-567_000, obj.vint3);
            Aver.AreEqual(-123.8002341d, obj.vdouble);
            Aver.AreEqual(123000456.1233m, obj.vdecimal);

            Aver.AreEqual(0xABABu, obj.hex_v1);
            Aver.AreEqual(0xABABu, obj.hex_v2);
            Aver.AreEqual(0xABABu, obj.hex_v3);
            Aver.AreEqual(0xABAB, obj.hex_v4);
            Aver.AreEqual(0xABAB, (int)(ushort)obj.hex_v5);
            Aver.AreEqual(0xABAB, obj.hex_v6);

            Aver.AreEqual(0xaa55u, obj.bin_v1);
            Aver.AreEqual(0xaa55u, obj.bin_v2);
            Aver.AreEqual(0xaa55u, obj.bin_v3);
            Aver.AreEqual(0xaa55, obj.bin_v4);
            Aver.AreEqual(0xaa55, (int)(ushort)obj.bin_v5);
            Aver.AreEqual(0xaa55, obj.bin_v6);

            Aver.AreEqual(4, obj.vbuffer1.Length);
            Aver.AreEqual(0xfa, obj.vbuffer1[0]);
            Aver.AreEqual(0xca, obj.vbuffer1[1]);
            Aver.AreEqual(0xda, obj.vbuffer1[2]);
            Aver.AreEqual(0xba, obj.vbuffer1[3]);

            Aver.AreEqual(3, obj.vbuffer2.Length);
            Aver.AreEqual(0xfa, obj.vbuffer2[0]);
            Aver.AreEqual(0x12, obj.vbuffer2[1]);
            Aver.AreEqual(0b1010, obj.vbuffer2[2]);

            Aver.AreEqual(7, obj.vintarray.Length);
            Aver.AreEqual(1, obj.vintarray[0]);
            Aver.AreEqual(-1666123000, obj.vintarray[6]);

            Aver.AreEqual(7, obj.vlongarray.Length);
            Aver.AreEqual(1L, obj.vlongarray[0]);
            Aver.AreEqual(-9666123000L, obj.vlongarray[6]);

            Aver.AreEqual(5, obj.vfloatarray.Length);
            Aver.AreEqual(-5.6f, obj.vfloatarray[3]);
            Aver.AreEqual(7e2f, obj.vfloatarray[4]);

            Aver.AreEqual(5, obj.vdoublearray.Length);
            Aver.AreEqual(-5.6d, obj.vdoublearray[3]);
            Aver.AreEqual(7e2d, obj.vdoublearray[4]);

            Aver.AreEqual(5, obj.vdecimalarray.Length);
            Aver.AreEqual(180780.23m, obj.vdecimalarray[3]);
            Aver.AreEqual(-99.71m, obj.vdecimalarray[4]);

            Aver.AreEqual(GDID.ZERO, obj.vgdid1);
            Aver.AreEqual(new GDID(1, 1, 123), obj.vgdid2);

            Aver.IsNull(obj.vuri1);
            Aver.AreEqual("http://google.com", obj.vuri2.OriginalString);

            Aver.IsTrue(obj.vatom1.IsZero);
            Aver.AreEqual("abcd1234", obj.vatom2.Value);
            Aver.AreEqual(new Atom(0x3031), obj.vatom3);
        }
コード例 #17
0
ファイル: ErlangTests.cs プロジェクト: zhabis/nfx
    public void ErlInsertManyDeleteAndQuery()
    {
      var schema = store.GetSchema(new Query("CRUD.SECDEF"));

      for (var i = 0; i < CCY_PAIRS.Length; i++)
      {
        var row = new DynamicRow(schema);

        row.ApplyDefaultFieldValues(store.TargetName);

        var ccy1 = CCY_PAIRS[i].Substring(0, 3);
        var ccy2 = CCY_PAIRS[i].Substring(4, 3);

        row["xchg"]       = "NYSE";
        row["symbol"]     = ccy1 + ccy2;
        row["instr"]      = CCY_PAIRS[i];
        row["secid"]      = i;
        row["xchg_secid"] = 1000 + i;
        row["ccy"]        = ccy1;
        row["settl_ccy"]  = ccy2;

        row["contr_mult"] = 1.0d;
        row["px_step"]    = 10e-5d;

        Aver.IsNull(row.Validate());

        var affected = store.Upsert(row);
        Aver.AreEqual(1, affected);
      }

      var qry = new Query("CRUD.SecDef.ByExchange")
      {
          new Query.Param("Exchange", "NYSE")
      };

      var data = store.LoadOneRowset(qry);

      Aver.IsNotNull(data);

      Console.WriteLine(data.ToJSON(JSONWritingOptions.PrettyPrintRowsAsMap));

      Aver.AreEqual(CCY_PAIRS.Length, data.Count);

      var del = new DynamicRow(schema);

      del["xchg"]   = "CLE";
      del["symbol"] = "USDMXN";

      Aver.AreEqual(1, store.Delete(del));

      data = store.LoadOneRowset(qry);//NYSE

      Aver.IsNotNull(data);
      Aver.AreEqual(CCY_PAIRS.Length, data.Count);

      qry = new Query("CRUD.SecDef.ByExchange")
      {
          new Query.Param("Exchange", "CLE")
      };

      data = store.LoadOneRowset(qry);//Requery for CLE

      Aver.IsNotNull(data);
      Aver.AreEqual(CCY_PAIRS.Length - 1, data.Count);//1 was deleted!!!!!!!!!!!
    }