コード例 #1
0
        private Build(BuildDto fullDto, TeamCityServer instance)
            : base(fullDto, instance)
        {
            this.Changes = new AsyncLazy <List <IChange> >(async()
                                                           => {
                var changes = await instance.Service.Changes(
                    $"build:{IdString}",
                    "change(id,version,username,user,date,comment,vcsRootInstance)").ConfigureAwait(false);

                var tasks = changes.Items
                            ?.Select(dto => Change.Create(dto, true, instance));

                return((await Task.WhenAll(tasks).ConfigureAwait(false))
                       .ToList()
                       ?? throw new NullReferenceException());
            });

            this.SnapshotDependencies = new AsyncLazy <List <IBuild> >(async()
                                                                       => {
                var tasks = fullDto.SnapshotDependencies
                            ?.Items
                            ?.Select(dto => Build.Create(dto.Id, instance));

                return(tasks != null
                        ? (await Task.WhenAll(tasks).ConfigureAwait(false))
                       .ToList <IBuild>()
                        : new List <IBuild>());
            });

            this.Agent = new AsyncLazy <IBuildAgent>(async()
                                                     => (Dto.Agent?.Id == null)
                    ? null
                    : await BuildAgent.Create(Dto.Agent.Id, Instance).ConfigureAwait(false)
                                                     );
        }
コード例 #2
0
        private BuildAgentPool(BuildAgentPoolDto fullDto, TeamCityServer instance)
            : base(fullDto, instance)
        {
            this.Projects = new AsyncLazy <List <IProject> >(async()
                                                             => {
                var tasks = this.Dto.Projects
                            ?.Items
                            ?.Select(project => Project.Create(project, false, Instance));

                return(tasks != null
                        ? (await Task.WhenAll(tasks).ConfigureAwait(false)).ToList()
                        : new List <IProject>());
            });

            this.Agents = new AsyncLazy <List <IBuildAgent> >(async()
                                                              => {
                var tasks = this.Dto.Agents
                            ?.Items
                            ?.Select(agent => BuildAgent.Create(agent.Id, Instance));

                return(tasks != null
                        ? (await Task.WhenAll(tasks).ConfigureAwait(false)).ToList()
                        : new List <IBuildAgent>());
            });
        }
コード例 #3
0
 public Triggered(TriggeredDto dto, TeamCityServer instance)
 {
     this.User = new AsyncLazy <IUser>(async()
                                       => await Domain.User.Create(dto.User.Id, instance).ConfigureAwait(false));
     this.Build = new AsyncLazy <IBuild>(async()
                                         => await Domain.Build.Create(dto.Build.Id, instance).ConfigureAwait(false));
 }
コード例 #4
0
        private BuildType(BuildTypeDto dto, TeamCityServer instance)
            : base(dto, instance)
        {
            this.BuildTags = new AsyncLazy <List <string> >(async()
                                                            => (await Service.BuildTypeTags(IdString).ConfigureAwait(false))
                                                            .Tag
                                                            .Select(tag => tag.Name ?? throw new NullReferenceException())
                                                            .ToList());

            this.FinishBuildTriggers = new AsyncLazy <List <IFinishBuildTrigger> >(async()
                                                                                   => (await Service.BuildTypeTriggers(IdString).ConfigureAwait(false))
                                                                                   .Trigger
                                                                                   ?.Where(trigger => trigger.Type == "buildDependencyTrigger")
                                                                                   ?.Select(trigger => new FinishBuildTrigger(trigger))
                                                                                   .ToList <IFinishBuildTrigger>()
                                                                                   ?? new List <IFinishBuildTrigger>());

            this.ArtifactDependencies = new AsyncLazy <List <IArtifactDependency> >(async()
                                                                                    => (await Service.BuildTypeArtifactDependencies(IdString).ConfigureAwait(false))
                                                                                    .ArtifactDependency
                                                                                    ?.Where(dep => dep.Disabled == false)
                                                                                    ?.Select(dep => new ArtifactDependency(dep, Instance))
                                                                                    .ToList <IArtifactDependency>()
                                                                                    ?? new List <IArtifactDependency>());
        }
コード例 #5
0
        public static async Task <IVcsRoot> Create(VcsRootDto dto, bool isFullDto, TeamCityServer instance)
        {
            var fullDto = isFullDto
                ? dto
                :await instance.Service.VcsRoot(dto.Id).ConfigureAwait(false);

            return(new VcsRoot(fullDto, instance));
        }
コード例 #6
0
 private VcsRoot(VcsRootDto fullDto, TeamCityServer instance)
     : base(fullDto, instance)
 {
     this.Properties = this.Dto.Properties
                       ?.Property
                       ?.ToDictionary(prop => prop.Name, prop => prop.Value)
                       ?? new Dictionary <string, string>();
 }
