Generate arbitrary (random) values
Exemplo n.º 1
0
        public void RetrieveColumns()
        {
            bool bit = Any.Boolean;
            byte b = Any.Byte;
            short i16 = Any.Int16;
            ushort ui16 = Any.UInt16;
            int i32 = Any.Int32;
            uint ui32 = Any.UInt32;
            long i64 = Any.Int64;
            ulong ui64 = Any.UInt64;
            float f = Any.Float;
            double d = Any.Double;
            DateTime date = Any.DateTime;
            Guid guid = Any.Guid;
            string str = Any.String;
            byte[] bytes = Any.BytesOfLength(1023);

            using (var trx = new Transaction(this.session))
            using (var update = new Update(this.session, this.tableid, JET_prep.Insert))
            {
                Api.SetColumn(this.session, this.tableid, this.columnDict["Boolean"], bit);
                Api.SetColumn(this.session, this.tableid, this.columnDict["Byte"], b);
                Api.SetColumn(this.session, this.tableid, this.columnDict["Int16"], i16);
                Api.SetColumn(this.session, this.tableid, this.columnDict["UInt16"], ui16);
                Api.SetColumn(this.session, this.tableid, this.columnDict["Int32"], i32);
                Api.SetColumn(this.session, this.tableid, this.columnDict["UInt32"], ui32);
                Api.SetColumn(this.session, this.tableid, this.columnDict["Int64"], i64);
                Api.SetColumn(this.session, this.tableid, this.columnDict["UInt64"], ui64);
                Api.SetColumn(this.session, this.tableid, this.columnDict["Float"], f);
                Api.SetColumn(this.session, this.tableid, this.columnDict["Double"], d);
                Api.SetColumn(this.session, this.tableid, this.columnDict["DateTime"], date);
                Api.SetColumn(this.session, this.tableid, this.columnDict["Guid"], guid);
                Api.SetColumn(this.session, this.tableid, this.columnDict["Unicode"], str, Encoding.Unicode);
                Api.SetColumn(this.session, this.tableid, this.columnDict["Binary"], bytes);

                update.SaveAndGotoBookmark();
                trx.Commit(CommitTransactionGrbit.None);
            }

            var columnValues = new ColumnValue[]
            {
                new BoolColumnValue { Columnid = this.columnDict["Boolean"] },
                new ByteColumnValue { Columnid = this.columnDict["Byte"] },
                new Int16ColumnValue { Columnid = this.columnDict["Int16"] },
                new UInt16ColumnValue { Columnid = this.columnDict["UInt16"] },
                new Int32ColumnValue { Columnid = this.columnDict["Int32"] },
                new UInt32ColumnValue { Columnid = this.columnDict["UInt32"] },
                new Int64ColumnValue { Columnid = this.columnDict["Int64"] },
                new UInt64ColumnValue { Columnid = this.columnDict["UInt64"] },
                new FloatColumnValue { Columnid = this.columnDict["Float"] },
                new DoubleColumnValue { Columnid = this.columnDict["Double"] },
                new DateTimeColumnValue { Columnid = this.columnDict["DateTime"] },
                new GuidColumnValue { Columnid = this.columnDict["Guid"] },
                new StringColumnValue { Columnid = this.columnDict["Unicode"] },
                new BytesColumnValue { Columnid = this.columnDict["Binary"] },
            };

            Api.RetrieveColumns(this.session, this.tableid, columnValues);

            Assert.AreEqual(bit, columnValues[0].ValueAsObject);
            Assert.AreEqual(b, columnValues[1].ValueAsObject);
            Assert.AreEqual(i16, columnValues[2].ValueAsObject);
            Assert.AreEqual(ui16, columnValues[3].ValueAsObject);
            Assert.AreEqual(i32, columnValues[4].ValueAsObject);
            Assert.AreEqual(ui32, columnValues[5].ValueAsObject);
            Assert.AreEqual(i64, columnValues[6].ValueAsObject);
            Assert.AreEqual(ui64, columnValues[7].ValueAsObject);
            Assert.AreEqual(f, columnValues[8].ValueAsObject);
            Assert.AreEqual(d, columnValues[9].ValueAsObject);
            Assert.AreEqual(date, columnValues[10].ValueAsObject);
            Assert.AreEqual(guid, columnValues[11].ValueAsObject);
            Assert.AreEqual(str, columnValues[12].ValueAsObject);
            CollectionAssert.AreEqual(bytes, columnValues[13].ValueAsObject as byte[]);
        }
Exemplo n.º 2
0
        public void TestAnyStringOfLengthIsCorrectLength()
        {
            string s = Any.StringOfLength(10);

            Assert.AreEqual(10, s.Length);
        }
