diff --git a/src/WireMock.Net/Serialization/MappingConverter.cs b/src/WireMock.Net/Serialization/MappingConverter.cs index cdc32224..eee09ce7 100644 --- a/src/WireMock.Net/Serialization/MappingConverter.cs +++ b/src/WireMock.Net/Serialization/MappingConverter.cs @@ -26,9 +26,9 @@ namespace WireMock.Serialization var request = (Request)mapping.RequestMatcher; var response = (Response)mapping.Provider; - var clientIPMatchers = request.GetRequestMessageMatchers(); - var pathMatchers = request.GetRequestMessageMatchers(); - var urlMatchers = request.GetRequestMessageMatchers(); + var clientIPMatchers = request.GetRequestMessageMatchers().Where(m => m.Matchers != null).SelectMany(m => m.Matchers).ToList(); + var pathMatchers = request.GetRequestMessageMatchers().Where(m => m.Matchers != null).SelectMany(m => m.Matchers).ToList(); + var urlMatchers = request.GetRequestMessageMatchers().Where(m => m.Matchers != null).SelectMany(m => m.Matchers).ToList(); var headerMatchers = request.GetRequestMessageMatchers(); var cookieMatchers = request.GetRequestMessageMatchers(); var paramsMatchers = request.GetRequestMessageMatchers(); @@ -45,36 +45,36 @@ namespace WireMock.Serialization SetStateTo = mapping.NextState, Request = new RequestModel { - ClientIP = clientIPMatchers != null && clientIPMatchers.Any() ? new ClientIPModel + ClientIP = clientIPMatchers.Any() ? new ClientIPModel { - Matchers = _mapper.Map(clientIPMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)) + Matchers = _mapper.Map(clientIPMatchers) } : null, - Path = pathMatchers != null && pathMatchers.Any() ? new PathModel + Path = pathMatchers.Any() ? new PathModel { - Matchers = _mapper.Map(pathMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)) + Matchers = _mapper.Map(pathMatchers) } : null, - Url = urlMatchers != null && urlMatchers.Any() ? new UrlModel + Url = urlMatchers.Any() ? new UrlModel { - Matchers = _mapper.Map(urlMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)) + Matchers = _mapper.Map(urlMatchers) } : null, Methods = methodMatcher?.Methods, - Headers = headerMatchers != null && headerMatchers.Any() ? headerMatchers.Select(hm => new HeaderModel + Headers = headerMatchers.Any() ? headerMatchers.Select(hm => new HeaderModel { Name = hm.Name, Matchers = _mapper.Map(hm.Matchers) }).ToList() : null, - Cookies = cookieMatchers != null && cookieMatchers.Any() ? cookieMatchers.Select(cm => new CookieModel + Cookies = cookieMatchers.Any() ? cookieMatchers.Select(cm => new CookieModel { Name = cm.Name, Matchers = _mapper.Map(cm.Matchers) }).ToList() : null, - Params = paramsMatchers != null && paramsMatchers.Any() ? paramsMatchers.Select(pm => new ParamModel + Params = paramsMatchers.Any() ? paramsMatchers.Select(pm => new ParamModel { Name = pm.Key, IgnoreCase = pm.IgnoreCase == true ? true : (bool?)null, diff --git a/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj b/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj index 4f341c22..a225c8ee 100644 --- a/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj +++ b/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj @@ -66,7 +66,7 @@ - Always + PreserveNewest PreserveNewest