Exemple #1
0
        public void InferSchema()
        {
            var doc = new BSONDocument();
            doc.Set( new BSONStringElement("FullName", "Alex Bobby") );
            doc.Set( new BSONInt32Element("Age", 123) );
            doc.Set( new BSONBooleanElement("IsGood", true) );

            var c = new RowConverter();

            var schema = c.InferSchemaFromBSONDocument(doc);

            Assert.AreEqual(3, schema.FieldCount);

            Assert.AreEqual(0, schema["FullName"].Order);
            Assert.AreEqual(1, schema["Age"].Order);
            Assert.AreEqual(2, schema["IsGood"].Order);

            Assert.AreEqual(typeof(object), schema["FullName"].NonNullableType);
            Assert.AreEqual(typeof(object), schema["Age"].NonNullableType);
            Assert.AreEqual(typeof(object), schema["IsGood"].NonNullableType);

            var row = new DynamicRow(schema);
            c.BSONDocumentToRow(doc, row, null);

            Assert.AreEqual("Alex Bobby", row[0]);
            Assert.AreEqual(123,          row[1]);
            Assert.AreEqual(true,         row[2]);

            Assert.AreEqual("Alex Bobby", row["FullName"]);
            Assert.AreEqual(123,          row["Age"]);
            Assert.AreEqual(true,         row["IsGood"]);
        }
Exemple #2
0
      public void T_Null()
      {
        var rowA = new RowWithNulls
        {
           FirstName = "Vladimir",
           LastName = null,
           Age =  240,
           G_GDID = null
        };

        var rc = new RowConverter();

        var doc = rc.RowToBSONDocument(rowA, "A");

        Console.WriteLine(doc["LastName"]);
        Console.WriteLine(doc["G_GDID"]);
        Console.WriteLine( doc.ToString() );

        var row2 = new RowWithNulls();

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

        Assert.AreEqual("Vladimir", row2.FirstName);
        Assert.IsNull(row2.LastName);
        Assert.AreEqual(240, row2.Age);
        Assert.IsNull(row2.G_GDID);
      }
Exemple #3
0
        public void T_04_Array()
        {
            using (var client = new MongoClient("My Test"))
            {
                var db = client.DefaultLocalServer["db1"];

                db["t1"].Drop();

                var t1 = db["t1"];

                var row = new ArrayRow
                {
                    _id = 1,
                    Map = new JSONDataMap {
                        { "Name", "Xerson" }, { "Age", 123 }
                    },
                    List = new List <object> {
                        1, true, "YEZ!", -123.01
                    },
                    ObjectArray = new object[] { 123, -12, 789d, 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", -40.0789 }
                        }, new JSONDataMap {
                            { "nothing", null }
                        }
                    }
                };

                var rc  = new NFX.Serialization.BSON.RowConverter();
                var doc = rc.RowToBSONDocument(row, "A");
                Aver.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

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

                var row1 = new ArrayRow();
                rc.BSONDocumentToRow(got, row1, "A");

                Aver.AreObjectsEqual(row, row1);
            }
        }
Exemple #4
0
        public void T_03_Update()
        {
            var BIN = new byte[] { 0x00, 0x79, 0x14 };

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

                db["t1"].Drop();

                var t1 = db["t1"];

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

                    String1 = "Mudaker",
                };

                var rc  = new NFX.Serialization.BSON.RowConverter();
                var doc = rc.RowToBSONDocument(row, "A");
                Aver.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

                var updateResult = t1.Update
                                   (
                    new NFX.DataAccess.MongoDB.Connector.UpdateEntry
                    (
                        Query.ID_EQ_Int32(1),
                        new Update("{'String1': '$$VAL'}", true, new TemplateArg("VAL", BSONElementType.String, "makaka")),
                        false,
                        false
                    )
                                   );

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

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

                Aver.AreEqual("makaka", row1.String1);
            }
        }
Exemple #5
0
      public void T_00_Enum_Equals()
      {
        var row1 = new EnumRow
        {
          ETest1 = ETest.One,
          EFlags1 = EFlags.FirstSecond
        };

        var rc = new RowConverter();

        var docOriginal = rc.RowToBSONDocument(row1, "A");
        var doc = fullCopy(docOriginal);

        Console.WriteLine(doc.ToString());

        var row2 = new EnumRow();
        rc.BSONDocumentToRow(doc, row2, "A");

        Assert.AreEqual(row1, row2);

        Assert.AreEqual(ETest.One, row2.ETest1);
        Assert.AreEqual(EFlags.FirstSecond, row2.EFlags1);
      }
