public void Map_AnEmptyProjection_ShouldNotMapAnythingBecauseItsNotProjectingProperties() { // Arrange Expression <Func <Person, dynamic> > projector = p => new { }; // Act Expression projectorMapped = _columnExpressionMapper.Map(projector); // Assert List <ColumnExpression> columnExpressions = new ColumnExpressionsFetcher().FetchAll(projectorMapped); Assert.True(columnExpressions.Count == 0); }
public void Map_AnonymousTypeProjectionWithOneProperty_ShouldMapThePropertyToAColumnExpression() { // Arrange Expression <Func <Person, dynamic> > projector = p => new { p.Id }; // Act Expression projectorMapped = _columnExpressionMapper.Map(projector); // Assert var memberExpression = (MemberExpression)((NewExpression)projector.Body).GetExpressionByMember("Id"); ColumnExpression columnExpressionMapped = new ColumnExpressionsFetcher().FetchAll(projectorMapped)[0]; Assert.True(columnExpressionMapped.ColumnMapper == memberExpression); }
public void Map_UserDefinedTypeProjectionWithOneProperty_ShouldMapThePropertyToColumnExpression() { // Arrange Expression <Func <Person, dynamic> > projector = p => new Person() { Id = p.Id }; // Act Expression projectorMapped = _columnExpressionMapper.Map(projector); // Assert var m = (MemberExpression)((MemberInitExpression)projector.Body).GetExpressionByMember("Id"); var columnExpression = new ColumnExpression(m); List <ColumnExpression> columnExpressions = new ColumnExpressionsFetcher().FetchAll(projectorMapped); Assert.True(columnExpression.ColumnMapper == columnExpressions[0].ColumnMapper); }
public void Map_AnonymousTypeProjectionWithMultipleProperties_ShouldMapThePropertiesToColumnExpressions() { // Arrange Expression <Func <Person, dynamic> > projector = p => new { p.Id, p.FirstName, p.LastName }; // Act Expression projectorMapped = _columnExpressionMapper.Map(projector); // Asserts Expression[] newExpArgs = ((NewExpression)projector.Body).GetArguments(); ColumnExpression[] columnExpressions = new ColumnExpressionsFetcher().FetchAll(projectorMapped).ToArray(); Assert.False(newExpArgs.Length != columnExpressions.Length, $"Expected {newExpArgs.Length} columns mapped, but instead {columnExpressions.Length} columns were mapped."); for (int index = 0; index < newExpArgs.Length; index++) { Assert.False(newExpArgs[index] != columnExpressions[index].ColumnMapper, $"Dismatch between expressions mapped. Expected: {newExpArgs[index]} ; Mapped: {columnExpressions[index].ColumnMapper}"); } }
public void Map_UserDefinedTypeProjectionWithMultipleProperties_ShouldMapThePropertiesToColumnExpressions() { // Arrange Expression <Func <Person, dynamic> > projector = p => new Person() { Id = p.Id, FirstName = p.LastName }; // Act Expression projectorMapped = _columnExpressionMapper.Map(projector); // Asserts Expression[] bindingExpressions = ((MemberInitExpression)projector.Body).GetBindingExpressions(); ColumnExpression[] columnExpressions = new ColumnExpressionsFetcher().FetchAll(projectorMapped).ToArray(); Assert.False(bindingExpressions.Length != columnExpressions.Length, $"Expected {bindingExpressions.Length} columns mapped, but instead {columnExpressions.Length} columns were mapped."); for (int index = 0; index < bindingExpressions.Length; index++) { Assert.False(bindingExpressions[index] != columnExpressions[index].ColumnMapper, $"Dismatch between expressions mapped. Expected: {bindingExpressions[index]} ; Mapped: {columnExpressions[index].ColumnMapper}"); } }