public void When_ContactIsUpdatedAndParentAccountIsSet_Expected_TaskIsCreated() { var ctx = new XrmFakedContextWithProxy(); var service = ctx.GetOrganizationService(); var oldParentAccount = TestAccountBase; service.Create(oldParentAccount); var contact = GetTestContactWithParentAccount(oldParentAccount.ToEntityReference()); service.Create(contact); var newParentAccount = TestAccountBase; var target = new Contact { ContactId = contact.ContactId, ParentCustomerId = newParentAccount.ToEntityReference() }; var pluginCtx = new UpdatePostOperationSyncBase(ctx) { TargetEntity = target, PreImage = contact }; ctx.ExecutePluginWithConfigurations <Update>(pluginCtx, string.Empty, string.Empty); ValidateTask(ctx); }
// ReSharper disable once InconsistentNaming public void When_ContactIsUpdatedAndParentAccountIsCleanedUp_Expect_CountryAndStateAreNotChanged() { var ctx = new XrmFakedContextWithProxy(); var service = ctx.GetOrganizationService(); var contact = TestContactBase; var parentAccount = TestAccountBase; service.Create(parentAccount); contact.Address1_Country = parentAccount.Address1_Country; contact.Address1_StateOrProvince = parentAccount.Address1_StateOrProvince; contact.ParentCustomerId = parentAccount.ToEntityReference(); service.Create(contact); var target = contact.Clone <Contact>(); var preImage = target.Clone(); target.ParentCustomerId = null; var pluginCtx = new UpdatePreOperationSyncBase(ctx) { TargetEntity = target, PreImage = preImage }; ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Contact.Update>( pluginCtx, string.Empty, string.Empty); Assert.Equal(parentAccount.Address1_Country, target.Address1_Country); Assert.Equal(parentAccount.Address1_StateOrProvince, target.Address1_StateOrProvince); }
public void When_ContactIsCreatedAndParentAccountIsSet_Expected_TaskIsCreated() { var ctx = new XrmFakedContextWithProxy(); var service = ctx.GetOrganizationService(); var parentAccount = TestAccountBase; service.Create(parentAccount); var target = GetTestContactWithParentAccount(parentAccount.ToEntityReference()); var pluginCtx = new CreatePostOperationSyncBase(ctx) { TargetEntity = target }; ctx.ExecutePluginWithConfigurations <Create>(pluginCtx, string.Empty, string.Empty); ValidateTask(ctx); }
public void When_ContactIsBeingCreatedAndMandatoryFieldsAreSpecified_Expect_PluginNotToFail() { var ctx = new XrmFakedContextWithProxy(); var target = TestContactBase; var pluginCtx = new CreatePreValidationSyncBase(ctx) { TargetEntity = target }; var exc = Record.Exception( () => ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Contact.Create>( pluginCtx, string.Empty, string.Empty)); Assert.Null(exc); }
public void When_CustomExceptionIsEmulated_Expect_PluginNotToFail( string messageName, int stage, int mode, string dummyAccountName, string exceptionMessageTemplate, Type pluginType) { var ctx = new XrmFakedContextWithProxy(); var target = new Account { AccountId = Guid.NewGuid(), Name = $"{dummyAccountName}. Stage:{stage} Mode:{mode}", StateCode = AccountState.Active }; var pluginCtx = new WithTargetEntityBase(ctx) { MessageName = messageName, Stage = stage, Mode = mode, TargetEntity = target }; if (messageName == "Update") { pluginCtx.PreImage = target.Clone(); } var pluginInstance = (IPlugin)Activator.CreateInstance( pluginType, FakedPluginExecCtxBase.CustomVerboseLogSwitchedOnKeyword, string.Empty); if (exceptionMessageTemplate == null) { var exc = Record.Exception( () => ctx.ExecutePluginWith(pluginCtx, pluginInstance)); Assert.Null(exc); } else { var exc = Assert.Throws <InvalidPluginExecutionException>( () => ctx.ExecutePluginWith(pluginCtx, pluginInstance)); var exceptionMessage = string.Format(exceptionMessageTemplate, stage, mode); Assert.Contains(exceptionMessage, exc.Message); } }
public void When_ContactIsBeingCreatedAndMandatoryFieldIsNotSpecified_Expect_PluginToFail(string fieldName) { var ctx = new XrmFakedContextWithProxy(); var target = TestContactBase; target[fieldName] = null; var pluginCtx = new CreatePreValidationSyncBase(ctx) { TargetEntity = target }; var exc = Assert.Throws <InvalidPluginExecutionException>( () => ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Contact.Create>( pluginCtx, string.Empty, string.Empty)); var expectedMessage = string.Format(CommonConstants.MandatoryFieldExceptionMessageTemplate, fieldName); Assert.Contains(expectedMessage, exc.Message); }
public void When_ContactIsBeingUpdatedAndMandatoryFieldsAreSpecified_Expect_PluginNotToFail() { var ctx = new XrmFakedContextWithProxy(); var preImage = TestContactBase; preImage.Attributes.Remove("mobilephone"); var target = TestContactBase.Clone <Contact>(); target.Attributes.Remove("emailaddress"); var pluginCtx = new UpdatePreValidationSyncBase(ctx) { TargetEntity = target, PreImage = preImage }; var exc = Record.Exception( () => ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Contact.Update>( pluginCtx, string.Empty, string.Empty)); Assert.Null(exc); }
// ReSharper disable once InconsistentNaming public void When_ContactIsCreatedAndParentAccountIsSet_Expect_CountryAndStateAreUpdated() { var ctx = new XrmFakedContextWithProxy(); var service = ctx.GetOrganizationService(); var parentAccount = TestAccountBase; service.Create(parentAccount); var target = TestContactBase; target.ParentCustomerId = parentAccount.ToEntityReference(); var pluginCtx = new CreatePreOperationSyncBase(ctx) { TargetEntity = target }; ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Contact.Create>( pluginCtx, string.Empty, string.Empty); Assert.Equal(parentAccount.Address1_Country, target?.Address1_Country); Assert.Equal(parentAccount.Address1_StateOrProvince, target?.Address1_StateOrProvince); }