public void DateDiffDays_Add_Twenty_Five_Days() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StartingDate", new DateTime(2014, 7, 3, 8, 48, 0, 0) }, { "EndingDate", new DateTime(2014, 7, 28, 8, 48, 0, 0) } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const int expected = 25; //Act var result = xrmFakedContext.ExecuteCodeActivity <DateDiffDays>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["DaysDifference"]); }
public void AddMonths_Add_Plus_Fifty() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "OriginalDate", new DateTime(2014, 7, 3, 8, 48, 0, 0) }, { "MonthsToAdd", 50 } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); DateTime expected = new DateTime(2018, 9, 3, 8, 48, 0, 0); //Act var result = xrmFakedContext.ExecuteCodeActivity <AddMonths>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["UpdatedDate"]); }
public void RegexMatch_Contains_Url() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StringToSearch", "http://www.bing.com" }, { "Pattern", @"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const bool expected = true; //Act var result = xrmFakedContext.ExecuteCodeActivity <RegexMatch>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["ContainsPattern"]); }
public void RegexMatch_Does_Not_Contain_Email_Address() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StringToSearch", "test!test.com" }, { "Pattern", @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const bool expected = false; //Act var result = xrmFakedContext.ExecuteCodeActivity <RegexMatch>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["ContainsPattern"]); }
public void RegexMatch_Does_Not_Contain_Html_Tag() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StringToSearch", "Hello World" }, { "Pattern", @"^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const bool expected = false; //Act var result = xrmFakedContext.ExecuteCodeActivity <RegexMatch>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["ContainsPattern"]); }
public void GetWeekNumberOfYear_Valid_Week_Utc() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "DateToUse", new DateTime(2015, 1, 1, 5, 0, 0, DateTimeKind.Utc) }, { "EvaluateAsUserLocal", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const int expected = 1; //Act var result = xrmFakedContext.ExecuteCodeActivity <GetWeekNumberOfYear>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["WeekNumberOfYear"]); }
public void EmailBusinessUnit_No_Users_Business_Unit_With_No_Existing_Users() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); Guid id = Guid.NewGuid(); Entity email = new Entity("email") { Id = id, ["activityid"] = id, ["to"] = new EntityCollection() }; Entity businessUnit = new Entity("businessunit") { Id = Guid.NewGuid() }; var inputs = new Dictionary <string, object> { { "EmailToSend", email.ToEntityReference() }, { "RecipientBusinessUnit", new EntityReference("businessunit", Guid.NewGuid()) }, { "IncludeChildren", false }, { "SendEmail", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { email, businessUnit }); const int expected = 0; //Act var result = xrmFakedContext.ExecuteCodeActivity <EmailBusinessUnit>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["UsersAdded"]); }
public void GetFormattedDateString_2_Digit_24_Hour_Time_Only_User_Local() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); EntityCollection userSettings = new EntityCollection(); Entity userSetting = new Entity("usersettings") { Id = Guid.NewGuid(), ["systemuserid"] = Guid.NewGuid(), ["timezonecode"] = 20 }; userSettings.Entities.Add(userSetting); var inputs = new Dictionary <string, object> { { "DateToUse", new DateTime(2015, 1, 1, 5, 15, 20, DateTimeKind.Utc) }, { "EvaluateAsUserLocal", true }, { "Format", "HH:mm" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { userSetting }); xrmFakedContext.CallerId = new EntityReference("systemuser", userSetting.GetAttributeValue <Guid>("systemuserid")); var fakeLocalTimeFromUtcTimeRequestExecutor = new FakeLocalTimeFromUtcTimeRequestExecutor(); xrmFakedContext.AddFakeMessageExecutor <LocalTimeFromUtcTimeRequest>(fakeLocalTimeFromUtcTimeRequestExecutor); const string expected = "23:15"; //Act var result = xrmFakedContext.ExecuteCodeActivity <GetFormattedDateString>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["FormattedDateString"]); }
public void DependencyTest() { Guid userId = Guid.Parse("9e7ec57b-3a08-4a41-a4d4-354d66f19b65"); XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext { WorkflowCategory = 0, InitiatingUserId = userId, UserId = userId, CorrelationId = Guid.Parse("15cc775b-9ebc-48d1-93a6-b0ce9c920b66"), MessageName = "Update", Mode = 1, Depth = 1, OrganizationName = "test.crm.dynamics.com", OperationCreatedOn = DateTime.Now }; var aiSetup = Configs.GetAiSetup(false, false, false, false, false, false, true); string aiSetupJson = SerializationHelper.SerializeObject <AiSetup>(aiSetup); var inputs = new Dictionary <string, object> { { "AiSetupJson", aiSetupJson }, { "Name", "Hello from DependencyTest - 2" }, { "Method", "GET" }, { "Type", "HTTP" }, { "Duration", 12356 }, { "ResultCode", 200 }, { "Success", true }, { "Data", "Hello from DependencyTest - 2" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); var fakeLogActionExecutor = new FakeLogActionExecutor("lat_ApplicationInsightsLogDependency"); xrmFakedContext.AddFakeMessageExecutor <OrganizationRequest>(fakeLogActionExecutor); var result = xrmFakedContext.ExecuteCodeActivity <LogDependency>(workflowContext, inputs); Assert.IsTrue(bool.Parse(result["LogSuccess"].ToString())); }
public void IsBusinessDay_Week_Day_User_Local() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); EntityCollection userSettings = new EntityCollection(); Entity userSetting = new Entity("usersettings") { Id = Guid.NewGuid(), ["systemuserid"] = Guid.NewGuid(), ["timezonecode"] = 20 }; userSettings.Entities.Add(userSetting); var inputs = new Dictionary <string, object> { { "DateToCheck", new DateTime(2015, 5, 13, 3, 48, 0, 0) }, { "HolidayClosureCalendar", null }, { "EvaluateAsUserLocal", true } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { userSetting }); xrmFakedContext.CallerId = new EntityReference("systemuser", userSetting.GetAttributeValue <Guid>("systemuserid")); var fakeLocalTimeFromUtcTimeRequestExecutor = new FakeLocalTimeFromUtcTimeRequestExecutor(new DateTime(2015, 5, 12, 9, 48, 0, 0)); xrmFakedContext.AddFakeMessageExecutor <LocalTimeFromUtcTimeRequest>(fakeLocalTimeFromUtcTimeRequestExecutor); const bool expected = true; //Act var result = xrmFakedContext.ExecuteCodeActivity <IsBusinessDay>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["ValidBusinessDay"]); }
public void DeleteAttachmentByName_1_Match() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); Guid id = Guid.NewGuid(); Entity email = new Entity("email") { Id = id, ["activityid"] = id }; Entity activityMimeAttachment = new Entity("activitymimeattachment") { Id = Guid.NewGuid(), ["objectid"] = email.Id, ["filename"] = "test.txt" }; var inputs = new Dictionary <string, object> { { "EmailWithAttachments", email.ToEntityReference() }, { "FileName", "test.txt" }, { "AppendNotice", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); xrmFakedContext.Initialize(new List <Entity> { email, activityMimeAttachment }); const int expected = 1; //Act var result = xrmFakedContext.ExecuteCodeActivity <DeleteAttachmentByName>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["NumberOfAttachmentsDeleted"]); }
public void EndsWith_Case_Insensitive_String_Not_Found() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StringToSearch", "Hello" }, { "SearchFor", "test" }, { "CaseSensitive", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const bool expected = false; //Act var result = xrmFakedContext.ExecuteCodeActivity <EndsWith>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["EndsWithString"]); }
public void PadRight_Single_Character_Length_5() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StringToPad", "123456" }, { "PadCharacter", "0" }, { "Length", 5 } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const string expected = "12345600000"; //Act var result = xrmFakedContext.ExecuteCodeActivity <PadRight>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["PaddedString"]); }
public void Average_Mixed_Integers() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "Number1", -5 }, { "Number2", 5 }, { "RoundDecimalPlaces", -1 } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const decimal expected = 0; //Act var result = xrmFakedContext.ExecuteCodeActivity <Average>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["AverageValue"]); }
public void Average_Positive_Doubles_Rounding_2_Places() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "Number1", 5.12435m }, { "Number2", 5.98678m }, { "RoundDecimalPlaces", 2 } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const decimal expected = 5.56m; //Act var result = xrmFakedContext.ExecuteCodeActivity <Average>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["AverageValue"]); }
public void Contains_Case_Sensitive_String_Found() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StringToSearch", "Hello" }, { "SearchFor", "Hello" }, { "CaseSensitive", true } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const bool expected = true; //Act var result = xrmFakedContext.ExecuteCodeActivity <Contains>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["ContainsString"]); }
public void AddBusinessDays_Add_Minus_One_No_Weekend() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "OriginalDate", new DateTime(2014, 7, 3, 8, 48, 0, 0) }, { "BusinessDaysToAdd", -1 }, { "HolidayClosureCalendar", null } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); DateTime expected = new DateTime(2014, 7, 2, 8, 48, 0, 0); //Act var result = xrmFakedContext.ExecuteCodeActivity <AddBusinessDays>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["UpdatedDate"]); }
public void GetFormattedDateString_2_Digit_24_Hour_Time_Only_Utc() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "DateToUse", new DateTime(2015, 1, 1, 5, 15, 20, DateTimeKind.Utc) }, { "EvaluateAsUserLocal", false }, { "Format", "HH:mm" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const string expected = "05:15"; //Act var result = xrmFakedContext.ExecuteCodeActivity <GetFormattedDateString>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["FormattedDateString"]); }
public void DateDiff_Plus_10_Hours_5_Minutes_Without_Seconds() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StartingDate", new DateTime(2014, 7, 2, 18, 53, 0, 0) }, { "EndingDate", new DateTime(2014, 7, 2, 8, 48, 0, 0) }, { "ShowSeconds", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const string expected = "0d.10h:05m"; //Act var result = xrmFakedContext.ExecuteCodeActivity <DateDiff>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["Difference"]); }
public void GetFormattedDateString_2_Digit_With_Slashes_Date_And_Time_With_Milliseconds_Utc() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "DateToUse", new DateTime(2015, 1, 1, 5, 15, 20, DateTimeKind.Utc) }, { "EvaluateAsUserLocal", false }, { "Format", "MM/dd/yyyy HH:mm:ss" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const string expected = "01/01/2015 05:15:20"; //Act var result = xrmFakedContext.ExecuteCodeActivity <GetFormattedDateString>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["FormattedDateString"]); }
public void Substring_Start_Minus2_Length_Null() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StringToParse", "Hello World" }, { "StartPosition", -2 }, { "Length", 0 } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const string expected = "Hello World"; //Act var result = xrmFakedContext.ExecuteCodeActivity <Substring>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["PartialString"]); }
public void RegexReplaceWithSpace_Replace_Multiple() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StringToSearch", "This1is the first number,1is good" }, { "NumberOfSpaces", 1 }, { "Pattern", @"1" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const string expected = "This is the first number, is good"; //Act var result = xrmFakedContext.ExecuteCodeActivity <RegexReplaceWithSpace>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["ReplacedString"]); }
public void Subtract_5_Point_5_From_1() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "Number1", 1 }, { "Number2", 5.5m }, { "RoundDecimalPlaces", -1 } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const decimal expected = -4.5m; //Act var result = xrmFakedContext.ExecuteCodeActivity <Subtract>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["Difference"]); }
public void ToInteger_10() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "TextToConvert", "10" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const bool expected1 = true; const int expected2 = 10; //Act var result = xrmFakedContext.ExecuteCodeActivity <ToInteger>(workflowContext, inputs); //Assert Assert.AreEqual(expected1, result["IsValid"]); Assert.AreEqual(expected2, result["ConvertedNumber"]); }
public void Replace_Multiple_Instances() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StringToSearch", "1 is the first number, 1 is good" }, { "ValueToReplace", "1" }, { "ReplacementValue", "One" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const string expected = "One is the first number, One is good"; //Act var result = xrmFakedContext.ExecuteCodeActivity <Replace>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["ReplacedString"]); }
public void ToDecimal_Negative_10_Point_89() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "TextToConvert", "-10.89" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const bool expected1 = true; const decimal expected2 = -10.89m; //Act var result = xrmFakedContext.ExecuteCodeActivity <ToDecimal>(workflowContext, inputs); //Assert Assert.AreEqual(expected1, result["IsValid"]); Assert.AreEqual(expected2, result["ConvertedNumber"]); }
public void GetMonthName_Valid_Month_Utc_enUS() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "DateToUse", new DateTime(2015, 1, 1, 5, 0, 0, DateTimeKind.Utc) }, { "EvaluateAsUserLocal", false }, { "Culture", "en-US" } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const string expected = "January"; //Act var result = xrmFakedContext.ExecuteCodeActivity <GetMonthName>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["MonthName"]); }
public void Divide_5_By_5_Point_5_Without_Rounding() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary<string, object> { { "Number1", 1 }, { "Number2", 5.5m }, { "RoundDecimalPlaces", -1 } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const decimal expected = 0.1818181818181818181818181818m; //Act var result = xrmFakedContext.ExecuteCodeActivity<Divide>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["Quotient"]); }
public void IsBusinessDay_Week_Day_Utc() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "DateToCheck", new DateTime(2015, 5, 13, 3, 48, 0, 0) }, { "HolidayClosureCalendar", null }, { "EvaluateAsUserLocal", false } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const bool expected = true; //Act var result = xrmFakedContext.ExecuteCodeActivity <IsBusinessDay>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["ValidBusinessDay"]); }
public void DateDiff_Plus_1_Hour() { //Arrange XrmFakedWorkflowContext workflowContext = new XrmFakedWorkflowContext(); var inputs = new Dictionary <string, object> { { "StartingDate", new DateTime(2014, 7, 2, 9, 48, 0, 0) }, { "EndingDate", new DateTime(2014, 7, 2, 8, 48, 0, 0) }, { "ShowSeconds", true } }; XrmFakedContext xrmFakedContext = new XrmFakedContext(); const string expected = "0d.01h:00m:00s"; //Act var result = xrmFakedContext.ExecuteCodeActivity <DateDiff>(workflowContext, inputs); //Assert Assert.AreEqual(expected, result["Difference"]); }