-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from DynamicsValue/feature/2-6-improvements
Adding fake message executors for DynamicsValue/fake-xrm-easy#157
- Loading branch information
Showing
16 changed files
with
872 additions
and
36 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
69 changes: 69 additions & 0 deletions
69
src/FakeXrmEasy.Messages/FakeMessageExecutors/CommitFileBlocksUploadRequestExecutor.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,69 @@ | ||
#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 | ||
{ | ||
/// <summary> | ||
/// Returns true when the request is a CommitFileBlocksUploadRequest | ||
/// </summary> | ||
/// <param name="request">The request to check if it can be executed by this executor</param> | ||
/// <returns></returns> | ||
public bool CanExecute(OrganizationRequest request) | ||
{ | ||
return request is CommitFileBlocksUploadRequest; | ||
} | ||
|
||
/// <summary> | ||
/// Executes a CommitFileBlocksUploadRequest | ||
/// </summary> | ||
/// <param name="request">The request to execute</param> | ||
/// <param name="ctx">The IXrmFakedContext that this request will be executed against</param> | ||
/// <returns>CommitFileBlocksUploadResponse</returns> | ||
public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContext ctx) | ||
{ | ||
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 } | ||
} | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// The type of CommitFileBlocksUploadRequest | ||
/// </summary> | ||
/// <returns></returns> | ||
public Type GetResponsibleRequestType() | ||
{ | ||
return typeof(CommitFileBlocksUploadRequest); | ||
} | ||
} | ||
} | ||
#endif |
54 changes: 54 additions & 0 deletions
54
src/FakeXrmEasy.Messages/FakeMessageExecutors/DeleteFileRequestExecutor.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,54 @@ | ||
#if FAKE_XRM_EASY_9 | ||
using System; | ||
using FakeXrmEasy.Abstractions; | ||
using FakeXrmEasy.Abstractions.FakeMessageExecutors; | ||
using Microsoft.Crm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk; | ||
|
||
namespace FakeXrmEasy.FakeMessageExecutors | ||
{ | ||
/// <summary> | ||
/// Implements the DeleteFileRequest message https://learn.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.deletefilerequest?view=dataverse-sdk-latest | ||
/// </summary> | ||
public class DeleteFileRequestExecutor: IFakeMessageExecutor | ||
{ | ||
/// <summary> | ||
/// Returns true if the request is a DeleteFileRequest message | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public bool CanExecute(OrganizationRequest request) | ||
{ | ||
return request is DeleteFileRequest; | ||
} | ||
|
||
/// <summary> | ||
/// Implements a fake DeleteFileRequest message | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <param name="ctx"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContext ctx) | ||
{ | ||
var req = request as DeleteFileRequest; | ||
|
||
var fileDb = (ctx as XrmFakedContext).FileDb; | ||
fileDb.DeleteFile(req.FileId.ToString()); | ||
|
||
return new DeleteFileResponse(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the type of DeleteFileRequest | ||
/// </summary> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public Type GetResponsibleRequestType() | ||
{ | ||
return typeof(DeleteFileRequest); | ||
} | ||
} | ||
} | ||
#endif |
66 changes: 66 additions & 0 deletions
66
src/FakeXrmEasy.Messages/FakeMessageExecutors/DownloadBlockRequestExecutor.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,66 @@ | ||
#if FAKE_XRM_EASY_9 | ||
using System; | ||
using FakeXrmEasy.Abstractions; | ||
using FakeXrmEasy.Abstractions.FakeMessageExecutors; | ||
using FakeXrmEasy.Core.FileStorage.Download; | ||
using Microsoft.Crm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk; | ||
|
||
namespace FakeXrmEasy.FakeMessageExecutors | ||
{ | ||
/// <summary> | ||
/// Implements the DownloadBlockRequest message https://learn.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.downloadblockrequest?view=dataverse-sdk-latest | ||
/// </summary> | ||
public class DownloadBlockRequestExecutor: IFakeMessageExecutor | ||
{ | ||
/// <summary> | ||
/// Returns true if the request is a DownloadBlockRequest | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public bool CanExecute(OrganizationRequest request) | ||
{ | ||
return request is DownloadBlockRequest; | ||
} | ||
|
||
/// <summary> | ||
/// Executes a fake implementation of DownloadBlockRequest | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <param name="ctx"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContext ctx) | ||
{ | ||
var req = request as DownloadBlockRequest; | ||
|
||
var fileDb = (ctx as XrmFakedContext).FileDb; | ||
|
||
var data = fileDb.DownloadFileBlock(new DownloadBlockProperties() | ||
{ | ||
FileDownloadSessionId = req.FileContinuationToken, | ||
Offset = req.Offset, | ||
BlockLength = req.BlockLength | ||
}); | ||
|
||
return new DownloadBlockResponse() | ||
{ | ||
Results = new ParameterCollection() | ||
{ | ||
{ "Data", data } | ||
} | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the DownloadBlockRequest type | ||
/// </summary> | ||
/// <returns></returns> | ||
public Type GetResponsibleRequestType() | ||
{ | ||
return typeof(DownloadBlockRequest); | ||
} | ||
} | ||
} | ||
#endif |
71 changes: 71 additions & 0 deletions
71
src/FakeXrmEasy.Messages/FakeMessageExecutors/InitializeFileBlocksDownloadRequestExecutor.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,71 @@ | ||
#if FAKE_XRM_EASY_9 | ||
using System; | ||
using FakeXrmEasy.Abstractions; | ||
using FakeXrmEasy.Abstractions.FakeMessageExecutors; | ||
using FakeXrmEasy.Core.FileStorage.Download; | ||
using Microsoft.Crm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk; | ||
|
||
namespace FakeXrmEasy.FakeMessageExecutors | ||
{ | ||
/// <summary> | ||
/// Implements the InitializeFileBlocksDownloadRequest message https://learn.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.initializefileblocksdownloadrequest?view=dataverse-sdk-latest | ||
/// </summary> | ||
public class InitializeFileBlocksDownloadRequestExecutor: IFakeMessageExecutor | ||
{ | ||
/// <summary> | ||
/// Returns true if InitializeFileBlocksDownloadRequest can be executed | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public bool CanExecute(OrganizationRequest request) | ||
{ | ||
return request is InitializeFileBlocksDownloadRequest; | ||
} | ||
|
||
/// <summary> | ||
/// Executes a fake implementation of InitializeFileBlocksDownloadRequest | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <param name="ctx"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContext ctx) | ||
{ | ||
var req = request as InitializeFileBlocksDownloadRequest; | ||
|
||
var fileDb = (ctx as XrmFakedContext).FileDb; | ||
|
||
var fileContinuationToken = fileDb.InitFileDownloadSession(new FileDownloadProperties() | ||
{ | ||
Target = req.Target, | ||
FileAttributeName = req.FileAttributeName | ||
}); | ||
|
||
var fileDownloadSession = fileDb.GetFileDownloadSession(fileContinuationToken); | ||
|
||
return new InitializeFileBlocksDownloadResponse() | ||
{ | ||
Results = new ParameterCollection() | ||
{ | ||
{ "FileContinuationToken", fileContinuationToken }, | ||
{ "FileSizeInBytes", (long) fileDownloadSession.File.Content.Length }, | ||
{ "FileName", fileDownloadSession.File.FileName }, | ||
{ "IsChunkingSupported", true }, | ||
} | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the type of InitializeFileBlocksDownloadRequest | ||
/// </summary> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public Type GetResponsibleRequestType() | ||
{ | ||
return typeof(InitializeFileBlocksDownloadRequest); | ||
} | ||
} | ||
} | ||
#endif |
64 changes: 64 additions & 0 deletions
64
src/FakeXrmEasy.Messages/FakeMessageExecutors/InitializeFileBlocksUploadRequestExecutor.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,64 @@ | ||
#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 InitializeFileBlocksUploadRequest message: https://learn.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.initializefileblocksuploadrequest?view=dataverse-sdk-latest | ||
/// </summary> | ||
public class InitializeFileBlocksUploadRequestExecutor: IFakeMessageExecutor | ||
{ | ||
/// <summary> | ||
/// Returns true when asked if it can execute an InitializeFileBlocksUploadRequest message | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <returns></returns> | ||
public bool CanExecute(OrganizationRequest request) | ||
{ | ||
return request is InitializeFileBlocksUploadRequest; | ||
} | ||
|
||
/// <summary> | ||
/// Executes a fake implementation of the request using an In-Memory File Storage mechanism | ||
/// </summary> | ||
/// <param name="request">The request to execute</param> | ||
/// <param name="ctx">The context to store the files against</param> | ||
/// <returns>InitializeFileBlocksUploadResponse</returns> | ||
public OrganizationResponse Execute(OrganizationRequest request, IXrmFakedContext ctx) | ||
{ | ||
InitializeFileBlocksUploadRequest req = (InitializeFileBlocksUploadRequest)request; | ||
|
||
var fileDb = (ctx as XrmFakedContext).FileDb; | ||
|
||
var fileUploadSession = fileDb.InitFileUploadSession(new FileUploadProperties() | ||
{ | ||
Target = req.Target, | ||
FileName = req.FileName, | ||
FileAttributeName = req.FileAttributeName | ||
}); | ||
|
||
return new InitializeFileBlocksUploadResponse() | ||
{ | ||
Results = new ParameterCollection() | ||
{ | ||
{ "FileContinuationToken" , fileUploadSession } | ||
} | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the type of InitializeFileBlocksUploadResponse | ||
/// </summary> | ||
/// <returns></returns> | ||
public Type GetResponsibleRequestType() | ||
{ | ||
return typeof(InitializeFileBlocksUploadRequest); | ||
} | ||
} | ||
} | ||
#endif |
Oops, something went wrong.