Skip to content

Commit

Permalink
Fixed issue where method
Browse files Browse the repository at this point in the history
string ABC<T>([InjectSourceOfType(typeof(Entity)] Entity entity, string someValue))

could not be resolved and concreted accordingly.
  • Loading branch information
Puchaczov committed Apr 20, 2024
1 parent 3c66280 commit a7f5808
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
18 changes: 18 additions & 0 deletions Musoq.Evaluator.Tests/GenericTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,22 @@ public void WhenSkipAndTakeWithoutReductionRequired_ShouldPass()
Assert.AreEqual(1, table.Count);
Assert.AreEqual("e", Encoding.UTF8.GetString((byte[])table[0].Values[0]));
}

[TestMethod]
public void WhenInferredValueIsNull_ShouldUseDefaultValue()
{
var table = TestResultMethodTemplate("GetCountryOrDefault('test')");

Assert.AreEqual(1, table.Count);
Assert.AreEqual("test", table[0].Values[0]);
}

[TestMethod]
public void WhenResolvedMethodIsGenericWithInjectSpecificSourceAttribute_ShouldConcretizeItAccordingly()
{
var table = TestResultMethodTemplate("GetCountryOrDefaultGeneric('test')");

Assert.AreEqual(1, table.Count);
Assert.AreEqual("test", table[0].Values[0]);
}
}
3 changes: 0 additions & 3 deletions Musoq.Evaluator.Tests/Schema/Basic/BasicEntityTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Musoq.Converter;
using Musoq.Converter.Build;
using Musoq.Evaluator.Tables;
using Musoq.Evaluator.Tests.Schema.Dynamic;
using Musoq.Evaluator.Tests.Schema.Unknown;
using Musoq.Plugins;
using Musoq.Schema;
using Musoq.Tests.Common;
Expand Down
12 changes: 12 additions & 0 deletions Musoq.Evaluator.Tests/Schema/Basic/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ public decimal GetPopulation([InjectSpecificSource(typeof(BasicEntity))] BasicEn
{
return entity.Population;
}

[BindableMethod]
public string GetCountryOrDefault([InjectSpecificSource(typeof(BasicEntity))] BasicEntity entity, string @default)
{
return entity.Country ?? @default;
}

[BindableMethod]
public string GetCountryOrDefaultGeneric<TColumn>([InjectSpecificSource(typeof(BasicEntity))] BasicEntity entity, TColumn @default)
{
return entity.Country ?? @default.ToString();
}

[BindableMethod]
public string ThrowException()
Expand Down
11 changes: 9 additions & 2 deletions Musoq.Evaluator/Visitors/BuildMetadataAndInferTypeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1687,10 +1687,17 @@ private static bool TryConstructGenericMethod(MethodInfo methodInfo, ArgsListNod

foreach (var genericArgument in genericArguments)
{
for (var i = 0; i < parameters.Length; i++)
var i = 0;
var shiftArgsWhenInjectSpecificSourcePresent = 0;
if (parameters[0].GetCustomAttribute<InjectSpecificSourceAttribute>() != null)
{
i = 1;
shiftArgsWhenInjectSpecificSourcePresent = 1;
}
for (; i < parameters.Length; i++)
{
var parameter = parameters[i];
var returnType = args.Args.Where((arg, index) => index == i).Single().ReturnType;
var returnType = args.Args.Where((_, index) => index == i - shiftArgsWhenInjectSpecificSourcePresent).Single().ReturnType;
var elementType = returnType.GetElementType();

if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == parameter.ParameterType.GetGenericTypeDefinition())
Expand Down

0 comments on commit a7f5808

Please sign in to comment.