Пример #1
0
        private static ExpiredFileRemovalJob GetTestObject(List <UploadedFile> files)
        {
            IUploadedFileRepository repository = Substitute.For <IUploadedFileRepository>();

            repository.GetFiles().Returns(Task.FromResult <IList <UploadedFile> >(files.ToList()));
            repository.When(r => r.Delete(Arg.Any <FileIdentifier>()))
            .Do(c => files.RemoveAll(f => c.Arg <FileIdentifier>().Equals(f.Id)));

            return(new ExpiredFileRemovalJob(repository, FakeLogger.Get <ExpiredFileRemovalJob>()));
        }
Пример #2
0
    public async Task UploadedFileRepository_Success_ReturnsFileWithMetadata()
    {
        // Given
        IFileStore      fileStore      = Substitute.For <IFileStore>();
        IMetadataReader metadataReader = new MetadataReader(Substitute.For <ILogger <MetadataReader> >());

        var metadataString = (new StoredMetadata {
            OriginalFileName = "TestFile.txt"
        }).Serialize();

        fileStore.GetMetadataFile(Arg.Any <FileIdentifier>()).Returns(new FakeFile(contents: metadataString));

        fileStore.GetDataFile(Arg.Any <FileIdentifier>()).Returns(new FakeFile());

        // When
        IUploadedFileRepository testObject    = new UploadedFileRepository(fileStore, null, metadataReader, FakeLogger.Get <UploadedFileRepository>());
        UploadedFile            returnedValue = await testObject.GetFile(FileIdentifier.CreateNew());

        // Then
        Assert.That(returnedValue.Metadata.OriginalFileName, Is.EqualTo("TestFile.txt"));
    }
Пример #3
0
    public async Task UploadedFileRepository_DataFileMissing_GetFile_ReturnsNull()
    {
        // Given
        IFileStore fileStore = Substitute.For <IFileStore>();

        fileStore.GetMetadataFile(Arg.Any <FileIdentifier>()).Returns(new FakeFile());
        fileStore.GetDataFile(Arg.Any <FileIdentifier>()).Returns(new NotFoundFileInfo("_"));

        // When
        IUploadedFileRepository testObject    = new UploadedFileRepository(fileStore, null, null, FakeLogger.Get <UploadedFileRepository>());
        UploadedFile            returnedValue = await testObject.GetFile(FileIdentifier.CreateNew());

        // Then
        Assert.That(returnedValue, Is.Null);
    }