-
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.
Deletes a file when an update to the file attribute is set to null Dy…
- Loading branch information
1 parent
7be6fb0
commit fe3db51
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
7 changes: 7 additions & 0 deletions
7
tests/FakeXrmEasy.Core.Tests/FileStorage/Db/InMemoryFileDbInternalTests.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,7 @@ | ||
namespace FakeXrmEasy.Core.Tests.FileStorage.Db | ||
{ | ||
public class InMemoryFileDbInternalTests | ||
{ | ||
|
||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
tests/FakeXrmEasy.Core.Tests/FileStorage/Db/UpdateFileTests.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,60 @@ | ||
using System; | ||
using DataverseEntities; | ||
using FakeXrmEasy.Core.Db; | ||
using FakeXrmEasy.Core.FileStorage.Db; | ||
using Microsoft.Xrm.Sdk; | ||
using Xunit; | ||
using FileAttachment = FakeXrmEasy.Core.FileStorage.Db.FileAttachment; | ||
|
||
namespace FakeXrmEasy.Core.Tests.FileStorage.Db | ||
{ | ||
public class UpdateFileTests: FakeXrmEasyTestsBase | ||
{ | ||
private const string FILE_ATTRIBUTE_NAME = "dv_file"; | ||
|
||
private readonly InMemoryDb _db; | ||
private readonly InMemoryFileDb _fileDb; | ||
private readonly Entity _entity; | ||
private readonly FileAttachment _file; | ||
|
||
public UpdateFileTests() | ||
{ | ||
_db = (_context as XrmFakedContext).Db; | ||
_fileDb = (_context as XrmFakedContext).FileDb; | ||
|
||
_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 = FILE_ATTRIBUTE_NAME, | ||
Content = new byte[] { 1, 2, 3, 4 } | ||
}; | ||
|
||
_entity[FILE_ATTRIBUTE_NAME] = _file.Id; | ||
} | ||
|
||
[Fact] | ||
public void Should_remove_file_when_updating_file_attribute_to_null() | ||
{ | ||
_fileDb.AddFile(_file); | ||
_context.Initialize(_entity); | ||
|
||
var entityToUpdate = new Entity(_entity.LogicalName) | ||
{ | ||
Id = _entity.Id, | ||
[FILE_ATTRIBUTE_NAME] = null | ||
}; | ||
|
||
_service.Update(entityToUpdate); | ||
|
||
Assert.Empty(_fileDb.GetAllFiles()); | ||
} | ||
} | ||
} |