Esempio n. 1
0
        static ProviderSettings getTypesProvider(string location)
        {
            var path = "";

            if (location.Contains(".." + Path.DirectorySeparatorChar))
            {
                path = new PathParser(Environment.CurrentDirectory).ToAbsolute(location);
            }
            else
            {
                path = Path.GetFullPath(location);
            }

            if (File.Exists(path) || Path.GetFileName(path).Contains("*"))
            {
                path = Path.GetDirectoryName(path);
            }

            path = Path.GetFullPath(path);
            var projectFile = new ProjectLocator().Locate(path);

            if (projectFile == null)
            {
                Console.WriteLine("error|Could not locate a project file for {0}", path);
                return(null);
            }
            return(getTypesProviderByProject(projectFile));
        }
        public void FindSlnFiles_ReturnsSlnFiles()
        {
            var files = ProjectLocator.FindSlnFiles().ToArray();

            Assert.NotEmpty(files);
            Assert.NotNull(files.FirstOrDefault(f => f.Name == $"{nameof(DockerizedTesting)}.sln"));
        }
        public async Task <IReadOnlyCollection <IProjectModelZoneNode> > GetZoneNodesAsync(
            ProjectLocator project,
            bool forceReload,
            CancellationToken token)
        {
            using (ApplicationTraceSources.Default.TraceMethod().WithParameters(project, forceReload))
            {
                IReadOnlyCollection <IProjectModelZoneNode> zones = null;
                using (await this.cacheLock.AcquireAsync(token).ConfigureAwait(false))
                {
                    if (!this.cachedZones.TryGetValue(
                            project,
                            out zones) || forceReload)
                    {
                        //
                        // Load from backend and cache.
                        //
                        zones = await LoadZones(project, token)
                                .ConfigureAwait(false);

                        this.cachedZones[project] = zones;
                    }
                }

                Debug.Assert(zones != null);

                return(zones);
            }
        }
Esempio n. 4
0
        public void WhenReferencesAreEquivalent_ThenGetHasCodeIsSame()
        {
            var ref1 = new ProjectLocator("proj");
            var ref2 = new ProjectLocator("proj");

            Assert.AreEqual(ref1.GetHashCode(), ref2.GetHashCode());
        }
Esempio n. 5
0
        public void WhenCreatedFromPath_ThenToStringReturnsPath()
        {
            var path = "projects/project-1";

            Assert.AreEqual(
                path,
                ProjectLocator.FromString(path).ToString());
        }
        void GetPathOfDockerProjectReturnsCorrectPath(string name)
        {
            var projectLocator = new ProjectLocator();
            var fileInfo       = projectLocator.GetDockerProject(name);

            Assert.True(fileInfo.Exists);
            Assert.Equal("ExampleProject.csproj", fileInfo.Name);
        }
Esempio n. 7
0
        public void WhenQualifiedByGoogleapisHost_FromStringReturnsObject()
        {
            var ref1 = ProjectLocator.FromString(
                "https://www.googleapis.com/compute/v1/projects/project-1");

            Assert.AreEqual("projects", ref1.ResourceType);
            Assert.AreEqual("project-1", ref1.Name);
            Assert.AreEqual("project-1", ref1.ProjectId);
        }
Esempio n. 8
0
        public void WhenPathIsValid_FromStringReturnsObject()
        {
            var ref1 = ProjectLocator.FromString(
                "projects/project-1");

            Assert.AreEqual("projects", ref1.ResourceType);
            Assert.AreEqual("project-1", ref1.Name);
            Assert.AreEqual("project-1", ref1.ProjectId);
        }
Esempio n. 9
0
        public void WhenCreatedFromUrl_ThenToStringReturnsPath()
        {
            var path = "projects/project-1";

            Assert.AreEqual(
                path,
                ProjectLocator.FromString(
                    "https://www.googleapis.com/compute/v1/" + path).ToString());
        }
        //---------------------------------------------------------------------
        // Ctor.
        //---------------------------------------------------------------------

        public ProjectNode(
            ProjectLocator locator,
            bool accessible,
            string displayName)
        {
            this.Project     = locator;
            this.IsAccesible = accessible;
            this.DisplayName = displayName;
        }
Esempio n. 11
0
        public void WhenReferencesAreEquivalent_ThenEqualsReturnsTrue()
        {
            var ref1 = new ProjectLocator("proj");
            var ref2 = new ProjectLocator("proj");

            Assert.IsTrue(ref1.Equals(ref2));
            Assert.IsTrue(ref1.Equals((object)ref2));
            Assert.IsTrue(ref1 == ref2);
            Assert.IsFalse(ref1 != ref2);
        }
