public async Task <IActionResult> AddDocument()
        {
            string[] fileExtentions = { ".doc", ".docx", ".pdf", ".html" };
            var      document       = Request.Form.Files[0];

            if (Array.IndexOf(fileExtentions, Path.GetExtension(document.FileName)) != -1)
            {
                string FileType = Path.GetExtension(document.FileName).Split('.')[1];
                string FileName = document.FileName.Split('.')[0];
                await dr.AddAsync(new Document
                {
                    DirectoryId = 1,
                    FileType    = FileType,
                    Name        = FileName
                });

                var pathSave = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot", "documents", document.FileName);
                using (var steam = new FileStream(pathSave, FileMode.Create))
                {
                    await document.CopyToAsync(steam);
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 2
0
        public async Task ルート直下のサブディレクトリをディレクトリとして認識すること()
        {
            var ctx = new MockDocmsContext("DocumentsRepositoryTests");
            var sut = new DocumentRepository(ctx);
            await sut.AddAsync(DocumentUtils.Create("dir1/test.txt", "Hello, world"));

            await sut.UnitOfWork.SaveEntitiesAsync();

            Assert.IsTrue(await sut.IsContainerPath("dir1"));
        }
Esempio n. 3
0
        public async Task DocumentがPathで取得できること()
        {
            var ctx = new MockDocmsContext("DocumentsRepositoryTests");
            var sut = new DocumentRepository(ctx);
            await sut.AddAsync(DocumentUtils.Create("dir1/test.txt", "Hello, world"));

            await sut.UnitOfWork.SaveEntitiesAsync();

            var document = await sut.GetAsync("dir1/test.txt");

            Assert.AreEqual("dir1/test.txt", document.Path);
        }
Esempio n. 4
0
        public async Task AddAsync_GivenVaidInput_CorectlyUpdatesBlob(
            [Frozen] Mock <IBlobStore> blobStoreMock,
            DocumentRepository sut,
            string mimeType,
            string userFileName,
            MemoryStream content)
        {
            using (content)
            {
                // Arrange // Act
                string id = await sut.AddAsync(mimeType, userFileName, content);

                // Verify
                BlobHttpHeaders expectedHeaders = new BlobHttpHeaders()
                {
                    ContentType        = mimeType,
                    ContentDisposition = $"attachment; filename = \"{userFileName}\""
                };

                blobStoreMock.Verify(store =>
                                     store.UpsertAsync(id, content, It.Is <BlobHttpHeaders>(actualHeaders => Equals(actualHeaders, expectedHeaders)), null),
                                     Times.Once);
            }
        }