Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds methods to retrieve one file by Id and a Queryable of files #89

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using FakeXrmEasy.Abstractions.FileStorage;
using Microsoft.Xrm.Sdk;

namespace FakeXrmEasy.Core.FileStorage.Db
{
internal interface IInMemoryFileDbInternal
{
IFileAttachment GetFileById(string fileId);
List<IFileAttachment> GetAllFiles();
IQueryable<IFileAttachment> CreateQuery();

void AddFile(IFileAttachment fileAttachment);
void DeleteFile(string fileId);
List<IFileAttachment> GetFilesForTarget(EntityReference target);
Expand Down
8 changes: 7 additions & 1 deletion src/FakeXrmEasy.Core/FileStorage/Db/InMemoryFileDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public List<FileUploadSession> GetAllFileUploadSessions()
}

#region Internal File Manipulation
public IFileAttachment GetFileById(string fileId)
{
_files.TryGetValue(fileId, out var file);
return file;
}

public List<IFileAttachment> GetAllFiles()
{
return _files.Values.ToList();
Expand Down Expand Up @@ -234,7 +240,7 @@ public bool IsMimeTypeAllowed(string mimeType, OrganizationFileSettings fileSett


/// <summary>
///
/// Creates a query to query files by ay criteria
/// </summary>
/// <returns></returns>
public IQueryable<IFileAttachment> CreateQuery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public void Should_init_file()

var allFiles = _fileDb.GetAllFiles();
Assert.Single(allFiles);

var singleFile = _fileDb.GetFileById(_file.Id);
Assert.NotNull(singleFile);
}

[Fact]
Expand Down
Loading