public void SetUp()
        {
            longFolderName = Path.Combine(Path.GetTempPath(), new String('a', 230));

            _blobId       = new BlobId(_originalFormat, 1);
            _pathToTask   = Path.Combine(longFolderName, "File_1.dsimport");
            _fileToImport = Path.Combine(longFolderName, "A Word Document.docx");
            _fileUri      = new Uri(Path.Combine(longFolderName, "A word document.docx"));

            ClearQueueTempFolder();
            Directory.CreateDirectory(longFolderName);

            File.Copy(Path.Combine(TestConfig.DocumentsFolder, "Queue\\File_1.dsimport"), _pathToTask);
            File.Copy(TestConfig.PathToWordDocument, _fileToImport);
            var accessor = Substitute.For <ITenantAccessor>();
            var tenant   = Substitute.For <ITenant>();

            tenant.Id.Returns(new TenantId("tests"));
            var container = Substitute.For <IWindsorContainer>();

            _commandBus = Substitute.For <ICommandBus>();
            var identityGenerator = Substitute.For <IIdentityGenerator>();

            _blobstore = Substitute.For <IBlobStore>();
            _blobstore.Upload(Arg.Is(_originalFormat), Arg.Any <string>()).Returns(_blobId);
            _blobstore.Upload(Arg.Is(_originalFormat), Arg.Any <FileNameWithExtension>(), Arg.Any <Stream>()).Returns(_blobId);

            accessor.GetTenant(_testTenant).Returns(tenant);
            accessor.Current.Returns(tenant);
            tenant.Container.Returns(container);

            container.Resolve <IBlobStore>().Returns(_blobstore);
            container.Resolve <IIdentityGenerator>().Returns(identityGenerator);
            container.Resolve <IMongoDatabase>().Returns(MongoDbTestConnectionProvider.ReadModelDb);
            var collection = MongoDbTestConnectionProvider.ReadModelDb.GetCollection <ImportFailure>("sys.importFailures");

            collection.Drop();
            DocumentStoreTestConfiguration config = new DocumentStoreTestConfiguration(tenantId: "tests");

            config.SetFolderToMonitor(longFolderName);
            var sysDb = config.TenantSettings.Single(t => t.TenantId == "tests").Get <IMongoDatabase>("system.db");

            sysDb.Drop();
            _queue = new ImportFormatFromFileQueue(config, accessor, _commandBus)
            {
                Logger = new ConsoleLogger()
            };

            _queue.DeleteTaskFileAfterImport = false;
        }
        void CreateDocument(int id, string handle, string pathToFile)
        {
            var fname = Path.GetFileName(pathToFile);
            var info  = new DocumentHandleInfo(new DocumentHandle(handle), new FileNameWithExtension(fname));

            _bus.Send(new InitializeDocumentDescriptor(
                          new DocumentDescriptorId(id),
                          _filestore.Upload(DocumentFormats.Original, pathToFile),
                          info,
                          new FileHash("1234abcd"),
                          new FileNameWithExtension("a", "file")
                          ));
            Thread.Sleep(50);
        }
        public void SetUp()
        {
            longFolderName = Path.Combine(Path.GetTempPath(), new String('a', 230));
          
            _blobId = new BlobId(_originalFormat, 1);
            _pathToTask = Path.Combine(longFolderName, "File_1.dsimport");
            _fileToImport = Path.Combine(longFolderName, "A Word Document.docx");
            _fileUri = new Uri(Path.Combine(longFolderName, "A word document.docx"));

            ClearQueueTempFolder();
            Directory.CreateDirectory(longFolderName);

            File.Copy(Path.Combine(TestConfig.DocumentsFolder, "Queue\\File_1.dsimport"), _pathToTask);
            File.Copy(TestConfig.PathToWordDocument, _fileToImport);
            var accessor = Substitute.For<ITenantAccessor>();
            var tenant = Substitute.For<ITenant>();
            tenant.Id.Returns(new TenantId("tests"));
            var container = Substitute.For<IWindsorContainer>();
            _commandBus = Substitute.For<ICommandBus>();
            var identityGenerator = Substitute.For<IIdentityGenerator>();

            _blobstore = Substitute.For<IBlobStore>();
            _blobstore.Upload(Arg.Is(_originalFormat), Arg.Any<string>()).Returns(_blobId);
            _blobstore.Upload(Arg.Is(_originalFormat), Arg.Any<FileNameWithExtension>(), Arg.Any<Stream>()).Returns(_blobId);

            accessor.GetTenant(_testTenant).Returns(tenant);
            accessor.Current.Returns(tenant);
            tenant.Container.Returns(container);

            container.Resolve<IBlobStore>().Returns(_blobstore);
            container.Resolve<IIdentityGenerator>().Returns(identityGenerator);
            container.Resolve<IMongoDatabase>().Returns(MongoDbTestConnectionProvider.ReadModelDb);
            var collection = MongoDbTestConnectionProvider.ReadModelDb.GetCollection<ImportFailure>("sys.importFailures");
            collection.Drop();
            DocumentStoreTestConfiguration config = new DocumentStoreTestConfiguration(tenantId : "tests");
            config.SetFolderToMonitor(longFolderName);
            var sysDb = config.TenantSettings.Single(t => t.TenantId == "tests").Get<IMongoDatabase>("system.db");
            sysDb.Drop();
            _queue = new ImportFormatFromFileQueue(config, accessor, _commandBus)
            {
                Logger = new ConsoleLogger()
            };

            _queue.DeleteTaskFileAfterImport = false;
        }
        public void should_write_pdf_format_to_original_store()
        {
            var blobId = new BlobId(DocumentFormats.Pdf, 1);

            _artifacts.Upload(Arg.Any <DocumentFormat>(), Arg.Any <string>()).Returns(blobId);

            var id = _manager.Upload(DocumentFormats.Pdf, TestConfig.PathToDocumentPdf);

            Assert.AreEqual(blobId, id);
        }
Exemplo n.º 5
0
        public void Verify_basic_save_and_reload_stream()
        {
            const String content      = "this is the content of the file";
            String       tempFileName = GenerateTempTextFile(content, "test1.txt");
            var          id           = _sut.Upload(DocumentFormats.Original, tempFileName);

            Assert.That(id, Is.Not.Null);

            var download = _sut.Download(id, _tempLocalDirectory);

            Assert.That(Path.GetFileName(download), Is.EqualTo("test1.txt"));
            Assert.That(File.ReadAllText(download), Is.EqualTo(content));
        }