Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Jan 28, 2024
1 parent eea7e31 commit d5b35e6
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ public override Task TrimStart_with_char_array_argument_in_predicate(bool async)
return base.TrimStart_with_char_array_argument_in_predicate(async);
}

[NotSupportedOnFirebirdTheory]
[MemberData(nameof(IsAsyncData))]
public override Task Where_math_degrees(bool async)
{
return base.Where_math_degrees(async);
}

[NotSupportedOnFirebirdTheory]
[MemberData(nameof(IsAsyncData))]
public override Task Where_math_radians(bool async)
{
return base.Where_mathf_radians(async);
}

[NotSupportedOnFirebirdTheory]
[MemberData(nameof(IsAsyncData))]
public override Task Where_mathf_degrees(bool async)
{
return base.Where_math_degrees(async);
}

[NotSupportedOnFirebirdTheory]
[MemberData(nameof(IsAsyncData))]
public override Task Where_mathf_radians(bool async)
{
return base.Where_mathf_radians(async);
}

[NotSupportedByProviderTheory]
[MemberData(nameof(IsAsyncData))]
public override Task Regex_IsMatch_MethodCall(bool async)
Expand Down Expand Up @@ -268,18 +296,4 @@ public override Task Datetime_subtraction_TotalDays(bool async)
{
return base.Datetime_subtraction_TotalDays(async);
}

[Theory]
[MemberData(nameof(IsAsyncData))]
public override Task String_FirstOrDefault_MethodCall(bool async)
{
return base.String_FirstOrDefault_MethodCall(async);
}

[Theory]
[MemberData(nameof(IsAsyncData))]
public override Task String_LastOrDefault_MethodCall(bool async)
{
return base.String_LastOrDefault_MethodCall(async);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* All Rights Reserved.
*/

//$Authors = Jiri Cincura ([email protected])

using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;

namespace FirebirdSql.EntityFrameworkCore.Firebird.Query.ExpressionTranslators.Internal;

public class SqlServerDateOnlyMethodTranslator : IMethodCallTranslator
{
readonly Dictionary<MethodInfo, string> _methodInfoDatePartMapping = new()
{
{ typeof(DateOnly).GetRuntimeMethod(nameof(DateOnly.AddYears), [typeof(int)]), "year" },
{ typeof(DateOnly).GetRuntimeMethod(nameof(DateOnly.AddMonths), [typeof(int)]), "month" },
{ typeof(DateOnly).GetRuntimeMethod(nameof(DateOnly.AddDays), [typeof(int)]), "day" }
};

readonly ISqlExpressionFactory _sqlExpressionFactory;

public SqlServerDateOnlyMethodTranslator(ISqlExpressionFactory sqlExpressionFactory)
{
_sqlExpressionFactory = sqlExpressionFactory;
}

public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
if (_methodInfoDatePartMapping.TryGetValue(method, out var datePart) && instance != null)
{
instance = _sqlExpressionFactory.ApplyDefaultTypeMapping(instance);

return _sqlExpressionFactory.Function(
"DATEADD",
new[] { _sqlExpressionFactory.Fragment(datePart), _sqlExpressionFactory.Convert(arguments[0], typeof(int)), instance },
nullable: true,
argumentsPropagateNullability: new[] { false, true, true },
instance.Type,
instance.TypeMapping);
}

if (method.DeclaringType == typeof(DateOnly) && method.Name == nameof(DateOnly.FromDateTime) && arguments.Count == 1)
{
return _sqlExpressionFactory.Convert(arguments[0], typeof(DateOnly));
}

return null;
}
}

0 comments on commit d5b35e6

Please sign in to comment.