public void CreatePluginManifest_Owners_NotAvailable()
        {
            // When the package.Owners field is null, we should fallback to Authors for setting the organization.

            // Arrange
            DataServicePackage testPackage = CreateTestDataServicePackage();

            testPackage.Owners  = null;
            testPackage.Authors = "Foo,Bar,Test";

            // Act
            PluginManifest actualPluginManifest = AnalyzerPluginGenerator.CreatePluginManifest(testPackage);

            // Assert
            actualPluginManifest.Should().NotBeNull();
            actualPluginManifest.Organization.Should().Be(testPackage.Authors);
        }
        public void CreatePluginManifest_FromLocalPackage()
        {
            // We should also be able to create a plugin manifest from an IPackage that is not a DataServicePackage

            // Arrange
            string outputDir = TestUtils.CreateTestDirectory(TestContext, ".out");

            RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(TestContext);
            IPackage          testPackage       = remoteRepoBuilder.CreatePackage("Foo.Bar", "1.0.0", TestUtils.CreateTextFile("dummy.txt", outputDir), License.NotRequired);

            // Act
            PluginManifest actualPluginManifest = AnalyzerPluginGenerator.CreatePluginManifest(testPackage);

            // Assert
            actualPluginManifest.Should().NotBeNull();
            actualPluginManifest.License.Should().Be(testPackage.LicenseUrl.ToString());
        }
        public void CreatePluginManifest_FriendlyLicenseName_NotAvailable()
        {
            // When a short licensename is not assigned by NuGet.org, we should try to use the license URL instead.

            // Arrange
            DataServicePackage testPackage = CreateTestDataServicePackage();

            testPackage.LicenseNames = null;
            testPackage.LicenseUrl   = new Uri("http://foo.bar");

            // Act
            PluginManifest actualPluginManifest = AnalyzerPluginGenerator.CreatePluginManifest(testPackage);

            // Assert
            actualPluginManifest.Should().NotBeNull();
            actualPluginManifest.License.Should().Be(testPackage.LicenseUrl.ToString());
        }
        public void CreatePluginManifest_TitleMissing()
        {
            // When no title is available, ID should be used as a fallback, removing the dot separators for legibility.

            // Arrange
            DataServicePackage testPackage = CreateTestDataServicePackage();

            testPackage.Title = null;
            testPackage.Id    = "Foo.Bar.Test";

            // Act
            PluginManifest actualPluginManifest = AnalyzerPluginGenerator.CreatePluginManifest(testPackage);

            // Assert
            actualPluginManifest.Should().NotBeNull();
            actualPluginManifest.Name.Should().Be("Foo Bar Test");
        }
        public void CreatePluginManifest_FriendlyLicenseName_Available()
        {
            // When available, a short licensename assigned by NuGet.org should be used.
            // The license url is a fallback only.

            // Arrange
            DataServicePackage testPackage = CreateTestDataServicePackage();

            testPackage.LicenseNames = "Foo Bar License";
            testPackage.LicenseUrl   = new Uri("http://foo.bar");

            // Act
            PluginManifest actualPluginManifest = AnalyzerPluginGenerator.CreatePluginManifest(testPackage);

            // Assert
            actualPluginManifest.Should().NotBeNull();
            actualPluginManifest.License.Should().Be(testPackage.LicenseNames);
        }
        public void CreatePluginManifest_AllProperties()
        {
            // All properties present, all properties expected.

            // Arrange
            DataServicePackage testPackage = CreateTestDataServicePackage();

            testPackage.Description = "Test Description";
            testPackage.Authors     = "TestAuthor1,TestAuthor2";
            testPackage.ProjectUrl  = new Uri("http://test.project.url");
            testPackage.Id          = "Test.Id";

            testPackage.Title   = "Test Title";
            testPackage.Owners  = "TestOwner1,TestOwner2";
            testPackage.Version = "1.1.1-RC5";

            testPackage.LicenseUrl   = new Uri("http://test.license.url");
            testPackage.LicenseNames = "Test License1;Test License2";

            // Act
            PluginManifest actualPluginManifest = AnalyzerPluginGenerator.CreatePluginManifest(testPackage);

            // Assert
            actualPluginManifest.Should().NotBeNull();

            actualPluginManifest.Description.Should().Be(testPackage.Description);
            actualPluginManifest.Developers.Should().Be(testPackage.Authors);
            actualPluginManifest.Homepage.Should().Be(testPackage.ProjectUrl.ToString());
            actualPluginManifest.Key.Should().Be(PluginKeyUtilities.GetValidKey(testPackage.Id));

            actualPluginManifest.Name.Should().Be(testPackage.Title);
            actualPluginManifest.Organization.Should().Be(testPackage.Owners);
            actualPluginManifest.Version.Should().Be(testPackage.Version);

            actualPluginManifest.TermsConditionsUrl.Should().Be(testPackage.LicenseUrl.ToString());
            actualPluginManifest.License.Should().Be(testPackage.LicenseNames);
        }