Esempio n. 12
0
        public void TestEqualsNull()
        {
            var ref1 = new ProjectLocator("proj");

            Assert.IsFalse(ref1.Equals(null));
            Assert.IsFalse(ref1.Equals((object)null));
            Assert.IsFalse(ref1 == null);
            Assert.IsFalse(null == ref1);
            Assert.IsTrue(ref1 != null);
            Assert.IsTrue(null != ref1);
        }
Esempio n. 13
0
        public async Task BuildsImageFromDockerfile()
        {
            var dockerFile = ProjectLocator.FindSlnFiles().First().Directory
                             .GetDirectories("Examples").Single()
                             .GetDirectories("ExampleProject").Single()
                             .GetFiles("Dockerfile").Single();

            var client   = new DockerClientProvider().GetDockerClient();
            var provider = new DockerfileImageProvider(dockerFile, "..");

            string image = await provider.GetImage(client);

            Assert.NotNull(image);
        }
        //---------------------------------------------------------------------
        // IProjectModelService.
        //---------------------------------------------------------------------

        public async Task AddProjectAsync(ProjectLocator project)
        {
            using (ApplicationTraceSources.Default.TraceMethod().WithParameters(project))
            {
                this.serviceProvider
                .GetService <IProjectRepository>()
                .AddProject(project);

                await this.serviceProvider
                .GetService <IEventService>()
                .FireAsync(new ProjectAddedEvent(project.ProjectId))
                .ConfigureAwait(false);
            }
        }
Esempio n. 15
0
        public List <TestOccurrences> All(ProjectLocator locator)
        {
            var result = new List <TestOccurrences>()
            {
                ByProjectLocator(locator)
            };

            while (!(string.IsNullOrEmpty(result.Last().NextHref)))
            {
                var response = m_caller.Get <TestOccurrences>(result.Last().NextHref, false);
                result.Add(response);
            }
            return(result);
        }
        public async Task GetImageBuildsProjectFromFile()
        {
            var file = ProjectLocator.GetCurrentDir().Parent?.Parent?.Parent?.Parent
                       ?.GetFiles("ExampleProject.csproj", SearchOption.AllDirectories).Single();
            var imageSource = new DockerfileImageProvider(file);

            string tag = await imageSource.GetImage(null);

            var image = await new DockerClientProvider().GetDockerClient().Images
                        .ListImagesAsync(new ImagesListParameters {
                MatchName = tag
            });

            Assert.Single(image);
        }
