diff --git a/Mockaco.sln b/Mockaco.sln index 932cbd4..548d28c 100644 --- a/Mockaco.sln +++ b/Mockaco.sln @@ -10,7 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mockaco.Tests", "test\Mockaco.AspNetCore.Tests\Mockaco.AspNetCore.Tests.csproj", "{EE57B1B4-29D2-4AE3-8F23-5E622302C30F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mockaco.AspNetCore.Tests", "test\Mockaco.AspNetCore.Tests\Mockaco.AspNetCore.Tests.csproj", "{EE57B1B4-29D2-4AE3-8F23-5E622302C30F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mockaco.AspNetCore", "src\Mockaco.AspNetCore\Mockaco.AspNetCore.csproj", "{7766C592-9887-4162-8B9C-51003ED30335}" EndProject diff --git a/src/Mockaco.AspNetCore/Templating/Request/RequestConditionMatcher.cs b/src/Mockaco.AspNetCore/Templating/Request/RequestConditionMatcher.cs index 858a674..ec6aefd 100644 --- a/src/Mockaco.AspNetCore/Templating/Request/RequestConditionMatcher.cs +++ b/src/Mockaco.AspNetCore/Templating/Request/RequestConditionMatcher.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using System; -using System.Linq; -using System.Threading.Tasks; namespace Mockaco { @@ -43,12 +40,18 @@ public async Task IsMatch(HttpRequest httpRequest, Mock mock) } await conditionMatcherScriptContext.AttachRouteParameters(httpRequest, mock); + try + { + var template = await _templateTransformer.Transform(mock.RawTemplate, conditionMatcherScriptContext); - var template = await _templateTransformer.Transform(mock.RawTemplate, conditionMatcherScriptContext); - - var isMatch = template.Request?.Condition ?? true; + var isMatch = template.Request?.Condition ?? true; - return isMatch; + return isMatch; + } + catch (Exception) + { + return false; + } } //TODO Remove redundant code diff --git a/src/Mockaco.AspNetCore/Templating/TemplateTransformer.cs b/src/Mockaco.AspNetCore/Templating/TemplateTransformer.cs index 941f8e7..529da81 100644 --- a/src/Mockaco.AspNetCore/Templating/TemplateTransformer.cs +++ b/src/Mockaco.AspNetCore/Templating/TemplateTransformer.cs @@ -1,9 +1,7 @@ using Microsoft.Extensions.Logging; using Mono.TextTemplating; using Newtonsoft.Json; -using System; using System.Text; -using System.Threading.Tasks; namespace Mockaco { @@ -28,12 +26,12 @@ public async Task