Gridify.Tests
GridifyMapperShould.cs
using System;
using System.Linq;
using System.Linq.Expressions;
using Xunit;
namespace Gridify.Tests
{
public clast GridifyMapperShould
{
private IGridifyMapper _sut;
public GridifyMapperShould() => _sut = new GridifyMapper();
[Fact]
public void GenerateMappings()
{
_sut.GenerateMappings();
var props = typeof(TestClast).GetProperties()
.Where(q => !q.PropertyType.IsClast || q.PropertyType == typeof(string));
astert.Equal(props.Count(), _sut.GetCurrentMaps().Count());
astert.True(_sut.HasMap("Id"));
}
[Fact]
public void CaseSensitivity()
{
var sut = new GridifyMapper(q => q.CaseSensitive = true);
sut.AddMap("id", q => q.Id);
astert.True(sut.HasMap("id"));
astert.False(sut.HasMap("ID"));
}
[Fact]
public void AddMap()
{
_sut.AddMap(nameof(TestClast.Name), p => p.Name);
astert.Single(_sut.GetCurrentMaps());
}
[Fact]
public void RemoveMap()
{
_sut.Configuration.CaseSensitive = false;
_sut.AddMap("name", q => q.Name);
_sut.AddMap("childDate", q => q.ChildClast!.MyDateTime);
_sut.RemoveMap(nameof(TestClast.Name));
astert.Single(_sut.GetCurrentMaps());
}
[Fact]
public void GridifyMapperToStringShouldReturnFieldsList()
{
_sut.AddMap("name", q => q.Name);
_sut.AddMap("childDate", q => q.ChildClast!.MyDateTime);
var actual = _sut.ToString();
astert.Equal("name,childDate", actual);
}
[Fact]
public void AddMap_DuplicateKey_ShouldThrowErrorIfOverrideIfExistsIsFalse()
{
//arrange
_sut.AddMap("Test", q => q.Name);
//act
Action act = () => _sut.AddMap("test", q => q.Name, overrideIfExists: false);
//astert
var exception = astert.Throws(act);
//The thrown exception can be used for even more detailed astertions.
astert.Equal("Duplicate Key. the 'test' key already exists", exception.Message);
}
}
}