-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
increase code coverage and some code changes
- Loading branch information
Showing
27 changed files
with
2,232 additions
and
44 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace ProtoBuf.Data | ||
{ | ||
internal static class Throw | ||
{ | ||
public static void IfNull<T>(T value, string parameterName) | ||
{ | ||
if (value == null) | ||
{ | ||
throw new ArgumentNullException(parameterName); | ||
} | ||
} | ||
} | ||
} |
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,32 @@ | ||
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information. | ||
|
||
using System.Data; | ||
using System.IO; | ||
|
||
namespace ProtoBuf.Data.Tests | ||
{ | ||
internal static class DataReaderHelper | ||
{ | ||
public static ProtoDataReader CreateDataReader<TDataType>(TDataType value) | ||
{ | ||
var dataTable = new DataTable(); | ||
|
||
dataTable.Columns.Add(typeof(TDataType).Name, typeof(TDataType)); | ||
|
||
dataTable.Rows.Add(value); | ||
|
||
return ToProtoDataReader(dataTable.CreateDataReader()); | ||
} | ||
|
||
public static ProtoDataReader ToProtoDataReader(IDataReader dataReader) | ||
{ | ||
var memoryStream = new MemoryStream(); | ||
|
||
DataSerializer.Serialize(memoryStream, dataReader); | ||
|
||
memoryStream.Position = 0; | ||
|
||
return (ProtoDataReader)DataSerializer.Deserialize(memoryStream); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
test/protobuf-net-data.Tests/ProtoBufDataReaderTests.TheDisposeMethod.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,38 @@ | ||
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Data; | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace ProtoBuf.Data.Tests | ||
{ | ||
public partial class ProtoDataReaderTests | ||
{ | ||
public class TheDisposeMethod : ProtoDataReaderTests | ||
{ | ||
[Fact] | ||
public void ShouldDisposeStream() | ||
{ | ||
// Arrange | ||
var dataTable = new DataTable(); | ||
|
||
dataTable.Columns.Add("foo", typeof(int)); | ||
|
||
var memoryStream = new MemoryStream(); | ||
|
||
DataSerializer.Serialize(memoryStream, dataTable.CreateDataReader()); | ||
|
||
memoryStream.Position = 0; | ||
|
||
var dataReader = (ProtoDataReader)DataSerializer.Deserialize(memoryStream); | ||
|
||
// Act | ||
dataReader.Dispose(); | ||
|
||
// Assert | ||
Assert.Throws<ObjectDisposedException>(() => memoryStream.Position = 0); | ||
} | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
test/protobuf-net-data.Tests/ProtoBufDataReaderTests.TheGetBooleanMethod.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,75 @@ | ||
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Data; | ||
using Xunit; | ||
|
||
namespace ProtoBuf.Data.Tests | ||
{ | ||
public partial class ProtoDataReaderTests | ||
{ | ||
public class TheGetBooleanMethod : ProtoDataReaderTests | ||
{ | ||
[Fact] | ||
public void ShouldThrowExceptionWhenDataReaderIsClosed() | ||
{ | ||
// Arrange | ||
var dataReader = DataReaderHelper.CreateDataReader(value: true); | ||
|
||
dataReader.Close(); | ||
|
||
// Assert | ||
Assert.Throws<InvalidOperationException>(() => dataReader.GetBoolean(0)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldThrowExceptionWhenNoData() | ||
{ | ||
// Arrange | ||
var dataReader = DataReaderHelper.CreateDataReader(value: true); | ||
|
||
// Assert | ||
Assert.Throws<InvalidOperationException>(() => dataReader.GetBoolean(0)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldThrowExceptionWhenIndexIsOutOfRange() | ||
{ | ||
// Arrange | ||
var dataReader = DataReaderHelper.CreateDataReader(value: true); | ||
|
||
dataReader.Read(); | ||
|
||
// Assert | ||
Assert.Throws<IndexOutOfRangeException>(() => dataReader.GetBoolean(dataReader.FieldCount)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldThrowExceptionWhenIsNull() | ||
{ | ||
// Arrange | ||
var dataReader = DataReaderHelper.CreateDataReader(value: (string)null); | ||
|
||
dataReader.Read(); | ||
|
||
// Assert | ||
Assert.Throws<InvalidOperationException>(() => dataReader.GetBoolean(0)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnCorrespondingValue() | ||
{ | ||
// Arrange | ||
var dataReader = DataReaderHelper.CreateDataReader(value: true); | ||
|
||
dataReader.Read(); | ||
|
||
// Act | ||
var result = dataReader.GetBoolean(0); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
test/protobuf-net-data.Tests/ProtoBufDataReaderTests.TheGetByteMethod.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,75 @@ | ||
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using Xunit; | ||
|
||
namespace ProtoBuf.Data.Tests | ||
{ | ||
public partial class ProtoDataReaderTests | ||
{ | ||
public class TheGetByteMethod : ProtoDataReaderTests | ||
{ | ||
[Fact] | ||
public void ShouldThrowExceptionWhenDataReaderIsClosed() | ||
{ | ||
// Arrange | ||
var dataReader = DataReaderHelper.CreateDataReader(value: (byte)0b0010_1010); | ||
|
||
dataReader.Close(); | ||
|
||
// Assert | ||
Assert.Throws<InvalidOperationException>(() => dataReader.GetByte(1)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldThrowExceptionWhenNoData() | ||
{ | ||
// Arrange | ||
var dataReader = DataReaderHelper.CreateDataReader(value: (byte)0b0010_1010); | ||
|
||
// Assert | ||
Assert.Throws<InvalidOperationException>(() => dataReader.GetByte(1)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldThrowExceptionWhenIndexIsOutOfRange() | ||
{ | ||
// Arrange | ||
var dataReader = DataReaderHelper.CreateDataReader(value: (byte)0b0010_1010); | ||
|
||
dataReader.Read(); | ||
|
||
// Assert | ||
Assert.Throws<IndexOutOfRangeException>(() => dataReader.GetByte(dataReader.FieldCount)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldThrowExceptionWhenIsNull() | ||
{ | ||
// Arrange | ||
var dataReader = DataReaderHelper.CreateDataReader(value: (string)null); | ||
|
||
dataReader.Read(); | ||
|
||
// Assert | ||
Assert.Throws<InvalidOperationException>(() => dataReader.GetByte(0)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnCorrespondingValue() | ||
{ | ||
// Arrange | ||
var value = (byte)0b0010_1010; | ||
var dataReader = DataReaderHelper.CreateDataReader(value: value); | ||
|
||
dataReader.Read(); | ||
|
||
// Act | ||
var result = dataReader.GetByte(0); | ||
|
||
// Assert | ||
Assert.Equal(value, result); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.