Skip to content

Commit 00f30cf

Browse files
committed
Fixed Sandcastle doc warnings and minor refactoring of ByteBufferStream.
1 parent fdfbedc commit 00f30cf

File tree

9 files changed

+51
-49
lines changed

9 files changed

+51
-49
lines changed

src/MongoDB.Bson.Tests/IO/ByteBufferStreamTests.cs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,6 @@ public void CanWrite_get_should_return_expected_result(bool bufferIsReadOnly, bo
113113
result.Should().Be(expectedResult);
114114
}
115115

116-
[Test]
117-
public void Capacity_get_should_call_buffer()
118-
{
119-
var subject = CreateSubject();
120-
subject.Buffer.Capacity.Returns(1);
121-
122-
var result = subject.Capacity;
123-
124-
result.Should().Be(1);
125-
var temp = subject.Buffer.Received(1).Capacity;
126-
}
127-
128-
[Test]
129-
public void Capacity_get_should_throw_when_subject_is_disposed()
130-
{
131-
var subject = CreateDisposedSubject();
132-
133-
Action action = () => { var _ = subject.Capacity; };
134-
135-
action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("ByteBufferStream");
136-
}
137-
138116
[Test]
139117
public void constructor_should_initialize_subject(
140118
[Values(false, true)]
@@ -914,29 +892,41 @@ public void SetLength_should_throw_when_buffer_is_not_writable()
914892
}
915893

916894
[Test]
917-
public void SetLength_should_have_expected_effect(
895+
public void SetLength_should_set_length(
918896
[Values(0, 1, 2, 3)]
919897
long length)
920898
{
921899
var subject = CreateSubject();
922-
subject.Buffer.Capacity.Returns(3);
923900

924901
subject.SetLength(length);
925902

926903
subject.Length.Should().Be(length);
904+
subject.Buffer.Received(1).EnsureCapacity((int)length);
905+
}
906+
907+
[Test]
908+
public void SetLength_should_set_position_when_position_is_greater_than_new_length(
909+
[Values(0, 1, 2, 3)]
910+
long length)
911+
{
912+
var subject = CreateSubject();
913+
subject.Position = length + 1;
914+
915+
subject.SetLength(length);
916+
917+
subject.Position.Should().Be(length);
927918
}
928919

929920
[Test]
930921
public void SetLength_should_throw_when_length_is_out_of_range(
931-
[Values(-1, 4)]
922+
[Values(-1, (long)int.MaxValue + 1)]
932923
long length)
933924
{
934925
var subject = CreateSubject();
935-
subject.Buffer.Capacity.Returns(3);
936926

937927
Action action = () => subject.SetLength(length);
938928

939-
action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("length");
929+
action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("value");
940930
}
941931

942932
[Test]

src/MongoDB.Bson/IO/BsonStreamAdapter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ public BsonStreamAdapter(Stream stream, bool ownsStream = false)
5252
}
5353

5454
// properties
55-
/// <inheritdoc/>
55+
/// <summary>
56+
/// Gets the base stream.
57+
/// </summary>
58+
/// <value>
59+
/// The base stream.
60+
/// </value>
5661
public Stream BaseStream
5762
{
5863
get

src/MongoDB.Bson/IO/ByteBufferStream.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ public override bool CanWrite
9292
get { return !_disposed && !_buffer.IsReadOnly; }
9393
}
9494

95-
/// <inheritdoc/>
96-
public int Capacity
97-
{
98-
get
99-
{
100-
ThrowIfDisposed();
101-
return _buffer.Capacity;
102-
}
103-
}
104-
10595
/// <inheritdoc/>
10696
public override long Length
10797
{
@@ -211,16 +201,21 @@ public override long Seek(long offset, SeekOrigin origin)
211201
}
212202

213203
/// <inheritdoc/>
214-
public override void SetLength(long length)
204+
public override void SetLength(long value)
215205
{
216-
if (length < 0 || length > Capacity)
206+
if (value < 0 || value > int.MaxValue)
217207
{
218-
throw new ArgumentOutOfRangeException("length");
208+
throw new ArgumentOutOfRangeException("value");
219209
}
220210
ThrowIfDisposed();
221-
EnsureWriteable();
211+
EnsureWriteable();
222212

223-
_length = (int)length;
213+
_buffer.EnsureCapacity((int)value);
214+
_length = (int)value;
215+
if (_position > _length)
216+
{
217+
_position = _length;
218+
}
224219
}
225220

226221
/// <inheritdoc/>

src/MongoDB.Driver.Legacy/MongoServer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ public static class MongoClientExtensions
4343
/// <summary>
4444
/// Gets a MongoServer object using this client's settings.
4545
/// </summary>
46-
/// <returns>A MongoServer.</returns>
46+
/// <param name="client">The client.</param>
47+
/// <returns>
48+
/// A MongoServer.
49+
/// </returns>
4750
[Obsolete("Use the new API instead.")]
4851
public static MongoServer GetServer(this MongoClient client)
4952
{

src/MongoDB.Driver/AggregateFluent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public override IAggregateFluent<TResult> Sort(SortDefinition<TResult> sort)
125125
return AppendStage(stage);
126126
}
127127

