Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependencies node is not mandatory #281

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/ripple.Testing/Nuget/NuspecDocumentTester.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using NuGet;
using NUnit.Framework;
using ripple.Nuget;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using FubuTestingSupport;
using System.Xml.Linq;

namespace ripple.Testing.Nuget
{
public class NuspecDocumentTester
{
public NuspecDocument createDocument(string fileName, string id, string version)
{
XNamespace ns = NuspecDocument.Schema;
var xdoc = (new XDocument(new XElement(ns + "package",
new XElement(ns + "metadata",
new XElement(ns + "id",
new XText(id)
),
new XElement(ns + "version",
new XText(version)
)
))));
xdoc.Save(fileName);
var doc = new NuspecDocument(fileName);
return doc;
}

[Test]
public void when_no_depency_add_depency_works()
{
var fileName = Path.GetTempFileName();
var doc = createDocument(fileName, "Test", "1.2.1");
doc.AddDependency(new NuspecDependency()
{
Name = "Test2",
VersionSpec = new VersionSpec(SemanticVersion.Parse("1.0.0"))
});
doc.FindDependencies().ShouldContain(c => c.Name == "Test2");

File.Delete(fileName);
}
}
}
1 change: 1 addition & 0 deletions src/ripple.Testing/ripple.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
<Compile Include="Nuget\NugetSearchTester.cs" />
<Compile Include="Nuget\NugetStepRunnerTester.cs" />
<Compile Include="Nuget\NugetXmlFeedTester.cs" />
<Compile Include="Nuget\NuspecDocumentTester.cs" />
<Compile Include="Nuget\Operations\installing_a_fixed_project_dependency_any_stability.cs" />
<Compile Include="Nuget\Operations\installing_a_fixed_project_dependency_released_only.cs" />
<Compile Include="Nuget\Operations\installing_a_fixed_project_dependency_with_existing_transitive_dependencies.cs" />
Expand Down
7 changes: 7 additions & 0 deletions src/ripple/Nuget/NuspecDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public void AddDependency(NuspecDependency dependency)
{
var dependencies = _document.XPathSelectElement("//nuspec:dependencies", _xmlNamespaceManager);

if (dependencies == null)
{
var metadata = _document.XPathSelectElement("//nuspec:metadata", _xmlNamespaceManager);
dependencies = new XElement(XName.Get("dependencies", Schema));
metadata.Add(dependencies);
}

foreach (XElement dependencyElement in dependencies.Nodes())
{
if (dependencyElement.Attribute("id").Value == dependency.Name)
Expand Down