Ejemplo n.º 1
0
        public void Projects_CanBeCreatedAndDeleted_Successfully()
        {
            var name = "Test Project " + DateTime.Now.ToStringInvariant();

            //Test create a new project successfully
            var project = _api.CreateProject(name, Language.CSharp);

            Assert.IsTrue(project.Success);
            Assert.IsTrue(project.Projects.First().ProjectId > 0);
            Assert.IsTrue(project.Projects.First().Name == name);

            // Delete the project
            var deleteProject = _api.DeleteProject(project.Projects.First().ProjectId);

            Assert.IsTrue(deleteProject.Success);

            // Make sure the project is really deleted
            var projectList = _api.ListProjects();

            Assert.IsFalse(projectList.Projects.Any(p => p.ProjectId == project.Projects.First().ProjectId));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs the algorithm with the given settings and file
        /// </summary>
        /// <param name="settings">Settings for Lean</param>
        /// <param name="file">File to run</param>
        private void RunLiveAlgorithm(BaseLiveAlgorithmSettings settings, ProjectFile file)
        {
            // Create a new project
            var project = _api.CreateProject($"Test project - {DateTime.Now.ToStringInvariant()}", Language.CSharp);

            // Add Project Files
            var addProjectFile = _api.AddProjectFile(project.Projects.First().ProjectId, file.Name, file.Code);

            Assert.IsTrue(addProjectFile.Success);

            // Create compile
            var compile = _api.CreateCompile(project.Projects.First().ProjectId);

            Assert.IsTrue(compile.Success);

            // Wait at max 30 seconds for project to compile
            Compile compileCheck = WaitForCompilerResponse(project.Projects.First().ProjectId, compile.CompileId, 30);

            Assert.IsTrue(compileCheck.Success);
            Assert.IsTrue(compileCheck.State == CompileState.BuildSuccess);

            // Get a live node to launch the algorithm on
            var nodes = _api.ReadNodes(_testOrganization);

            Assert.IsTrue(nodes.Success);
            var freeNode = nodes.LiveNodes.Where(x => x.Busy == false);

            Assert.IsNotEmpty(freeNode, "No free Live Nodes found");

            // Create live default algorithm
            var createLiveAlgorithm = _api.CreateLiveAlgorithm(project.Projects.First().ProjectId, compile.CompileId, freeNode.FirstOrDefault().Id, settings);

            Assert.IsTrue(createLiveAlgorithm.Success);

            if (stopLiveAlgos)
            {
                // Liquidate live algorithm; will also stop algorithm
                var liquidateLive = _api.LiquidateLiveAlgorithm(project.Projects.First().ProjectId);
                Assert.IsTrue(liquidateLive.Success);

                // Delete the project
                var deleteProject = _api.DeleteProject(project.Projects.First().ProjectId);
                Assert.IsTrue(deleteProject.Success);
            }
        }