コード例 #7
0
 internal BuildCanceledInfo(BuildCanceledDto dto, TeamCityServer instance)
 {
     this._dto = dto;
     this.User = new AsyncLazy <IUser>(async()
                                       => dto.User != null
             ? await Domain.User.Create(dto.User.Id, instance).ConfigureAwait(false)
             : null);
 }
コード例 #8
0
        public static async Task <IChange> Create(ChangeDto dto, bool isFullDto, TeamCityServer instance)
        {
            var fullDto = isFullDto
                ? dto
                : await instance.Service.Change(dto.Id).ConfigureAwait(false);

            return(new Change(fullDto, instance));
        }
コード例 #9
0
        public static async Task <IUser> Create(UserDto dto, bool isFullDto, TeamCityServer instance)
        {
            var fullDto = isFullDto
                ? dto
                : await instance.Service.Users($"id:{dto.Id}").ConfigureAwait(false);

            return(new User(fullDto, instance));
        }
コード例 #10
0
 public ArtifactDependency(ArtifactDependencyDto fullDto, TeamCityServer instance)
     : base(fullDto, instance)
 {
     this.DependsOnBuildType = new AsyncLazy <IBuildType>(async()
                                                          => await BuildType.Create(
                                                              NotNull(dto => dto.SourceBuildType.Id),
                                                              Instance)
                                                          .ConfigureAwait(false));
 }
コード例 #11
0
        private Change(ChangeDto fullDto, TeamCityServer instance)
            : base(fullDto, instance)
        {
            this.User = new AsyncLazy <IUser>(async()
                                              => await Domain.User.Create(IdString, Instance).ConfigureAwait(false));

            this.VcsRootInstance = new AsyncLazy <IVcsRootInstance>(async()
                                                                    => await Domain.VcsRootInstance.Create(this.Dto.VcsRootInstance, false, Instance).ConfigureAwait(false));
        }
コード例 #12
0
 public Paged(
     TeamCityServer instance,
     Func <Task <TTeamCityDto> > getFirst,
     Func <TTeamCityDto, Task <Page <TTeamCityEntity> > > convertToPage)
 {
     this._instance      = instance;
     this._service       = instance.Service;
     this._getFirst      = getFirst;
     this._convertToPage = convertToPage;
 }
コード例 #13
0
        protected Base(TDto fullDto, TeamCityServer instance)
        {
            this.Dto = fullDto ?? throw new ArgumentNullException($"{nameof(fullDto)} must not be null.");

            if (String.IsNullOrWhiteSpace(fullDto.Id))
            {
                throw new InvalidOperationException($"{nameof(fullDto)}.Id must not be null.");
            }

            this.Instance = instance ?? throw new ArgumentNullException("Instance must not be null.");
        }
コード例 #14
0
        public void Reading_the_status_of_a_non_default_build()
        {
            // Given
            CreateClient();
            var expectedBuildInfo = new Build()
            {
                Status = "SUCCESS"
            };
            string expectedBuildConfigurationId = "BuildServer_Branch";

            var locator = BuildLocator.WithDimensions(
                buildType: BuildTypeLocator.WithId(expectedBuildConfigurationId),
                maxResults: 1,
                branch: "branched:true");

            var mockBuilds = ExpectReadOfBuildStatus(expectedBuildConfigurationId, expectedBuildInfo, locator: locator);

            ExpectReadOfBuildConfiguration(expectedBuildConfigurationId, expectedBuildConfigurationId + "_hello");


            var server = new TeamCityServer("localhost", "Username", "Password");

            var wait = new System.Threading.AutoResetEvent(false);

            BuildStatus?actualStatus = null;
            string      actualBuildConfigurationId = null;

            System.Threading.Thread actualThread = null;
            string actualName = null;

            server.ReadBuildStatusComplete += (sender, e) =>
            {
                actualThread = System.Threading.Thread.CurrentThread;
                actualStatus = e.Status;
                actualBuildConfigurationId = e.BuildConfigurationId;
                actualName = e.Name;
                wait.Set();
            };

            server.UseDefault = false; // Set the server to not use the builds default branch

            // When
            server.ReadBuildStatusAsync(expectedBuildConfigurationId);

            Assert.IsTrue(wait.WaitOne(5000));

            // Then
            clientMock.VerifyAll();
            mockBuilds.VerifyAll();
            Assert.AreEqual(BuildStatus.Success, actualStatus);
            Assert.AreEqual(expectedBuildConfigurationId, actualBuildConfigurationId);
            Assert.AreEqual(expectedBuildConfigurationId + "_hello", actualName);
            Assert.AreNotEqual(System.Threading.Thread.CurrentThread, actualThread);
        }
