public void ShouldNotReadKeyfileIfKeyIsInPath()
        {
            var key           = 1L;
            var filesystem    = new MemoryFileSystem();
            var options       = new FilesystemStorageOptions();
            var mockFormatter = new Mock <IFormatter <BinaryReader, BinaryWriter> >();

            var entityIO = new FilesystemEntityReaderWriter <long, BinaryReader, BinaryWriter>(
                filesystem,
                mockFormatter.Object,
                options
                );

            using (var stream = entityIO.BeginWrite(key)) stream.Write("mock");
            Assert.True(entityIO.Exists(key));
            var keys = entityIO.GetAllKeys();

            Assert.Contains(key, keys);
            Assert.Single(keys);

            mockFormatter.Verify(mock => mock.Deserialize(
                                     It.IsAny <Type>(),
                                     It.IsAny <BinaryReader>(),
                                     null
                                     ), Times.Never());
        }
        public FilesystemEntityReaderWriterTest()
        {
            var filesystem = new MemoryFileSystem();
            var options    = new FilesystemStorageOptions();

            entityIO = new FilesystemEntityReaderWriter <long, BinaryReader, BinaryWriter>(
                filesystem,
                FastBinaryFormatter.Instance,
                options
                );
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets up the engine to use file-based entity storage.
        /// </summary>
        /// <param name="formatter">
        /// Specifies a <see cref="IFormatter<TInputStream, TOutputStream>"/> which
        /// will be used for serialization and deserialization.
        /// </param>
        /// <param name="options">
        /// If not null, overrides the default <see cref="FilesystemStorageOptions"/>.
        /// </param>
        /// <param name="fileSystem">
        /// If not null, uses the specified IFileSystem, otherwise uses
        /// what has been called before.
        /// </param>
        public DiffstoreBuilder <TKey, TValue> WithFileBasedEntities <TIn, TOut>(
            IFormatter <TIn, TOut> formatter,
            FilesystemStorageOptions options = null,
            IFileSystem fileSystem           = null)
            where TIn : IDisposable
            where TOut : IDisposable
        {
            (fileSystem, options) = PrepareFileStorage(fileSystem, options);
            var entityIO = new FilesystemEntityReaderWriter <TKey, TIn, TOut>(
                fileSystem, formatter, options);

            em = new EntityManager <TKey, TValue, TIn, TOut>(formatter, entityIO);
            return(this);
        }
Exemplo n.º 4
0
        internal override IEntityManager <long, SampleData> Build()
        {
            var filesystem = new MemoryFileSystem();
            var formatter  = FastBinaryFormatter.Instance;
            var options    = new FilesystemStorageOptions()
            {
                EntitiesPerDirectory = 1000
            };

            var entityIO = new FilesystemEntityReaderWriter <long, BinaryReader, BinaryWriter>
                               (filesystem, formatter, options);

            return(new EntityManager <long, SampleData, BinaryReader, BinaryWriter>
                       (formatter, entityIO));
        }