Exemplo n.º 1
0
        private async Task <ProjectInfo> AddTwoProjectsWithSameRepoStamp(RepositoryManagementService service)
        {
            ManifestQueryResult allProjects;

//add two projects with same repo stamp
            RepoCat.Transmission.Models.ProjectInfo prj = new RepoCat.Transmission.Models.ProjectInfo()
            {
                ProjectName    = "Project1",
                ProjectUri     = "SomeLocation",
                RepositoryInfo = new RepoCat.Transmission.Models.RepositoryInfo()
                {
                    RepositoryName   = this.testRepoOne.RepositoryName,
                    OrganizationName = this.testRepoOne.OrganizationName,
                },

                TargetExtension = "exe",
                RepositoryStamp = "1.0"
            };
            await service.Upsert(prj).ConfigureAwait(false);

            RepoCat.Transmission.Models.ProjectInfo prj2 = new RepoCat.Transmission.Models.ProjectInfo()
            {
                ProjectName      = "Project2",
                ProjectUri       = "SomeLocation",
                DocumentationUri = "http://google.com/Somewhere",
                RepositoryInfo   = new RepoCat.Transmission.Models.RepositoryInfo()
                {
                    RepositoryName   = this.testRepoOne.RepositoryName,
                    OrganizationName = this.testRepoOne.OrganizationName,
                },

                TargetExtension = "exe",
                RepositoryStamp = "1.0",
                AssemblyName    = "Project2AssName",
                Components      =
                {
                    new ComponentManifest(new List <string>()
                    {
                        "One", "Two"
                    }, new PropertiesCollection()
                    {
                        ("KeyOne", "ValueOne")
                    }
                                          )
                }
            };
            ProjectInfo returnedPrj2 = await service.Upsert(prj2).ConfigureAwait(false);

            allProjects = await service.GetAllCurrentProjects(this.testRepoOne).ConfigureAwait(false);

            allProjects.Projects.Count.Should().Be(2, "because we just added 2 projects with same stamp");
            allProjects.Projects.Should().OnlyContain(x => x.ProjectInfo.RepositoryStamp == "1.0");

            return(returnedPrj2);
        }
Exemplo n.º 2
0
 private static async Task SeedProjects(RepositoryManagementService service, string projectName, RepositoryInfo repo, params string[] stamps)
 {
     foreach (string stamp in stamps)
     {
         RepoCat.Transmission.Models.ProjectInfo prj = new RepoCat.Transmission.Models.ProjectInfo()
         {
             ProjectName     = projectName,
             RepositoryStamp = stamp,
             RepositoryInfo  = new RepoCat.Transmission.Models.RepositoryInfo()
             {
                 OrganizationName = repo.OrganizationName,
                 RepositoryName   = repo.RepositoryName
             }
         };
         await service.Upsert(prj).ConfigureAwait(false);
     }
 }
Exemplo n.º 3
0
        public async Task SnapshotRepo_ShouldOnlyReturnLastProjects()
        {
            RepositoryDatabase database = new RepositoryDatabase(Settings);
            var service = new RepositoryManagementService(database, new Mapper(MappingConfigurationFactory.Create()), this.telemetryClient);

            await SetSnapshotMode(database, this.testRepoOne).ConfigureAwait(false);

            var allProjects = await service.GetAllCurrentProjects(this.testRepoOne).ConfigureAwait(false);

            allProjects.Projects.Count.Should().Be(0, "because there are no projects yet");

            ProjectInfo returnedPrj2 = await this.AddTwoProjectsWithSameRepoStamp(service).ConfigureAwait(false);

            //now add just one with new stamp
            RepoCat.Transmission.Models.ProjectInfo prj2Again = new RepoCat.Transmission.Models.ProjectInfo()
            {
                ProjectName    = "Project2",
                ProjectUri     = "SomeLocation",
                RepositoryInfo = new RepoCat.Transmission.Models.RepositoryInfo()
                {
                    RepositoryName   = this.testRepoOne.RepositoryName,
                    OrganizationName = this.testRepoOne.OrganizationName,
                },

                TargetExtension = "exe",
                RepositoryStamp = "2.0"
            };
            var returnedPrj2Again = await service.Upsert(prj2Again).ConfigureAwait(false);

            allProjects = await service.GetAllCurrentProjects(this.testRepoOne).ConfigureAwait(false);


            allProjects.Projects.Count.Should().Be(1, "because recently only added 1 project");
            allProjects.Projects.Should().OnlyContain(x => x.ProjectInfo.RepositoryStamp == "2.0");

            returnedPrj2Again.Id.Should().NotBe(returnedPrj2.Id);
            returnedPrj2Again.ProjectUri.Should().Be(returnedPrj2.ProjectUri);
            returnedPrj2Again.ProjectName.Should().Be(returnedPrj2.ProjectName);
            returnedPrj2Again.RepositoryId.Should().Be(returnedPrj2.RepositoryId);
        }