Exemple #6
0
      public void T_17_VersionChange_AmorphousExtra()
      {
        var BYTES = new byte[] {0x00, 0x79, 0x14};

        var rowA = new RowVersionA
        {
           FirstName = "Vladimir",
           LastName = "Lenin",
           Age =  DateTime.Now.Year - 1870
        };

        rowA.AmorphousData["AABB"] = "extra data";
        rowA.AmorphousData["Bytes"] = BYTES;

        var rc = new RowConverter();

        var doc = rc.RowToBSONDocument(rowA, "A", useAmorphousData: true);

        Console.WriteLine( doc.ToString() );

        var rowB = new RowVersionB();

        rc.BSONDocumentToRow(doc, rowB, "MyLegacySystem", useAmorphousData: true);

        Assert.AreEqual("Vladimir", rowB.FirstName);
        Assert.AreEqual("Lenin", rowB.LastName);
        Assert.AreEqual(1870, rowB.DOB.Year);
        Assert.AreEqual("extra data", rowB.AmorphousData["AABB"]);
        Assert.IsTrue( BYTES.SequenceEqual((byte[])rowB.AmorphousData["Bytes"]));
      }
Exemple #7
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 RowConverter();

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

        Console.WriteLine(doc.ToString());

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

        var row2 = new RowA();
        rc.BSONDocumentToRow(doc, row2, "A");

        Assert.IsTrue(row.Equals(row2));
        Assert.IsTrue(BIN.SequenceEqual(row2.Bytes1));
        Assert.IsNull(row2.Bytes2);
        Assert.IsFalse(object.ReferenceEquals(BIN, row2.Bytes1));
      }
Exemple #8
0
      public void T_16_VersionChange_AmorphousDisabled_WithFilter()
      {
        var rowA = new RowVersionA
        {
           FirstName = "Vladimir",
           LastName = "Lenin",
           Age =  DateTime.Now.Year - 1870
        };

        var rc = new RowConverter();

        var doc = rc.RowToBSONDocument(rowA, "A", useAmorphousData: false);

        Console.WriteLine( doc.ToString() );

        var rowB = new RowVersionB();

        rc.BSONDocumentToRow(doc, rowB, "MyLegacySystem", useAmorphousData: false, filter: (d,e) => e.Name!="LastName");

        Assert.AreEqual("Vladimir", rowB.FirstName);
        Assert.IsNull( rowB.LastName );
        Assert.AreEqual(new DateTime(), rowB.DOB);
      }
Exemple #9
0
      public void T_09_DynamicRow()
      {
          var BYTES = new byte[] {0x00, 0x79, 0x14};

          var schema = new Schema("Dynamic Schema", 
                new Schema.FieldDef("ID", typeof(int), new List<FieldAttribute>{ new FieldAttribute(required: true, key: true)}),
                new Schema.FieldDef("Description", typeof(string), new List<FieldAttribute>{ new FieldAttribute(required: true)}),
                new Schema.FieldDef("Bytes", typeof(byte[]), new List<FieldAttribute>{ new FieldAttribute(required: true)})
          );

          var row = new DynamicRow(schema);
            
          row["ID"] = 123;
          row["Description"] = "T-90 Tank";
          row["Bytes"] = BYTES;
     
          var rc = new RowConverter();
      
          var doc = rc.RowToBSONDocument( row, "A" );

          Console.WriteLine(doc.ToString());

          var row2 = new DynamicRow(schema);
          rc.BSONDocumentToRow(doc, row2, "A");

          Assert.AreEqual(123, row2["ID"]);
          Assert.AreEqual("T-90 Tank", row2["Description"]);
          Assert.IsTrue(BYTES.SequenceEqual((byte[])row2["Bytes"]));
      }
Exemple #10
0
      public void T_10_RowCycle_NoCycle()
      {
          var root = new RowCycle();

          root.SomeInt = 1234;
          root.InnerRow = new RowCycle();
          root.InnerRow.SomeInt = 567;
          root.InnerRow.InnerRow = null; //NO CYCLE!!!!
            
          var rc = new RowConverter();
      
          var doc = rc.RowToBSONDocument( root, "A" );

          Console.WriteLine(doc.ToString());

          var root2 = new RowCycle();
          rc.BSONDocumentToRow(doc, root2, "A");

          Assert.AreEqual(1234, root2.SomeInt);
          Assert.IsNotNull( root2.InnerRow );
          Assert.AreEqual(567, root2.InnerRow.SomeInt);
      }
