Ejemplo n.º 1
0
        public void TestDownloadFiles()
        {
            CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["integration_testing"].ConnectionString);
            var userId = crmSvc.GetMyCrmUserId();
            var trace  = new TraceLogger();
            var task   = new DownloadWebresourceFileTask(crmSvc, trace);
            var path   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                      @"..\..\..\Webresources");

            task.Execute(path);
        }
Ejemplo n.º 2
0
        public void TestDownloadnNewFiles()
        {
            // Test that the files are downloaded and added to the spkl.json
            // as well as saved to disc
            // Arrange
            var config = A.Fake <ConfigFile>(a => a.CallsBaseMethods());

            config.filePath  = @"C:\tests\";
            config.solutions = new List <SolutionPackageConfig>()
            {
                new SolutionPackageConfig()
                {
                    solution_uniquename = "testsolution",
                    map = new List <SolutionPackageMap>()
                    {
                        new SolutionPackageMap()
                        {
                            map  = MapTypes.path,
                            from = "WebResources\\*.*",
                            to   = "WebResourcesFiles\\**"
                        }
                    }
                }
            };

            IDirectoryService    directoryService;
            IOrganizationService service;
            TraceLogger          trace;

            Arrange(config, out directoryService, out service, out trace);

            A.CallTo(() => directoryService.SaveFile(
                         A <string> .Ignored,
                         A <byte[]> .Ignored,
                         A <bool> .Ignored)).Invokes((string name, byte[] content, bool overwrite) =>
            {
                Assert.AreEqual(@"C:\tests\WebResourcesFiles\new_\foo\bar.js", name);
            });

            A.CallTo(() => service.Execute(A <OrganizationRequest> .Ignored))
            .ReturnsLazily((OrganizationRequest request) =>
            {
                var query = request as RetrieveMultipleRequest;
                Assert.IsNotNull(query);
                var expression = query.Query as QueryExpression;
                Assert.IsNotNull(expression);
                Assert.AreEqual(WebResource.EntityLogicalName, expression.EntityName);

                var list = new List <Entity>()
                {
                    new WebResource
                    {
                        Name        = @"new_\foo\bar.js",
                        Description = @"something",
                        DisplayName = @"new_\foo\bar.js",
                        Content     = Convert.ToBase64String(Encoding.ASCII.GetBytes("test"))
                    }
                };

                var response = new RetrieveMultipleResponse();
                response.Results["EntityCollection"] = new EntityCollection(list);
                response.ResponseName = "RetrieveMultipleResponse";
                return(response);
            });

            // Act
            var task = new DownloadWebresourceFileTask(service, trace);

            task.Execute(config.filePath);

            // Assert
            Assert.AreEqual(1, config.webresources[0].files.Count);
            Assert.AreEqual(@"new_\foo\bar.js", config.webresources[0].files[0].uniquename);
            Assert.AreEqual(@"new_\foo\bar.js", config.webresources[0].files[0].displayname);
            Assert.AreEqual(@"WebResourcesFiles\new_\foo\bar.js", config.webresources[0].files[0].file);
            A.CallTo(() => config.Save()).MustHaveHappened(Repeated.Exactly.Once);
        }
