diff --git a/API/Services/SoilServices.cs b/API/Services/SoilServices.cs index 19adf7d..f0bdb4a 100644 --- a/API/Services/SoilServices.cs +++ b/API/Services/SoilServices.cs @@ -56,9 +56,9 @@ public static SoilsFromDb Search(SoilDbContext context, string name = null, stri { IQueryable 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) diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 5fd1c8d..557b047 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -26,5 +26,6 @@ + diff --git a/Tests/UnitTest.cs b/Tests/UnitTest.cs index d527179..6884769 100644 --- a/Tests/UnitTest.cs +++ b/Tests/UnitTest.cs @@ -32,13 +32,13 @@ public void AddModifiedSoil_ShouldOverwriteExistingSoil() var soil = ResourceFile.FromResourceXML("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 @@ -47,6 +47,26 @@ public void AddModifiedSoil_ShouldOverwriteExistingSoil() Assert.That(updatedSoil.Region, Is.EqualTo("New region")); } + /// + /// The Farm4Prophet soils have trailing spaces in their names. Need to make sure + /// they can be retrieved. + /// https://github.com/APSIMInitiative/APSoil/issues/51 + /// + [Test] + public void GetUsingFullName_ShouldIgnoreTrailingSpaces() + { + var options = MockDb.CreateOptions(); + 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() { diff --git a/Tests/testsoil1-trailing-spaces.xml b/Tests/testsoil1-trailing-spaces.xml new file mode 100644 index 0000000..8cadf60 --- /dev/null +++ b/Tests/testsoil1-trailing-spaces.xml @@ -0,0 +1,413 @@ + + + + 1265 + Soils/Tests/Clay (Kerikeri No1353) + + + Clay + Kerikeri + SH 10, Bulls Rd + Kerikeri + Northland + + New Zealand + + 1353 + -35.258 + 173.937 + +/-50 m + 1979 + The database of New Zealand soils was compiled by AgResearch (www.agresearch.co.nz) and based on soil properties gathered, mainly from publications, in the course of conducting several simulation-based research projects but particularly from the Pastoral 21 Environment program which was funded by the New Zealand Ministry for Business, Innovation and Employment, Dairy NZ, Fonterra and Meat & Wool NZ. + Gravel soil. The bulk density of this APSoil reflects weight of fine-earth fraction per volume of bulk soil. Use with gravimetric water contents measured on the fine-earth fraction. Gravel assumed to not hold water as reflected in low SAT, DUL, LL15, LL and AD. The data is a combination of published or supplied measurements, pedotransfer functions, and expert opinion. See Cichota et al. (2013; Soil Research 51: 92-111, http://dx.doi.org/10.1071/SR12338) for a description of the pedotransfer functions. The soil carbon and fresh organic matter settings have been set as those broadly appropriate for permanent productive pastoral systems, see Cichota el al. (2012; Soil Research 50: 694-707, http://dx.doi.org/10.1071/SR12208). Users should take care to adapt these to local conditions before using the data in simulations. FOM values estimated to be 900 kg/ha of FOM in top 600mm of soil and another 100 kg/ha below. + + + 150 + 120 + 180 + 270 + 380 + 400 + + + 0.876 + 1.07 + 1.129 + 1.078 + 1.013 + 1.118 + + + 0.093 + 0.097 + 0.103 + 0.1 + 0.094 + 0.097 + + + 0.282 + 0.295 + 0.313 + 0.304 + 0.286 + 0.295 + + + 0.502 + 0.437 + 0.439 + 0.435 + 0.426 + 0.429 + + + 0.607 + 0.57 + 0.557 + 0.564 + 0.565 + 0.541 + + + 1991.893 + 339.391 + 129.04 + 130.089 + 141.539 + 85.509 + + + Field measured and checked for sensibility + Field measured and checked for sensibility + Field measured and checked for sensibility + Field measured and checked for sensibility + Field measured and checked for sensibility + Field measured and checked for sensibility + + + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + + + Laboratory measured + Laboratory measured + Laboratory measured + Laboratory measured + Laboratory measured + Laboratory measured + + + Laboratory measured + Laboratory measured + Laboratory measured + Laboratory measured + Laboratory measured + Laboratory measured + + + Calculated from measured, estimated or calculated BD + Calculated from measured, estimated or calculated BD + Calculated from measured, estimated or calculated BD + Calculated from measured, estimated or calculated BD + Calculated from measured, estimated or calculated BD + Calculated from measured, estimated or calculated BD + + + + 150 + 120 + 180 + 270 + 380 + 400 + + + 0.282 + 0.295 + 0.313 + 0.304 + 0.286 + 0.295 + + + 0.06 + 0.06 + 0.06 + 0.051 + 0.04 + 0.025 + + + 1 + 1 + 1 + 1 + 1 + 1 + + + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + + + + + 150 + 120 + 180 + 270 + 380 + 400 + + + 0.282 + 0.295 + 0.313 + 0.304 + 0.286 + 0.295 + + + 0.06 + 0.06 + 0.06 + 0.051 + 0.04 + 0.025 + + + 1 + 1 + 1 + 1 + 1 + 1 + + + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + + + + + 3.5 + 6 + 1-nov + 2 + 2 + 1-apr + 88 + 35 + 0.13 + 73 + 20 + 0.8 + NaN + NaN + NaN + NaN + + 150 + 120 + 180 + 270 + 380 + 400 + + + 0.574 + 0.532 + 0.454 + 0.405 + 0.367 + 0.34 + + + + 40 + 225 + 15.849 + 7.4 + 0.2 + + 150 + 120 + 180 + 270 + 380 + 400 + + + 8.4 + 3.3 + 2.4 + 1.4 + 1.1 + 0.9 + + + Measured + Measured + Measured + Measured + Measured + Measured + + + 0.078 + 0.036 + 0.008 + 0.008 + 0.008 + 0.008 + + + 0.666 + 0.733 + 0.875 + 0.943 + 0.977 + 0.995 + + WalkleyBlack + + + + 150 + 120 + 180 + 270 + 380 + 400 + + + 0.5 + 0.5 + 1 + 2 + 4 + 1.5 + + + Measured + Measured + Measured + Measured + Measured + Measured + + + Clay + Heavy clay + Heavy clay + Heavy clay + Heavy clay + Silt clay + + + Unknown source or quality of data + Unknown source or quality of data + Unknown source or quality of data + Unknown source or quality of data + Unknown source or quality of data + Unknown source or quality of data + + + 6.5 + 6.5 + 6.5 + 6.5 + 6.5 + 6.5 + + + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + Estimated based on local knowledge + + + 28.5 + 12.4 + 8 + 5.3 + 4.3 + 4.3 + + + Measured + Measured + Measured + Measured + Measured + Measured + + + 6.448 + 7.363 + 5.519 + 6.435 + 5.518 + 5.136 + + + Measured + Measured + Measured + Measured + Measured + Measured + + + 36.552 + 29.637 + 26.481 + 23.565 + 24.482 + 41.364 + + + Measured + Measured + Measured + Measured + Measured + Measured + + + 57 + 63 + 68 + 70 + 70 + 53.5 + + + Measured + Measured + Measured + Measured + Measured + Measured + + Water + HotWater + + + +