diff --git a/API/Services/Extensions.cs b/API/Services/Extensions.cs index 32e704f..34b5022 100644 --- a/API/Services/Extensions.cs +++ b/API/Services/Extensions.cs @@ -214,7 +214,7 @@ public static Graph ToGraph(this Models.Soil soil, double[] thickness = null, .Multiply(soil.Water.Thickness).Sum(); // To stop the sw line crossing over ll, constrain it to ll. - var swConstainedToLL = sw.LowerConstraint(ll); + var swConstainedToLL = sw?.LowerConstraint(ll); return SoilGraph.Create(soil.Name, soil.Water.Thickness.ToMidPoints(), soil.Water.AirDry, soil.Water.LL15, soil.Water.DUL, soil.Water.SAT, ll, cropName, pawc, paw, thickness?.ToMidPoints(), swConstainedToLL); } diff --git a/Tests/UnitTest.cs b/Tests/UnitTest.cs index ed268d7..ab84bdc 100644 --- a/Tests/UnitTest.cs +++ b/Tests/UnitTest.cs @@ -286,4 +286,17 @@ public void ToAPSIMSoil_ShouldPopulateAllMembers() var apsimSoilXml = soil.ToAPSIMSoil().ToXML(); Assert.That(apsimSoilXml, Is.EqualTo(ResourceFile.Get("Tests.testsoil1.apsim.xml"))); } + + [Test] + public void ToGraph_ShouldWorkWithoutSWSpecified() + { + var soil = ResourceFile.FromResourceXML("Tests.testsoil1.xml"); + + var graph = soil.ToGraph(); + Assert.That(graph, Is.Not.Null); + + // should be 5 graph series: + // shaded bucket, ll, airdry, dul, sat + Assert.That(graph.Series.Count, Is.EqualTo(5)); + } } \ No newline at end of file