diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index d9469c7..57e149f 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -19,15 +19,6 @@ jobs: steps: - uses: actions/checkout@v1 - - name: NuGet Setup - uses: actions/setup-dotnet@v2 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: "NuGet Add Source Organization" - run: if ("${{ secrets.ORGANIZATION_SOURCE_PACKAGE_PASSWORD }}" -ne "") { dotnet nuget add source --username ${{ secrets.ORGANIZATION_SOURCE_PACKAGE_USERNAME }} --password ${{ secrets.ORGANIZATION_SOURCE_PACKAGE_PASSWORD }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{github.repository_owner}}/index.json" } - - name: Run './build/build.cmd' run: ./build/build.cmd --root ./build env: diff --git a/Autodesk.PackageBuilder.Examples/Autodesk.PackageBuilder.Example.csproj b/Autodesk.PackageBuilder.Examples/Autodesk.PackageBuilder.Example.csproj index 98adad9..56ae28d 100644 --- a/Autodesk.PackageBuilder.Examples/Autodesk.PackageBuilder.Example.csproj +++ b/Autodesk.PackageBuilder.Examples/Autodesk.PackageBuilder.Example.csproj @@ -1,10 +1,10 @@ - + Exe - net6.0 + net4.8;net6.0;net8.0 false - false + true diff --git a/Autodesk.PackageBuilder.Examples/DemoAddinBuilder.cs b/Autodesk.PackageBuilder.Examples/DemoAddinBuilder.cs index 6c1b312..7d51f30 100644 --- a/Autodesk.PackageBuilder.Examples/DemoAddinBuilder.cs +++ b/Autodesk.PackageBuilder.Examples/DemoAddinBuilder.cs @@ -8,8 +8,8 @@ public DemoAddinBuilder() { AddIn.CreateEntry("Application") .Name("RevitAddin") - .AddInId("F6DB5994-D788-4060-9C97-16F6C1B07857") .Assembly("RevitAddin.dll") + .AddInId("11111111-2222-3333-4444-555555555555") .FullClassName("RevitAddin.App") .VendorId("RevitAddin") .VendorDescription("RevitAddin"); diff --git a/Autodesk.PackageBuilder.Examples/Program.cs b/Autodesk.PackageBuilder.Examples/Program.cs index 90b4b05..a4d77b7 100644 --- a/Autodesk.PackageBuilder.Examples/Program.cs +++ b/Autodesk.PackageBuilder.Examples/Program.cs @@ -57,8 +57,8 @@ static void BuildAddinFile() { builder.AddIn.CreateEntry("Application") .Name("RevitAddin") - .AddInId("F6DB5994-D788-4060-9C97-16F6C1B07857") .Assembly("RevitAddin.dll") + .AddInId("11111111-2222-3333-4444-555555555555") .FullClassName("RevitAddin.App") .VendorId("RevitAddin") .VendorDescription("RevitAddin"); diff --git a/Autodesk.PackageBuilder.Tests/Addin/RevitAddInsBuilder_Tests.cs b/Autodesk.PackageBuilder.Tests/Addin/RevitAddInsBuilder_Tests.cs new file mode 100644 index 0000000..4d3b129 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Addin/RevitAddInsBuilder_Tests.cs @@ -0,0 +1,110 @@ +using Autodesk.PackageBuilder.Tests.Utils; +using NUnit.Framework; +using System; + +namespace Autodesk.PackageBuilder.Tests.Addin +{ + public class RevitAddInsBuilder_Tests + { + RevitAddInsBuilder builder; + [SetUp] + public void Setup() + { + builder = BuilderUtils.Build(); + } + + [Test] + public void Build_RevitAddIns() + { + builder.AssertElement("RevitAddIns"); + } + + [TestCase("Command")] + [TestCase("Application")] + [TestCase("DBApplication")] + public void Build_CreateEntry(string type) + { + builder.AddIn.CreateEntry(type); + builder.AssertElementAttribute("AddIn", "Type", type); + } + + [Test] + public void Build_CreateEntry_Empty() + { + string type = "Application"; + builder.AddIn.CreateEntry(); + builder.AssertElementAttribute("AddIn", "Type", type); + } + + [TestCase("Value")] + [TestCase("PropertyValue")] + public void Build_CreateEntry_AddInId(string value) + { + builder.AddIn.CreateEntry() + .Name(value) + .Assembly(value) + .AddInId(value) + .FullClassName(value) + .VendorId(value) + .VendorDescription(value); + + builder.AssertElement("Name", value); + builder.AssertElement("Assembly", value); + builder.AssertElement("AddInId", value); + builder.AssertElement("FullClassName", value); + builder.AssertElement("VendorId", value); + builder.AssertElement("VendorDescription", value); + } + + [TestCase(5)] + [TestCase(9)] + public void Build_CreateEntry_AddInId_Multiple(int length) + { + for (int i = 0; i < length; i++) + { + builder.AddIn.CreateEntry() + .Name(i.ToString()); + } + + for (int i = 0; i < length; i++) + { + builder.AssertElement("Name", i); + } + } + + [Test] + public void Build_RevitAddIns_DemoClass() + { + var builder = BuilderUtils.Build(); + var content = builder.ToString(); + Assert.AreEqual(DemoAddinBuilder.Expected, content, $"Expected: {DemoAddinBuilder.Expected}\nContent: {content}"); + } + + public class DemoAddinBuilder : RevitAddInsBuilder + { + public static string Expected => """" + + + + RevitAddin + RevitAddin.dll + 11111111-2222-3333-4444-555555555555 + RevitAddin.App + RevitAddin + RevitAddin + + + """"; + public DemoAddinBuilder() + { + AddIn.CreateEntry("Application") + .Name("RevitAddin") + .Assembly("RevitAddin.dll") + .AddInId("11111111-2222-3333-4444-555555555555") + .FullClassName("RevitAddin.App") + .VendorId("RevitAddin") + .VendorDescription("RevitAddin"); + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Addin/RevitUtils_Tests.cs b/Autodesk.PackageBuilder.Tests/Addin/RevitUtils_Tests.cs new file mode 100644 index 0000000..dac1ddd --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Addin/RevitUtils_Tests.cs @@ -0,0 +1,43 @@ +using Autodesk.PackageBuilder.Tests.Utils; +using NUnit.Framework; + +namespace Autodesk.PackageBuilder.Tests.Addin +{ + public class RevitUtils_Tests + { + PackageContentsBuilder builder; + [SetUp] + public void Setup() + { + builder = BuilderUtils.Build(); + } + + [Test] + public void Build_RevitApplication() + { + builder.ApplicationPackage.Create() + .RevitApplication(); + + builder.AssertAttribute("AutodeskProduct", AutodeskProducts.Revit); + builder.AssertAttribute("ProductType", ProductTypes.Application); + } + + [TestCase(2021)] + [TestCase(2022)] + [TestCase(2023)] + [TestCase(2024)] + public void Build_RevitPlatform(int revitVersion) + { + var description = "RevitPlatform"; + builder.Components + .CreateEntry(description) + .RevitPlatform(revitVersion); + + builder.AssertAttribute("Description", description); + builder.AssertAttribute("OS", "Win64"); + builder.AssertAttribute("Platform", "Revit"); + builder.AssertAttribute("SeriesMin", "R" + revitVersion); + builder.AssertAttribute("SeriesMax", "R" + revitVersion); + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Tests.cs b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Tests.cs new file mode 100644 index 0000000..b246ecc --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Tests.cs @@ -0,0 +1,222 @@ +using Autodesk.PackageBuilder.Tests.Utils; +using NUnit.Framework; +using System; + +namespace Autodesk.PackageBuilder.Tests.Application +{ + public class PackageContentsBuilder_Tests + { + PackageContentsBuilder builder; + [SetUp] + public void Setup() + { + builder = BuilderUtils.Build(); + } + + [Test] + public void Build_PackageBuilder() + { + var content = builder.ToString(); + //Console.WriteLine(content); + builder.AssertElement("ApplicationPackage"); + } + + [TestCase("1.0")] + [TestCase("2.0")] + [TestCase("3.0")] + public void Build_ApplicationPackage(string schemaVersion) + { + builder.ApplicationPackage.Create(schemaVersion); + builder.AssertAttribute("SchemaVersion", schemaVersion); + } + + [Test] + public void Build_ApplicationPackage_Empty() + { + var schemaVersion = "1.0"; + builder.ApplicationPackage.Create(); + builder.AssertAttribute("SchemaVersion", schemaVersion); + } + + [TestCase("Value")] + [TestCase("AttributeValue")] + public void Build_ApplicationPackage_Attribute(string value) + { + builder.ApplicationPackage.Create() + .Name(value) + .AutodeskProduct(value) + .Description(value) + .AppVersion(value) + //.AppVersion(version) + .FriendlyVersion(value) + .ProductType(value) + .ProductCode(value) + //.ProductCode(guid) + .Author(value) + .HelpFile(value) + .SupportedLocales(value) + .OnlineDocumentation(value); + + builder.AssertAttribute("Name", value); + builder.AssertAttribute("AutodeskProduct", value); + builder.AssertAttribute("Description", value); + builder.AssertAttribute("AppVersion", value); + builder.AssertAttribute("FriendlyVersion", value); + builder.AssertAttribute("ProductType", value); + builder.AssertAttribute("ProductCode", value); + builder.AssertAttribute("Author", value); + builder.AssertAttribute("HelpFile", value); + builder.AssertAttribute("SupportedLocales", value); + builder.AssertAttribute("OnlineDocumentation", value); + } + + [Test] + public void Build_ApplicationPackage_Attribute_AppVersion() + { + var version = new Version(1, 2, 3, 4); + builder.ApplicationPackage.Create() + .AppVersion(version); + + builder.AssertAttribute("AppVersion", version); + } + + [Test] + public void Build_ApplicationPackage_Attribute_ProductCode() + { + var guid = Guid.NewGuid(); + builder.ApplicationPackage.Create() + .ProductCode(guid); + + builder.AssertAttribute("ProductCode", guid); + } + + [TestCase("Name")] + [TestCase("Company")] + public void Build_CompanyDetails(string name) + { + builder.CompanyDetails.Create(name); + builder.AssertAttribute("Name", name); + } + + [TestCase("Value")] + [TestCase("AttributeValue")] + public void Build_CompanyDetails_Attribute(string value) + { + builder.CompanyDetails.Create(value) + .Url(value) + .Email(value); + + builder.AssertAttribute("Name", value); + builder.AssertAttribute("Url", value); + builder.AssertAttribute("Email", value); + } + + [TestCase("Name")] + [TestCase("Description")] + public void Build_Components_CreateEntry(string description) + { + builder.Components.CreateEntry(description); + //Console.WriteLine(builder); + builder.AssertElementAttribute("Components", "Description", description); + } + + [TestCase(5)] + [TestCase(9)] + public void Build_Components_CreateEntry_Multiple(int length) + { + for (int i = 0; i < length; i++) + { + builder.Components.CreateEntry(i.ToString()); + } + //Console.WriteLine(builder); + for (int i = 0; i < length; i++) + { + builder.AssertElementAttribute("Components", "Description", i); + } + } + + [TestCase("Value")] + [TestCase("AttributeValue")] + public void Build_Components_CreateEntry_Attribute(string value) + { + builder.Components.CreateEntry(value) + .OS(value) + .Platform(value) + .SeriesMin(value) + .SeriesMax(value) + .AppName(value) + .ModuleName(value) + .Version(value) + .AppDescription(value); + + builder.AssertAttribute("Description", value); + builder.AssertAttribute("OS", value); + builder.AssertAttribute("Platform", value); + builder.AssertAttribute("SeriesMin", value); + builder.AssertAttribute("SeriesMax", value); + builder.AssertAttribute("AppName", value); + builder.AssertAttribute("ModuleName", value); + builder.AssertAttribute("Version", value); + builder.AssertAttribute("AppDescription", value); + } + + [Test] + public void Build_PackageBuilder_DemoClass() + { + var builder = BuilderUtils.Build(); + var content = builder.ToString(); +#if NET6_0 + if (DemoPackageBuilder.Expected.Equals(content) == false) + Assert.Ignore("Not equal, order not match in version net6.0 for some reason..."); +#endif + Assert.AreEqual(DemoPackageBuilder.Expected, content, $"Expected: {DemoPackageBuilder.Expected}\nContent: {content}"); + } + + public class DemoPackageBuilder : PackageContentsBuilder + { + public static string Expected => """" + + + + + + + + + + + + + """"; + public DemoPackageBuilder() + { + ApplicationPackage + .Create() + .AutodeskProduct(AutodeskProducts.Revit) + .Name("RevitAddin") + .AppVersion("1.0.0") + .ProductType(ProductTypes.Application); + + CompanyDetails + .Create("Company Name") + .Url("url") + .Email("email"); + + Components + .CreateEntry("Revit 2021") + .OS("Win64") + .Platform("Revit") + .SeriesMin("R2021") + .SeriesMax("R2021") + .AppName("RevitAddin") + .ModuleName(@"./Contents/2021/RevitAddin.addin"); + + Components + .CreateEntry("Revit 2022") + .RevitPlatform(2022) + .AppName("RevitAddin") + .ModuleName(@"./Contents/2022/RevitAddin.addin"); + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Autodesk.PackageBuilder.Tests.csproj b/Autodesk.PackageBuilder.Tests/Autodesk.PackageBuilder.Tests.csproj new file mode 100644 index 0000000..8c77bdb --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Autodesk.PackageBuilder.Tests.csproj @@ -0,0 +1,19 @@ + + + + net48;net6.0;net8.0 + false + latest + + + + + + + + + + + + + diff --git a/Autodesk.PackageBuilder.Tests/Builder/BuilderBaseTests.cs b/Autodesk.PackageBuilder.Tests/Builder/BuilderBaseTests.cs new file mode 100644 index 0000000..f9d3cb6 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Builder/BuilderBaseTests.cs @@ -0,0 +1,54 @@ +using NUnit.Framework; +using System.IO; + +namespace Autodesk.PackageBuilder.Tests.Builder +{ + public abstract class BuilderBaseTests where T : IBuilder, new() + { + public abstract string FileName { get; } + [SetUp] + [TearDown] + public void DeleteFileName() + { + if (File.Exists(FileName)) + File.Delete(FileName); + } + + [Test] + public void Build_Should_NotNull() + { + var builder = BuilderUtils.Build(); + Assert.IsNotNull(builder); + } + + [Test] + public void Build_Should_CreateFile() + { + var builder = BuilderUtils.Build(); + builder.Build(FileName); + Assert.IsTrue(File.Exists(FileName)); + } + + [Test] + public void Build_Should_CreateFile_WithPath() + { + BuilderUtils.Build(FileName); + Assert.IsTrue(File.Exists(FileName)); + } + + [Test] + public void Build_Should_CreateFile_WithConfig() + { + var builder = BuilderUtils.Build((build) => { }); + builder.Build(FileName); + Assert.IsTrue(File.Exists(FileName)); + } + + [Test] + public void Build_Should_CreateFile_WithConfigAndPath() + { + BuilderUtils.Build((build) => { }, FileName); + Assert.IsTrue(File.Exists(FileName)); + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Builder/PackageContentsBuilder_Tests.cs b/Autodesk.PackageBuilder.Tests/Builder/PackageContentsBuilder_Tests.cs new file mode 100644 index 0000000..2b3803f --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Builder/PackageContentsBuilder_Tests.cs @@ -0,0 +1,18 @@ +using NUnit.Framework; +using System.IO; + +namespace Autodesk.PackageBuilder.Tests.Builder +{ + public class PackageContentsBuilder_Tests : BuilderBaseTests + { + public override string FileName => "PackageContents.xml"; + + [Test] + public void Build_Should_CreateFile_WithoutName() + { + var builder = BuilderUtils.Build(); + builder.Build(string.Empty); + Assert.IsTrue(File.Exists(FileName)); + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Builder/RevitAddInsBuilder_Tests.cs b/Autodesk.PackageBuilder.Tests/Builder/RevitAddInsBuilder_Tests.cs new file mode 100644 index 0000000..8e44397 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Builder/RevitAddInsBuilder_Tests.cs @@ -0,0 +1,18 @@ +using NUnit.Framework; +using System.IO; + +namespace Autodesk.PackageBuilder.Tests.Builder +{ + public class RevitAddInsBuilder_Tests : BuilderBaseTests + { + public override string FileName => "RevitAddin.addin"; + + [Test] + public void Build_Should_CreateFile_WithoutExtension() + { + var builder = BuilderUtils.Build(); + builder.Build(Path.GetFileNameWithoutExtension(FileName)); + Assert.IsTrue(File.Exists(FileName)); + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/BuilderUtils_Tests.cs b/Autodesk.PackageBuilder.Tests/BuilderUtils_Tests.cs new file mode 100644 index 0000000..55e3bf3 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/BuilderUtils_Tests.cs @@ -0,0 +1,72 @@ +using NUnit.Framework; + +namespace Autodesk.PackageBuilder.Tests +{ + public class BuilderUtils_Tests + { + public class Builder : IBuilder + { + public string Path { get; set; } + public bool Config { get; set; } + public string Build(string path) + { + Path = path; + return Path; + } + } + + [Test] + public void Build_ShouldBe_NotNull() + { + var builder = BuilderUtils.Build(); + Assert.IsNotNull(builder); + } + + [Test] + public void Build_ShouldBe_NotNull_Config() + { + var builder = BuilderUtils.Build((build) => { build.Config = true; }); + Assert.IsTrue(builder.Config); + } + + [TestCase("path")] + [TestCase("path2")] + [TestCase("path3")] + public void Build_ShouldBe_Config_Build(string path) + { + var builder = BuilderUtils.Build((build) => { build.Config = true; }); + builder.Build(path); + Assert.IsTrue(builder.Config); + Assert.AreEqual(builder.Path, path); + } + + [TestCase("path")] + [TestCase("path2")] + [TestCase("path3")] + public void Build_ShouldBe_Path(string path) + { + var builder = BuilderUtils.Build(path); + Assert.AreEqual(builder.Path, path); + } + + [TestCase("path")] + [TestCase("path2")] + [TestCase("path3")] + public void Build_ShouldBe_Config_Path(string path) + { + var builder = BuilderUtils.Build((build) => { build.Config = true; }, path); + Assert.IsTrue(builder.Config); + Assert.AreEqual(builder.Path, path); + } + + [TestCase("path")] + [TestCase("path2")] + [TestCase("path3")] + public void Build_ShouldBe_Path_Config(string path) + { + var builder = BuilderUtils.Build(path, (build) => { build.Config = true; }); + Assert.IsTrue(builder.Config); + Assert.AreEqual(builder.Path, path); + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Constants/AutodeskProducts_Tests.cs b/Autodesk.PackageBuilder.Tests/Constants/AutodeskProducts_Tests.cs new file mode 100644 index 0000000..8a2b697 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Constants/AutodeskProducts_Tests.cs @@ -0,0 +1,31 @@ +using NUnit.Framework; + +namespace Autodesk.PackageBuilder.Tests.Constants +{ + public class AutodeskProducts_Tests + { + [Test] + public void AutoCAD_Test() + { + Assert.AreEqual("AutoCAD", AutodeskProducts.AutoCAD); + } + + [Test] + public void Revit_Test() + { + Assert.AreEqual("Revit", AutodeskProducts.Revit); + } + + [Test] + public void Maya_Test() + { + Assert.AreEqual("Maya", AutodeskProducts.Maya); + } + + [Test] + public void Navisworks_Test() + { + Assert.AreEqual("Navisworks", AutodeskProducts.Navisworks); + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Constants/ProductTypes_Tests.cs b/Autodesk.PackageBuilder.Tests/Constants/ProductTypes_Tests.cs new file mode 100644 index 0000000..1c162f8 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Constants/ProductTypes_Tests.cs @@ -0,0 +1,19 @@ +using NUnit.Framework; + +namespace Autodesk.PackageBuilder.Tests.Constants +{ + public class ProductTypes_Tests + { + [Test] + public void Application_Test() + { + Assert.AreEqual("Application", ProductTypes.Application); + } + + [Test] + public void Content_Test() + { + Assert.AreEqual("Content", ProductTypes.Content); + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Utils/AssertBuilderUtils.cs b/Autodesk.PackageBuilder.Tests/Utils/AssertBuilderUtils.cs new file mode 100644 index 0000000..0171145 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Utils/AssertBuilderUtils.cs @@ -0,0 +1,76 @@ +using NUnit.Framework; +using System; + +namespace Autodesk.PackageBuilder.Tests.Utils +{ + public static class AssertBuilderUtils + { + /// + /// Assert with '<'. + /// + /// + /// + public static void AssertElement(this IBuilder builder, string element) + { + var content = builder.ToString(); + var elementValue = ElementStart(element); + Assert.IsTrue(content.Contains(elementValue), $"The string '{elementValue}' is not found in '{content}'"); + } + + /// + /// Assert with '<></>'. + /// + /// + /// + /// + public static void AssertElement(this IBuilder builder, string element, object value) + { + var content = builder.ToString(); + var elementValue = ElementValue(element, value); + Assert.IsTrue(content.Contains(elementValue), $"The string '{elementValue}' is not found in '{content}'"); + } + + /// + /// Assert with '=""'. + /// + /// + /// + /// + public static void AssertAttribute(this IBuilder builder, string attribute, object value) + { + var content = builder.ToString(); + var attributeValue = AttributeValue(attribute, value); + Assert.IsTrue(content.Contains(attributeValue), $"The string '{attributeValue}' is not found in '{content}'"); + } + + /// + /// Assert with '< =""'. + /// + /// + /// + /// + /// + public static void AssertElementAttribute(this IBuilder builder, string element, string attribute, object value) + { + var content = builder.ToString(); + var attributeValue = AttributeValue(attribute, value); + var elementAttibute = $"{ElementStart(element)} {attributeValue}"; + Assert.IsTrue(content.Contains(elementAttibute), $"The string '{elementAttibute}' is not found in '{content}'"); + } + + internal static string ElementStart(string element) + { + return $"<{element}"; + } + + internal static string ElementValue(string element, object value) + { + return $"<{element}>{value}"; + } + + internal static string AttributeValue(string attribute, object value) + { + return $"{attribute}=\"{value}\""; + } + } +} diff --git a/Autodesk.PackageBuilder.sln b/Autodesk.PackageBuilder.sln index 5198932..ad09bca 100644 --- a/Autodesk.PackageBuilder.sln +++ b/Autodesk.PackageBuilder.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31911.196 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34316.72 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autodesk.PackageBuilder", "Autodesk.PackageBuilder\Autodesk.PackageBuilder.csproj", "{647FFB28-1412-45FC-989A-0EA93FB2378E}" EndProject @@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project", "Project", "{F716 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autodesk.PackageBuilder.Example", "Autodesk.PackageBuilder.Examples\Autodesk.PackageBuilder.Example.csproj", "{FFBDD53B-D4E9-458E-9DF0-E117295D1593}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Autodesk.PackageBuilder.Tests", "Autodesk.PackageBuilder.Tests\Autodesk.PackageBuilder.Tests.csproj", "{AA0E5843-B360-4CB5-AE33-6F549E9EF394}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,6 +31,10 @@ Global {59542136-031D-4D65-959B-F4819E10FDA2}.Release|Any CPU.ActiveCfg = Release|Any CPU {FFBDD53B-D4E9-458E-9DF0-E117295D1593}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FFBDD53B-D4E9-458E-9DF0-E117295D1593}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA0E5843-B360-4CB5-AE33-6F549E9EF394}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA0E5843-B360-4CB5-AE33-6F549E9EF394}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA0E5843-B360-4CB5-AE33-6F549E9EF394}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA0E5843-B360-4CB5-AE33-6F549E9EF394}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Autodesk.PackageBuilder/Autodesk.PackageBuilder.csproj b/Autodesk.PackageBuilder/Autodesk.PackageBuilder.csproj index 021bdc6..0919422 100644 --- a/Autodesk.PackageBuilder/Autodesk.PackageBuilder.csproj +++ b/Autodesk.PackageBuilder/Autodesk.PackageBuilder.csproj @@ -3,10 +3,11 @@ netstandard2.0 false + latest - 1.0.5 + 1.0.6 @@ -29,6 +30,14 @@ icon.png LICENSE + README.md + + + + $(OutputPath)\$(AssemblyName).xml + + + false diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/IAddInEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IAddInEntryBuilder.cs similarity index 100% rename from Autodesk.PackageBuilder/Builder/Abstractions/IAddInEntryBuilder.cs rename to Autodesk.PackageBuilder/Builder/Abstractions/Addin/IAddInEntryBuilder.cs diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/IApplicationPackageBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Application/IApplicationPackageBuilder.cs similarity index 100% rename from Autodesk.PackageBuilder/Builder/Abstractions/IApplicationPackageBuilder.cs rename to Autodesk.PackageBuilder/Builder/Abstractions/Application/IApplicationPackageBuilder.cs diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/ICompanyDetailsBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Application/ICompanyDetailsBuilder.cs similarity index 100% rename from Autodesk.PackageBuilder/Builder/Abstractions/ICompanyDetailsBuilder.cs rename to Autodesk.PackageBuilder/Builder/Abstractions/Application/ICompanyDetailsBuilder.cs diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/IComponentsEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Application/IComponentsEntryBuilder.cs similarity index 100% rename from Autodesk.PackageBuilder/Builder/Abstractions/IComponentsEntryBuilder.cs rename to Autodesk.PackageBuilder/Builder/Abstractions/Application/IComponentsEntryBuilder.cs diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/BuilderBase.cs b/Autodesk.PackageBuilder/Builder/Abstractions/BuilderBase.cs index e95a8ec..02994e0 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/BuilderBase.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/BuilderBase.cs @@ -2,12 +2,27 @@ { using System; using System.Runtime.CompilerServices; + /// + /// BuilderBase + /// + /// + /// public abstract class BuilderBase where TBuilder : class where TData : new() { + /// + /// Data + /// protected TData Data { get; set; } + /// + /// SetNewPropertyValue + /// + /// + /// + /// + /// protected TBuilder SetNewPropertyValue(object value, [CallerMemberName] string name = null) where T : new() { return SetNewPropertyValue(Data, name, value); @@ -29,6 +44,12 @@ public abstract class BuilderBase return SetPropertyValue(property.GetValue(instance), method, value); } + /// + /// SetPropertyValue + /// + /// + /// + /// protected TBuilder SetPropertyValue(object value, [CallerMemberName] string name = null) { return SetPropertyValue(Data, name, value); diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/IBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/IBuilder.cs index c20da84..e3ac8fd 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/IBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/IBuilder.cs @@ -1,7 +1,15 @@ namespace Autodesk.PackageBuilder { + /// + /// IBuilder + /// public interface IBuilder { + /// + /// Build + /// + /// + /// string Build(string path); } } \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/ListBuilderBase.cs b/Autodesk.PackageBuilder/Builder/Abstractions/ListBuilderBase.cs index a75b6fd..7dc95e9 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/ListBuilderBase.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/ListBuilderBase.cs @@ -1,17 +1,31 @@ namespace Autodesk.PackageBuilder { using System.Collections.Generic; + /// + /// ListBuilderBase + /// + /// + /// public abstract class ListBuilderBase : BuilderBase where TBuilder : class where TData : new() { private List _entryList; + /// + /// CreateEntryInternal + /// + /// protected TBuilder CreateEntryInternal() { _entryList.Add(Data = new TData()); return this as TBuilder; } + /// + /// SetDataInternal + /// + /// + /// protected TBuilder SetDataInternal(List list) { _entryList = list; diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/SingleBuilderBase.cs b/Autodesk.PackageBuilder/Builder/Abstractions/SingleBuilderBase.cs index 0f357f3..b85d023 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/SingleBuilderBase.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/SingleBuilderBase.cs @@ -1,9 +1,19 @@ namespace Autodesk.PackageBuilder { + /// + /// SingleBuilderBase + /// + /// + /// public abstract class SingleBuilderBase : BuilderBase where TBuilder : class where TData : new() { + /// + /// SetDataInternal + /// + /// + /// protected TBuilder SetDataInternal(TData data) { Data = data; diff --git a/Autodesk.PackageBuilder/Builder/AddInEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Addin/AddInEntryBuilder.cs similarity index 80% rename from Autodesk.PackageBuilder/Builder/AddInEntryBuilder.cs rename to Autodesk.PackageBuilder/Builder/Addin/AddInEntryBuilder.cs index 371afa8..6aa7f82 100644 --- a/Autodesk.PackageBuilder/Builder/AddInEntryBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/Addin/AddInEntryBuilder.cs @@ -23,6 +23,7 @@ public AddInEntryBuilder CreateEntry(string type) public AddInEntryBuilder FullClassName(string value) => SetPropertyValue(value); public AddInEntryBuilder VendorId(string value) => SetPropertyValue(value); public AddInEntryBuilder VendorDescription(string value) => SetPropertyValue(value); - public AddInEntryBuilder AllowLoadingIntoExistingSession(bool value) => SetPropertyValue(value); + [System.Obsolete("This method does not have a Property 'AllowLoadingIntoExistingSession' in class AddInModel, will be removed in a future version.")] + internal AddInEntryBuilder AllowLoadingIntoExistingSession(bool value) => SetPropertyValue(value); } } \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/RevitAddInsEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Addin/RevitAddInsEntryBuilder.cs similarity index 100% rename from Autodesk.PackageBuilder/Builder/RevitAddInsEntryBuilder.cs rename to Autodesk.PackageBuilder/Builder/Addin/RevitAddInsEntryBuilder.cs diff --git a/Autodesk.PackageBuilder/Builder/ApplicationPackageBuilder.cs b/Autodesk.PackageBuilder/Builder/Application/ApplicationPackageBuilder.cs similarity index 100% rename from Autodesk.PackageBuilder/Builder/ApplicationPackageBuilder.cs rename to Autodesk.PackageBuilder/Builder/Application/ApplicationPackageBuilder.cs diff --git a/Autodesk.PackageBuilder/Builder/CompanyDetailsBuilder.cs b/Autodesk.PackageBuilder/Builder/Application/CompanyDetailsBuilder.cs similarity index 100% rename from Autodesk.PackageBuilder/Builder/CompanyDetailsBuilder.cs rename to Autodesk.PackageBuilder/Builder/Application/CompanyDetailsBuilder.cs diff --git a/Autodesk.PackageBuilder/Builder/ComponentsBuilder.cs b/Autodesk.PackageBuilder/Builder/Application/ComponentsBuilder.cs similarity index 100% rename from Autodesk.PackageBuilder/Builder/ComponentsBuilder.cs rename to Autodesk.PackageBuilder/Builder/Application/ComponentsBuilder.cs diff --git a/Autodesk.PackageBuilder/Builder/PackageContentsBuilder.cs b/Autodesk.PackageBuilder/Builder/PackageContentsBuilder.cs index b67630d..b540322 100644 --- a/Autodesk.PackageBuilder/Builder/PackageContentsBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/PackageContentsBuilder.cs @@ -24,6 +24,11 @@ public PackageContentsBuilder() _components = new ComponentsBuilder(applicationPackage.Components); } + /// + /// Build and serialize the PackageContents.xml file. + /// + /// + /// public string Build(string path) { return applicationPackage.SerializeFile(path, "PackageContents.xml"); diff --git a/Autodesk.PackageBuilder/Builder/RevitAddInsBuilder.cs b/Autodesk.PackageBuilder/Builder/RevitAddInsBuilder.cs index 19e3b98..32a8361 100644 --- a/Autodesk.PackageBuilder/Builder/RevitAddInsBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/RevitAddInsBuilder.cs @@ -17,11 +17,20 @@ public RevitAddInsBuilder() _addInEntryBuilder = new AddInEntryBuilder(revitAddIns.AddIn); } + /// + /// Build and serialize the .addin file. + /// + /// + /// public string Build(string path) { return revitAddIns.SerializeFile(path, ".addin"); } + /// + /// Serialize the RevitAddIns object. + /// + /// public override string ToString() { return revitAddIns.SerializeObject(); diff --git a/Autodesk.PackageBuilder/Builder/SerializeExtensions.cs b/Autodesk.PackageBuilder/Builder/SerializeExtensions.cs index 8bf9683..962a3d2 100644 --- a/Autodesk.PackageBuilder/Builder/SerializeExtensions.cs +++ b/Autodesk.PackageBuilder/Builder/SerializeExtensions.cs @@ -1,11 +1,14 @@ namespace Autodesk.PackageBuilder { + using Model; using System.IO; using System.Text; using System.Xml; using System.Xml.Serialization; - using Model; + /// + /// SerializeExtensions + /// public static class SerializeExtensions { /// @@ -14,6 +17,7 @@ public static class SerializeExtensions /// /// /// + /// /// public static string SerializeFile(this T toSerialize, string path, string forceFile = null) where T : IPackageSerializable { @@ -32,7 +36,7 @@ public static string SerializeFile(this T toSerialize, string path, string fo path = Path.ChangeExtension(path, extension); } } - return SerializeFile(toSerialize, path); + return toSerialize.SerializeFile(path); } /// /// Serializar IPackageSerializable @@ -75,6 +79,7 @@ public static string SerializeObject(this T toSerialize) where T : IPackageSe /// public class Utf8StringWriter : StringWriter { + /// public override Encoding Encoding => Encoding.UTF8; } } diff --git a/Autodesk.PackageBuilder/Model/IPackageSerializable.cs b/Autodesk.PackageBuilder/Model/IPackageSerializable.cs index d2aa99d..0918cb9 100644 --- a/Autodesk.PackageBuilder/Model/IPackageSerializable.cs +++ b/Autodesk.PackageBuilder/Model/IPackageSerializable.cs @@ -1,5 +1,9 @@ namespace Autodesk.PackageBuilder.Model { + /// + /// IPackageSerializable + /// + /// Interface to SerializeFile with public interface IPackageSerializable { diff --git a/Autodesk.PackageBuilder/Utils/BuilderUtils.cs b/Autodesk.PackageBuilder/Utils/BuilderUtils.cs index e674b9f..98ebc8a 100644 --- a/Autodesk.PackageBuilder/Utils/BuilderUtils.cs +++ b/Autodesk.PackageBuilder/Utils/BuilderUtils.cs @@ -2,32 +2,74 @@ { using System; + /// + /// BuilderUtils + /// public static class BuilderUtils { + /// + /// Create a new instance of the type. + /// + /// + /// public static TBuilder Build() where TBuilder : IBuilder, new() { return Activator.CreateInstance(); } - public static void Build(string path) + /// + /// Create a new instance of the type and . + /// + /// + /// + /// + public static TBuilder Build(string path) where TBuilder : IBuilder, new() { - var builder = Activator.CreateInstance(); + var builder = Build(); builder.Build(path); + return builder; + } + + /// + /// Create a new instance of the type, the instance, and . + /// + /// + /// + /// + /// + public static TBuilder Build(string path, Action config) + where TBuilder : IBuilder, new() + { + return Build(config, path); } - public static void Build(Action config, string path) + /// + /// Create a new instance of the type, the instance, and . + /// + /// + /// + /// + /// + public static TBuilder Build(Action config, string path) where TBuilder : IBuilder, new() { var builder = Build(config); builder.Build(path); + return builder; } + /// + /// Create a new instance of the type and the instance./>. + /// + /// + /// + /// public static TBuilder Build(Action config) where TBuilder : IBuilder, new() { - var builder = Activator.CreateInstance(); + var builder = Build(); config?.Invoke(builder); return builder; } diff --git a/Autodesk.PackageBuilder/Utils/RevitUtils.cs b/Autodesk.PackageBuilder/Utils/RevitUtils.cs index cd58493..4b1f239 100644 --- a/Autodesk.PackageBuilder/Utils/RevitUtils.cs +++ b/Autodesk.PackageBuilder/Utils/RevitUtils.cs @@ -1,9 +1,12 @@ namespace Autodesk.PackageBuilder { + /// + /// RevitUtils + /// public static class RevitUtils { /// - /// Set and . + /// Set AutodeskProduct to and ProductType to . /// /// /// diff --git a/Build/.nuke/build.schema.json b/Build/.nuke/build.schema.json index 99ea92c..a0854f5 100644 --- a/Build/.nuke/build.schema.json +++ b/Build/.nuke/build.schema.json @@ -1,7 +1,7 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Build Schema", "$ref": "#/definitions/build", + "title": "Build Schema", "definitions": { "build": { "type": "object", @@ -13,6 +13,10 @@ "Folder": { "type": "string" }, + "GitHubToken": { + "type": "string", + "default": "Secrets must be entered via 'nuke :secrets [profile]'" + }, "Help": { "type": "boolean", "description": "Shows the help text for this build assembly" @@ -24,6 +28,7 @@ "AppVeyor", "AzurePipelines", "Bamboo", + "Bitbucket", "Bitrise", "GitHubActions", "GitLab", @@ -47,6 +52,14 @@ "type": "boolean", "description": "Disables displaying the NUKE logo" }, + "NugetApiKey": { + "type": "string", + "default": "Secrets must be entered via 'nuke :secrets [profile]'" + }, + "NugetApiUrl": { + "type": "string", + "default": "Secrets must be entered via 'nuke :secrets [profile]'" + }, "Partition": { "type": "string", "description": "Partition to use on CI" @@ -65,10 +78,24 @@ "ReleaseExample": { "type": "boolean" }, + "ReleaseFolder": { + "type": "string" + }, + "ReleaseNameVersion": { + "type": "boolean" + }, "Root": { "type": "string", "description": "Root directory during build execution" }, + "SignFile": { + "type": "string", + "default": "Secrets must be entered via 'nuke :secrets [profile]'" + }, + "SignPassword": { + "type": "string", + "default": "Secrets must be entered via 'nuke :secrets [profile]'" + }, "Skip": { "type": "array", "description": "List of targets to be skipped. Empty list skips all dependencies", @@ -82,7 +109,8 @@ "GitRelease", "Pack", "Release", - "Sign" + "Sign", + "Test" ] } }, @@ -103,10 +131,20 @@ "GitRelease", "Pack", "Release", - "Sign" + "Sign", + "Test" ] } }, + "TestBuildStopWhenFailed": { + "type": "boolean" + }, + "TestProjectName": { + "type": "string" + }, + "TestResults": { + "type": "boolean" + }, "Verbosity": { "type": "string", "description": "Logging verbosity during build execution. Default is 'Normal'", @@ -120,4 +158,4 @@ } } } -} \ No newline at end of file +} diff --git a/Build/Build.cs b/Build/Build.cs index 26ca27d..fb1c8e4 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -3,7 +3,7 @@ using ricaun.Nuke; using ricaun.Nuke.Components; -partial class Build : NukeBuild, IPublishPack, ICompileExample +partial class Build : NukeBuild, IPublishPack, ICompileExample, ITest { public static int Main() => Execute(x => x.From().Build); } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 063f02e..072e7d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.0.6] / 2023-11-24 - 2023-12-06 +### Features +- `Tests` project. +- Update `BuilderUtils` to return instance and features (#16). +### PackageBuilder +- Enable `DocumentationFile` in package. +- Update `BuilderUtils` to return instance. +- Obsolete and internal `AllowLoadingIntoExistingSession` +- Update `Example` Guid. +### Tests +- Test `Constants` +- Test `BuilderUtils` +- Test `Builder` create file. +- Test `RevitAddInsBuilder` +- Test `PackageContentsBuilder` +- Add `AssertBuilderUtils` +- Test `RevitUtils` + ## [1.0.5] / 2021-12-21 - Update Build Project - 2021-12-21 diff --git a/README.md b/README.md index 028656e..32e3f23 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,15 @@ BuilderUtils.Build("PackageContents.xml"); // or +BuilderUtils.Build("PackageContents.xml", builder => {...}); + +// or + BuilderUtils.Build(builder => {...}, "PackageContents.xml"); + +// or + +BuilderUtils.Build(builder => {...}).Build("PackageContents.xml"); ``` ### Create RevitAddin.addin @@ -134,12 +142,11 @@ To get the `RevitAddin.addin` like this: RevitAddin - F6DB5994-D788-4060-9C97-16F6C1B07857 + 11111111-2222-3333-4444-555555555555 RevitAddin.dll RevitAddin.App RevitAddin RevitAddin - true ``` @@ -153,7 +160,7 @@ public class DemoAddinBuilder : RevitAddInsBuilder { AddIn.CreateEntry("Application") .Name("RevitAddin") - .AddInId("F6DB5994-D788-4060-9C97-16F6C1B07857") + .AddInId("11111111-2222-3333-4444-555555555555") .Assembly("RevitAddin.dll") .FullClassName("RevitAddin.App") .VendorId("RevitAddin") @@ -169,7 +176,7 @@ var builder = BuilderUtils.Build(builder => { builder.AddIn.CreateEntry("Application") .Name("RevitAddin") - .AddInId("F6DB5994-D788-4060-9C97-16F6C1B07857") + .AddInId("11111111-2222-3333-4444-555555555555") .Assembly("RevitAddin.dll") .FullClassName("RevitAddin.App") .VendorId("RevitAddin") @@ -198,7 +205,15 @@ BuilderUtils.Build("RevitAddin.addin"); // or +BuilderUtils.Build("RevitAddin.addin", builder => {...}); + +// or + BuilderUtils.Build(builder => {...}, "RevitAddin.addin"); + +// or + +BuilderUtils.Build(builder => {...}).Build("RevitAddin.addin"); ``` ## Package Inspiration / Reference