-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#if FAKE_XRM_EASY_9 | ||
using System; | ||
using System.Linq; | ||
using FakeXrmEasy.Abstractions; | ||
using FakeXrmEasy.Abstractions.FakeMessageExecutors; | ||
using FakeXrmEasy.Core.FileStorage.Upload; | ||
using Microsoft.Crm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk; | ||
|
||
namespace FakeXrmEasy.FakeMessageExecutors | ||
{ | ||
/// <summary> | ||
/// Implements the CommitFileBlocksUploadRequest https://learn.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.commitfileblocksuploadrequest?view=dataverse-sdk-latest | ||
/// </summary> | ||
public class CommitFileBlocksUploadRequestExecutor: IFakeMessageExecutor | ||
{ | ||
public bool CanExecute(OrganizationRequest request) | ||
Check warning on line 17 in src/FakeXrmEasy.Messages/FakeMessageExecutors/CommitFileBlocksUploadRequestExecutor.cs GitHub Actions / build-windows (FAKE_XRM_EASY_9)
|
||
{ | ||
return request is CommitFileBlocksUploadRequest; | ||
} | ||
|
||
public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContext ctx) | ||
Check warning on line 22 in src/FakeXrmEasy.Messages/FakeMessageExecutors/CommitFileBlocksUploadRequestExecutor.cs GitHub Actions / build-windows (FAKE_XRM_EASY_9)
|
||
{ | ||
var req = request as CommitFileBlocksUploadRequest; | ||
|
||
var fileDb = (ctx as XrmFakedContext).FileDb; | ||
|
||
var fileId = fileDb.CommitFileUploadSession(new CommitFileUploadSessionProperties() | ||
{ | ||
FileName = req.FileName, | ||
MimeType = req.MimeType, | ||
BlockIdsListSequence = req.BlockList, | ||
FileUploadSessionId = req.FileContinuationToken | ||
}); | ||
|
||
var file = fileDb.GetFileById(fileId); | ||
|
||
return new CommitFileBlocksUploadResponse() | ||
{ | ||
Results = new ParameterCollection() | ||
{ | ||
{ "FileId" , new Guid(fileId) }, | ||
{ "FileSizeInBytes" , (long) file.Content.Length } | ||
} | ||
}; | ||
} | ||
|
||
public Type GetResponsibleRequestType() | ||
Check warning on line 48 in src/FakeXrmEasy.Messages/FakeMessageExecutors/CommitFileBlocksUploadRequestExecutor.cs GitHub Actions / build-windows (FAKE_XRM_EASY_9)
|
||
{ | ||
return typeof(CommitFileBlocksUploadRequest); | ||
} | ||
} | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#if FAKE_XRM_EASY_9 | ||
using System; | ||
using FakeXrmEasy.Abstractions; | ||
using FakeXrmEasy.Abstractions.FakeMessageExecutors; | ||
using FakeXrmEasy.Core.FileStorage.Upload; | ||
using Microsoft.Crm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk; | ||
|
||
namespace FakeXrmEasy.FakeMessageExecutors | ||
{ | ||
/// <summary> | ||
/// Implements the UploadBlockRequest message https://learn.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.uploadblockrequest?view=dataverse-sdk-latest | ||
/// </summary> | ||
public class UploadBlockRequestExecutor: IFakeMessageExecutor | ||
{ | ||
/// <summary> | ||
/// Returns true if the request to execute is an UploadBlockRequest | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public bool CanExecute(OrganizationRequest request) | ||
{ | ||
return request is UploadBlockRequest; | ||
} | ||
|
||
/// <summary> | ||
/// Executes the current request | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <param name="ctx"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContext ctx) | ||
{ | ||
var uploadBlockRequest = request as UploadBlockRequest; | ||
var fileDb = (ctx as XrmFakedContext).FileDb; | ||
|
||
var fileUploadSession = fileDb.GetFileUploadSession(uploadBlockRequest.FileContinuationToken); | ||
fileUploadSession.AddFileBlock(new UploadBlockProperties() | ||
{ | ||
FileContinuationToken = uploadBlockRequest.FileContinuationToken, | ||
BlockContents = uploadBlockRequest.BlockData, | ||
BlockId = uploadBlockRequest.BlockId | ||
}); | ||
|
||
return new UploadBlockResponse(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the type of UploadBlockRequest | ||
/// </summary> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public Type GetResponsibleRequestType() | ||
{ | ||
return typeof(UploadBlockRequest); | ||
} | ||
} | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using FakeXrmEasy.Core.FileStorage.Db; | ||
using Microsoft.Crm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk; | ||
using Xunit; | ||
|
||
namespace FakeXrmEasy.Messages.Tests.FakeMessageExecutors.CommitFileBlocksUploadRequestTests | ||
{ | ||
public class CommitFileBlocksUploadRequestTests: FakeXrmEasyTestsBase | ||
{ | ||
private readonly InMemoryFileDb _fileDb; | ||
private readonly Entity _entity; | ||
|
||
private readonly InitializeFileBlocksUploadRequest _initFileUploadRequest; | ||
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2015)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2015)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2013)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2013)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2016)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2016)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
Check failure on line 14 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
|
||
private readonly CommitFileBlocksUploadRequest _commitFileBlocksUploadRequest; | ||
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2015)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2015)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2013)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2013)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2016)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2016)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
Check failure on line 15 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
|
||
private readonly UploadBlockRequest _uploadBlockRequest; | ||
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2015)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2015)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2013)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2013)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2016)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_2016)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
Check failure on line 16 in tests/FakeXrmEasy.Messages.Tests/FakeMessageExecutors/CommitFileBlocksUploadRequestTests/CommitFileBlocksUploadRequestTests.cs GitHub Actions / build-windows (FAKE_XRM_EASY_365)
|
||
|
||
public CommitFileBlocksUploadRequestTests() | ||
{ | ||
_fileDb = (_context as XrmFakedContext).FileDb; | ||
|
||
_entity = new Entity("dv_test") { Id = Guid.NewGuid() }; | ||
|
||
_initFileUploadRequest = new InitializeFileBlocksUploadRequest() | ||
{ | ||
FileName = "Test.pdf", | ||
Target = _entity.ToEntityReference(), | ||
FileAttributeName = "dv_file" | ||
}; | ||
|
||
_uploadBlockRequest = new UploadBlockRequest() | ||
{ | ||
BlockData = new byte[] { 1, 2, 3, 4 }, | ||
BlockId = new Guid().ToString(), | ||
}; | ||
|
||
_commitFileBlocksUploadRequest = new CommitFileBlocksUploadRequest() | ||
{ | ||
FileName = "Test.pdf", | ||
BlockList = new[] { _uploadBlockRequest.BlockId }, | ||
MimeType = "application/pdf" | ||
}; | ||
} | ||
|
||
[Fact] | ||
public void Should_commit_file_block_upload() | ||
{ | ||
_context.Initialize(_entity); | ||
|
||
var initFileUploadResponse = _service.Execute(_initFileUploadRequest) as InitializeFileBlocksUploadResponse; | ||
|
||
_uploadBlockRequest.FileContinuationToken = initFileUploadResponse.FileContinuationToken; | ||
_service.Execute(_uploadBlockRequest); | ||
|
||
_commitFileBlocksUploadRequest.FileContinuationToken = initFileUploadResponse.FileContinuationToken; | ||
var response = _service.Execute(_commitFileBlocksUploadRequest); | ||
Assert.NotNull(response); | ||
Assert.IsType<CommitFileBlocksUploadResponse>(response); | ||
|
||
var commitResponse = response as CommitFileBlocksUploadResponse; | ||
Assert.Equal(4L, commitResponse.FileSizeInBytes); | ||
Assert.NotEqual(Guid.Empty, commitResponse.FileId); | ||
|
||
var file = _fileDb.GetFileById(commitResponse.FileId.ToString()); | ||
Assert.NotNull(file); | ||
|
||
Assert.Equal(_commitFileBlocksUploadRequest.MimeType, file.MimeType); | ||
Assert.Equal(_uploadBlockRequest.BlockData, file.Content); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#if FAKE_XRM_EASY_9 | ||
using System; | ||
using System.Linq; | ||
using FakeXrmEasy.Core.FileStorage.Db; | ||
using Microsoft.Crm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk; | ||
using Xunit; | ||
|
||
namespace FakeXrmEasy.Messages.Tests.FakeMessageExecutors.UploadBlockRequestTests | ||
{ | ||
public class UploadBlockRequestTests: FakeXrmEasyTestsBase | ||
{ | ||
private readonly InMemoryFileDb _fileDb; | ||
private readonly Entity _entity; | ||
private readonly InitializeFileBlocksUploadRequest _request; | ||
|
||
public UploadBlockRequestTests() | ||
{ | ||
_fileDb = (_context as XrmFakedContext).FileDb; | ||
|
||
_entity = new Entity("dv_test") { Id = Guid.NewGuid() }; | ||
|
||
_request = new InitializeFileBlocksUploadRequest() | ||
{ | ||
FileName = "Test.pdf", | ||
Target = _entity.ToEntityReference(), | ||
FileAttributeName = "dv_file" | ||
}; | ||
} | ||
|
||
[Fact] | ||
public void Should_call_upload_blob_request_with_correct_parameters() | ||
{ | ||
_context.Initialize(_entity); | ||
|
||
var initFileUploadResponse = _service.Execute(_request) as InitializeFileBlocksUploadResponse; | ||
|
||
var request = new UploadBlockRequest() | ||
{ | ||
FileContinuationToken = initFileUploadResponse.FileContinuationToken, | ||
BlockData = new byte[] { 1, 2, 3, 4 }, | ||
BlockId = new Guid().ToString(), | ||
}; | ||
|
||
var response = _service.Execute(request); | ||
Assert.NotNull(response); | ||
Assert.IsType<UploadBlockResponse>(response); | ||
|
||
//Check the blob was added | ||
var fileUploadSession = _fileDb.GetFileUploadSession(initFileUploadResponse.FileContinuationToken); | ||
var fileBlocks = fileUploadSession.GetAllBlocks(); | ||
|
||
Assert.Single(fileBlocks); | ||
|
||
var uploadedFileBlock = fileBlocks.FirstOrDefault(); | ||
Assert.Equal(request.BlockData, uploadedFileBlock.Content); | ||
Assert.Equal(request.BlockId, uploadedFileBlock.BlockId); | ||
} | ||
} | ||
} | ||
#endif |