コード例 #15
0
        private BuildAgent(BuildAgentDto fullDto, TeamCityServer instance)
            : base(fullDto, instance)
        {
            this.Pool = new AsyncLazy <IBuildAgentPool>(async()
                                                        => await BuildAgentPool.Create(this.Dto.Pool.Id, Instance).ConfigureAwait(false));

            this.CurrentBuild = new AsyncLazy <IBuild>(async()
                                                       => String.IsNullOrEmpty(this.Dto.Build.Id)
                    ? null
                    : await Build.Create(this.Dto.Build.Id, Instance).ConfigureAwait(false));
        }
コード例 #16
0
 public BuildCommentInfo(BuildCommentDto dto, TeamCityServer instance)
 {
     this._dto = dto;
     this.User = new AsyncLazy <IUser>(async()
                                       => {
         var user = (dto.User != null)
                ? await Domain.User.Create(dto.User.Id, instance).ConfigureAwait(false)
                 : null;
         if (user != null)
         {
             _username = user.Name;
         }
         return(user);
     });
 }
コード例 #17
0
        public static async Task <IBuild> Create(string idString, TeamCityServer instance)
        {
            var dto = await instance.Service.Build(idString).ConfigureAwait(false);

            if (dto.BuildType == null)
            {
                dto.BuildType = new BuildTypeDto();
            }

            if (String.IsNullOrEmpty(dto.BuildType.Name))
            {
                dto.BuildType.Name = (await instance.BuildTypes.ById(new Id(dto.BuildTypeId)).ConfigureAwait(false)).Name;
            }

            return(new Build(dto, instance));
        }
コード例 #18
0
        private void Reading_the_status_of_a_XYZ_build(string status, BuildStatus expectedStatus,
                                                       string expectedBuildConfigurationId = "BuildServer_Branch",
                                                       string returnedName = "Name", string expectedName = "Name")
        {
            // Given
            CreateClient();
            var expectedBuildInfo = new Build()
            {
                Status = status
            };
            var mockBuilds = ExpectReadOfBuildStatus(expectedBuildConfigurationId, expectedBuildInfo);

            ExpectReadOfBuildConfiguration(expectedBuildConfigurationId, returnedName);

            var server = new TeamCityServer("localhost", "Username", "Password");

            var wait = new System.Threading.AutoResetEvent(false);

            BuildStatus?actualStatus = null;
            string      actualBuildConfigurationId = null;

            System.Threading.Thread actualThread = null;
            string actualBuildName = null;

            server.ReadBuildStatusComplete += (sender, e) =>
            {
                actualThread = System.Threading.Thread.CurrentThread;
                actualStatus = e.Status;
                actualBuildConfigurationId = e.BuildConfigurationId;
                actualBuildName            = e.Name;
                wait.Set();
            };

            // When
            server.ReadBuildStatusAsync(expectedBuildConfigurationId);

            Assert.IsTrue(wait.WaitOne(5000));

            // Then
            clientMock.VerifyAll();
            mockBuilds.VerifyAll();
            Assert.AreEqual(expectedStatus, actualStatus);
            Assert.AreEqual(expectedBuildConfigurationId, actualBuildConfigurationId);
            Assert.AreEqual(expectedName, actualBuildName);
            Assert.AreNotEqual(System.Threading.Thread.CurrentThread, actualThread);
        }
コード例 #19
0
        private Investigation(InvestigationDto fullDto, TeamCityServer instance)
            : base(fullDto, instance)
        {
            Assignee = new AsyncLazy <IUser>(async() =>
                                             await User.Create(fullDto.Assignee.Id, instance).ConfigureAwait(false));

            Reporter = new AsyncLazy <IUser>(async() =>
            {
                if (Dto.Assignment == null || Dto.Assignment.User == null)
                {
                    return(null);
                }
                return(await User.Create(Dto.Assignment.User.Id, instance).ConfigureAwait(false));
            });

            Scope = new AsyncLazy <IInvestigationScope>(async() =>
            {
                var scope   = fullDto.Scope;
                var project = scope.Project != null
                    ? await Project.Create(scope.Project, false, instance).ConfigureAwait(false)
                    : null;

                if (project != null)
                {
                    return(new InProject(project));
                }

                /* neither teamcity.jetbrains nor buildserver contain more then one assignment build type */
                if (scope.BuildTypes?.Items != null && scope.BuildTypes.Items.Count > 1)
                {
                    throw new Exception("more then one buildType");
                }

                var buildType = scope.BuildTypes != null
                    ? await BuildType.Create(scope.BuildTypes.Items[0].Id, instance).ConfigureAwait(false)
                    : null;

                if (buildType != null)
                {
                    return(new InBuildType(buildType));
                }

                throw new Exception("scope is missed in the bean");
            });
        }
