diff --git a/src/ripple.Testing/Nuget/NuspecDocumentTester.cs b/src/ripple.Testing/Nuget/NuspecDocumentTester.cs
new file mode 100644
index 0000000..ae1c088
--- /dev/null
+++ b/src/ripple.Testing/Nuget/NuspecDocumentTester.cs
@@ -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);
+ }
+ }
+}
diff --git a/src/ripple.Testing/ripple.Testing.csproj b/src/ripple.Testing/ripple.Testing.csproj
index 70b5c79..e873886 100644
--- a/src/ripple.Testing/ripple.Testing.csproj
+++ b/src/ripple.Testing/ripple.Testing.csproj
@@ -197,6 +197,7 @@
+
diff --git a/src/ripple/Nuget/NuspecDocument.cs b/src/ripple/Nuget/NuspecDocument.cs
index 273f117..67ef4bd 100644
--- a/src/ripple/Nuget/NuspecDocument.cs
+++ b/src/ripple/Nuget/NuspecDocument.cs
@@ -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)