Exemplo n.º 4
0
#pragma warning disable 1998
        public async Task <IActionResult> AddProject([FromBody] AddProjectModel project)
#pragma warning restore 1998
        {
            if (!this.ModelState.IsValid || project == null)
            {
                this.TempData["error"] = "Incorrect input.";
                return(this.Json(this.Url.Action("AddProject")));
            }

            try
            {
                var validator = new SchemaValidator();

                var errors = validator.ValidateManifest(project.EmptyManifestXml, out XDocument _);

                if (errors.Count > 0)
                {
                    this.TempData["error"] = "Schema validation errors:\r\n" + string.Join("\r\n", errors);
                    return(this.Json(this.Url.Action("AddProject")));
                }
                else
                {
                    ProjectInfo projectInfo = ManifestDeserializer.DeserializeProjectInfo(XElement.Parse(project.EmptyManifestXml));

                    var upsertedProject = await this.repositoryService.Upsert(projectInfo).ConfigureAwait(false);

                    this.TempData["success"] = $"Added project to catalog. Internal ID: {upsertedProject.Id}";

                    return(this.Json(this.Url.Action("AddProject")));
                }
            }
            catch (Exception ex)
            {
                this.TempData["error"] = $"Error: {ex.Message}";
                return(this.Json(this.Url.Action("AddProject")));
            }
        }
Exemplo n.º 5
0
        public async Task DefaultRepo_ShouldReturnUpdatedProjects()
        {
            RepositoryDatabase database = new RepositoryDatabase(Settings);
            var service     = new RepositoryManagementService(database, new Mapper(MappingConfigurationFactory.Create()), this.telemetryClient);
            var allProjects = await service.GetAllCurrentProjects(this.testRepoOne).ConfigureAwait(false);

            allProjects.Projects.Count.Should().Be(0, "because there are no projects yet");

            await this.AddTwoProjectsWithSameRepoStamp(service).ConfigureAwait(false);

            ProjectInfo returnedPrj2 = await this.AddTwoProjectsWithSameRepoStamp(service).ConfigureAwait(false);

            //now add just one with new stamp and some changed properties (except for name and URI)
            RepoCat.Transmission.Models.ProjectInfo prj2Again = new RepoCat.Transmission.Models.ProjectInfo()
            {
                ProjectName        = "Project2",
                ProjectUri         = "SomeLocation",
                Owner              = "An Owner",
                ProjectDescription = "A description",
                RepositoryInfo     = new RepoCat.Transmission.Models.RepositoryInfo()
                {
                    RepositoryName   = this.testRepoOne.RepositoryName,
                    OrganizationName = this.testRepoOne.OrganizationName,
                },

                TargetExtension = "exe",
                RepositoryStamp = "2.0",
                AssemblyName    = "Project2AssName_NEW",
                Components      =
                {
                    new ComponentManifest(new List <string>()
                    {
                        "Three", "Four"
                    }, new PropertiesCollection()
                    {
                        { "KeyTwo", "ValueTwo" }
                    }
                                          )
                }
            };

            var returnedPrj2Again = await service.Upsert(prj2Again).ConfigureAwait(false);

            allProjects = await service.GetAllCurrentProjects(this.testRepoOne).ConfigureAwait(false);


            allProjects.Projects.Count.Should().Be(2, "because we don't return latest stamp only");
            allProjects.Projects.Should().Contain(x => x.ProjectInfo.RepositoryStamp == "2.0");
            allProjects.Projects.Should().Contain(x => x.ProjectInfo.RepositoryStamp == "1.0");

            returnedPrj2Again.Id.Should().Be(returnedPrj2.Id);
            returnedPrj2Again.ProjectUri.Should().Be(returnedPrj2.ProjectUri);
            returnedPrj2Again.ProjectName.Should().Be(returnedPrj2.ProjectName);
            returnedPrj2Again.RepositoryId.Should().Be(returnedPrj2.RepositoryId);

            var prj2ReturnedFromQuery = allProjects.Projects.Single(x => string.Equals(x.ProjectInfo.ProjectName, "Project2", StringComparison.Ordinal));

            prj2ReturnedFromQuery.ProjectInfo.Id.Should().Be(returnedPrj2Again.Id);
            prj2ReturnedFromQuery.ProjectInfo.RepositoryStamp.Should().Be("2.0");
            prj2ReturnedFromQuery.ProjectInfo.AssemblyName.Should().Be("Project2AssName_NEW");
            prj2ReturnedFromQuery.ProjectInfo.Components.Single().Tags.Count.Should().Be(2);
            prj2ReturnedFromQuery.ProjectInfo.Components.Single().Properties.Count.Should().Be(1);
            prj2ReturnedFromQuery.ProjectInfo.Components.Single().Properties["KeyTwo"].Should().Be("ValueTwo");
            prj2ReturnedFromQuery.ProjectInfo.Owner.Should().Be("An Owner");
            prj2ReturnedFromQuery.ProjectInfo.ProjectDescription.Should().Be("A description");
        }