Skip to content

Commit

Permalink
add GetExpression test
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezanet committed Jul 5, 2020
1 parent f02ac4c commit 0866b9d
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions test/Core.Tests/GridifyMapperShould.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
using Xunit;
using System;
using System.Linq;
using System.Linq.Expressions;
using Gridify;
using Xunit;

namespace Core.Query.Tests
{
public class GridifyMapperShould
{
namespace Core.Query.Tests {
public class GridifyMapperShould {

class TestClass
{
class TestClass {
public int Id { get; set; }
public string Name { get; set; }
public TestClass ClassProp { get; set; }
}

[Fact]
public void GenerateMappings()
{
var sut = new GridifyMapper<TestClass>();
sut.GenerateMappings();
Assert.Equal(typeof(TestClass).GetProperties().Count(), sut.Mappings.Count);
Assert.True(sut.Mappings.ContainsKey("Id"));
public void GenerateMappings () {
var sut = new GridifyMapper<TestClass> ();
sut.GenerateMappings ();
Assert.Equal (typeof (TestClass).GetProperties ().Count (), sut.Mappings.Count);
Assert.True (sut.Mappings.ContainsKey ("Id"));
}

[Fact]
public void CaseSensitivity()
{
var sut = new GridifyMapper<TestClass>(true);
sut.Mappings.Add("id", q=>q.Id);

Assert.True(sut.CaseSensitive);
Assert.True(sut.Mappings.ContainsKey("id"));
Assert.False(sut.Mappings.ContainsKey("ID"));
public void CaseSensitivity () {
var sut = new GridifyMapper<TestClass> (true);
sut.Mappings.Add ("id", q => q.Id);

Assert.True (sut.CaseSensitive);
Assert.True (sut.Mappings.ContainsKey ("id"));
Assert.False (sut.Mappings.ContainsKey ("ID"));
}

[Fact]
public void AddMap()
{
var sut = new GridifyMapper<TestClass>();
sut.AddMap(nameof(TestClass.Name), p => p.Name);
Assert.Single(sut.Mappings);
public void AddMap () {
var sut = new GridifyMapper<TestClass> ();
sut.AddMap (nameof (TestClass.Name), p => p.Name);
Assert.Single (sut.Mappings);
}

[Fact]
public void RemoveMap()
{
var sut = new GridifyMapper<TestClass>();
sut.Mappings.Add("name",q=>q.Name);
sut.Mappings.Add("Id",q=>q.Id);
sut.RemoveMap( nameof(TestClass.Name) );
Assert.Single(sut.Mappings);
public void RemoveMap () {
var sut = new GridifyMapper<TestClass> ();
sut.Mappings.Add ("name", q => q.Name);
sut.Mappings.Add ("Id", q => q.Id);
sut.RemoveMap (nameof (TestClass.Name));
Assert.Single (sut.Mappings);
}

[Fact]
public void GetExpression () {
var sut = new GridifyMapper<TestClass> ();

Expression<Func<TestClass, object>> expected = Param_0 => (object)Param_0.Name;
var actual = sut.GetExpression ("Name");

Assert.IsType (expected.GetType() , actual);
Assert.Equal( expected.Body.ToString() ,actual.Body.ToString());

}
}
}
}

0 comments on commit 0866b9d

Please sign in to comment.