-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from OData/users/TehWardy/foundations-expressi…
…on-apply FOUNDATIONS: Apply Expression to Source
- Loading branch information
Showing
61 changed files
with
1,141 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...Tests.Unit/Services/Foundations/OExpressions/OExpressionServiceTests.Validations.Apply.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
//----------------------------------------------------------------------- | ||
// Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
// See License.txt in the project root for license information. | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Moq; | ||
using OData.Neo.Core.Models.OExpressions; | ||
using OData.Neo.Core.Models.OExpressions.Exceptions; | ||
using Xunit; | ||
|
||
namespace OData.Neo.Core.Tests.Unit.Services.Foundations.OExpressions | ||
{ | ||
public partial class OExpressionServiceTests | ||
{ | ||
[Fact] | ||
public void ShouldThrowValidationExceptionOnApplyIfSourceIsNull() | ||
{ | ||
// given | ||
OExpression someOExpression = CreateRandomOExpression(); | ||
IQueryable<object> nullSource = null; | ||
|
||
var nullSourceOExpressionException = | ||
new NullSourceOExpressionException(); | ||
|
||
var expectedOExpressionValidationException = | ||
new OExpressionValidationException( | ||
nullSourceOExpressionException); | ||
|
||
// when | ||
Action applyExpressionAction = () => | ||
this.oExpressionService.ApplyExpression( | ||
nullSource, | ||
someOExpression); | ||
|
||
OExpressionValidationException actualOExpressionValidationException = | ||
Assert.Throws<OExpressionValidationException>( | ||
applyExpressionAction); | ||
|
||
// then | ||
actualOExpressionValidationException.Should().BeEquivalentTo( | ||
expectedOExpressionValidationException); | ||
|
||
this.expressionBrokerMock.Verify(broker => | ||
broker.ApplyExpression<object>( | ||
It.IsAny<IQueryable<object>>(), | ||
It.IsAny<Expression>()), | ||
Times.Never); | ||
|
||
this.expressionBrokerMock.VerifyNoOtherCalls(); | ||
} | ||
|
||
[Fact] | ||
public void ShouldThrowValidationExceptionOnApplyIfOexpressionIsNull() | ||
{ | ||
// given | ||
OExpression nullOExpression = null; | ||
IQueryable<object> someSource = CreateRandomSource(); | ||
|
||
var nullOExpressionException = | ||
new NullOExpressionException(); | ||
|
||
var expectedOExpressionValidationException = | ||
new OExpressionValidationException( | ||
nullOExpressionException); | ||
|
||
// when | ||
Action applyExpressionAction = () => | ||
this.oExpressionService.ApplyExpression( | ||
someSource, | ||
nullOExpression); | ||
|
||
OExpressionValidationException actualOExpressionValidationException = | ||
Assert.Throws<OExpressionValidationException>( | ||
applyExpressionAction); | ||
|
||
// then | ||
actualOExpressionValidationException.Should().BeEquivalentTo( | ||
expectedOExpressionValidationException); | ||
|
||
this.expressionBrokerMock.Verify(broker => | ||
broker.ApplyExpression<object>( | ||
It.IsAny<IQueryable<object>>(), | ||
It.IsAny<Expression>()), | ||
Times.Never); | ||
|
||
this.expressionBrokerMock.VerifyNoOtherCalls(); | ||
} | ||
|
||
[Fact] | ||
public void ShouldThrowValidationExceptionOnApplyIfExpressionIsNull() | ||
{ | ||
// given | ||
OExpression randomOExpression = CreateRandomOExpression(); | ||
IQueryable<object> someSource = CreateRandomSource(); | ||
OExpression invalidOExpression = randomOExpression; | ||
invalidOExpression.Expression = null; | ||
|
||
var invalidOExpressionException = | ||
new InvalidOExpressionException(); | ||
|
||
invalidOExpressionException.AddData( | ||
key: nameof(OExpression.Expression), | ||
values: "Value is required"); | ||
|
||
var expectedOExpressionValidationException = | ||
new OExpressionValidationException( | ||
invalidOExpressionException); | ||
|
||
// when | ||
Action applyExpressionAction = () => | ||
this.oExpressionService.ApplyExpression( | ||
someSource, | ||
invalidOExpression); | ||
|
||
OExpressionValidationException actualOExpressionValidationException = | ||
Assert.Throws<OExpressionValidationException>( | ||
applyExpressionAction); | ||
|
||
// then | ||
actualOExpressionValidationException.Should().BeEquivalentTo( | ||
expectedOExpressionValidationException); | ||
|
||
this.expressionBrokerMock.Verify(broker => | ||
broker.ApplyExpression<object>( | ||
It.IsAny<IQueryable<object>>(), | ||
It.IsAny<Expression>()), | ||
Times.Never); | ||
|
||
this.expressionBrokerMock.VerifyNoOtherCalls(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.