Пример #1
0
    public void T_01_Equals()
    {
      var row = 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
      };
        
      var rc = new RowConverter();
      
      var doc = rc.RowToBSONDocument( row, "A" );

      Console.WriteLine(doc.ToString());

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

      Assert.IsTrue( row.Equals( row2 ) );
    }
Пример #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), 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,

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

              var rc = new RowConverter();

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

              Console.WriteLine(doc.ToString());

              Assert.IsTrue( BIN.SequenceEqual( (byte[])doc["Bytes1"] ));
              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) );
        }
Пример #3
0
        private BSONDocument docFromMessage(Message msg)
        {
            var doc = new BSONDocument();

            var rc = new RowConverter();

            doc.Set(new BSONStringElement("Guid", msg.Guid.ToString("N")));
            doc.Set(new BSONStringElement("RelatedTo", msg.RelatedTo.ToString("N")));
            doc.Set(new BSONStringElement("Type", msg.Type.ToString()));
            doc.Set(new BSONInt32Element("Source", msg.Source));
            doc.Set(new BSONInt64Element("TimeStamp", msg.TimeStamp.Ticks));
            doc.Set(new BSONStringElement("Host", msg.Host));
            doc.Set(new BSONStringElement("From", msg.From));
            doc.Set(new BSONStringElement("Topic", msg.Topic));
            doc.Set(new BSONStringElement("Text", msg.Text));
            doc.Set(new BSONStringElement("Parameters", msg.Parameters));
            doc.Set(new BSONStringElement("Exception", msg.Exception.ToMessageWithType()));

            return(doc);
        }
Пример #4
0
 public MongoDBDataStore() : base()
 {
     m_QueryResolver = new QueryResolver(this);
     m_Converter     = new RowConverter();
 }
Пример #5
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"]));
        }
Пример #6
0
 private void ctor()
 {
     m_QueryResolver = new QueryResolver(this);
     m_Converter     = new RowConverter();
 }
Пример #7
0
        public void T_15_BSONtoJSONDataMapFilter()
        {
            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 map = rc.BSONDocumentToJSONMap(doc, (d, e) => e.Name!="LastName");

              Assert.AreEqual(rowA.FirstName, map["FirstName"]);
              Assert.IsNull( map["LastName"] ); //filter skipped
              Assert.AreEqual(rowA.Age, map["Age"]);
        }
Пример #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);
        }
Пример #9
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 ) );
        }
Пример #10
0
        public void T_14_RowCycle_TransitiveCycle_3()
        {
            var root = new JSONDataMap();

            root["a"] = 1;
            root["b"] = true;
            root["array"] = new JSONDataArray(){1,2,3,true,true,root};  //TRANSITIVE(via another instance) CYCLE!!!!

            var rc = new RowConverter();

            var doc = rc.ConvertCLRtoBSON(root, "A");//exception
        }
Пример #11
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), 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
              };

              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);
        }
Пример #12
0
        public void T_13_RowCycle_TransitiveCycle_2()
        {
            var root = new RowCycle();

            root.SomeInt = 1234;
            root.InnerRow = new RowCycle();
            root.InnerRow.SomeInt = 567;
            root.InnerRow.InnerRow = new RowCycle();
            root.InnerRow.InnerRow.SomeInt = 890;
            root.InnerRow.InnerRow.InnerRow = root.InnerRow;  //TRANSITIVE(via another instance) CYCLE!!!!

            var rc = new RowConverter();

            var doc = rc.RowToBSONDocument( root, "A" );  //exception
        }
Пример #13
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"]));
        }
Пример #14
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);
        }
Пример #15
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);
        }
Пример #16
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},
            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(5, 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]);

              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"]);
        }
Пример #17
0
        public void T_06_TargetingInnerRows()
        {
            var row = new RowB{
               Row1 = new RowA  { String1 = "Mudaker", String2 = "Someone"},
               Row2 = new RowA  { String1 = "Zar", String2 = "Boris"}
              };

              var rc = new RowConverter();

              var doc = rc.RowToBSONDocument( row, "A" );
              Console.WriteLine(doc.ToString());
              Assert.AreEqual( "Someone", doc["Row1"]["s2"].ToString());
              Assert.AreEqual( "Boris", doc["Row2"]["s2"].ToString());

              doc = rc.RowToBSONDocument( row, "B" );
              Console.WriteLine(doc.ToString());
              Assert.AreEqual( "Someone", doc["Row1"]["STRING-2"].ToString());
              Assert.AreEqual( "Boris", doc["Row2"]["STRING-2"].ToString());

              doc = rc.RowToBSONDocument( row, "NonExistent" );
              Console.WriteLine(doc.ToString());
              Assert.AreEqual( "Someone", doc["Row1"]["String2"].ToString());
              Assert.AreEqual( "Boris", doc["Row2"]["String2"].ToString());
        }
Пример #18
0
 public MongoDBDataStore(string connectString, string dbName) : base(connectString, dbName)
 {
     m_QueryResolver = new QueryResolver(this);
     m_Converter     = new RowConverter();
 }
Пример #19
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), Date2 = new DateTime(1680, 12, 11),
            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
              };

              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));
        }
Пример #20
0
        public void T_11_RowCycle_DirectCycle()
        {
            var root = new RowCycle();

            root.SomeInt = 1234;
            root.InnerRow = root; //Direct cycle

            var rc = new RowConverter();

            var doc = rc.RowToBSONDocument( root, "A" );  //exception
        }
Пример #21
0
        public void T_04_Targeting()
        {
            var row = new RowA
              {
            String1 = "Mudaker", String2 = "Someone",
              };

              var rc = new RowConverter();

              var doc = rc.RowToBSONDocument( row, "A" );
              Console.WriteLine(doc.ToString());
              Assert.AreEqual( "Someone", doc["s2"].ToString());

              doc = rc.RowToBSONDocument( row, "B" );
              Console.WriteLine(doc.ToString());
              Assert.AreEqual( "Someone", doc["STRING-2"].ToString());

              doc = rc.RowToBSONDocument( row, "NonExistent" );
              Console.WriteLine(doc.ToString());
              Assert.AreEqual( "Someone", doc["String2"].ToString());
        }