コード例 #1
0
        public void NullValueString(EnumKeyDataType dataType)
        {
            var key = new BtrieveKey {
                Segments = new List <BtrieveKeyDefinition> {
                    new BtrieveKeyDefinition {
                        Number       = 0,
                        Offset       = 2,
                        Length       = 8,
                        DataType     = dataType,
                        Attributes   = EnumKeyAttributeMask.UseExtendedDataType | EnumKeyAttributeMask.NullAllSegments,
                        Segment      = true,
                        SegmentIndex = 0,
                        NullValue    = (byte)' ',
                    }
                }
            };

            var record = new byte[128];

            Array.Fill(record, (byte)0xFF, 0, record.Length);
            // first segment is all spaces i.e. null
            Array.Fill(record, (byte)' ', 2, 8);

            var sqlLiteObject = key.ExtractKeyInRecordToSqliteObject(record);

            sqlLiteObject.Should().Be(DBNull.Value);
        }
コード例 #2
0
        public void ACSReplacement_SingleKey()
        {
            var acs = UpperACS();

            var key = new BtrieveKey {
                Segments = new List <BtrieveKeyDefinition> {
                    new BtrieveKeyDefinition {
                        Number       = 0,
                        Offset       = 2,
                        Length       = 8,
                        DataType     = EnumKeyDataType.Zstring,
                        Attributes   = EnumKeyAttributeMask.UseExtendedDataType | EnumKeyAttributeMask.NumberedACS,
                        ACS          = acs,
                        Segment      = true,
                        SegmentIndex = 0,
                        NullValue    = 0,
                    }
                }
            };

            var record = new byte[128];

            Array.Fill(record, (byte)0xFF, 0, record.Length);
            // first segment is all spaces i.e. null
            record[2] = (byte)'a';
            record[3] = (byte)'B';
            record[4] = (byte)'t';
            record[5] = (byte)'Z';
            record[6] = (byte)'%';
            record[7] = 0;

            var sqlLiteObject = key.ExtractKeyInRecordToSqliteObject(record);

            sqlLiteObject.Should().Be("ABTZ%");
        }
コード例 #3
0
        public void CompositeKeyConcatentation()
        {
            var key = new BtrieveKey()
            {
                Segments = new List <BtrieveKeyDefinition>()
                {
                    new BtrieveKeyDefinition()
                    {
                        Number       = 0,
                        Offset       = 2,
                        Length       = 8,
                        DataType     = EnumKeyDataType.Integer,
                        Attributes   = EnumKeyAttributeMask.UseExtendedDataType,
                        Segment      = true,
                        SegmentIndex = 0,
                        NullValue    = 0,
                    },
                    new BtrieveKeyDefinition()
                    {
                        Number       = 0,
                        Offset       = 20,
                        Length       = 4,
                        DataType     = EnumKeyDataType.Zstring,
                        Attributes   = EnumKeyAttributeMask.UseExtendedDataType,
                        Segment      = false,
                        SegmentIndex = 1,
                        NullValue    = 0,
                    }
                }
            };

            var record = new byte[128];

            Array.Fill(record, (byte)0xFF, 0, record.Length);
            // first segment is all 0x5
            Array.Fill(record, (byte)0x5, 2, 8);
            // second segment is just a letter
            Array.Fill(record, (byte)'T', 20, 4);

            var sqlLiteObject = key.ExtractKeyInRecordToSqliteObject(record);

            sqlLiteObject.Should().BeEquivalentTo(new byte[] { 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, (byte)'T', (byte)'T', (byte)'T', (byte)'T' });
        }
コード例 #4
0
        public void ACSReplacement_ACSOnlyOnSecondKey(string input, string expected)
        {
            var acs = UpperACS();

            var key = new BtrieveKey()
            {
                Segments = new List <BtrieveKeyDefinition> {
                    new BtrieveKeyDefinition {
                        Number       = 0,
                        Offset       = 2,
                        Length       = 8,
                        DataType     = EnumKeyDataType.Zstring,
                        Attributes   = EnumKeyAttributeMask.UseExtendedDataType,
                        Segment      = true,
                        SegmentIndex = 0,
                        NullValue    = 0,
                    },
                    new BtrieveKeyDefinition {
                        Number       = 0,
                        Offset       = 10,
                        Length       = 8,
                        DataType     = EnumKeyDataType.Zstring,
                        Attributes   = EnumKeyAttributeMask.UseExtendedDataType | EnumKeyAttributeMask.NumberedACS,
                        ACS          = acs,
                        Segment      = false,
                        SegmentIndex = 1,
                        NullValue    = 0,
                    }
                }
            };

            var record = new byte[128];

            Array.Fill(record, (byte)0x0, 0, record.Length);
            Array.Copy(Encoding.ASCII.GetBytes(input), 0, record, 2, input.Length);

            var sqlLiteObject = Encoding.ASCII.GetString((byte[])key.ExtractKeyInRecordToSqliteObject(record)).TrimEnd((char)0);

            sqlLiteObject.Should().Be(expected);
        }