From 9c3da9b5e3e3150214f1fd0a264ca8fc96c4211b Mon Sep 17 00:00:00 2001 From: Alexandre Brandizzi Date: Fri, 21 Aug 2026 09:40:51 -0300 Subject: [PATCH] fix(vendors): keep location fallback atomic --- .../VendorDataServiceTests.cs | 17 +++++++++++------ .../Implementation/VendorDataService.cs | 8 ++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Api.SeaHavenIndustries.Tests/VendorDataServiceTests.cs b/Api.SeaHavenIndustries.Tests/VendorDataServiceTests.cs index 2bed953..a7d91f1 100644 --- a/Api.SeaHavenIndustries.Tests/VendorDataServiceTests.cs +++ b/Api.SeaHavenIndustries.Tests/VendorDataServiceTests.cs @@ -440,15 +440,15 @@ public class VendorDataServiceTests Name = "Searchable Co", NormalizedName = "searchable co", City = "Chicago", - State = "IL" + State = null }; context.VendorCompanies.Add(company); context.Vendors.Add(new Vendor { CompanyName = "Searchable Co", ContactName = "Pat", - City = null, - State = null, + City = "Stale City", + State = "TX", IsActive = true, IsDeleted = false, Company = company @@ -461,10 +461,15 @@ public class VendorDataServiceTests 1, 50, isActive: true, - locations: new[] { "Chicago, IL" }); + locations: new[] { "Chicago" }); - search.Items.Should().ContainSingle(i => i.ContactName == "Pat"); - location.Items.Should().ContainSingle(i => i.ContactName == "Pat"); + var searchRow = search.Items.Should().ContainSingle(i => i.ContactName == "Pat").Subject; + searchRow.City.Should().Be("Chicago"); + searchRow.State.Should().BeNull(); + + var locationRow = location.Items.Should().ContainSingle(i => i.ContactName == "Pat").Subject; + locationRow.City.Should().Be("Chicago"); + locationRow.State.Should().BeNull(); } [Theory] diff --git a/SeaHaven.DataServices/Implementation/VendorDataService.cs b/SeaHaven.DataServices/Implementation/VendorDataService.cs index 81f77ba..dc09d71 100644 --- a/SeaHaven.DataServices/Implementation/VendorDataService.cs +++ b/SeaHaven.DataServices/Implementation/VendorDataService.cs @@ -200,10 +200,14 @@ namespace SeaHaven.DataServices.Implementation CompanyPhone = v.CompanyPhone, PreferredContact = v.PreferredContact, Address = v.Address, - City = v.Company != null && v.Company.City != null && v.Company.City.Trim() != "" + City = v.Company != null && + ((v.Company.City != null && v.Company.City.Trim() != "") || + (v.Company.State != null && v.Company.State.Trim() != "")) ? v.Company.City : v.City, - State = v.Company != null && v.Company.State != null && v.Company.State.Trim() != "" + State = v.Company != null && + ((v.Company.City != null && v.Company.City.Trim() != "") || + (v.Company.State != null && v.Company.State.Trim() != "")) ? v.Company.State : v.State, Zip = v.Zip,