Skip to content
Merged
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
4 changes: 2 additions & 2 deletions API/Services/SoilServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public static SoilsFromDb Search(SoilDbContext context, string name = null, stri
{
IQueryable<Models.Soil> soils = context.Soils;
if (name != null)
soils = soils.Where(s => s.Name.Contains(name));
soils = soils.Where(s => s.Name.Trim().Contains(name));
if (fullName != null)
soils = soils.Where(s => s.FullName == fullName);
soils = soils.Where(s => s.FullName.Trim() == fullName);
if (folder != null)
soils = soils.Where(s => s.FullName.Contains(folder));
if (soilType != null)
Expand Down
1 change: 1 addition & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
<EmbeddedResource Include="testsoils.xml" />
<EmbeddedResource Include="testsoil12.xml" />
<EmbeddedResource Include="testsoil1.apsim.xml" />
<EmbeddedResource Include="testsoil1-trailing-spaces.xml" />
</ItemGroup>
</Project>
24 changes: 22 additions & 2 deletions Tests/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public void AddModifiedSoil_ShouldOverwriteExistingSoil()
var soil = ResourceFile.FromResourceXML<API.Models.Soil>("Tests.testsoil1.xml");

// Add soil
API.Services.Soil.Add(context, [ soil ]);
API.Services.Soil.Add(context, [soil]);

// Change a field
soil.Region = "New region";

// Add soil with new region.
API.Services.Soil.Add(context, [ soil ]);
API.Services.Soil.Add(context, [soil]);

// check the soil has been updated
var updatedSoil = context.Soils
Expand All @@ -47,6 +47,26 @@ public void AddModifiedSoil_ShouldOverwriteExistingSoil()
Assert.That(updatedSoil.Region, Is.EqualTo("New region"));
}

/// <summary>
/// The Farm4Prophet soils have trailing spaces in their names. Need to make sure
/// they can be retrieved.
/// https://github.com/APSIMInitiative/APSoil/issues/51
/// </summary>
[Test]
public void GetUsingFullName_ShouldIgnoreTrailingSpaces()
{
var options = MockDb.CreateOptions<SoilDbContext>();
using var context = new SoilDbContext(options);
var folder = ResourceFile.Get("Tests.testsoil1-trailing-spaces.xml").ToSoils();

API.Services.Soil.Add(context, folder);

var soils = API.Services.Soil.Search(context, fullName: "Soils/Tests/Clay (Kerikeri No1353)")
.ToSoils();
Assert.That(soils.Length, Is.EqualTo(1));
Assert.That(soils[0].Name, Is.EqualTo("Clay (Kerikeri No1353)"));
}

[Test]
public void GetWithLatLong_ShouldReturnSoilsClosestToPoint()
{
Expand Down
Loading