Skip to content

Commit 533fe3e

Browse files
committed
fix tests
1 parent c0d08cf commit 533fe3e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/MongoDB.Driver/SortDirectionExtensions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ namespace MongoDB.Driver
2020
{
2121
internal static class SortDirectionExtensions
2222
{
23-
internal static BsonValue Render(this SortDirection direction)
24-
{
25-
return direction switch
23+
internal static BsonValue Render(this SortDirection direction) =>
24+
direction switch
2625
{
2726
SortDirection.Ascending => 1,
2827
SortDirection.Descending => -1,
2928
_ => throw new InvalidOperationException($"Invalid sort direction: {direction}.")
3029
};
31-
}
3230
}
3331
}

tests/MongoDB.Driver.Tests/SortDefinitionBuilderTests.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void Ascending_value()
3737
{
3838
var subject = CreateSubject<BsonDocument>();
3939

40-
Assert(subject.Ascending(), "{direction: 1}");
40+
Assert(subject.Ascending(), "1");
4141
}
4242

4343
[Fact]
@@ -108,7 +108,7 @@ public void Descending_value()
108108
{
109109
var subject = CreateSubject<BsonDocument>();
110110

111-
Assert(subject.Descending(), "{direction: -1}");
111+
Assert(subject.Descending(), "-1");
112112
}
113113

114114
[Fact]
@@ -144,10 +144,20 @@ public void MetaTextScore()
144144
Assert(subject.MetaTextScore("awesome"), "{awesome: {$meta: 'textScore'}}");
145145
}
146146

147+
[Fact]
148+
public void CallingRenderOnValueBasedSortShouldThrow()
149+
{
150+
var subject = CreateSubject<BsonDocument>();
151+
152+
var exception = Record.Exception(() => subject.Ascending().Render(new RenderArgs<BsonDocument>()));
153+
154+
exception.Should().BeOfType<InvalidOperationException>();
155+
}
156+
147157
private void Assert<TDocument>(SortDefinition<TDocument> sort, string expectedJson)
148158
{
149159
var documentSerializer = BsonSerializer.SerializerRegistry.GetSerializer<TDocument>();
150-
var renderedSort = sort.Render(new(documentSerializer, BsonSerializer.SerializerRegistry));
160+
var renderedSort = sort.RenderAsBsonValue(new(documentSerializer, BsonSerializer.SerializerRegistry));
151161

152162
renderedSort.Should().Be(expectedJson);
153163
}

0 commit comments

Comments
 (0)