Skip to content

Commit

Permalink
test: add Mapper DisableCollectionNullChecks
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezanet committed Dec 2, 2024
1 parent b2a570c commit b4bdc29
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/Gridify.Tests/GridifyExtensionsShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Gridify.Syntax;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using Xunit;
Expand Down Expand Up @@ -135,7 +136,7 @@ public void ApplyFiltering_NullHandlingUsingCustomConvertor()
Assert.Equal(expected, actual);
Assert.True(actual.Any());
}

[Fact] // issue #220
public void ApplyFiltering_CustomConvertor_ReturningNull_ShouldWork()
{
Expand Down Expand Up @@ -695,6 +696,20 @@ public void ApplyFiltering_UnmappedFields_ShouldSkipWhenIgnored()
Assert.True(actual.Any());
}

[Fact] // issue #238
public void ApplyFiltering_MapperDisableCollectionNullChecks_ShouldPreventAddingNullChecks()
{
var gm = new GridifyMapper<TestClass>(configuration => configuration.DisableCollectionNullChecks = true)
.AddMap("name", q => q.Children.Select(w => w.Name));

#pragma warning disable CS8602 // Dereference of a possibly null reference.
var expected = _fakeRepository.AsQueryable().Where(q => q.Children.Any(w => w.Name.Contains("a"))).ToString();
#pragma warning restore CS8602 // Dereference of a possibly null reference.
var actual = _fakeRepository.AsQueryable().ApplyFiltering("name=*a", gm).ToString();

Assert.Equal(expected, actual);
}

#endregion


Expand Down Expand Up @@ -723,6 +738,8 @@ private class TestOperator : UpperCaseEqual
};

[Fact]
[SuppressMessage("Assertions", "xUnit2031:Do not use Where clause with Assert.Single")]
[SuppressMessage("Assertions", "xUnit2029:Do not use Assert.Empty to check if a value does not exist in a collection")]
public void CustomOperator_GenericRegisterAndRemove_ShouldNotThrowAnyException()
{
GridifyGlobalConfiguration.CustomOperators.Register<TestOperator>();
Expand Down

0 comments on commit b4bdc29

Please sign in to comment.