-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with State attribute types rasied by srauda in Codeplex, see …
- Loading branch information
ramon.tebar
committed
Sep 19, 2017
1 parent
836ae4a
commit 6bd4b73
Showing
7 changed files
with
160 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,10 @@ internal enum PaymentDirections | |
{ | ||
IN = 503530000 | ||
} | ||
|
||
internal enum State | ||
{ | ||
Active = 0, | ||
Inactive = 1 | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...tions.CustomEmails.UnitTests/Common/TextProcessing/BasicTypes/TextProcessorTest_Status.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,76 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using DXTools.CRM.Solutions.CustomEmails.Common.TextProcessing; | ||
using Microsoft.Xrm.Sdk; | ||
using Microsoft.Xrm.Sdk.Fakes; | ||
using Microsoft.Xrm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk.Metadata; | ||
using Microsoft.Xrm.Sdk.Metadata.Fakes; | ||
using Microsoft.QualityTools.Testing.Fakes; | ||
|
||
namespace DXTools.CRM.Solutions.CustomEmails.UnitTests.Common.TextProcessing | ||
{ | ||
[TestClass] | ||
public class TextProcessorTest_Status | ||
{ | ||
[TestMethod] | ||
public void TestTextProcessor_Status() | ||
{ | ||
using (ShimsContext.Create()) | ||
{ | ||
Entity recordContext = new Entity("dxtools_payment"); | ||
recordContext["statecode"] = new OptionSet; | ||
recordContext.Id = Guid.NewGuid(); | ||
|
||
IOrganizationService stubOrganisationService = SetupIOrganisationService(recordContext, "createdon", AttributeTypeCode.DateTime); | ||
|
||
ITextProcessor dynTextProcessor = new TextProcessor(stubOrganisationService); | ||
|
||
string inputText = "Payment Status (statecode) is {statecode}."; | ||
string expected = "Your payment was created on " + DateTime.Now + ", thanks. "; | ||
|
||
string resultOuput = dynTextProcessor.Process(inputText, recordContext.ToEntityReference()); | ||
|
||
Assert.AreEqual(expected, resultOuput); | ||
} | ||
|
||
} | ||
|
||
private IOrganizationService SetupIOrganisationService(Entity recordContext, string attributeName, AttributeTypeCode attributeType) | ||
{ | ||
StubIOrganizationService stubIOrganisationService = new StubIOrganizationService(); | ||
stubIOrganisationService.RetrieveStringGuidColumnSet = (entityLogicalName, recordId, columnSet) | ||
=> | ||
{ | ||
return recordContext; | ||
}; | ||
|
||
stubIOrganisationService.ExecuteOrganizationRequest = (request) | ||
=> | ||
{ | ||
if (request.RequestName == "RetrieveEntity") | ||
{ | ||
RetrieveEntityResponse retrieveEntityResponse = new RetrieveEntityResponse(); | ||
EntityMetadata entityMetadata = new EntityMetadata(); | ||
retrieveEntityResponse["EntityMetadata"] = entityMetadata; | ||
return retrieveEntityResponse; | ||
} | ||
return null; | ||
}; | ||
|
||
Microsoft.Xrm.Sdk.Metadata.Fakes.ShimEntityMetadata.AllInstances.AttributesGet = | ||
(item) => | ||
{ | ||
return new AttributeMetadata[] | ||
{ | ||
new StubAttributeMetadata(attributeType) | ||
{ | ||
LogicalName = attributeName | ||
} | ||
}; | ||
}; | ||
|
||
return stubIOrganisationService; | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ols.CRM.Solutions.CustomEmails.UnitTests/Common/TextProcessing/DuplicateAttributesTest.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,51 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using DXTools.CRM.Solutions.CustomEmails.Common; | ||
using Microsoft.Xrm.Sdk.Fakes; | ||
using Microsoft.Xrm.Sdk; | ||
using System.Collections.Generic; | ||
using Microsoft.Xrm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk.Metadata; | ||
using Microsoft.Xrm.Sdk.Metadata.Fakes; | ||
using Microsoft.QualityTools.Testing.Fakes; | ||
using DXTools.CRM.Solutions.CustomEmails.Common.TextProcessing; | ||
|
||
namespace DXTools.CRM.Solutions.CustomEmails.UnitTests.Common.TextProcessing | ||
{ | ||
[TestClass] | ||
public class DuplicateAttributesTest | ||
{ | ||
[TestMethod] | ||
public void TestTextProcessor_DuplicateAttributes() | ||
{ | ||
string fullname = "John Smith"; | ||
|
||
Entity recordContext = new Entity("dxtools_payment"); | ||
recordContext["fullname"] = fullname; | ||
recordContext.Id = Guid.NewGuid(); | ||
|
||
IOrganizationService stubIOrganizationService = SetupIOrganisationService(recordContext); | ||
|
||
ITextProcessor crmTextProcessor = new TextProcessor(stubIOrganizationService); | ||
|
||
string textToBeProcessed = "Hello dear {fullname}. Now this is a duplicate {fullname}"; | ||
string expected = string.Format("Hello dear {0}. Now this is a duplicate {0}", fullname); | ||
string actualResult = crmTextProcessor.Process(textToBeProcessed, recordContext.ToEntityReference()); | ||
|
||
Assert.AreEqual(expected, actualResult); | ||
} | ||
|
||
private IOrganizationService SetupIOrganisationService(Entity recordContext) | ||
{ | ||
StubIOrganizationService stubIOrganisationService = new StubIOrganizationService(); | ||
stubIOrganisationService.RetrieveStringGuidColumnSet = (entityLogicalName, recordId, columnSet) | ||
=> | ||
{ | ||
return recordContext; | ||
}; | ||
|
||
return stubIOrganisationService; | ||
} | ||
|
||
} | ||
} |
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