Exemplo n.º 3
0
 public void TestAnyBytesOfLengthIsCorrectLength()
 {
     byte[] s = Any.BytesOfLength(20);
     Assert.AreEqual(20, s.Length);
 }
Exemplo n.º 4
0
        public void SetColumns()
        {
            bool     bit  = true;
            byte     b    = Any.Byte;
            short    i16  = Any.Int16;
            ushort   ui16 = Any.UInt16;
            int      i32  = Any.Int32;
            uint     ui32 = Any.UInt32;
            long     i64  = Any.Int64;
            ulong    ui64 = Any.UInt64;
            float    f    = Any.Float;
            double   d    = Any.Double;
            DateTime date = Any.DateTime;
            Guid     guid = Any.Guid;
            string   s    = Any.String;

            byte[] bytes = Any.BytesOfLength(1023);

            var columnValues = new ColumnValue[]
            {
                new BoolColumnValue {
                    Columnid = this.columnDict["Boolean"], Value = bit
                },
                new ByteColumnValue {
                    Columnid = this.columnDict["Byte"], Value = b
                },
                new Int16ColumnValue {
                    Columnid = this.columnDict["Int16"], Value = i16
                },
                new UInt16ColumnValue {
                    Columnid = this.columnDict["UInt16"], Value = ui16
                },
                new Int32ColumnValue {
                    Columnid = this.columnDict["Int32"], Value = i32
                },
                new UInt32ColumnValue {
                    Columnid = this.columnDict["UInt32"], Value = ui32
                },
                new Int64ColumnValue {
                    Columnid = this.columnDict["Int64"], Value = i64
                },
                new UInt64ColumnValue {
                    Columnid = this.columnDict["UInt64"], Value = ui64
                },
                new FloatColumnValue {
                    Columnid = this.columnDict["Float"], Value = f
                },
                new DoubleColumnValue {
                    Columnid = this.columnDict["Double"], Value = d
                },
                new DateTimeColumnValue {
                    Columnid = this.columnDict["DateTime"], Value = date
                },
                new GuidColumnValue()
                {
                    Columnid = this.columnDict["Guid"], Value = guid
                },
                new StringColumnValue {
                    Columnid = this.columnDict["Unicode"], Value = s
                },
                new BytesColumnValue {
                    Columnid = this.columnDict["Binary"], Value = bytes
                },
            };

            using (var trx = new Transaction(this.session))
                using (var update = new Update(this.session, this.tableid, JET_prep.Insert))
                {
                    Api.SetColumns(this.session, this.tableid, columnValues);
                    update.Save();
                    trx.Commit(CommitTransactionGrbit.None);
                }

            Api.TryMoveFirst(this.session, this.tableid);

            Assert.AreEqual(bit, Api.RetrieveColumnAsBoolean(this.session, this.tableid, this.columnDict["Boolean"]));
            Assert.AreEqual(b, Api.RetrieveColumnAsByte(this.session, this.tableid, this.columnDict["Byte"]));
            Assert.AreEqual(i16, Api.RetrieveColumnAsInt16(this.session, this.tableid, this.columnDict["Int16"]));
            Assert.AreEqual(ui16, Api.RetrieveColumnAsUInt16(this.session, this.tableid, this.columnDict["UInt16"]));
            Assert.AreEqual(i32, Api.RetrieveColumnAsInt32(this.session, this.tableid, this.columnDict["Int32"]));
            Assert.AreEqual(ui32, Api.RetrieveColumnAsUInt32(this.session, this.tableid, this.columnDict["UInt32"]));
            Assert.AreEqual(i64, Api.RetrieveColumnAsInt64(this.session, this.tableid, this.columnDict["Int64"]));
            Assert.AreEqual(ui64, Api.RetrieveColumnAsUInt64(this.session, this.tableid, this.columnDict["UInt64"]));
            Assert.AreEqual(f, Api.RetrieveColumnAsFloat(this.session, this.tableid, this.columnDict["Float"]));
            Assert.AreEqual(d, Api.RetrieveColumnAsDouble(this.session, this.tableid, this.columnDict["Double"]));
            Assert.AreEqual(date, Api.RetrieveColumnAsDateTime(this.session, this.tableid, this.columnDict["DateTime"]));
            Assert.AreEqual(guid, Api.RetrieveColumnAsGuid(this.session, this.tableid, this.columnDict["Guid"]));
            Assert.AreEqual(s, Api.RetrieveColumnAsString(this.session, this.tableid, this.columnDict["Unicode"]));
            CollectionAssert.AreEqual(bytes, Api.RetrieveColumn(this.session, this.tableid, this.columnDict["Binary"]));
        }