Ejemplo n.º 3
0
        public void TestDownloadExistingFilesWithRoot()
        {
            // Test that if we are using a root folder path in the spkl.json then
            // it is used when adding the file locations
            // Also check that the spkl.json isn't added to if the files are there already
            var config = A.Fake <ConfigFile>(a => a.CallsBaseMethods());

            config.filePath  = @"C:\tests\another";
            config.solutions = new List <SolutionPackageConfig>()
            {
                new SolutionPackageConfig()
                {
                    solution_uniquename = "testsolution",
                    map = new List <SolutionPackageMap>()
                    {
                        new SolutionPackageMap()
                        {
                            map  = MapTypes.path,
                            from = "WebResources\\*.*",
                            to   = "WebResourcesFiles\\**"
                        }
                    }
                }
            };
            config.webresources = new List <WebresourceDeployConfig>()
            {
                new WebresourceDeployConfig()
                {
                    root  = "root_folder",
                    files = new List <WebResourceFile>()
                    {
                        new WebResourceFile()
                        {
                            uniquename  = @"new_\foo\bar.js",
                            displayname = @"new_\foo\bar.js",
                            file        = @"WebResourcesFiles\new_\foo\bar.js"
                        }
                    }
                }
            };

            IDirectoryService    directoryService;
            IOrganizationService service;
            TraceLogger          trace;

            Arrange(config, out directoryService, out service, out trace);

            A.CallTo(() => directoryService.SaveFile(
                         A <string> .Ignored,
                         A <byte[]> .Ignored,
                         A <bool> .Ignored)).Invokes((string name, byte[] content, bool overwrite) =>
            {
                Assert.AreEqual(@"C:\tests\another\root_folder\WebResourcesFiles\new_\foo\bar.js", name);
            });

            A.CallTo(() => service.Execute(A <OrganizationRequest> .Ignored))
            .ReturnsLazily((OrganizationRequest request) =>
            {
                var query = request as RetrieveMultipleRequest;
                Assert.IsNotNull(query);
                var expression = query.Query as QueryExpression;
                Assert.IsNotNull(expression);
                Assert.AreEqual(WebResource.EntityLogicalName, expression.EntityName);

                var list = new List <Entity>()
                {
                    new WebResource
                    {
                        Name        = @"new_\foo\bar.js",
                        Description = @"something",
                        DisplayName = @"new_\foo\bar.js",
                        Content     = Convert.ToBase64String(Encoding.ASCII.GetBytes("test"))
                    }
                };

                var response = new RetrieveMultipleResponse();
                response.Results["EntityCollection"] = new EntityCollection(list);
                response.ResponseName = "RetrieveMultipleResponse";
                return(response);
            });

            // Act
            var task = new DownloadWebresourceFileTask(service, trace);

            task.Execute(config.filePath);

            // Assert
            // There shouldn't be any additional files added because they were already there
            Assert.AreEqual(1, config.webresources[0].files.Count);
            Assert.AreEqual(@"new_\foo\bar.js", config.webresources[0].files[0].uniquename);
            Assert.AreEqual(@"new_\foo\bar.js", config.webresources[0].files[0].displayname);
            Assert.AreEqual(@"WebResourcesFiles\new_\foo\bar.js", config.webresources[0].files[0].file);
            A.CallTo(() => config.Save()).MustHaveHappened(Repeated.Exactly.Once);
        }
Ejemplo n.º 4
0
        private static void RunTask(CommandLineArgs arguments, IOrganizationService service, ITrace trace)
        {
            if (arguments.Path == null)
            {
                arguments.Path = Directory.GetCurrentDirectory();
            }
            else
            {
                // Strip trailing \
                arguments.Path = arguments.Path.TrimEnd('\\');
                arguments.Path = Path.Combine(Directory.GetCurrentDirectory(), arguments.Path);
            }

            BaseTask task    = null;
            string   command = arguments.Task.ToLower();

            switch (command)
            {
            case "plugins":
                trace.WriteLine("Deploying Plugins");
                task = new DeployPluginsTask(service, trace);
                break;

            case "workflow":
                trace.WriteLine("Deploying Custom Workflow Activities");
                task = new DeployWorkflowActivitiesTask(service, trace);
                break;

            case "webresources":
                trace.WriteLine("Deploying WebResources");
                task = new DeployWebResourcesTask(service, trace);
                break;

            case "instrument":
                trace.WriteLine("Downloading Plugin/Workflow Activity Metadata");
                task = new DownloadPluginMetadataTask(service, trace);
                break;

            case "download-webresources":
                trace.WriteLine("Downloading Webresources");
                task = new DownloadWebresourceFileTask(service, trace)
                {
                    Overwrite = arguments.Overwrite
                };
                break;

            case "get-webresources":
                trace.WriteLine("Downloading Webresources");
                task        = new DownloadWebresourceConfigTask(service, trace);
                task.Prefix = arguments.Prefix;
                break;

            case "earlybound":
                trace.WriteLine("Generating early bound types");
                var earlyBound = new EarlyBoundClassGeneratorTask(service, trace);
                task = earlyBound;
                earlyBound.ConectionString = arguments.Connection;
                break;

            case "unpack":
                trace.WriteLine("Unpacking solution");
                var packager = new SolutionPackagerTask(service, trace);
                packager.command = command;
                task             = packager;
                break;

            case "unpacksolution":
                trace.WriteLine("Unpacking solution Zip");
                var unpackfromsolution = new SolutionPackagerTask(service, trace);
                unpackfromsolution.command = command;
                task = unpackfromsolution;
                break;

            case "pack":
                trace.WriteLine("Packing Solution");
                var pack = new SolutionPackagerTask(service, trace);
                pack.command = command;
                task         = pack;
                break;

            case "import":
                trace.WriteLine("Packing & Import Solution");
                var import = new SolutionPackagerTask(service, trace);
                import.command = command;
                task           = import;
                break;

            case "compare":
                trace.WriteLine("Comparing Solution");
                var compare = new SolutionPackagerTask(service, trace);
                compare.command = command;
                task            = compare;
                break;
            }


            if (task != null)
            {
                if (arguments.Profile != null)
                {
                    task.Profile = arguments.Profile;
                }
                task.Execute(arguments.Path);
            }
            else
            {
                throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.NO_TASK_SUPPLIED, String.Format("Task '{0}' not recognised. Please consult help!", arguments.Task.ToLower()));
            }
        }