128-
public override IAggregateFluent<TNewResult> Unwind<TNewResult>(FieldDefinition<TResult> field, IBsonSerializer<TNewResult> resultSerializer)
128+
public override IAggregateFluent<TNewResult> Unwind<TNewResult>(FieldDefinition<TResult> field, IBsonSerializer<TNewResult> newResultSerializer)
129129
{
130130
const string operatorName = "$unwind";
131131
var stage = new DelegatedPipelineStageDefinition<TResult, TNewResult>(
@@ -134,7 +134,7 @@ public override IAggregateFluent<TNewResult> Unwind<TNewResult>(FieldDefinition<
134134
operatorName, new BsonDocument(
135135
operatorName,
136136
"$" + field.Render(s, sr).FieldName),
137-
resultSerializer ?? (s as IBsonSerializer<TNewResult>) ?? sr.GetSerializer<TNewResult>()));
137+
newResultSerializer ?? (s as IBsonSerializer<TNewResult>) ?? sr.GetSerializer<TNewResult>()));
138138

139139
return AppendStage<TNewResult>(stage);
140140
}

src/MongoDB.Driver/AggregateFluentBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public abstract class AggregateFluentBase<TResult> : IOrderedAggregateFluent<TRe
5858
public abstract IAggregateFluent<TResult> Sort(SortDefinition<TResult> sort);
5959

6060
/// <inheritdoc />
61-
public abstract IAggregateFluent<TNewResult> Unwind<TNewResult>(FieldDefinition<TResult> field, IBsonSerializer<TNewResult> resultSerializer = null);
61+
public abstract IAggregateFluent<TNewResult> Unwind<TNewResult>(FieldDefinition<TResult> field, IBsonSerializer<TNewResult> newResultSerializer = null);
6262

6363
/// <inheritdoc />
6464
public abstract Task<IAsyncCursor<TResult>> ToCursorAsync(CancellationToken cancellationToken);

src/MongoDB.Driver/MapReduceOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace MongoDB.Driver
2626
/// <summary>
2727
/// Represents the options for a map-reduce operation.
2828
/// </summary>
29+
/// <typeparam name="TDocument">The type of the document.</typeparam>
30+
/// <typeparam name="TResult">The type of the result.</typeparam>
2931
public sealed class MapReduceOptions<TDocument, TResult>
3032
{
3133
// fields

src/MongoDB.Driver/PipelineDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public abstract class PipelineDefinition<TInput, TOutput>
7575
public abstract RenderedPipelineDefinition<TOutput> Render(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry);
7676

7777
/// <summary>
78-
/// Performs an implicit conversion from <see cref="T:IPipelineStage[]"/> to <see cref="PipelineDefinition{TInput, TOutput}"/>.
78+
/// Performs an implicit conversion from <see cref="IPipelineStageDefinition"/>[] to <see cref="PipelineDefinition{TInput, TOutput}"/>.
7979
/// </summary>
8080
/// <param name="stages">The stages.</param>
8181
/// <returns>
@@ -109,7 +109,7 @@ public static implicit operator PipelineDefinition<TInput, TOutput>(List<IPipeli
109109
}
110110

111111
/// <summary>
112-
/// Performs an implicit conversion from <see cref="T:BsonDocument[]"/> to <see cref="PipelineDefinition{TInput, TOutput}"/>.
112+
/// Performs an implicit conversion from <see cref="BsonDocument"/>[] to <see cref="PipelineDefinition{TInput, TOutput}"/>.
113113
/// </summary>
114114
/// <param name="stages">The stages.</param>
115115
/// <returns>

src/MongoDB.Driver/PipelineStageDefinition.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public interface IRenderedPipelineStageDefinition
4747
/// <summary>
4848
/// A rendered pipeline stage.
4949
/// </summary>
50+
/// <typeparam name="TOutput">The type of the output.</typeparam>
5051
public class RenderedPipelineStageDefinition<TOutput> : IRenderedPipelineStageDefinition
5152
{
5253
private string _operatorName;
@@ -125,6 +126,8 @@ public interface IPipelineStageDefinition
125126
/// <summary>
126127
/// Base class for pipeline stages.
127128
/// </summary>
129+
/// <typeparam name="TInput">The type of the input.</typeparam>
130+
/// <typeparam name="TOutput">The type of the output.</typeparam>
128131
public abstract class PipelineStageDefinition<TInput, TOutput> : IPipelineStageDefinition
129132
{
130133
/// <summary>
@@ -198,6 +201,8 @@ IRenderedPipelineStageDefinition IPipelineStageDefinition.Render(IBsonSerializer
198201
/// <summary>
199202
/// A <see cref="BsonDocument"/> based stage.
200203
/// </summary>
204+
/// <typeparam name="TInput">The type of the input.</typeparam>
205+
/// <typeparam name="TOutput">The type of the output.</typeparam>
201206
public sealed class BsonDocumentPipelineStageDefinition<TInput, TOutput> : PipelineStageDefinition<TInput, TOutput>
202207
{
203208
private readonly BsonDocument _document;
@@ -233,6 +238,8 @@ public override RenderedPipelineStageDefinition<TOutput> Render(IBsonSerializer<
233238
/// <summary>
234239
/// A JSON <see cref="String"/> based pipeline stage.
235240
/// </summary>
241+
/// <typeparam name="TInput">The type of the input.</typeparam>
242+
/// <typeparam name="TOutput">The type of the output.</typeparam>
236243
public sealed class JsonPipelineStageDefinition<TInput, TOutput> : PipelineStageDefinition<TInput, TOutput>
237244
{
238245
private readonly BsonDocument _document;

0 commit comments

Comments
 (0)