Esempio n. 1
0
        public async void SaveDocumentValid()
        {
            var expectedPath    = _metadataMock.Valuta.Year + @"\" + _documentMock.Id + FileSuffix + _documentMock.Metadata.FileEnding;
            var metadataService = new Mock <IMetadataService>();

            metadataService.Setup(x => x.SaveMetadata(It.IsAny <MetadataItem>(), It.IsAny <Guid>())).Returns(Task.FromResult(_documentMock.Metadata));
            var fileHandlerService = new Mock <IFileHandler>();

            fileHandlerService.Setup(x => x.SaveFile(_documentMock.File, It.IsAny <string>()));
            var storageHandler = new FilesystemStorageHandler(metadataService.Object, _appSettings, fileHandlerService.Object);

            await storageHandler.SaveDocument(_documentMock);

            metadataService.Verify(x => x.SaveMetadata(_documentMock.Metadata, _documentMock.Id));
            fileHandlerService.Verify(x => x.SaveFile(_documentMock.File, expectedPath));
        }
Esempio n. 2
0
        public void SaveDocumentNoFile()
        {
            var doc = new Document()
            {
                Id       = Guid.NewGuid(),
                Metadata = _metadataMock,
                File     = null
            };
            var metadataService    = new Mock <IMetadataService>();
            var fileHandlerService = new Mock <IFileHandler>();
            var storageHandler     = new FilesystemStorageHandler(metadataService.Object, _appSettings, fileHandlerService.Object);

            Func <Task> t = async() =>
                            await storageHandler.SaveDocument(doc);

            t.Should().Throw <FileNotFoundException>();
        }
Esempio n. 3
0
        public async void SaveDocumentMissingId()
        {
            var doc = new Document()
            {
                Id       = Guid.Empty,
                Metadata = _metadataMock,
                File     = new MemoryStream()
            };
            var metadataService = new Mock <IMetadataService>();

            metadataService.Setup(x => x.SaveMetadata(It.IsAny <MetadataItem>(), It.IsAny <Guid>())).Returns(Task.FromResult(_metadataMock));
            var fileHandlerService = new Mock <IFileHandler>();

            fileHandlerService.Setup(x => x.SaveFile(doc.File, It.IsAny <string>()));
            var storageHandler = new FilesystemStorageHandler(metadataService.Object, _appSettings, fileHandlerService.Object);

            await storageHandler.SaveDocument(doc);

            doc.Id.Should().NotBeEmpty();
        }