コード例 #20
0
        public void Connecting_to_a_server()
        {
            // Given
            string hostName = "localhost";
            string userName = "******";
            string password = "******";

            CreateClient(userName, password);

            // When
            var server = new TeamCityServer(hostName, userName, password);

            // Then
            Assert.AreEqual(hostName, mockFactory._createHost);
            Assert.AreEqual(false, mockFactory._creaseUseSsl);

            clientMock.VerifyAll();
        }
コード例 #21
0
        private Project(ProjectDto dto, TeamCityServer instance)
            : base(dto, instance)
        {
            this.ChildProjects = new AsyncLazy <List <IProject> >(async()
                                                                  => {
                var tasks = dto.Projects.Items
                            .Select(proj => Project.Create(proj, false, instance));
                var projects = await Task.WhenAll(tasks).ConfigureAwait(false);
                return(projects.ToList());
            });

            this.BuildTypes = new AsyncLazy <List <IBuildType> >(async()
                                                                 => {
                var tasks = dto.BuildTypes.Items
                            .Select(type => BuildType.Create(type.Id, instance));
                var configs = await Task.WhenAll(tasks).ConfigureAwait(false);
                return(configs.ToList());
            });
        }
コード例 #22
0
        public void An_exception_during_the_reading_the_status()
        {
            // Given
            CreateClient();
            var expectedBuildInfo = new Build()
            {
                Status = "FAILED"
            };
            string    expectedBuildConfigurationId = "BuildServer_Branch";
            Exception expectedException            = new Exception();
            var       mockBuilds = ExpectReadOfBuildStatus(expectedBuildConfigurationId, expectedBuildInfo, expectedException);

            var server = new TeamCityServer("localhost", "Username", "Password");

            var wait = new System.Threading.AutoResetEvent(false);

            Exception actualException            = null;
            string    actualBuildConfigurationId = null;

            System.Threading.Thread actualThread = null;

            server.ReadBuildStatusError += (sender, e) =>
            {
                actualThread               = System.Threading.Thread.CurrentThread;
                actualException            = e.ThrownException;
                actualBuildConfigurationId = e.BuildConfigurationId;
                wait.Set();
            };

            // When
            server.ReadBuildStatusAsync(expectedBuildConfigurationId);

            Assert.IsTrue(wait.WaitOne(5000));

            // Then
            clientMock.VerifyAll();
            mockBuilds.VerifyAll();
            Assert.AreEqual(expectedException, actualException);
            Assert.AreEqual(expectedBuildConfigurationId, actualBuildConfigurationId);
            Assert.AreNotEqual(System.Threading.Thread.CurrentThread, actualThread);
        }
コード例 #23
0
        protected LazyBase(TDto dto, bool isFullDto, TeamCityServer instance)
        {
            this.Dto = dto ?? throw new ArgumentNullException("dto must not be null.");

            if (String.IsNullOrWhiteSpace(dto.Id))
            {
                throw new InvalidOperationException($"{nameof(dto)}.Id must not be null.");
            }

            this.IsFullDto = isFullDto;
            this.Instance  = instance ?? throw new ArgumentNullException("Instance must not be null.");

            this.FullDto = new AsyncLazy <TDto>(async() =>
            {
                if (!this.IsFullDto)
                {
                    this.Dto       = await FetchFullDto().ConfigureAwait(false);
                    this.IsFullDto = true;
                }
                return(this.Dto);
            });
        }
コード例 #24
0
 private VcsRootInstance(VcsRootInstanceDto fullDto, TeamCityServer instance)
     : base(fullDto, instance)
 {
 }
コード例 #25
0
 public void SetUp()
 {
     _client = new Client("localhost:81");
     _client.Connect("admin", "qwerty");
 }
コード例 #26
0
 public BuildAgentLocator(TeamCityServer instance) : base(instance)
 {
 }
コード例 #27
0
 public ChangeLocator(TeamCityServer instance) : base(instance)
 {
 }
コード例 #28
0
        public static async Task <IInvestigation> Create(InvestigationDto dto, bool isFullDto, TeamCityServer instance)
        {
            var fullDto = isFullDto
                ? dto
                : await instance.Service.Investigation(dto.Id).ConfigureAwait(false);

            return(new Investigation(fullDto, instance));
        }
コード例 #29
0
 public static async Task <IInvestigation> Create(string idString, TeamCityServer instance)
 => await Create(new InvestigationDto { Id = idString }, false, instance).ConfigureAwait(false);
コード例 #30
0
 public BuildTypeLocator(TeamCityServer instance) : base(instance)
 {
 }
コード例 #31
0
 public BuildAgentInfo(string userId, DateTimeOffset timestamp, string text, TeamCityServer instance)
 {
     this.User = new AsyncLazy <IUser>(async()
                                       => await Domain.User.Create(userId, instance).ConfigureAwait(false));
     this.Timestamp = timestamp;
     this.Text      = text;
 }