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/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.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/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs')
-rw-r--r-- | csharp/src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs | 127 |
1 files changed, 63 insertions, 64 deletions
diff --git a/csharp/src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs b/csharp/src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs index 0430c4a1..5377ea6a 100644 --- a/csharp/src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs +++ b/csharp/src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs @@ -35,34 +35,31 @@ #endregion
using System;
-using System.Collections;
using System.Collections.Generic;
-using Google.ProtocolBuffers;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class ExtendableBuilderLiteTest
{
- [TestMethod]
+ [Fact]
public void TestHasExtensionT()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
.SetExtension(UnittestLite.OptionalInt32ExtensionLite, 123);
- Assert.IsTrue(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.True(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
}
- [TestMethod]
+ [Fact]
public void TestHasExtensionTMissing()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
- Assert.IsFalse(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.False(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
}
- [TestMethod]
+ [Fact]
public void TestGetExtensionCountT()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
@@ -70,41 +67,41 @@ namespace Google.ProtocolBuffers .AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 2)
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 3);
- Assert.AreEqual(3, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(3, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
}
- [TestMethod]
+ [Fact]
public void TestGetExtensionCountTEmpty()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
- Assert.AreEqual(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
}
- [TestMethod]
+ [Fact]
public void TestGetExtensionTNull()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
string value = builder.GetExtension(UnittestLite.OptionalStringExtensionLite);
- Assert.IsNull(value);
+ Assert.Null(value);
}
- [TestMethod]
+ [Fact]
public void TestGetExtensionTValue()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
.SetExtension(UnittestLite.OptionalInt32ExtensionLite, 3);
- Assert.AreEqual(3, builder.GetExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.Equal(3, builder.GetExtension(UnittestLite.OptionalInt32ExtensionLite));
}
- [TestMethod]
+ [Fact]
public void TestGetExtensionTEmpty()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
- Assert.AreEqual(0, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite).Count);
+ Assert.Equal(0, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite).Count);
}
- [TestMethod]
+ [Fact]
public void TestGetExtensionTList()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
@@ -113,10 +110,10 @@ namespace Google.ProtocolBuffers .AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 3);
IList<int> values = builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite);
- Assert.AreEqual(3, values.Count);
+ Assert.Equal(3, values.Count);
}
- [TestMethod]
+ [Fact]
public void TestGetExtensionTIndex()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
@@ -125,17 +122,17 @@ namespace Google.ProtocolBuffers .AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 2);
for (int i = 0; i < 3; i++)
- Assert.AreEqual(i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
+ Assert.Equal(i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
}
- [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
+ [Fact]
public void TestGetExtensionTIndexOutOfRange()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
- builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0);
+ Assert.Throws<ArgumentOutOfRangeException>(() => builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0));
}
- [TestMethod]
+ [Fact]
public void TestSetExtensionTIndex()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
@@ -144,107 +141,107 @@ namespace Google.ProtocolBuffers .AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 2);
for (int i = 0; i < 3; i++)
- Assert.AreEqual(i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
+ Assert.Equal(i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0, 5);
builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 1, 6);
builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 2, 7);
for (int i = 0; i < 3; i++)
- Assert.AreEqual(5 + i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
+ Assert.Equal(5 + i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
}
- [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
+ [Fact]
public void TestSetExtensionTIndexOutOfRange()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
- builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0, -1);
+ Assert.Throws<ArgumentOutOfRangeException>(() => builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0, -1));
}
- [TestMethod]
+ [Fact]
public void TestClearExtensionTList()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0);
- Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
builder.ClearExtension(UnittestLite.RepeatedInt32ExtensionLite);
- Assert.AreEqual(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
}
- [TestMethod]
+ [Fact]
public void TestClearExtensionTValue()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
.SetExtension(UnittestLite.OptionalInt32ExtensionLite, 0);
- Assert.IsTrue(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.True(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
builder.ClearExtension(UnittestLite.OptionalInt32ExtensionLite);
- Assert.IsFalse(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.False(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
}
- [TestMethod]
+ [Fact]
public void TestIndexedByDescriptor()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
- Assert.IsFalse(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.False(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
builder[UnittestLite.OptionalInt32ExtensionLite.Descriptor] = 123;
- Assert.IsTrue(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
- Assert.AreEqual(123, builder.GetExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.True(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.Equal(123, builder.GetExtension(UnittestLite.OptionalInt32ExtensionLite));
}
- [TestMethod]
+ [Fact]
public void TestIndexedByDescriptorAndOrdinal()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0);
- Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
IFieldDescriptorLite f = UnittestLite.RepeatedInt32ExtensionLite.Descriptor;
builder[f, 0] = 123;
- Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
- Assert.AreEqual(123, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0));
+ Assert.Equal(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(123, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0));
}
- [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
+ [Fact]
public void TestIndexedByDescriptorAndOrdinalOutOfRange()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
- Assert.AreEqual(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
IFieldDescriptorLite f = UnittestLite.RepeatedInt32ExtensionLite.Descriptor;
- builder[f, 0] = 123;
+ Assert.Throws<ArgumentOutOfRangeException>(() => builder[f, 0] = 123);
}
- [TestMethod]
+ [Fact]
public void TestClearFieldByDescriptor()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0);
- Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
IFieldDescriptorLite f = UnittestLite.RepeatedInt32ExtensionLite.Descriptor;
builder.ClearField(f);
- Assert.AreEqual(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
}
- [TestMethod]
+ [Fact]
public void TestAddRepeatedFieldByDescriptor()
{
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0);
- Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
IFieldDescriptorLite f = UnittestLite.RepeatedInt32ExtensionLite.Descriptor;
builder.AddRepeatedField(f, 123);
- Assert.AreEqual(2, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
- Assert.AreEqual(123, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 1));
+ Assert.Equal(2, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
+ Assert.Equal(123, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 1));
}
- [TestMethod]
+ [Fact]
public void TestMissingExtensionsLite()
{
const int optionalInt32 = 12345678;
@@ -255,21 +252,21 @@ namespace Google.ProtocolBuffers builder.AddExtension(UnittestLite.RepeatedDoubleExtensionLite, 1.3);
TestAllExtensionsLite msg = builder.Build();
- Assert.IsTrue(msg.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
- Assert.AreEqual(3, msg.GetExtensionCount(UnittestLite.RepeatedDoubleExtensionLite));
+ Assert.True(msg.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.Equal(3, msg.GetExtensionCount(UnittestLite.RepeatedDoubleExtensionLite));
byte[] bits = msg.ToByteArray();
TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits);
- Assert.IsFalse(copy.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
- Assert.AreEqual(0, copy.GetExtensionCount(UnittestLite.RepeatedDoubleExtensionLite));
- Assert.AreNotEqual(msg, copy);
+ Assert.False(copy.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
+ Assert.Equal(0, copy.GetExtensionCount(UnittestLite.RepeatedDoubleExtensionLite));
+ Assert.NotEqual(msg, copy);
//The lite runtime removes all unknown fields and extensions
byte[] copybits = copy.ToByteArray();
- Assert.AreEqual(0, copybits.Length);
+ Assert.Equal(0, copybits.Length);
}
- [TestMethod]
+ [Fact]
public void TestMissingFieldsLite()
{
TestAllTypesLite msg = TestAllTypesLite.CreateBuilder()
@@ -278,12 +275,14 @@ namespace Google.ProtocolBuffers .Build();
byte[] bits = msg.ToByteArray();
- TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits);
- Assert.AreNotEqual(msg, copy);
+ IMessageLite copy = TestAllExtensionsLite.ParseFrom(bits);
+ // Use explicit call to Equals to avoid xUnit checking for type equality.
+ Assert.False(msg.Equals(copy));
+ Assert.False(copy.Equals(msg));
//The lite runtime removes all unknown fields and extensions
byte[] copybits = copy.ToByteArray();
- Assert.AreEqual(0, copybits.Length);
+ Assert.Equal(0, copybits.Length);
}
}
}
\ No newline at end of file |