aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers.Test/UnknownFieldSetTest.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-04-30 11:05:36 +0100
committerJon Skeet <jonskeet@google.com>2015-04-30 11:29:35 +0100
commitc56475088d2d36d29a2640f35b9a8621796c051c (patch)
treeeee4106598d0faf92b566f7e03930f25df38a56c /csharp/src/ProtocolBuffers.Test/UnknownFieldSetTest.cs
parentce97e686826147e2a071fd2321555f7d40ec5d93 (diff)
downloadprotobuf-c56475088d2d36d29a2640f35b9a8621796c051c.tar.gz
protobuf-c56475088d2d36d29a2640f35b9a8621796c051c.tar.bz2
protobuf-c56475088d2d36d29a2640f35b9a8621796c051c.zip
Change to using xUnit for all unit tests, and fetch that via NuGet.
This includes fetching the VS unit test runner package, so that tests can be run from Visual Studio's Test Explorer.
Diffstat (limited to 'csharp/src/ProtocolBuffers.Test/UnknownFieldSetTest.cs')
-rw-r--r--csharp/src/ProtocolBuffers.Test/UnknownFieldSetTest.cs130
1 files changed, 64 insertions, 66 deletions
diff --git a/csharp/src/ProtocolBuffers.Test/UnknownFieldSetTest.cs b/csharp/src/ProtocolBuffers.Test/UnknownFieldSetTest.cs
index b5fc606d..f20ba7cb 100644
--- a/csharp/src/ProtocolBuffers.Test/UnknownFieldSetTest.cs
+++ b/csharp/src/ProtocolBuffers.Test/UnknownFieldSetTest.cs
@@ -38,27 +38,25 @@ using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class UnknownFieldSetTest
{
- private MessageDescriptor descriptor;
- private TestAllTypes allFields;
- private ByteString allFieldsData;
+ private readonly MessageDescriptor descriptor;
+ private readonly TestAllTypes allFields;
+ private readonly ByteString allFieldsData;
/// <summary>
/// An empty message that has been parsed from allFieldsData. So, it has
/// unknown fields of every type.
/// </summary>
- private TestEmptyMessage emptyMessage;
+ private readonly TestEmptyMessage emptyMessage;
- private UnknownFieldSet unknownFields;
+ private readonly UnknownFieldSet unknownFields;
- [TestInitialize]
- public void SetUp()
+ public UnknownFieldSetTest()
{
descriptor = TestAllTypes.Descriptor;
allFields = TestUtil.GetAllSet();
@@ -70,7 +68,7 @@ namespace Google.ProtocolBuffers
private UnknownField GetField(String name)
{
FieldDescriptor field = descriptor.FindDescriptor<FieldDescriptor>(name);
- Assert.IsNotNull(field);
+ Assert.NotNull(field);
return unknownFields.FieldDictionary[field.FieldNumber];
}
@@ -105,75 +103,75 @@ namespace Google.ProtocolBuffers
// =================================================================
- [TestMethod]
+ [Fact]
public void Varint()
{
UnknownField field = GetField("optional_int32");
- Assert.AreEqual(1, field.VarintList.Count);
- Assert.AreEqual(allFields.OptionalInt32, (long) field.VarintList[0]);
+ Assert.Equal(1, field.VarintList.Count);
+ Assert.Equal(allFields.OptionalInt32, (long) field.VarintList[0]);
}
- [TestMethod]
+ [Fact]
public void Fixed32()
{
UnknownField field = GetField("optional_fixed32");
- Assert.AreEqual(1, field.Fixed32List.Count);
- Assert.AreEqual<long>(allFields.OptionalFixed32, (int) field.Fixed32List[0]);
+ Assert.Equal(1, field.Fixed32List.Count);
+ Assert.Equal<long>(allFields.OptionalFixed32, (int) field.Fixed32List[0]);
}
- [TestMethod]
+ [Fact]
public void Fixed64()
{
UnknownField field = GetField("optional_fixed64");
- Assert.AreEqual(1, field.Fixed64List.Count);
- Assert.AreEqual((long)allFields.OptionalFixed64, (long)field.Fixed64List[0]);
+ Assert.Equal(1, field.Fixed64List.Count);
+ Assert.Equal((long)allFields.OptionalFixed64, (long)field.Fixed64List[0]);
}
- [TestMethod]
+ [Fact]
public void LengthDelimited()
{
UnknownField field = GetField("optional_bytes");
- Assert.AreEqual(1, field.LengthDelimitedList.Count);
- Assert.AreEqual(allFields.OptionalBytes, field.LengthDelimitedList[0]);
+ Assert.Equal(1, field.LengthDelimitedList.Count);
+ Assert.Equal(allFields.OptionalBytes, field.LengthDelimitedList[0]);
}
- [TestMethod]
+ [Fact]
public void Group()
{
FieldDescriptor nestedFieldDescriptor =
TestAllTypes.Types.OptionalGroup.Descriptor.FindDescriptor<FieldDescriptor>("a");
- Assert.IsNotNull(nestedFieldDescriptor);
+ Assert.NotNull(nestedFieldDescriptor);
UnknownField field = GetField("optionalgroup");
- Assert.AreEqual(1, field.GroupList.Count);
+ Assert.Equal(1, field.GroupList.Count);
UnknownFieldSet group = field.GroupList[0];
- Assert.AreEqual(1, group.FieldDictionary.Count);
- Assert.IsTrue(group.HasField(nestedFieldDescriptor.FieldNumber));
+ Assert.Equal(1, group.FieldDictionary.Count);
+ Assert.True(group.HasField(nestedFieldDescriptor.FieldNumber));
UnknownField nestedField = group[nestedFieldDescriptor.FieldNumber];
- Assert.AreEqual(1, nestedField.VarintList.Count);
- Assert.AreEqual(allFields.OptionalGroup.A, (long) nestedField.VarintList[0]);
+ Assert.Equal(1, nestedField.VarintList.Count);
+ Assert.Equal(allFields.OptionalGroup.A, (long) nestedField.VarintList[0]);
}
- [TestMethod]
+ [Fact]
public void Serialize()
{
// Check that serializing the UnknownFieldSet produces the original data again.
ByteString data = emptyMessage.ToByteString();
- Assert.AreEqual(allFieldsData, data);
+ Assert.Equal(allFieldsData, data);
}
- [TestMethod]
+ [Fact]
public void CopyFrom()
{
TestEmptyMessage message =
TestEmptyMessage.CreateBuilder().MergeFrom(emptyMessage).Build();
- Assert.AreEqual(emptyMessage.ToString(), message.ToString());
+ Assert.Equal(emptyMessage.ToString(), message.ToString());
}
- [TestMethod]
+ [Fact]
public void MergeFrom()
{
TestEmptyMessage source =
@@ -202,7 +200,7 @@ namespace Google.ProtocolBuffers
.MergeFrom(source)
.Build();
- Assert.AreEqual(
+ Assert.Equal(
"1: 1\n" +
"2: 2\n" +
"3: 3\n" +
@@ -210,23 +208,23 @@ namespace Google.ProtocolBuffers
destination.ToString());
}
- [TestMethod]
+ [Fact]
public void Clear()
{
UnknownFieldSet fields =
UnknownFieldSet.CreateBuilder().MergeFrom(unknownFields).Clear().Build();
- Assert.AreEqual(0, fields.FieldDictionary.Count);
+ Assert.Equal(0, fields.FieldDictionary.Count);
}
- [TestMethod]
+ [Fact]
public void ClearMessage()
{
TestEmptyMessage message =
TestEmptyMessage.CreateBuilder().MergeFrom(emptyMessage).Clear().Build();
- Assert.AreEqual(0, message.SerializedSize);
+ Assert.Equal(0, message.SerializedSize);
}
- [TestMethod]
+ [Fact]
public void ParseKnownAndUnknown()
{
// Test mixing known and unknown fields when parsing.
@@ -241,14 +239,14 @@ namespace Google.ProtocolBuffers
TestAllTypes destination = TestAllTypes.ParseFrom(data);
TestUtil.AssertAllFieldsSet(destination);
- Assert.AreEqual(1, destination.UnknownFields.FieldDictionary.Count);
+ Assert.Equal(1, destination.UnknownFields.FieldDictionary.Count);
UnknownField field = destination.UnknownFields[123456];
- Assert.AreEqual(1, field.VarintList.Count);
- Assert.AreEqual(654321, (long) field.VarintList[0]);
+ Assert.Equal(1, field.VarintList.Count);
+ Assert.Equal(654321, (long) field.VarintList[0]);
}
- [TestMethod]
+ [Fact]
public void WrongTypeTreatedAsUnknown()
{
// Test that fields of the wrong wire type are treated like unknown fields
@@ -260,10 +258,10 @@ namespace Google.ProtocolBuffers
// All fields should have been interpreted as unknown, so the debug strings
// should be the same.
- Assert.AreEqual(emptyMessage.ToString(), allTypesMessage.ToString());
+ Assert.Equal(emptyMessage.ToString(), allTypesMessage.ToString());
}
- [TestMethod]
+ [Fact]
public void UnknownExtensions()
{
// Make sure fields are properly parsed to the UnknownFieldSet even when
@@ -272,12 +270,12 @@ namespace Google.ProtocolBuffers
TestEmptyMessageWithExtensions message =
TestEmptyMessageWithExtensions.ParseFrom(allFieldsData);
- Assert.AreEqual(unknownFields.FieldDictionary.Count,
+ Assert.Equal(unknownFields.FieldDictionary.Count,
message.UnknownFields.FieldDictionary.Count);
- Assert.AreEqual(allFieldsData, message.ToByteString());
+ Assert.Equal(allFieldsData, message.ToByteString());
}
- [TestMethod]
+ [Fact]
public void WrongExtensionTypeTreatedAsUnknown()
{
// Test that fields of the wrong wire type are treated like unknown fields
@@ -289,19 +287,19 @@ namespace Google.ProtocolBuffers
// All fields should have been interpreted as unknown, so the debug strings
// should be the same.
- Assert.AreEqual(emptyMessage.ToString(),
+ Assert.Equal(emptyMessage.ToString(),
allExtensionsMessage.ToString());
}
- [TestMethod]
+ [Fact]
public void ParseUnknownEnumValue()
{
FieldDescriptor singularField =
TestAllTypes.Descriptor.FindDescriptor<FieldDescriptor>("optional_nested_enum");
FieldDescriptor repeatedField =
TestAllTypes.Descriptor.FindDescriptor<FieldDescriptor>("repeated_nested_enum");
- Assert.IsNotNull(singularField);
- Assert.IsNotNull(repeatedField);
+ Assert.NotNull(singularField);
+ Assert.NotNull(repeatedField);
ByteString data =
UnknownFieldSet.CreateBuilder()
@@ -322,7 +320,7 @@ namespace Google.ProtocolBuffers
{
TestAllTypes message = TestAllTypes.ParseFrom(data);
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR,
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAR,
message.OptionalNestedEnum);
TestUtil.AssertEqual(new[] {TestAllTypes.Types.NestedEnum.FOO, TestAllTypes.Types.NestedEnum.BAZ},
message.RepeatedNestedEnumList);
@@ -333,7 +331,7 @@ namespace Google.ProtocolBuffers
{
TestAllExtensions message =
TestAllExtensions.ParseFrom(data, TestUtil.CreateExtensionRegistry());
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR,
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAR,
message.GetExtension(Unittest.OptionalNestedEnumExtension));
TestUtil.AssertEqual(new[] {TestAllTypes.Types.NestedEnum.FOO, TestAllTypes.Types.NestedEnum.BAZ},
message.GetExtension(Unittest.RepeatedNestedEnumExtension));
@@ -342,7 +340,7 @@ namespace Google.ProtocolBuffers
}
}
- [TestMethod]
+ [Fact]
public void LargeVarint()
{
ByteString data =
@@ -355,11 +353,11 @@ namespace Google.ProtocolBuffers
.ToByteString();
UnknownFieldSet parsed = UnknownFieldSet.ParseFrom(data);
UnknownField field = parsed[1];
- Assert.AreEqual(1, field.VarintList.Count);
- Assert.AreEqual(0x7FFFFFFFFFFFFFFFUL, field.VarintList[0]);
+ Assert.Equal(1, field.VarintList.Count);
+ Assert.Equal(0x7FFFFFFFFFFFFFFFUL, field.VarintList[0]);
}
- [TestMethod]
+ [Fact]
public void EqualsAndHashCode()
{
UnknownField fixed32Field = UnknownField.CreateBuilder().AddFixed32(1).Build();
@@ -407,10 +405,10 @@ namespace Google.ProtocolBuffers
private static void CheckNotEqual(UnknownFieldSet s1, UnknownFieldSet s2)
{
String equalsError = string.Format("{0} should not be equal to {1}", s1, s2);
- Assert.IsFalse(s1.Equals(s2), equalsError);
- Assert.IsFalse(s2.Equals(s1), equalsError);
+ Assert.False(s1.Equals(s2), equalsError);
+ Assert.False(s2.Equals(s1), equalsError);
- Assert.IsFalse(s1.GetHashCode() == s2.GetHashCode(),
+ Assert.False(s1.GetHashCode() == s2.GetHashCode(),
string.Format("{0} should have a different hash code from {1}", s1, s2));
}
@@ -421,13 +419,13 @@ namespace Google.ProtocolBuffers
private static void CheckEqualsIsConsistent(UnknownFieldSet set)
{
// Object should be equal to itself.
- Assert.AreEqual(set, set);
+ Assert.Equal(set, set);
// Object should be equal to a copy of itself.
UnknownFieldSet copy = UnknownFieldSet.CreateBuilder(set).Build();
- Assert.AreEqual(set, copy);
- Assert.AreEqual(copy, set);
- Assert.AreEqual(set.GetHashCode(), copy.GetHashCode());
+ Assert.Equal(set, copy);
+ Assert.Equal(copy, set);
+ Assert.Equal(set.GetHashCode(), copy.GetHashCode());
}
}
} \ No newline at end of file