Пример #1
0
        public static unsafe Mock <IRawFile> InMemoryFile(int bufferSize = 2048, int fileId = 0)
        {
            var core = new BufferBinaryReader(new byte[bufferSize]);
            var mock = new Mock <IRawFile>();

            mock.Setup(s => s.ReadBool(It.IsAny <long>())).Returns((long offset) => core.ReadBool(offset));
            mock.Setup(s => s.ReadByte(It.IsAny <long>())).Returns((long offset) => core.ReadByte(offset));
            mock.Setup(s => s.ReadInt32(It.IsAny <long>())).Returns((long offset) => core.ReadInt32(offset));
            mock.Setup(s => s.ReadInt64(It.IsAny <long>())).Returns((long offset) => core.ReadInt64(offset));
            mock.Setup(s => s.ReadInt16(It.IsAny <long>())).Returns((long offset) => core.ReadInt16(offset));
            mock.Setup(s => s.ReadUInt16(It.IsAny <long>())).Returns((long offset) => core.ReadUInt16(offset));
            mock.Setup(s => s.ReadDouble(It.IsAny <long>())).Returns((long offset) => core.ReadDouble(offset));
            mock.Setup(s => s.ReadBytes(It.IsAny <long>(), It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()))
            .Callback(
                (long offset, byte[] buff, int arrayOff, int len) => core.ReadBytes(offset, buff, arrayOff, len));

            mock.Setup(s => s.WriteBool(It.IsAny <long>(), It.IsAny <bool>())).Callback((long offset, bool val) => core.WriteBool(offset, val));
            mock.Setup(s => s.WriteByte(It.IsAny <long>(), It.IsAny <byte>())).Callback((long offset, byte val) => core.WriteByte(offset, val));
            mock.Setup(s => s.WriteInt32(It.IsAny <long>(), It.IsAny <int>())).Callback((long offset, int val) => core.WriteInt32(offset, val));
            mock.Setup(s => s.WriteInt64(It.IsAny <long>(), It.IsAny <long>())).Callback((long offset, long val) => core.WriteInt64(offset, val));
            mock.Setup(s => s.WriteInt16(It.IsAny <long>(), It.IsAny <short>())).Callback((long offset, short val) => core.WriteInt16(offset, val));
            mock.Setup(s => s.WriteDouble(It.IsAny <long>(), It.IsAny <double>())).Callback((long offset, double val) => core.WriteDouble(offset, val));
            mock.Setup(s => s.WriteBytes(It.IsAny <long>(), It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()))
            .Callback(
                (long offset, byte[] buff, int arrayOff, int len) => core.WriteBytes(offset, buff, arrayOff, len));

            mock.Setup(s => s.FileID).Returns(fileId);

            return(mock);
        }
Пример #2
0
        private StringColumn CreateStringColumn(int maxLen)
        {
            _readerContext = new ReadContext();
            var data  = new BufferBinaryReader(new byte[maxLen * 2 + 5]);
            var index = new BufferBinaryReader(new byte[2048]);

            return(new StringColumn(data, index, maxLen, "column1"));
        }
        private Mock <ICompositeFileFactory> AppendOffsetStub()
        {
            var dictSize = TestUtils.SplitNameSize(_fileNameSize);

            var stubFileF = new Mock <ICompositeFileFactory>();

            _createdFiles = new Dictionary <string, ICompositeFile>();
            _filePart     = new Dictionary <string, IRawFilePart>();

            stubFileF.Setup(f => f.OpenFile(It.IsAny <string>(), It.IsAny <int>(),
                                            It.IsAny <EFileAccess>())).Returns(
                (string filename, int bithint, EFileAccess access) =>
            {
                if (_createdFiles.ContainsKey(filename))
                {
                    return(_createdFiles[filename]);
                }

                var compFile = new Mock <ICompositeFile>();
                foreach (var keyVal in dictSize)
                {
                    if (filename.EndsWith("\\" + keyVal.Key))
                    {
                        IRawFilePart file;
                        if (_failOnCommitFile != null &&
                            filename.EndsWith("\\" + _failOnCommitFile))
                        {
                            var fileSub = new Mock <IRawFilePart>();
                            fileSub.Setup(f => f.WriteInt64(0, It.IsAny <long>()))
                            .Throws(new ArgumentException("stub exception"));
                            fileSub.Setup(f => f.ReadInt64(0)).Returns(keyVal.Value);
                            fileSub.Setup(f => f.Filename).Returns(filename);
                            file = fileSub.Object;
                        }
                        else
                        {
                            file = new BufferBinaryReader(new byte[1024])
                            {
                                Filename = filename
                            };
                            file.WriteInt64(0, keyVal.Value);
                        }
                        _filePart[filename] = file;
                        compFile
                        .Setup(cf => cf.CreateViewAccessor(0, It.IsAny <long>()))
                        .Returns(file);

                        _createdFiles[filename] = compFile.Object;
                        return(compFile.Object);
                    }
                }
                throw new ArgumentOutOfRangeException("No setup for filename " + filename);
            }
                );

            return(stubFileF);
        }
Пример #4
0
        private unsafe StringColumn CreateStringColumn(string value, int maxLen)
        {
            var data  = new BufferBinaryReader(new byte[maxLen * 2 + 5]);
            var index = new BufferBinaryReader(new byte[2048]);

            _readerContext = new ReadContext();

            int headLength = CreateHeader(value, data);

            if (value != null)
            {
                fixed(char *chars = value)
                {
                    var strBytes = (byte *)&chars[0];

                    data.WriteBytes(headLength, strBytes, value.Length * 2);
                }
            }

            return(new StringColumn(data, index, maxLen, "column1"));
        }
Пример #5
0
        public static IRawFile StringRawFile(byte[] header)
        {
            var rdr = new BufferBinaryReader(header);

            return(rdr);
        }