Exemple #11
0
        public void T_02_Update_Parallel()
        {
            const int CNT = 11973;
            var       BIN = new byte[] { 0x00, 0x79, 0x14 };

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

                db["t1"].Drop();

                var t1 = db["t1"];

                var rows = new TestRow[CNT];

                var rc = new NFX.Serialization.BSON.RowConverter();

                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 NFX.DataAccess.Distributed.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.RowToBSONDocument(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.RowToBSONDocument(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.BSONDocumentToRow(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);
            }
        }
Exemple #12
0
      public void T_08_VersionChange()
      {
        var rowA = new RowVersionA
        {
           FirstName = "Vladimir",
           LastName = "Lenin",
           Age =  DateTime.Now.Year - 1870
        };

        var rc = new RowConverter();

        var doc = rc.RowToBSONDocument(rowA, "A");

        Console.WriteLine( doc.ToString() );

        var rowB = new RowVersionB();

        rc.BSONDocumentToRow(doc, rowB, "MyLegacySystem");

        Assert.AreEqual("Vladimir", rowB.FirstName);
        Assert.AreEqual("Lenin", rowB.LastName);
        Assert.AreEqual(1870, rowB.DOB.Year);
      }
Exemple #13
0
        public void T_03_Update()
        {
            var BIN = new byte[] { 0x00, 0x79, 0x14 };

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

            db["t1"].Drop();

            var t1 = db["t1"];

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

              String1 = "Mudaker",
            };

            var rc = new NFX.Serialization.BSON.RowConverter();
            var doc = rc.RowToBSONDocument(row, "A");
            Assert.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

            var updateResult = t1.Update
            (
              new NFX.DataAccess.MongoDB.Connector.UpdateEntry
              (
            Query.ID_EQ_Int32(1),
            new Update("{'String1': '$$VAL'}", true, new TemplateArg("VAL", BSONElementType.String, "makaka")),
            false,
            false
              )
            );

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

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

            Assert.AreEqual("makaka", row1.String1);
              }
        }
