diff options
author | Jon Skeet <skeet@pobox.com> | 2015-04-30 14:51:42 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2015-04-30 14:51:42 +0100 |
commit | 0884b77975146be5d0557b254fbeab940cda641a (patch) | |
tree | eee4106598d0faf92b566f7e03930f25df38a56c /csharp/src/ProtocolBuffers.Test/WireFormatTest.cs | |
parent | 151018e888927f4e89e325af013613cc1b08196c (diff) | |
parent | c56475088d2d36d29a2640f35b9a8621796c051c (diff) | |
download | protobuf-0884b77975146be5d0557b254fbeab940cda641a.tar.gz protobuf-0884b77975146be5d0557b254fbeab940cda641a.tar.bz2 protobuf-0884b77975146be5d0557b254fbeab940cda641a.zip |
Merge pull request #324 from jskeet/csharp
Change to using xUnit for all unit tests, and fetch that via NuGet.
Diffstat (limited to 'csharp/src/ProtocolBuffers.Test/WireFormatTest.cs')
-rw-r--r-- | csharp/src/ProtocolBuffers.Test/WireFormatTest.cs | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/csharp/src/ProtocolBuffers.Test/WireFormatTest.cs b/csharp/src/ProtocolBuffers.Test/WireFormatTest.cs index 05241965..12a9d236 100644 --- a/csharp/src/ProtocolBuffers.Test/WireFormatTest.cs +++ b/csharp/src/ProtocolBuffers.Test/WireFormatTest.cs @@ -38,17 +38,16 @@ using System.IO; using System.Reflection;
using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class WireFormatTest
{
/// <summary>
/// Keeps the attributes on FieldType and the switch statement in WireFormat in sync.
/// </summary>
- [TestMethod]
+ [Fact]
public void FieldTypeToWireTypeMapping()
{
foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public))
@@ -56,34 +55,34 @@ namespace Google.ProtocolBuffers FieldType fieldType = (FieldType) field.GetValue(null);
FieldMappingAttribute mapping =
(FieldMappingAttribute) field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0];
- Assert.AreEqual(mapping.WireType, WireFormat.GetWireType(fieldType));
+ Assert.Equal(mapping.WireType, WireFormat.GetWireType(fieldType));
}
}
- [TestMethod]
+ [Fact]
public void Serialization()
{
TestAllTypes message = TestUtil.GetAllSet();
ByteString rawBytes = message.ToByteString();
- Assert.AreEqual(rawBytes.Length, message.SerializedSize);
+ Assert.Equal(rawBytes.Length, message.SerializedSize);
TestAllTypes message2 = TestAllTypes.ParseFrom(rawBytes);
TestUtil.AssertAllFieldsSet(message2);
}
- [TestMethod]
+ [Fact]
public void SerializationPacked()
{
TestPackedTypes message = TestUtil.GetPackedSet();
ByteString rawBytes = message.ToByteString();
- Assert.AreEqual(rawBytes.Length, message.SerializedSize);
+ Assert.Equal(rawBytes.Length, message.SerializedSize);
TestPackedTypes message2 = TestPackedTypes.ParseFrom(rawBytes);
TestUtil.AssertPackedFieldsSet(message2);
}
- [TestMethod]
+ [Fact]
public void SerializeExtensions()
{
// TestAllTypes and TestAllExtensions should have compatible wire formats,
@@ -91,14 +90,14 @@ namespace Google.ProtocolBuffers // it should work.
TestAllExtensions message = TestUtil.GetAllExtensionsSet();
ByteString rawBytes = message.ToByteString();
- Assert.AreEqual(rawBytes.Length, message.SerializedSize);
+ Assert.Equal(rawBytes.Length, message.SerializedSize);
TestAllTypes message2 = TestAllTypes.ParseFrom(rawBytes);
TestUtil.AssertAllFieldsSet(message2);
}
- [TestMethod]
+ [Fact]
public void SerializePackedExtensions()
{
// TestPackedTypes and TestPackedExtensions should have compatible wire
@@ -109,10 +108,10 @@ namespace Google.ProtocolBuffers TestPackedTypes message2 = TestUtil.GetPackedSet();
ByteString rawBytes2 = message2.ToByteString();
- Assert.AreEqual(rawBytes, rawBytes2);
+ Assert.Equal(rawBytes, rawBytes2);
}
- [TestMethod]
+ [Fact]
public void SerializeDelimited()
{
MemoryStream stream = new MemoryStream();
@@ -124,13 +123,13 @@ namespace Google.ProtocolBuffers stream.Position = 0;
TestUtil.AssertAllFieldsSet(TestAllTypes.ParseDelimitedFrom(stream));
- Assert.AreEqual(12, stream.ReadByte());
+ Assert.Equal(12, stream.ReadByte());
TestUtil.AssertPackedFieldsSet(TestPackedTypes.ParseDelimitedFrom(stream));
- Assert.AreEqual(34, stream.ReadByte());
- Assert.AreEqual(-1, stream.ReadByte());
+ Assert.Equal(34, stream.ReadByte());
+ Assert.Equal(-1, stream.ReadByte());
}
- [TestMethod]
+ [Fact]
public void ParseExtensions()
{
// TestAllTypes and TestAllExtensions should have compatible wire formats,
@@ -149,7 +148,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllExtensionsSet(message2);
}
- [TestMethod]
+ [Fact]
public void ParsePackedExtensions()
{
// Ensure that packed extensions can be properly parsed.
@@ -162,10 +161,10 @@ namespace Google.ProtocolBuffers TestUtil.AssertPackedExtensionsSet(message2);
}
- [TestMethod]
+ [Fact]
public void ExtensionsSerializedSize()
{
- Assert.AreEqual(TestUtil.GetAllSet().SerializedSize, TestUtil.GetAllExtensionsSet().SerializedSize);
+ Assert.Equal(TestUtil.GetAllSet().SerializedSize, TestUtil.GetAllExtensionsSet().SerializedSize);
}
private static void AssertFieldsInOrder(ByteString data)
@@ -177,13 +176,13 @@ namespace Google.ProtocolBuffers string name;
while (input.ReadTag(out tag, out name))
{
- Assert.IsTrue(tag > previousTag);
+ Assert.True(tag > previousTag);
previousTag = tag;
input.SkipField();
}
}
- [TestMethod]
+ [Fact]
public void InterleavedFieldsAndExtensions()
{
// Tests that fields are written in order even when extension ranges
@@ -214,7 +213,7 @@ namespace Google.ProtocolBuffers private static readonly int TypeId1 = TestMessageSetExtension1.Descriptor.Extensions[0].FieldNumber;
private static readonly int TypeId2 = TestMessageSetExtension2.Descriptor.Extensions[0].FieldNumber;
- [TestMethod]
+ [Fact]
public void SerializeMessageSet()
{
// Set up a TestMessageSet with two known messages and an unknown one.
@@ -240,23 +239,23 @@ namespace Google.ProtocolBuffers // Parse back using RawMessageSet and check the contents.
RawMessageSet raw = RawMessageSet.ParseFrom(data);
- Assert.AreEqual(0, raw.UnknownFields.FieldDictionary.Count);
+ Assert.Equal(0, raw.UnknownFields.FieldDictionary.Count);
- Assert.AreEqual(3, raw.ItemCount);
- Assert.AreEqual(TypeId1, raw.ItemList[0].TypeId);
- Assert.AreEqual(TypeId2, raw.ItemList[1].TypeId);
- Assert.AreEqual(UnknownTypeId, raw.ItemList[2].TypeId);
+ Assert.Equal(3, raw.ItemCount);
+ Assert.Equal(TypeId1, raw.ItemList[0].TypeId);
+ Assert.Equal(TypeId2, raw.ItemList[1].TypeId);
+ Assert.Equal(UnknownTypeId, raw.ItemList[2].TypeId);
TestMessageSetExtension1 message1 = TestMessageSetExtension1.ParseFrom(raw.GetItem(0).Message.ToByteArray());
- Assert.AreEqual(123, message1.I);
+ Assert.Equal(123, message1.I);
TestMessageSetExtension2 message2 = TestMessageSetExtension2.ParseFrom(raw.GetItem(1).Message.ToByteArray());
- Assert.AreEqual("foo", message2.Str);
+ Assert.Equal("foo", message2.Str);
- Assert.AreEqual("bar", raw.GetItem(2).Message.ToStringUtf8());
+ Assert.Equal("bar", raw.GetItem(2).Message.ToStringUtf8());
}
- [TestMethod]
+ [Fact]
public void ParseMessageSet()
{
ExtensionRegistry extensionRegistry = ExtensionRegistry.CreateInstance();
@@ -295,18 +294,18 @@ namespace Google.ProtocolBuffers TestMessageSet messageSet =
TestMessageSet.ParseFrom(data, extensionRegistry);
- Assert.AreEqual(123, messageSet.GetExtension(TestMessageSetExtension1.MessageSetExtension).I);
- Assert.AreEqual("foo", messageSet.GetExtension(TestMessageSetExtension2.MessageSetExtension).Str);
+ Assert.Equal(123, messageSet.GetExtension(TestMessageSetExtension1.MessageSetExtension).I);
+ Assert.Equal("foo", messageSet.GetExtension(TestMessageSetExtension2.MessageSetExtension).Str);
// Check for unknown field with type LENGTH_DELIMITED,
// number UNKNOWN_TYPE_ID, and contents "bar".
UnknownFieldSet unknownFields = messageSet.UnknownFields;
- Assert.AreEqual(1, unknownFields.FieldDictionary.Count);
- Assert.IsTrue(unknownFields.HasField(UnknownTypeId));
+ Assert.Equal(1, unknownFields.FieldDictionary.Count);
+ Assert.True(unknownFields.HasField(UnknownTypeId));
UnknownField field = unknownFields[UnknownTypeId];
- Assert.AreEqual(1, field.LengthDelimitedList.Count);
- Assert.AreEqual("bar", field.LengthDelimitedList[0].ToStringUtf8());
+ Assert.Equal(1, field.LengthDelimitedList.Count);
+ Assert.Equal("bar", field.LengthDelimitedList[0].ToStringUtf8());
}
}
}
\ No newline at end of file |