Esempio n. 17
0
        public async Task FindsDockerFileWhenSuppliedWithProjectName()
        {
            var dockerFile = ProjectLocator.FindSlnFiles().First().Directory
                             .GetDirectories("Examples").Single()
                             .GetDirectories("ExampleProject").Single()
                             .GetFiles("Dockerfile").Single();

            var locator = new Mock <IDockerfileLocator>();

            locator.Setup(l => l.GetDockerfile(new KeyValuePair <string, string>("project", "foo")))
            .Returns(dockerFile).Verifiable();
            var client   = new DockerClientProvider().GetDockerClient();
            var provider = new DockerfileImageProvider("foo", "..", null, locator.Object);
            var image    = await provider.GetImage(client);

            Assert.NotNull(image);
            locator.Verify();
        }
        private async Task <IReadOnlyCollection <IProjectModelZoneNode> > LoadZones(
            ProjectLocator project,
            CancellationToken token)
        {
            using (ApplicationTraceSources.Default.TraceMethod().WithoutParameters())
                using (var computeEngineAdapter = this.serviceProvider
                                                  .GetService <IComputeEngineAdapter>())
                {
                    var instances = await computeEngineAdapter
                                    .ListInstancesAsync(project.ProjectId, token)
                                    .ConfigureAwait(false);

                    var zoneLocators = instances
                                       .EnsureNotNull()
                                       .Select(i => ZoneLocator.FromString(i.Zone))
                                       .ToHashSet();

                    var zones = new List <ZoneNode>();
                    foreach (var zoneLocator in zoneLocators.OrderBy(z => z.Name))
                    {
                        var instancesInZone = instances
                                              .Where(i => ZoneLocator.FromString(i.Zone) == zoneLocator)
                                              .Where(i => i.Disks != null && i.Disks.Any())
                                              .OrderBy(i => i.Name)
                                              .Select(i => new InstanceNode(
                                                          i.Id.Value,
                                                          new InstanceLocator(
                                                              zoneLocator.ProjectId,
                                                              zoneLocator.Name,
                                                              i.Name),
                                                          i.IsWindowsInstance()
                                ? OperatingSystems.Windows
                                : OperatingSystems.Linux,
                                                          i.Status == "RUNNING"))
                                              .ToList();

                        zones.Add(new ZoneNode(
                                      zoneLocator,
                                      instancesInZone));
                    }

                    return(zones);
                }
        }
        public void Test()
        {
            var projectName = "ExtraCheckTest";
            var api         = new TeamCityClient("build.mvstelecom.ru");

            api.ConnectWithAccessToken("eyJ0eXAiOiAiVENWMiJ9.V0R5T1k5R0tPTklESUctNndDQjhkOVFkYzVn.OTczMGJhZGItMzVkYy00Y2QyLThmYWUtODg1NTk0N2RlYWFl");

            var project = api.Projects.ById(projectName);
            var tests   = api.Tests.ByProjectLocator(ProjectLocator.WithId(projectName));

            var disabled = project.BuildTypes.BuildType
                           .Where(x => x.Name.StartsWith("[disabled]"))
                           .Select(x => x.Id)
                           .ToList();

            var actualTests = tests.TestOccurrence
                              .Where(x => !disabled.Contains(x.Build.BuildTypeId))
                              .ToList();
        }
        public void GetProjectsInSln_ReturnsDockerizedProjects()
        {
            var slnPath = ProjectLocator.GetCurrentDir().Parent?.Parent?.Parent?.Parent?.GetFiles("*.sln").SingleOrDefault()?.FullName;

            if (slnPath == null)
            {
                throw new FileNotFoundException("Can't find sln file");
            }
            var locator            = new ProjectLocator();
            var dockerizedProjects = locator.GetProjectNamesFromSln(slnPath).ToArray();
            var exampleProj        = dockerizedProjects.SingleOrDefault(p => p.names.Contains(nameof(ExampleProject)));

            Assert.True(File.Exists(exampleProj.path));
            Assert.Contains("ExampleProjectAsm", exampleProj.names);
            Assert.Contains("ExampleProjectNs", exampleProj.names);

            var allProjects = locator.GetProjectNamesFromSln(slnPath, _ => true).ToArray();

            Assert.True(allProjects.Length > dockerizedProjects.Length);
        }
        public async Task GetImageBuildsProjectFromNames()
        {
            string name = "foo";
            var    file = ProjectLocator.GetCurrentDir().Parent?.Parent?.Parent?.Parent
                          ?.GetFiles("ExampleProject.csproj", SearchOption.AllDirectories).Single();
            var projectLocator = new Mock <IProjectLocator>();

            projectLocator.Setup(p => p.GetDockerProject(name)).Returns(file);

            var imageSource = new DockerfileImageProvider(name, projectLocator.Object);

            string tag = await imageSource.GetImage(null);

            var image = await new DockerClientProvider().GetDockerClient().Images
                        .ListImagesAsync(new ImagesListParameters {
                MatchName = tag
            });

            Assert.Single(image);
        }
        public async Task RemoveProjectAsync(ProjectLocator project)
        {
            using (ApplicationTraceSources.Default.TraceMethod().WithParameters(project))
            {
                this.serviceProvider
                .GetService <IProjectRepository>()
                .RemoveProject(project);

                //
                // Purge from cache.
                //
                using (await this.cacheLock.AcquireAsync(CancellationToken.None)
                       .ConfigureAwait(false))
                {
                    this.cachedZones.Remove(project);
                }

                await this.serviceProvider
                .GetService <IEventService>()
                .FireAsync(new ProjectDeletedEvent(project.ProjectId))
                .ConfigureAwait(false);
            }
        }
Esempio n. 23
0
 public TestOccurrences ByProjectLocator(ProjectLocator locator)
 {
     return(m_caller.Get <TestOccurrences>($"/testOccurrences?locator=currentlyFailing:true,affectedProject:({locator})"));
 }
Esempio n. 24
0
 public void OpenInstanceList(ProjectLocator project)
 {
     OpenUrl("https://console.cloud.google.com/compute/instances" +
             $"?project={project.ProjectId}");
 }
Esempio n. 25
0
 public List <TestOccurrences> All(ProjectLocator locator)
 {
     return(AllResults(ByProjectLocator(locator)));
 }
Esempio n. 26
0
 public TestOccurrences ByProjectLocator(ProjectLocator locator)
 {
     return(m_caller.Get <TestOccurrences>($"/testOccurrences?locator=currentlyFailing:true,affectedProject:({locator})&fields=testOccurrence(id,name,status,href,details,duration,newFailure,metadata,build)"));
 }
Esempio n. 27
0
 public ParentProjectWrapper(ProjectLocator locator)
 {
     _locator = locator;
 }
Esempio n. 28
0
 public void RemoveProject(ProjectLocator project)
 {
     this.baseKey.DeleteSubKeyTree(project.Name, false);
 }
        public void it_returns_the_builds_queued_by_project_id()
        {
            var result = m_client.BuildQueue.ByProjectLocater(ProjectLocator.WithId(m_queuedProjectId));

            Assert.IsNotEmpty(result);
        }
Esempio n. 30
0
 public void AddProject(ProjectLocator project)
 {
     using (this.baseKey.CreateSubKey(project.Name))
     { }
 }