Exemple #14
0
        public void T_02_Update()
        {
            var BIN = new byte[] { 0x00, 0x79, 0x14 };

              using(var client= new MongoClient("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 NFX.DataAccess.Distributed.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 NFX.Serialization.BSON.RowConverter();
            var doc = rc.RowToBSONDocument(row, "A");
            Assert.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

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

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

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

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

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

            Assert.AreEqual(row, row1);

              }
        }
Exemple #15
0
      public void T_03_Manual_wo_NULLs()
      {
        var BYTES1 = new byte[] {};
        var BYTES2 = new byte[] {0x00, 0x79, 0x14};

        var row = new RowA
        {
          String1 = "Mudaker", String2 = "Kapernik",
          Date1 = new DateTime(1980, 07, 12, 1, 2, 3, DateTimeKind.Utc), Date2 = new DateTime(1680, 12, 11, 5, 6, 7, DateTimeKind.Utc),
          Bool1 = false, Bool2 = true,
          Guid1 = new Guid("{9195F7DB-FE21-4BB2-B006-2496F4E24D14}"), Guid2 = new Guid("{BABACACA-FE21-4BB2-B006-2496F4E24D14}"),
          Gdid1 = new GDID(3, 12345), Gdid2 = new GDID(4, 1212345),
          Float1 = 127.0123f, Float2 = -0.123f,
          Double1 = 122345.012d, Double2 = -12345.11f,
          Decimal1 = 1234567.098M, Decimal2 = 22m,
          Amount1 = new Amount("din", 123.11M), Amount2 = new Amount("din", 8901234567890.012M),
          Bytes1 = BYTES1, Bytes2 = BYTES2,
          ETest1 = ETest.One, EFlags1 = EFlags.First,
          ETest2 = ETest.Two, EFlags2 = EFlags.Second | EFlags.Third
        };

        var rc = new RowConverter();
      
        var doc = rc.RowToBSONDocument( row, "A" );

        Console.WriteLine(doc.ToString());

        var row2 = new RowA();
        rc.BSONDocumentToRow(doc, row2, "A");

        Assert.AreEqual("Mudaker", row2.String1);
        Assert.AreEqual("Kapernik", row2.String2);
        Assert.IsFalse( row2.Bool1 );
        Assert.IsTrue( row2.Bool2.Value );
        Assert.AreEqual(new Guid("{9195F7DB-FE21-4BB2-B006-2496F4E24D14}"), row2.Guid1);
        Assert.AreEqual(new Guid("{BABACACA-FE21-4BB2-B006-2496F4E24D14}"), row2.Guid2);
        Assert.AreEqual(new GDID(3, 12345), row2.Gdid1);
        Assert.AreEqual(new GDID(4, 1212345), row2.Gdid2);
        Assert.AreEqual(127.0123f, row2.Float1);
        Assert.AreEqual(-0.123f, row2.Float2);
        Assert.AreEqual(122345.012d, row2.Double1);
        Assert.AreEqual(-12345.11f, row2.Double2);
        Assert.AreEqual(1234567.098M, row2.Decimal1);
        Assert.AreEqual(22m, row2.Decimal2);
        Assert.AreEqual(new Amount("din", 123.11M), row2.Amount1);
        Assert.AreEqual(new Amount("din", 8901234567890.012M), row2.Amount2);
        Assert.IsTrue(BYTES1.SequenceEqual(row2.Bytes1));
        Assert.IsTrue(BYTES2.SequenceEqual(row2.Bytes2));

        Assert.AreEqual(ETest.One, row2.ETest1);
        Assert.AreEqual(EFlags.First, row2.EFlags1);
        Assert.AreEqual(ETest.Two, row2.ETest2);
        Assert.AreEqual(EFlags.Second | EFlags.Third, row2.EFlags2);
      }
Exemple #16
0
      public void T_02_Manual()
      {
        var BYTES1 = new byte[] {0x00, 0x79, 0x14};

        var row = new RowA
        {
          String1 = "Mudaker", String2 = null,
          Date1 = new DateTime(1980, 07, 12, 10, 10, 10, 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 = BYTES1, Bytes2 = null,
          ETest1 = 0, EFlags1 = 0, ETest2 = null, EFlags2 = null 
        };
        
        var rc = new RowConverter();
      
        var docOriginal = rc.RowToBSONDocument( row, "A" );
      
        var doc = fullCopy( docOriginal );

        Console.WriteLine(doc.ToString());

        var row2 = new RowA();
        rc.BSONDocumentToRow(doc, row2, "A");

        Assert.AreEqual("Mudaker", row2.String1);
        Assert.IsNull( row2.String2);
        Assert.IsTrue( row2.Bool1 );
        Assert.IsNull( row2.Bool2);
        Assert.AreEqual(new Guid("{9195F7DB-FE21-4BB2-B006-2496F4E24D14}"), row2.Guid1);
        Assert.IsNull( row2.Guid2);
        Assert.AreEqual(new GDID(0, 12345), row2.Gdid1);
        Assert.IsNull( row2.Gdid2);
        Assert.AreEqual(127.0123f, row2.Float1);
        Assert.IsNull( row2.Float2);
        Assert.AreEqual(122345.012d, row2.Double1);
        Assert.IsNull( row2.Double2);
        Assert.AreEqual(1234567.098M, row2.Decimal1);
        Assert.IsNull( row2.Decimal2);
        Assert.AreEqual(new Amount("din", 123.11M), row2.Amount1);
        Assert.IsNull( row2.Amount2);
        Assert.NotNull( row2.Bytes1);
        Assert.IsTrue( BYTES1.SequenceEqual( row2.Bytes1) );
        Assert.IsNull( row2.Bytes2);

        Assert.AreEqual(0, (int)row2.ETest1);
        Assert.AreEqual(0, (int)row2.EFlags1);
        Assert.IsNull(row2.ETest2);
        Assert.IsNull(row2.EFlags2);
      }
Exemple #17
0
        public void T_01_Insert()
        {
            var BIN = new byte[] { 0x00, 0x79, 0x14 };

            using (var client = new MongoClient("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 NFX.DataAccess.Distributed.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 NFX.Serialization.BSON.RowConverter();
                var doc = rc.RowToBSONDocument(row, "A");
                Aver.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

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

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

                Aver.AreObjectsEqual(row, row1);
            }
        }
Exemple #18
0
        public void T_02_Update_Parallel()
        {
            const int CNT = 11973;
              var BIN = new byte[] { 0x00, 0x79, 0x14 };

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

            db["t1"].Drop();

            var t1 = db["t1"];

            var rows = new TestRow[CNT];

            var rc = new NFX.Serialization.BSON.RowConverter();

            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 NFX.DataAccess.Distributed.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.RowToBSONDocument(row, "A");
              Assert.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.RowToBSONDocument(row, "A");

              var r = t1.Save(doc);
              Assert.AreEqual(1, r.TotalDocumentsAffected);
              Assert.AreEqual(1, r.TotalDocumentsUpdatedAffected);
              Assert.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));
              Assert.IsNotNull( got );

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

              Assert.AreEqual(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);

              }
        }
