-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds internal DeleteFile method DynamicsValue/fake-xrm-easy#157
- Loading branch information
1 parent
3a74af8
commit 8d5fb2a
Showing
4 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/FakeXrmEasy.Core/FileStorage/Db/Exceptions/CouldNotDeleteFileException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace FakeXrmEasy.Core.FileStorage.Db.Exceptions | ||
{ | ||
/// <summary> | ||
/// Exception thrown when a particular file could not be deleted or it doesn't exists | ||
/// </summary> | ||
public class CouldNotDeleteFileException: Exception | ||
{ | ||
/// <summary> | ||
/// Default constructor | ||
/// </summary> | ||
/// <param name="fileId"></param> | ||
internal CouldNotDeleteFileException(string fileId) : base($"Could not delete file with Id '{fileId}'") | ||
{ | ||
|
||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/FakeXrmEasy.Core/FileStorage/Db/IInMemoryFileDbInternal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FakeXrmEasy.Core.FileStorage.Db | ||
{ | ||
internal interface IInMemoryFileDbInternal | ||
{ | ||
List<FileAttachment> GetAllFiles(); | ||
void AddFile(FileAttachment fileAttachment); | ||
void DeleteFile(string fileId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
tests/FakeXrmEasy.Core.Tests/FileStorage/Db/DeleteFileTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using DataverseEntities; | ||
using FakeXrmEasy.Core.Db; | ||
using FakeXrmEasy.Core.FileStorage.Db; | ||
using FakeXrmEasy.Core.FileStorage.Db.Exceptions; | ||
using FakeXrmEasy.Core.FileStorage.Download; | ||
using Microsoft.Xrm.Sdk; | ||
using Xunit; | ||
using FileAttachment = FakeXrmEasy.Core.FileStorage.Db.FileAttachment; | ||
|
||
namespace FakeXrmEasy.Core.Tests.FileStorage.Db | ||
{ | ||
public class DeleteFileTests | ||
{ | ||
private readonly InMemoryDb _db; | ||
private readonly InMemoryFileDb _fileDb; | ||
private readonly Entity _entity; | ||
private readonly FileAttachment _file; | ||
|
||
public DeleteFileTests() | ||
{ | ||
_db = new InMemoryDb(); | ||
_fileDb = new InMemoryFileDb(_db); | ||
|
||
_entity = new Entity(dv_test.EntityLogicalName) | ||
{ | ||
Id = Guid.NewGuid() | ||
}; | ||
|
||
_file = new FileAttachment() | ||
{ | ||
Id = Guid.NewGuid().ToString(), | ||
MimeType = "application/pdf", | ||
FileName = "TestFile.pdf", | ||
Target = _entity.ToEntityReference(), | ||
AttributeName = "dv_file", | ||
Content = new byte[] { 1, 2, 3, 4 } | ||
}; | ||
} | ||
|
||
[Fact] | ||
public void Should_be_empty_when_no_files_are_added() | ||
{ | ||
Assert.Empty(_fileDb.GetAllFiles()); | ||
} | ||
|
||
[Fact] | ||
public void Should_throw_exception_when_a_file_doesnt_exists() | ||
{ | ||
Assert.Throws<CouldNotDeleteFileException>(() => _fileDb.DeleteFile("invalid id")); | ||
} | ||
|
||
[Fact] | ||
public void Should_delete_an_existing_file() | ||
{ | ||
_fileDb.AddFile(_file); | ||
_fileDb.DeleteFile(_file.Id); | ||
|
||
Assert.Empty(_fileDb.GetAllFiles()); | ||
} | ||
} | ||
} |