Esempio n. 1
0
        public static T Create()
        {
            var createTask = new CreateTask {
                TaskType = typeof(T)
            };

            createTask.Execute();
            return(createTask.TaskInstance as T);
        }
Esempio n. 2
0
        public void should_provide_proxy_instance_if_given_type_is_decorated_with_execution_callbacks_attribute()
        {
            // Arrange
            var task = new CreateTask {
                TaskType = typeof(MockTaskWithAttributes)
            };

            // Act
            task.Execute();

            // Assert
            Assert.That(task.TaskInstance, Is.InstanceOf <MockTaskWithAttributes>());
            Assert.That(task.TaskInstance.GetType().Name, Is.EqualTo("MockTaskWithAttributesProxy"));
        }
Esempio n. 3
0
        public TaskModel CreateTask(string taskName, string description, string dateTimeDue)
        {
            if (taskName == null)
            {
                return(null);
            }

            var task = new TaskModel(taskName, description, dateTimeDue);

            bool result = _CreateTask.Execute(task);

            if (!result)
            {
                return(null);
            }

            return(task);
        }
Esempio n. 4
0
        public void Run(string options)
        {
            if (Task == null)
            {
                var createTask = new CreateTask {
                    In = { TaskType = typeof(TTask) }
                };
                createTask.Execute();
                Task = (TTask)createTask.Out.TaskInstance;
            }

            foreach (var option in Options)
            {
                var match = Regex.Match(options, option.Pattern);
                if (match.Success)
                {
                    option.Action((TTask)Task, match);
                    options = options.Replace(match.ToString(), "");
                }
            }

            Task.Execute();
        }
Esempio n. 5
0
        public void Execute_Test()
        {
            try
            {
                //ARRANGE
                var serviceMock             = new Mock <IOrganizationService>();
                var factoryMock             = new Mock <IOrganizationServiceFactory>();
                var tracingServiceMock      = new Mock <ITracingService>();
                var notificationServiceMock = new Mock <IServiceEndpointNotificationService>();
                var pluginContextMock       = new Mock <IPluginExecutionContext>();
                var serviceProviderMock     = new Mock <IServiceProvider>();

                //create a guid that we want our mock CRM organization service Create method to return when called
                Guid idToReturn = Guid.NewGuid();

                //next - create an entity object that will allow us to capture the entity record that is passed to the Create method
                Entity actualEntity = new Entity();

                //setup the CRM service mock
                serviceMock.Setup(t =>
                                  t.Create(It.IsAny <Entity>()))

                //when Create is called with any entity as an invocation parameter
                .Returns(idToReturn)                       //return the idToReturn guid
                .Callback <Entity>(s => actualEntity = s); //store the Create method invocation parameter for inspection later
                IOrganizationService service = serviceMock.Object;

                //set up a mock servicefactory using the CRM service mock
                factoryMock.Setup(t => t.CreateOrganizationService(It.IsAny <Guid>())).Returns(service);
                var factory = factoryMock.Object;

                //set up a mock tracingservice - will write output to console
                tracingServiceMock.Setup(t => t.Trace(It.IsAny <string>(), It.IsAny <object[]>())).Callback <string, object[]>((t1, t2) => Console.WriteLine(t1, t2));
                var tracingService = tracingServiceMock.Object;

                //set up mock notificationservice - not going to do anything with this
                var notificationService = notificationServiceMock.Object;

                //set up mock plugincontext with input/output parameters, etc.
                Entity targetEntity = new Entity("account");
                targetEntity.LogicalName = "account";

                //userid to be used inside the plug-in
                Guid userId = Guid.NewGuid();

                //"generated" account id
                Guid accountId = Guid.NewGuid();

                //get parameter collections ready
                ParameterCollection inputParameters = new ParameterCollection();
                inputParameters.Add("Target", targetEntity);
                ParameterCollection outputParameters = new ParameterCollection();
                outputParameters.Add("id", accountId);

                //finish preparing the plugincontextmock
                pluginContextMock.Setup(t => t.InputParameters).Returns(inputParameters);
                pluginContextMock.Setup(t => t.OutputParameters).Returns(outputParameters);
                pluginContextMock.Setup(t => t.UserId).Returns(userId);
                pluginContextMock.Setup(t => t.PrimaryEntityName).Returns("account");
                var pluginContext = pluginContextMock.Object;

                //set up a serviceprovidermock
                serviceProviderMock.Setup(t => t.GetService(It.Is <Type>(i => i == typeof(IServiceEndpointNotificationService)))).Returns(notificationService);
                serviceProviderMock.Setup(t => t.GetService(It.Is <Type>(i => i == typeof(ITracingService)))).Returns(tracingService);
                serviceProviderMock.Setup(t => t.GetService(It.Is <Type>(i => i == typeof(IOrganizationServiceFactory)))).Returns(factory);
                serviceProviderMock.Setup(t => t.GetService(It.Is <Type>(i => i == typeof(IPluginExecutionContext)))).Returns(pluginContext);
                var serviceProvider = serviceProviderMock.Object;

                //ACT
                //instantiate the plugin object and execute it with the testserviceprovider
                CreateTask followupPlugin = new CreateTask();
                followupPlugin.Execute(serviceProvider);

                //ASSERT
                //verify the entity created inside the plugin the values we expect
                Assert.AreEqual("Send e-mail to the new customer.", actualEntity["subject"]);
                Assert.AreEqual("Follow up with the customer. Check if there are any new issues that need resolution.", actualEntity["description"]);
                Assert.AreEqual(DateTime.Now.ToLongDateString(), ((DateTime)actualEntity["scheduledstart"]).ToLongDateString());          //lazy way to get around milliseconds being different
                Assert.AreEqual(DateTime.Now.AddDays(2).ToLongDateString(), ((DateTime)actualEntity["scheduledend"]).ToLongDateString()); //lazy way to get around milliseconds being different
                Assert.AreEqual("account", actualEntity["category"]);
                Assert.AreEqual(accountId, ((EntityReference)actualEntity["regardingobjectid"]).Id);
            }
            catch (Exception ex)
            {
                throw new System.IO.FileNotFoundException(ex.Message);
            }
        }