Exemple #19
0
      public void T_05_WithInnerRows()
      {
        var BYTES = new byte[] {0x00, 0x79, 0x14};

        var row = new RowB
        {
          Row1 = new RowA
          {
            String1 = "Mudaker", String2 = null,
            Date1 = new DateTime(1980, 07, 12), 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 = BYTES, Bytes2 = null
          },
          Row2= new RowA
          {
            String1 = "Abraham ILyach Lincoln", String2 = "I know that I know nothing",
            Date1 = new DateTime(1877, 01, 02), Date2 = new DateTime(1977, 03, 15),
            Bool1 = false, Bool2 = true,
            Guid1 = new Guid("{AAAAAAAA-FE21-4BB2-B006-2496F4E24D14}"), Guid2 = null,
            Gdid1 = new GDID(0, 12323423423), Gdid2 =  new GDID(0, 187760098292476423),
            Float1 = 127.0123f, Float2 = 123.2f,
            Double1 = 122345.012d, Double2 = -18293f,
            Decimal1 = 1234567.098M, Decimal2 = -2312m,
            Amount1 = new Amount("usd", 89123M), Amount2 = new Amount("usd", 12398933.123m),
            Bytes1 = null, Bytes2 = BYTES
          }
        };
        
        var rc = new RowConverter();
      
        var doc = rc.RowToBSONDocument( row, "A" );

        Console.WriteLine(doc.ToString());

        var row2 = new RowB();
        rc.BSONDocumentToRow(doc, row2, "A");

        Assert.IsTrue( row.Equals( row2 ) );
      }
Exemple #20
0
        public void T_04_Array()
        {
            using(var client= new MongoClient("My Test"))
              {
            var db = client.DefaultLocalServer["db1"];

            db["t1"].Drop();

            var t1 = db["t1"];

            var row = new ArrayRow
            {
              _id = 1,
              Map = new JSONDataMap{{"Name","Xerson"},{"Age",123}},
              List = new List<object>{ 1,true, "YEZ!", -123.01},
              ObjectArray = new object[]{123, -12, 789d, 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", -40.0789}},  new JSONDataMap{{"nothing",null}} }
            };

            var rc = new NFX.Serialization.BSON.RowConverter();
            var doc = rc.RowToBSONDocument(row, "A");
            Assert.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

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

            var row1 = new ArrayRow();
            rc.BSONDocumentToRow(got, row1, "A");

            Assert.AreEqual(row, row1);
              }
        }
Exemple #21
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 RowConverter();

        var doc = rc.RowToBSONDocument(row, "A");
        Console.WriteLine( doc.ToString() );

        var row2 = new RowC();
        rc.BSONDocumentToRow(doc, row2, "A");

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

        Assert.AreEqual(4, row2.List.Count);
        Assert.AreEqual(1, row2.List[0]);
        Assert.AreEqual(true, row2.List[1]);
        Assert.AreEqual("YEZ!", row2.List[2]);
        Assert.AreEqual(-123010m, row2.List[3]); //notice that "decimalness" is lost, because reading back into list<object>
      
        Assert.AreEqual(6, row2.ObjectArray.Length);
        Assert.AreEqual(123, row2.ObjectArray[0]);
        Assert.AreEqual(-12, row2.ObjectArray[1]);
        Assert.AreEqual(789, row2.ObjectArray[2]);
        Assert.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
        Assert.AreEqual(null, row2.ObjectArray[4]);
        var arr = (object[])row2.ObjectArray[5];
        Assert.IsNotNull(arr);
        Assert.AreEqual(54.67d, arr[0]);
        Assert.AreEqual("alpIna", arr[1]);

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

        Assert.AreEqual(2, row2.MapList.Count);
        Assert.AreEqual(2, row2.MapList[0].Count);
        Assert.AreEqual(0, row2.MapList[0]["abc"]);
        Assert.IsTrue((new byte[]{0,0,0,2,0,0,0,0,0,0,0x04,0xc7}).SequenceEqual( (byte[])(row2.MapList[0]["buba"]) ) );//"GDIDness" is lost
        Assert.AreEqual(1, row2.MapList[1].Count);
        Assert.AreEqual(null, row2.MapList[1]["nothing"]);
      }