Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inputfalken committed Jul 5, 2024
1 parent 9f0aad8 commit 4f756ca
Showing 1 changed file with 2 additions and 43 deletions.
45 changes: 2 additions & 43 deletions tests/Dynatello.Tests/HandlerTests/QueryRequestHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Dynatello.Builders.Types;
using NSubstitute;
using AutoFixture;
using System.Linq.Expressions;

namespace Dynatello.Tests.HandlerTests;
public class QueryRequestHandlerTests
Expand All @@ -29,7 +28,7 @@ public async Task Send_SuccessMock_ShouldReturnAttributes()
.ToQueryRequestHandler(x => x
.WithKeyConditionExpression(((x, y) => $"{x.Id} = {y.Id}"))
.ToQueryRequestBuilder() with
{ IndexName = "INDEX" }, amazonDynamoDB)
{ IndexName = "INDEX" }, x => x.AmazonDynamoDB = amazonDynamoDB)
.Send((Guid.NewGuid(), 2), default);

Assert.Equal(expected, actual);
Expand Down Expand Up @@ -78,49 +77,9 @@ public async Task Send_SuccessChunkedMock_ShouldReturnAttributes()
.ToQueryRequestHandler(x => x
.WithKeyConditionExpression(((x, y) => $"{x.Id} = {y.Id}"))
.ToQueryRequestBuilder() with
{ IndexName = "INDEX" }, amazonDynamoDB)
{ IndexName = "INDEX" }, x => x.AmazonDynamoDB = amazonDynamoDB)
.Send((Guid.NewGuid(), 2), default);

Assert.Equal(chunks.SelectMany(x => x.Elements).ToArray(), actual);
}
}
public static class PredicateBuilder
{

internal class SubstExpressionVisitor : System.Linq.Expressions.ExpressionVisitor
{
public Dictionary<Expression, Expression> subst = new Dictionary<Expression, Expression>();

protected override Expression VisitParameter(ParameterExpression node)
{
if (subst.TryGetValue(node, out var newValue))
{
return newValue;
}
return node;
}
}
public static Expression<Predicate<T>> And<T>(this Expression<Predicate<T>> a, Expression<Func<T, bool>> b)
{

ParameterExpression p = a.Parameters[0];

SubstExpressionVisitor visitor = new SubstExpressionVisitor();
visitor.subst[b.Parameters[0]] = p;

Expression body = Expression.AndAlso(a.Body, visitor.Visit(b.Body));
return Expression.Lambda<Predicate<T>>(body, p);
}

public static Expression<Predicate<T>> Or<T>(this Expression<Predicate<T>> a, Expression<Func<T, bool>> b)
{

ParameterExpression p = a.Parameters[0];

SubstExpressionVisitor visitor = new SubstExpressionVisitor();
visitor.subst[b.Parameters[0]] = p;

Expression body = Expression.OrElse(a.Body, visitor.Visit(b.Body));
return Expression.Lambda<Predicate<T>>(body, p);
}
}

0 comments on commit 4f756ca

Please sign in to comment.