diff options
author | Jon Skeet <jonskeet@google.com> | 2015-04-30 11:05:36 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-04-30 11:29:35 +0100 |
commit | c56475088d2d36d29a2640f35b9a8621796c051c (patch) | |
tree | eee4106598d0faf92b566f7e03930f25df38a56c /csharp/src/ProtocolBuffers.Test | |
parent | ce97e686826147e2a071fd2321555f7d40ec5d93 (diff) | |
download | protobuf-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')
37 files changed, 2836 insertions, 3147 deletions
diff --git a/csharp/src/ProtocolBuffers.Test/AbstractMessageTest.cs b/csharp/src/ProtocolBuffers.Test/AbstractMessageTest.cs index 54f400c3..51606a37 100644 --- a/csharp/src/ProtocolBuffers.Test/AbstractMessageTest.cs +++ b/csharp/src/ProtocolBuffers.Test/AbstractMessageTest.cs @@ -38,15 +38,14 @@ using System; using System.Collections.Generic;
using System.IO;
using Google.ProtocolBuffers.Descriptors;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Google.ProtocolBuffers.TestProtos;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class AbstractMessageTest
{
- [TestMethod]
+ [Fact]
public void Clear()
{
AbstractMessageWrapper message =
@@ -54,7 +53,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertClear((TestAllTypes) message.WrappedMessage);
}
- [TestMethod]
+ [Fact]
public void Copy()
{
AbstractMessageWrapper message =
@@ -62,31 +61,31 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllFieldsSet((TestAllTypes) message.WrappedMessage);
}
- [TestMethod]
+ [Fact]
public void CreateAndBuild()
{
TestAllTypes.CreateBuilder()
.Build();
}
- [TestMethod]
+ [Fact]
public void SerializedSize()
{
TestAllTypes message = TestUtil.GetAllSet();
IMessage abstractMessage = new AbstractMessageWrapper(TestUtil.GetAllSet());
- Assert.AreEqual(message.SerializedSize, abstractMessage.SerializedSize);
+ Assert.Equal(message.SerializedSize, abstractMessage.SerializedSize);
}
- [TestMethod]
+ [Fact]
public void Serialization()
{
IMessage abstractMessage = new AbstractMessageWrapper(TestUtil.GetAllSet());
TestUtil.AssertAllFieldsSet(TestAllTypes.ParseFrom(abstractMessage.ToByteString()));
- Assert.AreEqual(TestUtil.GetAllSet().ToByteString(), abstractMessage.ToByteString());
+ Assert.Equal(TestUtil.GetAllSet().ToByteString(), abstractMessage.ToByteString());
}
- [TestMethod]
+ [Fact]
public void Parsing()
{
IBuilder builder = new AbstractMessageWrapper.Builder(TestAllTypes.CreateBuilder());
@@ -95,15 +94,15 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllFieldsSet((TestAllTypes) message.WrappedMessage);
}
- [TestMethod]
+ [Fact]
public void PackedSerialization()
{
IMessage abstractMessage = new AbstractMessageWrapper(TestUtil.GetPackedSet());
TestUtil.AssertPackedFieldsSet(TestPackedTypes.ParseFrom(abstractMessage.ToByteString()));
- Assert.AreEqual(TestUtil.GetPackedSet().ToByteString(), abstractMessage.ToByteString());
+ Assert.Equal(TestUtil.GetPackedSet().ToByteString(), abstractMessage.ToByteString());
}
- [TestMethod]
+ [Fact]
public void PackedParsing()
{
AbstractMessageWrapper.Builder builder = new AbstractMessageWrapper.Builder(TestPackedTypes.CreateBuilder());
@@ -111,7 +110,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertPackedFieldsSet((TestPackedTypes)message.WrappedMessage);
}
- [TestMethod]
+ [Fact]
public void UnpackedParsingOfPackedInput()
{
byte[] bytes = TestUtil.GetPackedSet().ToByteArray();
@@ -119,7 +118,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertUnpackedFieldsSet(message);
}
- [TestMethod]
+ [Fact]
public void PackedParsingOfUnpackedInput()
{
byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray();
@@ -127,7 +126,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertPackedFieldsSet(message);
}
- [TestMethod]
+ [Fact]
public void UnpackedParsingOfPackedInputExtensions()
{
byte[] bytes = TestUtil.GetPackedSet().ToByteArray();
@@ -138,7 +137,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertUnpackedExtensionsSet(message);
}
- [TestMethod]
+ [Fact]
public void PackedParsingOfUnpackedInputExtensions()
{
byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray();
@@ -148,13 +147,13 @@ namespace Google.ProtocolBuffers TestUtil.AssertPackedExtensionsSet(message);
}
- [TestMethod]
+ [Fact]
public void OptimizedForSize()
{
// We're mostly only Checking that this class was compiled successfully.
TestOptimizedForSize message = TestOptimizedForSize.CreateBuilder().SetI(1).Build();
message = TestOptimizedForSize.ParseFrom(message.ToByteString());
- Assert.AreEqual(2, message.SerializedSize);
+ Assert.Equal(2, message.SerializedSize);
}
// -----------------------------------------------------------------
@@ -165,40 +164,40 @@ namespace Google.ProtocolBuffers private static readonly TestRequired TestRequiredInitialized =
TestRequired.CreateBuilder().SetA(1).SetB(2).SetC(3).Build();
- [TestMethod]
+ [Fact]
public void IsInitialized()
{
TestRequired.Builder builder = TestRequired.CreateBuilder();
AbstractMessageWrapper.Builder abstractBuilder = new AbstractMessageWrapper.Builder(builder);
- Assert.IsFalse(abstractBuilder.IsInitialized);
+ Assert.False(abstractBuilder.IsInitialized);
builder.A = 1;
- Assert.IsFalse(abstractBuilder.IsInitialized);
+ Assert.False(abstractBuilder.IsInitialized);
builder.B = 1;
- Assert.IsFalse(abstractBuilder.IsInitialized);
+ Assert.False(abstractBuilder.IsInitialized);
builder.C = 1;
- Assert.IsTrue(abstractBuilder.IsInitialized);
+ Assert.True(abstractBuilder.IsInitialized);
}
- [TestMethod]
+ [Fact]
public void ForeignIsInitialized()
{
TestRequiredForeign.Builder builder = TestRequiredForeign.CreateBuilder();
AbstractMessageWrapper.Builder abstractBuilder = new AbstractMessageWrapper.Builder(builder);
- Assert.IsTrue(abstractBuilder.IsInitialized);
+ Assert.True(abstractBuilder.IsInitialized);
builder.SetOptionalMessage(TestRequiredUninitialized);
- Assert.IsFalse(abstractBuilder.IsInitialized);
+ Assert.False(abstractBuilder.IsInitialized);
builder.SetOptionalMessage(TestRequiredInitialized);
- Assert.IsTrue(abstractBuilder.IsInitialized);
+ Assert.True(abstractBuilder.IsInitialized);
builder.AddRepeatedMessage(TestRequiredUninitialized);
- Assert.IsFalse(abstractBuilder.IsInitialized);
+ Assert.False(abstractBuilder.IsInitialized);
builder.SetRepeatedMessage(0, TestRequiredInitialized);
- Assert.IsTrue(abstractBuilder.IsInitialized);
+ Assert.True(abstractBuilder.IsInitialized);
}
// -----------------------------------------------------------------
@@ -227,7 +226,7 @@ namespace Google.ProtocolBuffers "repeated_string: \"qux\"\n" +
"repeated_string: \"bar\"\n";
- [TestMethod]
+ [Fact]
public void MergeFrom()
{
AbstractMessageWrapper result = (AbstractMessageWrapper)
@@ -235,13 +234,13 @@ namespace Google.ProtocolBuffers .MergeFrom(MergeSource)
.Build();
- Assert.AreEqual(MergeResultText, result.ToString());
+ Assert.Equal(MergeResultText, result.ToString());
}
// -----------------------------------------------------------------
// Tests for equals and hashCode
- [TestMethod]
+ [Fact]
public void EqualsAndHashCode()
{
TestAllTypes a = TestUtil.GetAllSet();
@@ -297,7 +296,7 @@ namespace Google.ProtocolBuffers private static void CheckEqualsIsConsistent(IMessage message)
{
// Object should be equal to itself.
- Assert.AreEqual(message, message);
+ Assert.Equal(message, message);
// Object should be equal to a dynamic copy of itself.
DynamicMessage dynamic = DynamicMessage.CreateBuilder(message).Build();
@@ -309,9 +308,11 @@ namespace Google.ProtocolBuffers /// </summary>
private static void CheckEqualsIsConsistent(IMessage message1, IMessage message2)
{
- Assert.AreEqual(message1, message2);
- Assert.AreEqual(message2, message1);
- Assert.AreEqual(message2.GetHashCode(), message1.GetHashCode());
+ // Not using Assert.AreEqual as that checks for type equality, which isn't
+ // what we want bearing in mind the dynamic message checks.
+ Assert.True(message1.Equals(message2));
+ Assert.True(message2.Equals(message1));
+ Assert.Equal(message2.GetHashCode(), message1.GetHashCode());
}
/// <summary>
@@ -325,10 +326,10 @@ namespace Google.ProtocolBuffers private static void CheckNotEqual(IMessage m1, IMessage m2)
{
String equalsError = string.Format("{0} should not be equal to {1}", m1, m2);
- Assert.IsFalse(m1.Equals(m2), equalsError);
- Assert.IsFalse(m2.Equals(m1), equalsError);
+ Assert.False(m1.Equals(m2), equalsError);
+ Assert.False(m2.Equals(m1), equalsError);
- Assert.IsFalse(m1.GetHashCode() == m2.GetHashCode(),
+ Assert.False(m1.GetHashCode() == m2.GetHashCode(),
string.Format("{0} should have a different hash code from {1}", m1, m2));
}
diff --git a/csharp/src/ProtocolBuffers.Test/ByteStringTest.cs b/csharp/src/ProtocolBuffers.Test/ByteStringTest.cs index 003307ae..92c4ef0b 100644 --- a/csharp/src/ProtocolBuffers.Test/ByteStringTest.cs +++ b/csharp/src/ProtocolBuffers.Test/ByteStringTest.cs @@ -36,113 +36,112 @@ using System;
using System.Text;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class ByteStringTest
{
- [TestMethod]
+ [Fact]
public void EmptyByteStringHasZeroSize()
{
- Assert.AreEqual(0, ByteString.Empty.Length);
+ Assert.Equal(0, ByteString.Empty.Length);
}
- [TestMethod]
+ [Fact]
public void CopyFromStringWithExplicitEncoding()
{
ByteString bs = ByteString.CopyFrom("AB", Encoding.Unicode);
- Assert.AreEqual(4, bs.Length);
- Assert.AreEqual(65, bs[0]);
- Assert.AreEqual(0, bs[1]);
- Assert.AreEqual(66, bs[2]);
- Assert.AreEqual(0, bs[3]);
+ Assert.Equal(4, bs.Length);
+ Assert.Equal(65, bs[0]);
+ Assert.Equal(0, bs[1]);
+ Assert.Equal(66, bs[2]);
+ Assert.Equal(0, bs[3]);
}
- [TestMethod]
+ [Fact]
public void IsEmptyWhenEmpty()
{
- Assert.IsTrue(ByteString.CopyFromUtf8("").IsEmpty);
+ Assert.True(ByteString.CopyFromUtf8("").IsEmpty);
}
- [TestMethod]
+ [Fact]
public void IsEmptyWhenNotEmpty()
{
- Assert.IsFalse(ByteString.CopyFromUtf8("X").IsEmpty);
+ Assert.False(ByteString.CopyFromUtf8("X").IsEmpty);
}
- [TestMethod]
+ [Fact]
public void CopyFromByteArrayCopiesContents()
{
byte[] data = new byte[1];
data[0] = 10;
ByteString bs = ByteString.CopyFrom(data);
- Assert.AreEqual(10, bs[0]);
+ Assert.Equal(10, bs[0]);
data[0] = 5;
- Assert.AreEqual(10, bs[0]);
+ Assert.Equal(10, bs[0]);
}
- [TestMethod]
+ [Fact]
public void ToByteArrayCopiesContents()
{
ByteString bs = ByteString.CopyFromUtf8("Hello");
byte[] data = bs.ToByteArray();
- Assert.AreEqual((byte)'H', data[0]);
- Assert.AreEqual((byte)'H', bs[0]);
+ Assert.Equal((byte)'H', data[0]);
+ Assert.Equal((byte)'H', bs[0]);
data[0] = 0;
- Assert.AreEqual(0, data[0]);
- Assert.AreEqual((byte)'H', bs[0]);
+ Assert.Equal(0, data[0]);
+ Assert.Equal((byte)'H', bs[0]);
}
- [TestMethod]
+ [Fact]
public void CopyFromUtf8UsesUtf8()
{
ByteString bs = ByteString.CopyFromUtf8("\u20ac");
- Assert.AreEqual(3, bs.Length);
- Assert.AreEqual(0xe2, bs[0]);
- Assert.AreEqual(0x82, bs[1]);
- Assert.AreEqual(0xac, bs[2]);
+ Assert.Equal(3, bs.Length);
+ Assert.Equal(0xe2, bs[0]);
+ Assert.Equal(0x82, bs[1]);
+ Assert.Equal(0xac, bs[2]);
}
- [TestMethod]
+ [Fact]
public void CopyFromPortion()
{
byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
ByteString bs = ByteString.CopyFrom(data, 2, 3);
- Assert.AreEqual(3, bs.Length);
- Assert.AreEqual(2, bs[0]);
- Assert.AreEqual(3, bs[1]);
+ Assert.Equal(3, bs.Length);
+ Assert.Equal(2, bs[0]);
+ Assert.Equal(3, bs[1]);
}
- [TestMethod]
+ [Fact]
public void ToStringUtf8()
{
ByteString bs = ByteString.CopyFromUtf8("\u20ac");
- Assert.AreEqual("\u20ac", bs.ToStringUtf8());
+ Assert.Equal("\u20ac", bs.ToStringUtf8());
}
- [TestMethod]
+ [Fact]
public void ToStringWithExplicitEncoding()
{
ByteString bs = ByteString.CopyFrom("\u20ac", Encoding.Unicode);
- Assert.AreEqual("\u20ac", bs.ToString(Encoding.Unicode));
+ Assert.Equal("\u20ac", bs.ToString(Encoding.Unicode));
}
- [TestMethod]
+ [Fact]
public void FromBase64_WithText()
{
byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
string base64 = Convert.ToBase64String(data);
ByteString bs = ByteString.FromBase64(base64);
- TestUtil.AssertBytesEqual(data, bs.ToByteArray());
+ Assert.Equal(data, bs.ToByteArray());
}
- [TestMethod]
+ [Fact]
public void FromBase64_Empty()
{
// Optimization which also fixes issue 61.
- Assert.AreSame(ByteString.Empty, ByteString.FromBase64(""));
+ Assert.Same(ByteString.Empty, ByteString.FromBase64(""));
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs b/csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs index b09d3340..20bfef9e 100644 --- a/csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs +++ b/csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs @@ -39,12 +39,10 @@ using System.Collections.Generic; using System.IO;
using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Diagnostics;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class CodedInputStreamTest
{
/// <summary>
@@ -68,21 +66,21 @@ namespace Google.ProtocolBuffers private static void AssertReadVarint(byte[] data, ulong value)
{
CodedInputStream input = CodedInputStream.CreateInstance(data);
- Assert.AreEqual((uint) value, input.ReadRawVarint32());
+ Assert.Equal((uint) value, input.ReadRawVarint32());
input = CodedInputStream.CreateInstance(data);
- Assert.AreEqual(value, input.ReadRawVarint64());
- Assert.IsTrue(input.IsAtEnd);
+ Assert.Equal(value, input.ReadRawVarint64());
+ Assert.True(input.IsAtEnd);
// Try different block sizes.
for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2)
{
input = CodedInputStream.CreateInstance(new SmallBlockInputStream(data, bufferSize));
- Assert.AreEqual((uint) value, input.ReadRawVarint32());
+ Assert.Equal((uint) value, input.ReadRawVarint32());
input = CodedInputStream.CreateInstance(new SmallBlockInputStream(data, bufferSize));
- Assert.AreEqual(value, input.ReadRawVarint64());
- Assert.IsTrue(input.IsAtEnd);
+ Assert.Equal(value, input.ReadRawVarint64());
+ Assert.True(input.IsAtEnd);
}
// Try reading directly from a MemoryStream. We want to verify that it
@@ -92,8 +90,8 @@ namespace Google.ProtocolBuffers memoryStream.Write(data, 0, data.Length);
memoryStream.WriteByte(0);
memoryStream.Position = 0;
- Assert.AreEqual((uint) value, CodedInputStream.ReadRawVarint32(memoryStream));
- Assert.AreEqual(data.Length, memoryStream.Position);
+ Assert.Equal((uint) value, CodedInputStream.ReadRawVarint32(memoryStream));
+ Assert.Equal(data.Length, memoryStream.Position);
}
/// <summary>
@@ -104,40 +102,19 @@ namespace Google.ProtocolBuffers private static void AssertReadVarintFailure(InvalidProtocolBufferException expected, byte[] data)
{
CodedInputStream input = CodedInputStream.CreateInstance(data);
- try
- {
- input.ReadRawVarint32();
- Assert.Fail("Should have thrown an exception.");
- }
- catch (InvalidProtocolBufferException e)
- {
- Assert.AreEqual(expected.Message, e.Message);
- }
+ var exception = Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawVarint32());
+ Assert.Equal(expected.Message, exception.Message);
input = CodedInputStream.CreateInstance(data);
- try
- {
- input.ReadRawVarint64();
- Assert.Fail("Should have thrown an exception.");
- }
- catch (InvalidProtocolBufferException e)
- {
- Assert.AreEqual(expected.Message, e.Message);
- }
+ exception = Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawVarint64());
+ Assert.Equal(expected.Message, exception.Message);
// Make sure we get the same error when reading directly from a Stream.
- try
- {
- CodedInputStream.ReadRawVarint32(new MemoryStream(data));
- Assert.Fail("Should have thrown an exception.");
- }
- catch (InvalidProtocolBufferException e)
- {
- Assert.AreEqual(expected.Message, e.Message);
- }
+ exception = Assert.Throws<InvalidProtocolBufferException>(() => CodedInputStream.ReadRawVarint32(new MemoryStream(data)));
+ Assert.Equal(expected.Message, exception.Message);
}
- [TestMethod]
+ [Fact]
public void ReadVarint()
{
AssertReadVarint(Bytes(0x00), 0);
@@ -182,16 +159,16 @@ namespace Google.ProtocolBuffers private static void AssertReadLittleEndian32(byte[] data, uint value)
{
CodedInputStream input = CodedInputStream.CreateInstance(data);
- Assert.AreEqual(value, input.ReadRawLittleEndian32());
- Assert.IsTrue(input.IsAtEnd);
+ Assert.Equal(value, input.ReadRawLittleEndian32());
+ Assert.True(input.IsAtEnd);
// Try different block sizes.
for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
{
input = CodedInputStream.CreateInstance(
new SmallBlockInputStream(data, blockSize));
- Assert.AreEqual(value, input.ReadRawLittleEndian32());
- Assert.IsTrue(input.IsAtEnd);
+ Assert.Equal(value, input.ReadRawLittleEndian32());
+ Assert.True(input.IsAtEnd);
}
}
@@ -202,20 +179,20 @@ namespace Google.ProtocolBuffers private static void AssertReadLittleEndian64(byte[] data, ulong value)
{
CodedInputStream input = CodedInputStream.CreateInstance(data);
- Assert.AreEqual(value, input.ReadRawLittleEndian64());
- Assert.IsTrue(input.IsAtEnd);
+ Assert.Equal(value, input.ReadRawLittleEndian64());
+ Assert.True(input.IsAtEnd);
// Try different block sizes.
for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
{
input = CodedInputStream.CreateInstance(
new SmallBlockInputStream(data, blockSize));
- Assert.AreEqual(value, input.ReadRawLittleEndian64());
- Assert.IsTrue(input.IsAtEnd);
+ Assert.Equal(value, input.ReadRawLittleEndian64());
+ Assert.True(input.IsAtEnd);
}
}
- [TestMethod]
+ [Fact]
public void ReadLittleEndian()
{
AssertReadLittleEndian32(Bytes(0x78, 0x56, 0x34, 0x12), 0x12345678);
@@ -227,41 +204,41 @@ namespace Google.ProtocolBuffers Bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef012345678UL);
}
- [TestMethod]
+ [Fact]
public void DecodeZigZag32()
{
- Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(0));
- Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(1));
- Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(2));
- Assert.AreEqual(-2, CodedInputStream.DecodeZigZag32(3));
- Assert.AreEqual(0x3FFFFFFF, CodedInputStream.DecodeZigZag32(0x7FFFFFFE));
- Assert.AreEqual(unchecked((int) 0xC0000000), CodedInputStream.DecodeZigZag32(0x7FFFFFFF));
- Assert.AreEqual(0x7FFFFFFF, CodedInputStream.DecodeZigZag32(0xFFFFFFFE));
- Assert.AreEqual(unchecked((int) 0x80000000), CodedInputStream.DecodeZigZag32(0xFFFFFFFF));
+ Assert.Equal(0, CodedInputStream.DecodeZigZag32(0));
+ Assert.Equal(-1, CodedInputStream.DecodeZigZag32(1));
+ Assert.Equal(1, CodedInputStream.DecodeZigZag32(2));
+ Assert.Equal(-2, CodedInputStream.DecodeZigZag32(3));
+ Assert.Equal(0x3FFFFFFF, CodedInputStream.DecodeZigZag32(0x7FFFFFFE));
+ Assert.Equal(unchecked((int) 0xC0000000), CodedInputStream.DecodeZigZag32(0x7FFFFFFF));
+ Assert.Equal(0x7FFFFFFF, CodedInputStream.DecodeZigZag32(0xFFFFFFFE));
+ Assert.Equal(unchecked((int) 0x80000000), CodedInputStream.DecodeZigZag32(0xFFFFFFFF));
}
- [TestMethod]
+ [Fact]
public void DecodeZigZag64()
{
- Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(0));
- Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(1));
- Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(2));
- Assert.AreEqual(-2, CodedInputStream.DecodeZigZag64(3));
- Assert.AreEqual(0x000000003FFFFFFFL, CodedInputStream.DecodeZigZag64(0x000000007FFFFFFEL));
- Assert.AreEqual(unchecked((long) 0xFFFFFFFFC0000000L), CodedInputStream.DecodeZigZag64(0x000000007FFFFFFFL));
- Assert.AreEqual(0x000000007FFFFFFFL, CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFEL));
- Assert.AreEqual(unchecked((long) 0xFFFFFFFF80000000L), CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFFL));
- Assert.AreEqual(0x7FFFFFFFFFFFFFFFL, CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFEL));
- Assert.AreEqual(unchecked((long) 0x8000000000000000L), CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFFL));
+ Assert.Equal(0, CodedInputStream.DecodeZigZag64(0));
+ Assert.Equal(-1, CodedInputStream.DecodeZigZag64(1));
+ Assert.Equal(1, CodedInputStream.DecodeZigZag64(2));
+ Assert.Equal(-2, CodedInputStream.DecodeZigZag64(3));
+ Assert.Equal(0x000000003FFFFFFFL, CodedInputStream.DecodeZigZag64(0x000000007FFFFFFEL));
+ Assert.Equal(unchecked((long) 0xFFFFFFFFC0000000L), CodedInputStream.DecodeZigZag64(0x000000007FFFFFFFL));
+ Assert.Equal(0x000000007FFFFFFFL, CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFEL));
+ Assert.Equal(unchecked((long) 0xFFFFFFFF80000000L), CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFFL));
+ Assert.Equal(0x7FFFFFFFFFFFFFFFL, CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFEL));
+ Assert.Equal(unchecked((long) 0x8000000000000000L), CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFFL));
}
- [TestMethod]
+ [Fact]
public void ReadWholeMessage()
{
TestAllTypes message = TestUtil.GetAllSet();
byte[] rawBytes = message.ToByteArray();
- Assert.AreEqual(rawBytes.Length, message.SerializedSize);
+ Assert.Equal(rawBytes.Length, message.SerializedSize);
TestAllTypes message2 = TestAllTypes.ParseFrom(rawBytes);
TestUtil.AssertAllFieldsSet(message2);
@@ -273,7 +250,7 @@ namespace Google.ProtocolBuffers }
}
- [TestMethod]
+ [Fact]
public void SkipWholeMessage()
{
TestAllTypes message = TestUtil.GetAllSet();
@@ -290,8 +267,8 @@ namespace Google.ProtocolBuffers while (input1.ReadTag(out tag, out name))
{
uint tag2;
- Assert.IsTrue(input2.ReadTag(out tag2, out name));
- Assert.AreEqual(tag, tag2);
+ Assert.True(input2.ReadTag(out tag2, out name));
+ Assert.Equal(tag, tag2);
unknownFields.MergeFieldFrom(tag, input1);
input2.SkipField();
@@ -302,7 +279,7 @@ namespace Google.ProtocolBuffers /// Test that a bug in SkipRawBytes has been fixed: if the skip
/// skips exactly up to a limit, this should bnot break things
/// </summary>
- [TestMethod]
+ [Fact]
public void SkipRawBytesBug()
{
byte[] rawBytes = new byte[] {1, 2};
@@ -311,7 +288,7 @@ namespace Google.ProtocolBuffers int limit = input.PushLimit(1);
input.SkipRawBytes(1);
input.PopLimit(limit);
- Assert.AreEqual(2, input.ReadRawByte());
+ Assert.Equal(2, input.ReadRawByte());
}
public void ReadHugeBlob()
@@ -334,7 +311,7 @@ namespace Google.ProtocolBuffers // reading.
TestAllTypes message2 = TestAllTypes.ParseFrom(message.ToByteString().CreateCodedInput());
- Assert.AreEqual(message.OptionalBytes, message2.OptionalBytes);
+ Assert.Equal(message.OptionalBytes, message2.OptionalBytes);
// Make sure all the other fields were parsed correctly.
TestAllTypes message3 = TestAllTypes.CreateBuilder(message2)
@@ -343,7 +320,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllFieldsSet(message3);
}
- [TestMethod]
+ [Fact]
public void ReadMaliciouslyLargeBlob()
{
MemoryStream ms = new MemoryStream();
@@ -359,19 +336,12 @@ namespace Google.ProtocolBuffers CodedInputStream input = CodedInputStream.CreateInstance(ms);
uint testtag;
string ignore;
- Assert.IsTrue(input.ReadTag(out testtag, out ignore));
- Assert.AreEqual(tag, testtag);
+ Assert.True(input.ReadTag(out testtag, out ignore));
+ Assert.Equal(tag, testtag);
- try
- {
- ByteString bytes = null;
- input.ReadBytes(ref bytes);
- Assert.Fail("Should have thrown an exception!");
- }
- catch (InvalidProtocolBufferException)
- {
- // success.
- }
+ ByteString bytes = null;
+ // TODO(jonskeet): Should this be ArgumentNullException instead?
+ Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes(ref bytes));
}
private static TestRecursiveMessage MakeRecursiveMessage(int depth)
@@ -391,17 +361,17 @@ namespace Google.ProtocolBuffers {
if (depth == 0)
{
- Assert.IsFalse(message.HasA);
- Assert.AreEqual(5, message.I);
+ Assert.False(message.HasA);
+ Assert.Equal(5, message.I);
}
else
{
- Assert.IsTrue(message.HasA);
+ Assert.True(message.HasA);
AssertMessageDepth(message.A, depth - 1);
}
}
- [TestMethod]
+ [Fact]
public void MaliciousRecursion()
{
ByteString data64 = MakeRecursiveMessage(64).ToByteString();
@@ -409,30 +379,14 @@ namespace Google.ProtocolBuffers AssertMessageDepth(TestRecursiveMessage.ParseFrom(data64), 64);
- try
- {
- TestRecursiveMessage.ParseFrom(data65);
- Assert.Fail("Should have thrown an exception!");
- }
- catch (InvalidProtocolBufferException)
- {
- // success.
- }
+ Assert.Throws<InvalidProtocolBufferException>(() => TestRecursiveMessage.ParseFrom(data65));
CodedInputStream input = data64.CreateCodedInput();
input.SetRecursionLimit(8);
- try
- {
- TestRecursiveMessage.ParseFrom(input);
- Assert.Fail("Should have thrown an exception!");
- }
- catch (InvalidProtocolBufferException)
- {
- // success.
- }
+ Assert.Throws<InvalidProtocolBufferException>(() => TestRecursiveMessage.ParseFrom(input));
}
- [TestMethod]
+ [Fact]
public void SizeLimit()
{
// Have to use a Stream rather than ByteString.CreateCodedInput as SizeLimit doesn't
@@ -441,18 +395,10 @@ namespace Google.ProtocolBuffers CodedInputStream input = CodedInputStream.CreateInstance(ms);
input.SetSizeLimit(16);
- try
- {
- TestAllTypes.ParseFrom(input);
- Assert.Fail("Should have thrown an exception!");
- }
- catch (InvalidProtocolBufferException)
- {
- // success.
- }
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.ParseFrom(input));
}
- [TestMethod]
+ [Fact]
public void ResetSizeCounter()
{
CodedInputStream input = CodedInputStream.CreateInstance(
@@ -460,28 +406,12 @@ namespace Google.ProtocolBuffers input.SetSizeLimit(16);
input.ReadRawBytes(16);
- try
- {
- input.ReadRawByte();
- Assert.Fail("Should have thrown an exception!");
- }
- catch (InvalidProtocolBufferException)
- {
- // Success.
- }
+ Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawByte());
input.ResetSizeCounter();
input.ReadRawByte(); // No exception thrown.
- try
- {
- input.ReadRawBytes(16); // Hits limit again.
- Assert.Fail("Should have thrown an exception!");
- }
- catch (InvalidProtocolBufferException)
- {
- // Success.
- }
+ Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawBytes(16));
}
/// <summary>
@@ -489,7 +419,7 @@ namespace Google.ProtocolBuffers /// is thrown. Instead, the invalid bytes are replaced with the Unicode
/// "replacement character" U+FFFD.
/// </summary>
- [TestMethod]
+ [Fact]
public void ReadInvalidUtf8()
{
MemoryStream ms = new MemoryStream();
@@ -507,11 +437,11 @@ namespace Google.ProtocolBuffers uint testtag;
string ignored;
- Assert.IsTrue(input.ReadTag(out testtag, out ignored));
- Assert.AreEqual(tag, testtag);
+ Assert.True(input.ReadTag(out testtag, out ignored));
+ Assert.Equal(tag, testtag);
string text = null;
input.ReadString(ref text);
- Assert.AreEqual('\ufffd', text[0]);
+ Assert.Equal('\ufffd', text[0]);
}
/// <summary>
@@ -537,7 +467,7 @@ namespace Google.ProtocolBuffers enum TestNegEnum { None = 0, Value = -2 }
- [TestMethod]
+ [Fact]
public void TestNegativeEnum()
{
byte[] bytes = new byte[10] { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 };
@@ -545,12 +475,12 @@ namespace Google.ProtocolBuffers object unk;
TestNegEnum val = TestNegEnum.None;
- Assert.IsTrue(input.ReadEnum(ref val, out unk));
- Assert.IsTrue(input.IsAtEnd);
- Assert.AreEqual(TestNegEnum.Value, val);
+ Assert.True(input.ReadEnum(ref val, out unk));
+ Assert.True(input.IsAtEnd);
+ Assert.Equal(TestNegEnum.Value, val);
}
- [TestMethod]
+ [Fact]
public void TestNegativeEnumPackedArray()
{
int arraySize = 1 + (10 * 5);
@@ -559,26 +489,26 @@ namespace Google.ProtocolBuffers CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WritePackedInt32Array(8, "", arraySize, new int[] { 0, -1, -2, -3, -4, -5 });
- Assert.AreEqual(0, output.SpaceLeft);
+ Assert.Equal(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag;
string name;
- Assert.IsTrue(input.ReadTag(out tag, out name));
+ Assert.True(input.ReadTag(out tag, out name));
List<TestNegEnum> values = new List<TestNegEnum>();
ICollection<object> unk;
input.ReadEnumArray(tag, name, values, out unk);
- Assert.AreEqual(2, values.Count);
- Assert.AreEqual(TestNegEnum.None, values[0]);
- Assert.AreEqual(TestNegEnum.Value, values[1]);
+ Assert.Equal(2, values.Count);
+ Assert.Equal(TestNegEnum.None, values[0]);
+ Assert.Equal(TestNegEnum.Value, values[1]);
- Assert.IsNotNull(unk);
- Assert.AreEqual(4, unk.Count);
+ Assert.NotNull(unk);
+ Assert.Equal(4, unk.Count);
}
- [TestMethod]
+ [Fact]
public void TestNegativeEnumArray()
{
int arraySize = 1 + 1 + (11 * 5);
@@ -587,27 +517,27 @@ namespace Google.ProtocolBuffers CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteInt32Array(8, "", new int[] { 0, -1, -2, -3, -4, -5 });
- Assert.AreEqual(0, output.SpaceLeft);
+ Assert.Equal(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag;
string name;
- Assert.IsTrue(input.ReadTag(out tag, out name));
+ Assert.True(input.ReadTag(out tag, out name));
List<TestNegEnum> values = new List<TestNegEnum>();
ICollection<object> unk;
input.ReadEnumArray(tag, name, values, out unk);
- Assert.AreEqual(2, values.Count);
- Assert.AreEqual(TestNegEnum.None, values[0]);
- Assert.AreEqual(TestNegEnum.Value, values[1]);
+ Assert.Equal(2, values.Count);
+ Assert.Equal(TestNegEnum.None, values[0]);
+ Assert.Equal(TestNegEnum.Value, values[1]);
- Assert.IsNotNull(unk);
- Assert.AreEqual(4, unk.Count);
+ Assert.NotNull(unk);
+ Assert.Equal(4, unk.Count);
}
//Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily
- [TestMethod]
+ [Fact]
public void TestSlowPathAvoidance()
{
using (var ms = new MemoryStream())
@@ -624,15 +554,15 @@ namespace Google.ProtocolBuffers string ignore;
ByteString value;
- Assert.IsTrue(input.ReadTag(out tag, out ignore));
- Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag));
+ Assert.True(input.ReadTag(out tag, out ignore));
+ Assert.Equal(1, WireFormat.GetTagFieldNumber(tag));
value = ByteString.Empty;
- Assert.IsTrue(input.ReadBytes(ref value) && value.Length == 100);
+ Assert.True(input.ReadBytes(ref value) && value.Length == 100);
- Assert.IsTrue(input.ReadTag(out tag, out ignore));
- Assert.AreEqual(2, WireFormat.GetTagFieldNumber(tag));
+ Assert.True(input.ReadTag(out tag, out ignore));
+ Assert.Equal(2, WireFormat.GetTagFieldNumber(tag));
value = ByteString.Empty;
- Assert.IsTrue(input.ReadBytes(ref value) && value.Length == 100);
+ Assert.True(input.ReadBytes(ref value) && value.Length == 100);
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs b/csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs index 8e4e9090..d9f53d74 100644 --- a/csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs +++ b/csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs @@ -38,11 +38,10 @@ using System; using System.Collections.Generic;
using System.IO;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class CodedOutputStreamTest
{
/// <summary>
@@ -58,9 +57,9 @@ namespace Google.ProtocolBuffers CodedOutputStream output = CodedOutputStream.CreateInstance(rawOutput);
output.WriteRawVarint32((uint) value);
output.Flush();
- TestUtil.AssertBytesEqual(data, rawOutput.ToArray());
+ Assert.Equal(data, rawOutput.ToArray());
// Also try computing size.
- Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint32Size((uint) value));
+ Assert.Equal(data.Length, CodedOutputStream.ComputeRawVarint32Size((uint) value));
}
{
@@ -68,10 +67,10 @@ namespace Google.ProtocolBuffers CodedOutputStream output = CodedOutputStream.CreateInstance(rawOutput);
output.WriteRawVarint64(value);
output.Flush();
- TestUtil.AssertBytesEqual(data, rawOutput.ToArray());
+ Assert.Equal(data, rawOutput.ToArray());
// Also try computing size.
- Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint64Size(value));
+ Assert.Equal(data.Length, CodedOutputStream.ComputeRawVarint64Size(value));
}
// Try different buffer sizes.
@@ -85,7 +84,7 @@ namespace Google.ProtocolBuffers CodedOutputStream.CreateInstance(rawOutput, bufferSize);
output.WriteRawVarint32((uint) value);
output.Flush();
- TestUtil.AssertBytesEqual(data, rawOutput.ToArray());
+ Assert.Equal(data, rawOutput.ToArray());
}
{
@@ -93,7 +92,7 @@ namespace Google.ProtocolBuffers CodedOutputStream output = CodedOutputStream.CreateInstance(rawOutput, bufferSize);
output.WriteRawVarint64(value);
output.Flush();
- TestUtil.AssertBytesEqual(data, rawOutput.ToArray());
+ Assert.Equal(data, rawOutput.ToArray());
}
}
}
@@ -101,7 +100,7 @@ namespace Google.ProtocolBuffers /// <summary>
/// Tests WriteRawVarint32() and WriteRawVarint64()
/// </summary>
- [TestMethod]
+ [Fact]
public void WriteVarint()
{
AssertWriteVarint(new byte[] {0x00}, 0);
@@ -143,7 +142,7 @@ namespace Google.ProtocolBuffers CodedOutputStream output = CodedOutputStream.CreateInstance(rawOutput);
output.WriteRawLittleEndian32(value);
output.Flush();
- TestUtil.AssertBytesEqual(data, rawOutput.ToArray());
+ Assert.Equal(data, rawOutput.ToArray());
// Try different buffer sizes.
for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2)
@@ -152,7 +151,7 @@ namespace Google.ProtocolBuffers output = CodedOutputStream.CreateInstance(rawOutput, bufferSize);
output.WriteRawLittleEndian32(value);
output.Flush();
- TestUtil.AssertBytesEqual(data, rawOutput.ToArray());
+ Assert.Equal(data, rawOutput.ToArray());
}
}
@@ -166,7 +165,7 @@ namespace Google.ProtocolBuffers CodedOutputStream output = CodedOutputStream.CreateInstance(rawOutput);
output.WriteRawLittleEndian64(value);
output.Flush();
- TestUtil.AssertBytesEqual(data, rawOutput.ToArray());
+ Assert.Equal(data, rawOutput.ToArray());
// Try different block sizes.
for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
@@ -175,14 +174,14 @@ namespace Google.ProtocolBuffers output = CodedOutputStream.CreateInstance(rawOutput, blockSize);
output.WriteRawLittleEndian64(value);
output.Flush();
- TestUtil.AssertBytesEqual(data, rawOutput.ToArray());
+ Assert.Equal(data, rawOutput.ToArray());
}
}
/// <summary>
/// Tests writeRawLittleEndian32() and writeRawLittleEndian64().
/// </summary>
- [TestMethod]
+ [Fact]
public void WriteLittleEndian()
{
AssertWriteLittleEndian32(new byte[] {0x78, 0x56, 0x34, 0x12}, 0x12345678);
@@ -196,7 +195,7 @@ namespace Google.ProtocolBuffers 0x9abcdef012345678UL);
}
- [TestMethod]
+ [Fact]
public void WriteWholeMessage()
{
TestAllTypes message = TestUtil.GetAllSet();
@@ -220,7 +219,7 @@ namespace Google.ProtocolBuffers /// Tests writing a whole message with every packed field type. Ensures the
/// wire format of packed fields is compatible with C++.
/// </summary>
- [TestMethod]
+ [Fact]
public void WriteWholePackedFieldsMessage()
{
TestPackedTypes message = TestUtil.GetPackedSet();
@@ -230,97 +229,97 @@ namespace Google.ProtocolBuffers rawBytes);
}
- [TestMethod]
+ [Fact]
public void EncodeZigZag32()
{
- Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag32(0));
- Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag32(-1));
- Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag32(1));
- Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag32(-2));
- Assert.AreEqual(0x7FFFFFFEu, CodedOutputStream.EncodeZigZag32(0x3FFFFFFF));
- Assert.AreEqual(0x7FFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0xC0000000)));
- Assert.AreEqual(0xFFFFFFFEu, CodedOutputStream.EncodeZigZag32(0x7FFFFFFF));
- Assert.AreEqual(0xFFFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0x80000000)));
+ Assert.Equal(0u, CodedOutputStream.EncodeZigZag32(0));
+ Assert.Equal(1u, CodedOutputStream.EncodeZigZag32(-1));
+ Assert.Equal(2u, CodedOutputStream.EncodeZigZag32(1));
+ Assert.Equal(3u, CodedOutputStream.EncodeZigZag32(-2));
+ Assert.Equal(0x7FFFFFFEu, CodedOutputStream.EncodeZigZag32(0x3FFFFFFF));
+ Assert.Equal(0x7FFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0xC0000000)));
+ Assert.Equal(0xFFFFFFFEu, CodedOutputStream.EncodeZigZag32(0x7FFFFFFF));
+ Assert.Equal(0xFFFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0x80000000)));
}
- [TestMethod]
+ [Fact]
public void EncodeZigZag64()
{
- Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag64(0));
- Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag64(-1));
- Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag64(1));
- Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag64(-2));
- Assert.AreEqual(0x000000007FFFFFFEuL,
+ Assert.Equal(0u, CodedOutputStream.EncodeZigZag64(0));
+ Assert.Equal(1u, CodedOutputStream.EncodeZigZag64(-1));
+ Assert.Equal(2u, CodedOutputStream.EncodeZigZag64(1));
+ Assert.Equal(3u, CodedOutputStream.EncodeZigZag64(-2));
+ Assert.Equal(0x000000007FFFFFFEuL,
CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL)));
- Assert.AreEqual(0x000000007FFFFFFFuL,
+ Assert.Equal(0x000000007FFFFFFFuL,
CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL)));
- Assert.AreEqual(0x00000000FFFFFFFEuL,
+ Assert.Equal(0x00000000FFFFFFFEuL,
CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL)));
- Assert.AreEqual(0x00000000FFFFFFFFuL,
+ Assert.Equal(0x00000000FFFFFFFFuL,
CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL)));
- Assert.AreEqual(0xFFFFFFFFFFFFFFFEL,
+ Assert.Equal(0xFFFFFFFFFFFFFFFEL,
CodedOutputStream.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL)));
- Assert.AreEqual(0xFFFFFFFFFFFFFFFFL,
+ Assert.Equal(0xFFFFFFFFFFFFFFFFL,
CodedOutputStream.EncodeZigZag64(unchecked((long) 0x8000000000000000UL)));
}
- [TestMethod]
+ [Fact]
public void RoundTripZigZag32()
{
// Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
// were chosen semi-randomly via keyboard bashing.
- Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0)));
- Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1)));
- Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1)));
- Assert.AreEqual(14927, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927)));
- Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612)));
+ Assert.Equal(0, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0)));
+ Assert.Equal(1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1)));
+ Assert.Equal(-1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1)));
+ Assert.Equal(14927, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927)));
+ Assert.Equal(-3612, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612)));
}
- [TestMethod]
+ [Fact]
public void RoundTripZigZag64()
{
- Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0)));
- Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1)));
- Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1)));
- Assert.AreEqual(14927, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927)));
- Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612)));
+ Assert.Equal(0, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0)));
+ Assert.Equal(1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1)));
+ Assert.Equal(-1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1)));
+ Assert.Equal(14927, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927)));
+ Assert.Equal(-3612, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612)));
- Assert.AreEqual(856912304801416L,
+ Assert.Equal(856912304801416L,
CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(856912304801416L)));
- Assert.AreEqual(-75123905439571256L,
+ Assert.Equal(-75123905439571256L,
CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L)));
}
- [TestMethod]
+ [Fact]
public void TestNegativeEnumNoTag()
{
- Assert.AreEqual(10, CodedOutputStream.ComputeInt32SizeNoTag(-2));
- Assert.AreEqual(10, CodedOutputStream.ComputeEnumSizeNoTag(-2));
+ Assert.Equal(10, CodedOutputStream.ComputeInt32SizeNoTag(-2));
+ Assert.Equal(10, CodedOutputStream.ComputeEnumSizeNoTag(-2));
byte[] bytes = new byte[10];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteEnumNoTag(-2);
- Assert.AreEqual(0, output.SpaceLeft);
- Assert.AreEqual("FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes));
+ Assert.Equal(0, output.SpaceLeft);
+ Assert.Equal("FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes));
}
- [TestMethod]
+ [Fact]
public void TestNegativeEnumWithTag()
{
- Assert.AreEqual(11, CodedOutputStream.ComputeInt32Size(8, -2));
- Assert.AreEqual(11, CodedOutputStream.ComputeEnumSize(8, -2));
+ Assert.Equal(11, CodedOutputStream.ComputeInt32Size(8, -2));
+ Assert.Equal(11, CodedOutputStream.ComputeEnumSize(8, -2));
byte[] bytes = new byte[11];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteEnum(8, "", -2, -2);
- Assert.AreEqual(0, output.SpaceLeft);
+ Assert.Equal(0, output.SpaceLeft);
//fyi, 0x40 == 0x08 << 3 + 0, field num + wire format shift
- Assert.AreEqual("40-FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes));
+ Assert.Equal("40-FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes));
}
- [TestMethod]
+ [Fact]
public void TestNegativeEnumArrayPacked()
{
int arraySize = 1 + (10 * 5);
@@ -329,22 +328,22 @@ namespace Google.ProtocolBuffers CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WritePackedEnumArray(8, "", arraySize, new int[] { 0, -1, -2, -3, -4, -5 });
- Assert.AreEqual(0, output.SpaceLeft);
+ Assert.Equal(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag;
string name;
- Assert.IsTrue(input.ReadTag(out tag, out name));
+ Assert.True(input.ReadTag(out tag, out name));
List<int> values = new List<int>();
input.ReadInt32Array(tag, name, values);
- Assert.AreEqual(6, values.Count);
+ Assert.Equal(6, values.Count);
for (int i = 0; i > -6; i--)
- Assert.AreEqual(i, values[Math.Abs(i)]);
+ Assert.Equal(i, values[Math.Abs(i)]);
}
- [TestMethod]
+ [Fact]
public void TestNegativeEnumArray()
{
int arraySize = 1 + 1 + (11 * 5);
@@ -353,22 +352,22 @@ namespace Google.ProtocolBuffers CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteEnumArray(8, "", new int[] { 0, -1, -2, -3, -4, -5 });
- Assert.AreEqual(0, output.SpaceLeft);
+ Assert.Equal(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag;
string name;
- Assert.IsTrue(input.ReadTag(out tag, out name));
+ Assert.True(input.ReadTag(out tag, out name));
List<int> values = new List<int>();
input.ReadInt32Array(tag, name, values);
- Assert.AreEqual(6, values.Count);
+ Assert.Equal(6, values.Count);
for (int i = 0; i > -6; i--)
- Assert.AreEqual(i, values[Math.Abs(i)]);
+ Assert.Equal(i, values[Math.Abs(i)]);
}
- [TestMethod]
+ [Fact]
public void TestCodedInputOutputPosition()
{
byte[] content = new byte[110];
@@ -381,19 +380,19 @@ namespace Google.ProtocolBuffers CodedOutputStream cout = CodedOutputStream.CreateInstance(ms, 20);
// Field 11: numeric value: 500
cout.WriteTag(11, WireFormat.WireType.Varint);
- Assert.AreEqual(1, cout.Position);
+ Assert.Equal(1, cout.Position);
cout.WriteInt32NoTag(500);
- Assert.AreEqual(3, cout.Position);
+ Assert.Equal(3, cout.Position);
//Field 12: length delimited 120 bytes
cout.WriteTag(12, WireFormat.WireType.LengthDelimited);
- Assert.AreEqual(4, cout.Position);
+ Assert.Equal(4, cout.Position);
cout.WriteBytesNoTag(ByteString.CopyFrom(content));
- Assert.AreEqual(115, cout.Position);
+ Assert.Equal(115, cout.Position);
// Field 13: fixed numeric value: 501
cout.WriteTag(13, WireFormat.WireType.Fixed32);
- Assert.AreEqual(116, cout.Position);
+ Assert.Equal(116, cout.Position);
cout.WriteSFixed32NoTag(501);
- Assert.AreEqual(120, cout.Position);
+ Assert.Equal(120, cout.Position);
cout.Flush();
}
@@ -402,19 +401,19 @@ namespace Google.ProtocolBuffers CodedOutputStream cout = CodedOutputStream.CreateInstance(bytes);
// Field 1: numeric value: 500
cout.WriteTag(1, WireFormat.WireType.Varint);
- Assert.AreEqual(1, cout.Position);
+ Assert.Equal(1, cout.Position);
cout.WriteInt32NoTag(500);
- Assert.AreEqual(3, cout.Position);
+ Assert.Equal(3, cout.Position);
//Field 2: length delimited 120 bytes
cout.WriteTag(2, WireFormat.WireType.LengthDelimited);
- Assert.AreEqual(4, cout.Position);
+ Assert.Equal(4, cout.Position);
cout.WriteBytesNoTag(ByteString.CopyFrom(child));
- Assert.AreEqual(125, cout.Position);
+ Assert.Equal(125, cout.Position);
// Field 3: fixed numeric value: 500
cout.WriteTag(3, WireFormat.WireType.Fixed32);
- Assert.AreEqual(126, cout.Position);
+ Assert.Equal(126, cout.Position);
cout.WriteSFixed32NoTag(501);
- Assert.AreEqual(130, cout.Position);
+ Assert.Equal(130, cout.Position);
cout.Flush();
}
//Now test Input stream:
@@ -423,49 +422,49 @@ namespace Google.ProtocolBuffers uint tag;
int intValue = 0;
string ignore;
- Assert.AreEqual(0, cin.Position);
+ Assert.Equal(0, cin.Position);
// Field 1:
- Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 1);
- Assert.AreEqual(1, cin.Position);
- Assert.IsTrue(cin.ReadInt32(ref intValue) && intValue == 500);
- Assert.AreEqual(3, cin.Position);
+ Assert.True(cin.ReadTag(out tag, out ignore) && tag >> 3 == 1);
+ Assert.Equal(1, cin.Position);
+ Assert.True(cin.ReadInt32(ref intValue) && intValue == 500);
+ Assert.Equal(3, cin.Position);
//Field 2:
- Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 2);
- Assert.AreEqual(4, cin.Position);
+ Assert.True(cin.ReadTag(out tag, out ignore) && tag >> 3 == 2);
+ Assert.Equal(4, cin.Position);
uint childlen = cin.ReadRawVarint32();
- Assert.AreEqual(120u, childlen);
- Assert.AreEqual(5, cin.Position);
+ Assert.Equal(120u, childlen);
+ Assert.Equal(5, cin.Position);
int oldlimit = cin.PushLimit((int)childlen);
- Assert.AreEqual(5, cin.Position);
+ Assert.Equal(5, cin.Position);
// Now we are reading child message
{
// Field 11: numeric value: 500
- Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 11);
- Assert.AreEqual(6, cin.Position);
- Assert.IsTrue(cin.ReadInt32(ref intValue) && intValue == 500);
- Assert.AreEqual(8, cin.Position);
+ Assert.True(cin.ReadTag(out tag, out ignore) && tag >> 3 == 11);
+ Assert.Equal(6, cin.Position);
+ Assert.True(cin.ReadInt32(ref intValue) && intValue == 500);
+ Assert.Equal(8, cin.Position);
//Field 12: length delimited 120 bytes
- Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 12);
- Assert.AreEqual(9, cin.Position);
+ Assert.True(cin.ReadTag(out tag, out ignore) && tag >> 3 == 12);
+ Assert.Equal(9, cin.Position);
ByteString bstr = null;
- Assert.IsTrue(cin.ReadBytes(ref bstr) && bstr.Length == 110 && bstr.ToByteArray()[109] == 109);
- Assert.AreEqual(120, cin.Position);
+ Assert.True(cin.ReadBytes(ref bstr) && bstr.Length == 110 && bstr.ToByteArray()[109] == 109);
+ Assert.Equal(120, cin.Position);
// Field 13: fixed numeric value: 501
- Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 13);
+ Assert.True(cin.ReadTag(out tag, out ignore) && tag >> 3 == 13);
// ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit
- Assert.AreEqual(121, cin.Position);
- Assert.IsTrue(cin.ReadSFixed32(ref intValue) && intValue == 501);
- Assert.AreEqual(125, cin.Position);
- Assert.IsTrue(cin.IsAtEnd);
+ Assert.Equal(121, cin.Position);
+ Assert.True(cin.ReadSFixed32(ref intValue) && intValue == 501);
+ Assert.Equal(125, cin.Position);
+ Assert.True(cin.IsAtEnd);
}
cin.PopLimit(oldlimit);
- Assert.AreEqual(125, cin.Position);
+ Assert.Equal(125, cin.Position);
// Field 3: fixed numeric value: 501
- Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 3);
- Assert.AreEqual(126, cin.Position);
- Assert.IsTrue(cin.ReadSFixed32(ref intValue) && intValue == 501);
- Assert.AreEqual(130, cin.Position);
- Assert.IsTrue(cin.IsAtEnd);
+ Assert.True(cin.ReadTag(out tag, out ignore) && tag >> 3 == 3);
+ Assert.Equal(126, cin.Position);
+ Assert.True(cin.ReadSFixed32(ref intValue) && intValue == 501);
+ Assert.Equal(130, cin.Position);
+ Assert.True(cin.IsAtEnd);
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/Collections/PopsicleListTest.cs b/csharp/src/ProtocolBuffers.Test/Collections/PopsicleListTest.cs index 0bce60d9..29584705 100644 --- a/csharp/src/ProtocolBuffers.Test/Collections/PopsicleListTest.cs +++ b/csharp/src/ProtocolBuffers.Test/Collections/PopsicleListTest.cs @@ -36,40 +36,39 @@ using System;
using System.Collections.Generic;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers.Collections
{
- [TestClass]
public class PopsicleListTest
{
- [TestMethod]
+ [Fact]
public void MutatingOperationsOnFrozenList()
{
PopsicleList<string> list = new PopsicleList<string>();
list.MakeReadOnly();
- TestUtil.AssertNotSupported(() => list.Add(""));
- TestUtil.AssertNotSupported(() => list.Clear());
- TestUtil.AssertNotSupported(() => list.Insert(0, ""));
- TestUtil.AssertNotSupported(() => list.Remove(""));
- TestUtil.AssertNotSupported(() => list.RemoveAt(0));
- TestUtil.AssertNotSupported(() => list.Add(new[] { "", "" }));
+ Assert.Throws<NotSupportedException>(() => list.Add(""));
+ Assert.Throws<NotSupportedException>(() => list.Clear());
+ Assert.Throws<NotSupportedException>(() => list.Insert(0, ""));
+ Assert.Throws<NotSupportedException>(() => list.Remove(""));
+ Assert.Throws<NotSupportedException>(() => list.RemoveAt(0));
+ Assert.Throws<NotSupportedException>(() => list.Add(new[] { "", "" }));
}
- [TestMethod]
+ [Fact]
public void NonMutatingOperationsOnFrozenList()
{
PopsicleList<string> list = new PopsicleList<string>();
list.MakeReadOnly();
- Assert.IsFalse(list.Contains(""));
- Assert.AreEqual(0, list.Count);
+ Assert.False(list.Contains(""));
+ Assert.Equal(0, list.Count);
list.CopyTo(new string[5], 0);
list.GetEnumerator();
- Assert.AreEqual(-1, list.IndexOf(""));
- Assert.IsTrue(list.IsReadOnly);
+ Assert.Equal(-1, list.IndexOf(""));
+ Assert.True(list.IsReadOnly);
}
- [TestMethod]
+ [Fact]
public void MutatingOperationsOnFluidList()
{
PopsicleList<string> list = new PopsicleList<string>();
@@ -81,73 +80,46 @@ namespace Google.ProtocolBuffers.Collections list.RemoveAt(0);
}
- [TestMethod]
+ [Fact]
public void NonMutatingOperationsOnFluidList()
{
PopsicleList<string> list = new PopsicleList<string>();
- Assert.IsFalse(list.Contains(""));
- Assert.AreEqual(0, list.Count);
+ Assert.False(list.Contains(""));
+ Assert.Equal(0, list.Count);
list.CopyTo(new string[5], 0);
list.GetEnumerator();
- Assert.AreEqual(-1, list.IndexOf(""));
- Assert.IsFalse(list.IsReadOnly);
+ Assert.Equal(-1, list.IndexOf(""));
+ Assert.False(list.IsReadOnly);
}
- [TestMethod]
+ [Fact]
public void DoesNotAddNullEnumerable()
{
PopsicleList<string> list = new PopsicleList<string>();
- try
- {
- list.Add((IEnumerable<string>)null);
- }
- catch (ArgumentNullException)
- { return; }
-
- Assert.Fail("List should not allow nulls.");
+ Assert.Throws<ArgumentNullException>(() => list.Add((IEnumerable<string>) null));
}
- [TestMethod]
+ [Fact]
public void DoesNotAddRangeWithNull()
{
PopsicleList<string> list = new PopsicleList<string>();
- try
- {
- list.Add(new[] { "a", "b", null });
- }
- catch (ArgumentNullException)
- { return; }
-
- Assert.Fail("List should not allow nulls.");
+ // TODO(jonskeet): Change to ArgumentException? The argument isn't null...
+ Assert.Throws<ArgumentNullException>(() => list.Add(new[] {"a", "b", null}));
}
- [TestMethod]
+ [Fact]
public void DoesNotAddNull()
{
PopsicleList<string> list = new PopsicleList<string>();
- try
- {
- list.Add((string)null);
- }
- catch (ArgumentNullException)
- { return; }
-
- Assert.Fail("List should not allow nulls.");
+ Assert.Throws<ArgumentNullException>(() => list.Add((string) null));
}
- [TestMethod]
+ [Fact]
public void DoesNotSetNull()
{
PopsicleList<string> list = new PopsicleList<string>();
list.Add("a");
- try
- {
- list[0] = null;
- }
- catch (ArgumentNullException)
- { return; }
-
- Assert.Fail("List should not allow nulls.");
+ Assert.Throws<ArgumentNullException>(() => list[0] = null);
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs b/csharp/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs index 9707f8e8..30d257ad 100644 --- a/csharp/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs +++ b/csharp/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs @@ -1,9 +1,7 @@ using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers.Compatibility
{
- [TestClass]
public class BinaryCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
diff --git a/csharp/src/ProtocolBuffers.Test/Compatibility/CompatibilityTests.cs b/csharp/src/ProtocolBuffers.Test/Compatibility/CompatibilityTests.cs index 5befe96f..d918c926 100644 --- a/csharp/src/ProtocolBuffers.Test/Compatibility/CompatibilityTests.cs +++ b/csharp/src/ProtocolBuffers.Test/Compatibility/CompatibilityTests.cs @@ -1,6 +1,6 @@ using System;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers.Compatibility
@@ -22,10 +22,10 @@ namespace Google.ProtocolBuffers.Compatibility protected virtual void AssertOutputEquals(object lhs, object rhs)
{
- Assert.AreEqual<object>(lhs, rhs);
+ Assert.Equal<object>(lhs, rhs);
}
- [TestMethod]
+ [Fact]
public virtual void RoundTripWithEmptyChildMessageSize()
{
SizeMessage1 msg = SizeMessage1.CreateBuilder()
@@ -37,12 +37,12 @@ namespace Google.ProtocolBuffers.Compatibility SizeMessage1 copy = DeserializeMessage<SizeMessage1, SizeMessage1.Builder>(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).BuildPartial();
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
AssertOutputEquals(content, SerializeMessage<SizeMessage1, SizeMessage1.Builder>(copy));
- Assert.AreEqual(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
+ Assert.Equal(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
}
- [TestMethod]
+ [Fact]
public virtual void RoundTripWithEmptyChildMessageSpeed()
{
SpeedMessage1 msg = SpeedMessage1.CreateBuilder()
@@ -54,12 +54,12 @@ namespace Google.ProtocolBuffers.Compatibility SpeedMessage1 copy = DeserializeMessage<SpeedMessage1, SpeedMessage1.Builder>(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).BuildPartial();
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
AssertOutputEquals(content, SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(copy));
- Assert.AreEqual(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
+ Assert.Equal(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
}
- [TestMethod]
+ [Fact]
public virtual void RoundTripMessage1OptimizeSize()
{
SizeMessage1 msg = SizeMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
@@ -67,12 +67,12 @@ namespace Google.ProtocolBuffers.Compatibility SizeMessage1 copy = DeserializeMessage<SizeMessage1, SizeMessage1.Builder>(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build();
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
AssertOutputEquals(content, SerializeMessage<SizeMessage1, SizeMessage1.Builder>(copy));
- Assert.AreEqual(Convert.ToBase64String(TestResources.google_message1), Convert.ToBase64String(copy.ToByteArray()));
+ Assert.Equal(Convert.ToBase64String(TestResources.google_message1), Convert.ToBase64String(copy.ToByteArray()));
}
- [TestMethod]
+ [Fact]
public virtual void RoundTripMessage2OptimizeSize()
{
SizeMessage2 msg = SizeMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
@@ -80,12 +80,12 @@ namespace Google.ProtocolBuffers.Compatibility SizeMessage2 copy = DeserializeMessage<SizeMessage2, SizeMessage2.Builder>(content, SizeMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build();
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
AssertOutputEquals(content, SerializeMessage<SizeMessage2, SizeMessage2.Builder>(copy));
- Assert.AreEqual(Convert.ToBase64String(TestResources.google_message2), Convert.ToBase64String(copy.ToByteArray()));
+ Assert.Equal(Convert.ToBase64String(TestResources.google_message2), Convert.ToBase64String(copy.ToByteArray()));
}
- [TestMethod]
+ [Fact]
public virtual void RoundTripMessage1OptimizeSpeed()
{
SpeedMessage1 msg = SpeedMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
@@ -93,12 +93,12 @@ namespace Google.ProtocolBuffers.Compatibility SpeedMessage1 copy = DeserializeMessage<SpeedMessage1, SpeedMessage1.Builder>(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build();
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
AssertOutputEquals(content, SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(copy));
- Assert.AreEqual(Convert.ToBase64String(TestResources.google_message1), Convert.ToBase64String(copy.ToByteArray()));
+ Assert.Equal(Convert.ToBase64String(TestResources.google_message1), Convert.ToBase64String(copy.ToByteArray()));
}
- [TestMethod]
+ [Fact]
public virtual void RoundTripMessage2OptimizeSpeed()
{
SpeedMessage2 msg = SpeedMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
@@ -106,9 +106,9 @@ namespace Google.ProtocolBuffers.Compatibility SpeedMessage2 copy = DeserializeMessage<SpeedMessage2, SpeedMessage2.Builder>(content, SpeedMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build();
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
AssertOutputEquals(content, SerializeMessage<SpeedMessage2, SpeedMessage2.Builder>(copy));
- Assert.AreEqual(Convert.ToBase64String(TestResources.google_message2), Convert.ToBase64String(copy.ToByteArray()));
+ Assert.Equal(Convert.ToBase64String(TestResources.google_message2), Convert.ToBase64String(copy.ToByteArray()));
}
#region Test message builders
@@ -185,7 +185,7 @@ namespace Google.ProtocolBuffers.Compatibility #endregion
- [TestMethod]
+ [Fact]
public void TestRoundTripAllTypes()
{
TestAllTypes msg = AddAllTypes(new TestAllTypes.Builder()).Build();
@@ -193,12 +193,12 @@ namespace Google.ProtocolBuffers.Compatibility TestAllTypes copy = DeserializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy));
- Assert.AreEqual(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
+ Assert.Equal(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
}
- [TestMethod]
+ [Fact]
public void TestRoundTripRepeatedTypes()
{
TestAllTypes msg = AddRepeatedTypes(new TestAllTypes.Builder(), 5).Build();
@@ -206,12 +206,12 @@ namespace Google.ProtocolBuffers.Compatibility TestAllTypes copy = DeserializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy));
- Assert.AreEqual(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
+ Assert.Equal(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
}
- [TestMethod]
+ [Fact]
public void TestRoundTripPackedTypes()
{
TestPackedTypes msg = AddPackedTypes(new TestPackedTypes.Builder(), 5).Build();
@@ -219,9 +219,9 @@ namespace Google.ProtocolBuffers.Compatibility TestPackedTypes copy = DeserializeMessage<TestPackedTypes, TestPackedTypes.Builder>(content, TestPackedTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
AssertOutputEquals(content, SerializeMessage<TestPackedTypes, TestPackedTypes.Builder>(copy));
- Assert.AreEqual(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
+ Assert.Equal(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs b/csharp/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs index 73037cce..f555b101 100644 --- a/csharp/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs +++ b/csharp/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs @@ -1,13 +1,10 @@ using System;
using System.Collections.Generic;
-using System.IO;
-using System.Text;
using Google.ProtocolBuffers.Serialization;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers.Compatibility
{
- [TestClass]
public class DictionaryCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
@@ -28,7 +25,7 @@ namespace Google.ProtocolBuffers.Compatibility IDictionary<string, object> left = (IDictionary<string, object>)lhs;
IDictionary<string, object> right = (IDictionary<string, object>)rhs;
- Assert.AreEqual(
+ Assert.Equal(
String.Join(",", new List<string>(left.Keys).ToArray()),
String.Join(",", new List<string>(right.Keys).ToArray())
);
diff --git a/csharp/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs b/csharp/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs index 74603108..3c943d33 100644 --- a/csharp/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs +++ b/csharp/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs @@ -1,11 +1,8 @@ using System.IO;
-using System.Text;
using Google.ProtocolBuffers.Serialization;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers.Compatibility
{
- [TestClass]
public class JsonCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
@@ -23,7 +20,6 @@ namespace Google.ProtocolBuffers.Compatibility }
}
- [TestClass]
public class JsonCompatibilityFormattedTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
diff --git a/csharp/src/ProtocolBuffers.Test/Compatibility/TestResources.cs b/csharp/src/ProtocolBuffers.Test/Compatibility/TestResources.cs index c3ce5883..4d1187a4 100644 --- a/csharp/src/ProtocolBuffers.Test/Compatibility/TestResources.cs +++ b/csharp/src/ProtocolBuffers.Test/Compatibility/TestResources.cs @@ -1,8 +1,5 @@ -using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.IO;
+using Xunit;
namespace Google.ProtocolBuffers.Compatibility
{
@@ -15,11 +12,11 @@ namespace Google.ProtocolBuffers.Compatibility Stream resource = typeof(TestResources).Assembly.GetManifestResourceStream(
typeof(TestResources).Namespace + ".google_message1.dat");
- Assert.IsNotNull(resource, "Unable to the locate resource: google_message1");
+ Assert.NotNull(resource);
byte[] bytes = new byte[resource.Length];
int amtRead = resource.Read(bytes, 0, bytes.Length);
- Assert.AreEqual(bytes.Length, amtRead);
+ Assert.Equal(bytes.Length, amtRead);
return bytes;
}
}
@@ -30,11 +27,10 @@ namespace Google.ProtocolBuffers.Compatibility Stream resource = typeof(TestResources).Assembly.GetManifestResourceStream(
typeof(TestResources).Namespace + ".google_message2.dat");
- Assert.IsNotNull(resource, "Unable to the locate resource: google_message2");
-
+ Assert.NotNull(resource);
byte[] bytes = new byte[resource.Length];
int amtRead = resource.Read(bytes, 0, bytes.Length);
- Assert.AreEqual(bytes.Length, amtRead);
+ Assert.Equal(bytes.Length, amtRead);
return bytes;
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/Compatibility/TextCompatibilityTests.cs b/csharp/src/ProtocolBuffers.Test/Compatibility/TextCompatibilityTests.cs index c2eaadf6..2d74cf9f 100644 --- a/csharp/src/ProtocolBuffers.Test/Compatibility/TextCompatibilityTests.cs +++ b/csharp/src/ProtocolBuffers.Test/Compatibility/TextCompatibilityTests.cs @@ -1,10 +1,8 @@ -using System.ComponentModel;
using System.IO;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers.Compatibility
{
- [TestClass]
public class TextCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
@@ -20,14 +18,14 @@ namespace Google.ProtocolBuffers.Compatibility return builder;
}
//This test can take a very long time to run.
- [TestMethod]
+ [Fact]
public override void RoundTripMessage2OptimizeSize()
{
//base.RoundTripMessage2OptimizeSize();
}
//This test can take a very long time to run.
- [TestMethod]
+ [Fact]
public override void RoundTripMessage2OptimizeSpeed()
{
//base.RoundTripMessage2OptimizeSpeed();
diff --git a/csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs b/csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs index 70614744..313523eb 100644 --- a/csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs +++ b/csharp/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs @@ -1,12 +1,9 @@ using System.IO;
using System.Xml;
using Google.ProtocolBuffers.Serialization;
-using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers.Compatibility
{
- [TestClass]
public class XmlCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
@@ -24,7 +21,6 @@ namespace Google.ProtocolBuffers.Compatibility }
}
- [TestClass]
public class XmlCompatibilityFormattedTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
diff --git a/csharp/src/ProtocolBuffers.Test/DeprecatedMemberTest.cs b/csharp/src/ProtocolBuffers.Test/DeprecatedMemberTest.cs index 0901f043..21d21928 100644 --- a/csharp/src/ProtocolBuffers.Test/DeprecatedMemberTest.cs +++ b/csharp/src/ProtocolBuffers.Test/DeprecatedMemberTest.cs @@ -1,22 +1,19 @@ using System;
-using System.Collections.Generic;
using System.Reflection;
-using System.Text;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitTest.Issues.TestProtos;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class DeprecatedMemberTest
{
private static void AssertIsDeprecated(MemberInfo member)
{
- Assert.IsNotNull(member);
- Assert.IsTrue(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
+ Assert.NotNull(member);
+ Assert.True(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
}
- [TestMethod]
+ [Fact]
public void TestDepreatedPrimitiveValue()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasPrimitiveValue"));
@@ -27,7 +24,7 @@ namespace Google.ProtocolBuffers AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetPrimitiveValue"));
}
- [TestMethod]
+ [Fact]
public void TestDepreatedPrimitiveArray()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("PrimitiveArrayList"));
@@ -42,7 +39,7 @@ namespace Google.ProtocolBuffers AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangePrimitiveArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveArray"));
}
- [TestMethod]
+ [Fact]
public void TestDepreatedMessageValue()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasMessageValue"));
@@ -55,7 +52,7 @@ namespace Google.ProtocolBuffers AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageValue", new[] { typeof(DeprecatedChild) }));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageValue", new[] { typeof(DeprecatedChild.Builder) }));
}
- [TestMethod]
+ [Fact]
public void TestDepreatedMessageArray()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("MessageArrayList"));
@@ -72,7 +69,7 @@ namespace Google.ProtocolBuffers AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangeMessageArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearMessageArray"));
}
- [TestMethod]
+ [Fact]
public void TestDepreatedEnumValue()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasEnumValue"));
@@ -83,7 +80,7 @@ namespace Google.ProtocolBuffers AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearEnumValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetEnumValue"));
}
- [TestMethod]
+ [Fact]
public void TestDepreatedEnumArray()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("EnumArrayList"));
diff --git a/csharp/src/ProtocolBuffers.Test/DescriptorsTest.cs b/csharp/src/ProtocolBuffers.Test/DescriptorsTest.cs index e74236fb..680887d3 100644 --- a/csharp/src/ProtocolBuffers.Test/DescriptorsTest.cs +++ b/csharp/src/ProtocolBuffers.Test/DescriptorsTest.cs @@ -34,10 +34,9 @@ #endregion
-using System.Text;
using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
@@ -45,106 +44,105 @@ namespace Google.ProtocolBuffers /// Tests for descriptors. (Not in its own namespace or broken up into individual classes as the
/// size doesn't warrant it. On the other hand, this makes me feel a bit dirty...)
/// </summary>
- [TestClass]
public class DescriptorsTest
{
- [TestMethod]
+ [Fact]
public void FileDescriptor()
{
FileDescriptor file = Unittest.Descriptor;
- Assert.AreEqual("google/protobuf/unittest.proto", file.Name);
- Assert.AreEqual("protobuf_unittest", file.Package);
+ Assert.Equal("google/protobuf/unittest.proto", file.Name);
+ Assert.Equal("protobuf_unittest", file.Package);
- Assert.AreEqual("UnittestProto", file.Options.JavaOuterClassname);
- Assert.AreEqual("google/protobuf/unittest.proto", file.Proto.Name);
+ Assert.Equal("UnittestProto", file.Options.JavaOuterClassname);
+ Assert.Equal("google/protobuf/unittest.proto", file.Proto.Name);
// unittest.proto doesn't have any public imports, but unittest_import.proto does.
- Assert.AreEqual(0, file.PublicDependencies.Count);
- Assert.AreEqual(1, UnittestImport.Descriptor.PublicDependencies.Count);
- Assert.AreEqual(UnittestImportPublic.Descriptor, UnittestImport.Descriptor.PublicDependencies[0]);
+ Assert.Equal(0, file.PublicDependencies.Count);
+ Assert.Equal(1, UnittestImport.Descriptor.PublicDependencies.Count);
+ Assert.Equal(UnittestImportPublic.Descriptor, UnittestImport.Descriptor.PublicDependencies[0]);
- Assert.AreEqual(1, file.Dependencies.Count);
- Assert.AreEqual(UnittestImport.Descriptor, file.Dependencies[0]);
+ Assert.Equal(1, file.Dependencies.Count);
+ Assert.Equal(UnittestImport.Descriptor, file.Dependencies[0]);
MessageDescriptor messageType = TestAllTypes.Descriptor;
- Assert.AreEqual(messageType, file.MessageTypes[0]);
- Assert.AreEqual(messageType, file.FindTypeByName<MessageDescriptor>("TestAllTypes"));
- Assert.IsNull(file.FindTypeByName<MessageDescriptor>("NoSuchType"));
- Assert.IsNull(file.FindTypeByName<MessageDescriptor>("protobuf_unittest.TestAllTypes"));
+ Assert.Equal(messageType, file.MessageTypes[0]);
+ Assert.Equal(messageType, file.FindTypeByName<MessageDescriptor>("TestAllTypes"));
+ Assert.Null(file.FindTypeByName<MessageDescriptor>("NoSuchType"));
+ Assert.Null(file.FindTypeByName<MessageDescriptor>("protobuf_unittest.TestAllTypes"));
for (int i = 0; i < file.MessageTypes.Count; i++)
{
- Assert.AreEqual(i, file.MessageTypes[i].Index);
+ Assert.Equal(i, file.MessageTypes[i].Index);
}
- Assert.AreEqual(file.EnumTypes[0], file.FindTypeByName<EnumDescriptor>("ForeignEnum"));
- Assert.IsNull(file.FindTypeByName<EnumDescriptor>("NoSuchType"));
- Assert.IsNull(file.FindTypeByName<EnumDescriptor>("protobuf_unittest.ForeignEnum"));
- Assert.AreEqual(1, UnittestImport.Descriptor.EnumTypes.Count);
- Assert.AreEqual("ImportEnum", UnittestImport.Descriptor.EnumTypes[0].Name);
+ Assert.Equal(file.EnumTypes[0], file.FindTypeByName<EnumDescriptor>("ForeignEnum"));
+ Assert.Null(file.FindTypeByName<EnumDescriptor>("NoSuchType"));
+ Assert.Null(file.FindTypeByName<EnumDescriptor>("protobuf_unittest.ForeignEnum"));
+ Assert.Equal(1, UnittestImport.Descriptor.EnumTypes.Count);
+ Assert.Equal("ImportEnum", UnittestImport.Descriptor.EnumTypes[0].Name);
for (int i = 0; i < file.EnumTypes.Count; i++)
{
- Assert.AreEqual(i, file.EnumTypes[i].Index);
+ Assert.Equal(i, file.EnumTypes[i].Index);
}
FieldDescriptor extension = Unittest.OptionalInt32Extension.Descriptor;
- Assert.AreEqual(extension, file.Extensions[0]);
- Assert.AreEqual(extension, file.FindTypeByName<FieldDescriptor>("optional_int32_extension"));
- Assert.IsNull(file.FindTypeByName<FieldDescriptor>("no_such_ext"));
- Assert.IsNull(file.FindTypeByName<FieldDescriptor>("protobuf_unittest.optional_int32_extension"));
- Assert.AreEqual(0, UnittestImport.Descriptor.Extensions.Count);
+ Assert.Equal(extension, file.Extensions[0]);
+ Assert.Equal(extension, file.FindTypeByName<FieldDescriptor>("optional_int32_extension"));
+ Assert.Null(file.FindTypeByName<FieldDescriptor>("no_such_ext"));
+ Assert.Null(file.FindTypeByName<FieldDescriptor>("protobuf_unittest.optional_int32_extension"));
+ Assert.Equal(0, UnittestImport.Descriptor.Extensions.Count);
for (int i = 0; i < file.Extensions.Count; i++)
{
- Assert.AreEqual(i, file.Extensions[i].Index);
+ Assert.Equal(i, file.Extensions[i].Index);
}
}
- [TestMethod]
+ [Fact]
public void MessageDescriptor()
{
MessageDescriptor messageType = TestAllTypes.Descriptor;
MessageDescriptor nestedType = TestAllTypes.Types.NestedMessage.Descriptor;
- Assert.AreEqual("TestAllTypes", messageType.Name);
- Assert.AreEqual("protobuf_unittest.TestAllTypes", messageType.FullName);
- Assert.AreEqual(Unittest.Descriptor, messageType.File);
- Assert.IsNull(messageType.ContainingType);
- Assert.AreEqual(DescriptorProtos.MessageOptions.DefaultInstance, messageType.Options);
- Assert.AreEqual("TestAllTypes", messageType.Proto.Name);
+ Assert.Equal("TestAllTypes", messageType.Name);
+ Assert.Equal("protobuf_unittest.TestAllTypes", messageType.FullName);
+ Assert.Equal(Unittest.Descriptor, messageType.File);
+ Assert.Null(messageType.ContainingType);
+ Assert.Equal(DescriptorProtos.MessageOptions.DefaultInstance, messageType.Options);
+ Assert.Equal("TestAllTypes", messageType.Proto.Name);
- Assert.AreEqual("NestedMessage", nestedType.Name);
- Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedMessage", nestedType.FullName);
- Assert.AreEqual(Unittest.Descriptor, nestedType.File);
- Assert.AreEqual(messageType, nestedType.ContainingType);
+ Assert.Equal("NestedMessage", nestedType.Name);
+ Assert.Equal("protobuf_unittest.TestAllTypes.NestedMessage", nestedType.FullName);
+ Assert.Equal(Unittest.Descriptor, nestedType.File);
+ Assert.Equal(messageType, nestedType.ContainingType);
FieldDescriptor field = messageType.Fields[0];
- Assert.AreEqual("optional_int32", field.Name);
- Assert.AreEqual(field, messageType.FindDescriptor<FieldDescriptor>("optional_int32"));
- Assert.IsNull(messageType.FindDescriptor<FieldDescriptor>("no_such_field"));
- Assert.AreEqual(field, messageType.FindFieldByNumber(1));
- Assert.IsNull(messageType.FindFieldByNumber(571283));
+ Assert.Equal("optional_int32", field.Name);
+ Assert.Equal(field, messageType.FindDescriptor<FieldDescriptor>("optional_int32"));
+ Assert.Null(messageType.FindDescriptor<FieldDescriptor>("no_such_field"));
+ Assert.Equal(field, messageType.FindFieldByNumber(1));
+ Assert.Null(messageType.FindFieldByNumber(571283));
for (int i = 0; i < messageType.Fields.Count; i++)
{
- Assert.AreEqual(i, messageType.Fields[i].Index);
+ Assert.Equal(i, messageType.Fields[i].Index);
}
- Assert.AreEqual(nestedType, messageType.NestedTypes[0]);
- Assert.AreEqual(nestedType, messageType.FindDescriptor<MessageDescriptor>("NestedMessage"));
- Assert.IsNull(messageType.FindDescriptor<MessageDescriptor>("NoSuchType"));
+ Assert.Equal(nestedType, messageType.NestedTypes[0]);
+ Assert.Equal(nestedType, messageType.FindDescriptor<MessageDescriptor>("NestedMessage"));
+ Assert.Null(messageType.FindDescriptor<MessageDescriptor>("NoSuchType"));
for (int i = 0; i < messageType.NestedTypes.Count; i++)
{
- Assert.AreEqual(i, messageType.NestedTypes[i].Index);
+ Assert.Equal(i, messageType.NestedTypes[i].Index);
}
- Assert.AreEqual(messageType.EnumTypes[0], messageType.FindDescriptor<EnumDescriptor>("NestedEnum"));
- Assert.IsNull(messageType.FindDescriptor<EnumDescriptor>("NoSuchType"));
+ Assert.Equal(messageType.EnumTypes[0], messageType.FindDescriptor<EnumDescriptor>("NestedEnum"));
+ Assert.Null(messageType.FindDescriptor<EnumDescriptor>("NoSuchType"));
for (int i = 0; i < messageType.EnumTypes.Count; i++)
{
- Assert.AreEqual(i, messageType.EnumTypes[i].Index);
+ Assert.Equal(i, messageType.EnumTypes[i].Index);
}
}
- [TestMethod]
+ [Fact]
public void FieldDescriptor()
{
MessageDescriptor messageType = TestAllTypes.Descriptor;
@@ -155,54 +153,54 @@ namespace Google.ProtocolBuffers FieldDescriptor extension = Unittest.OptionalInt32Extension.Descriptor;
FieldDescriptor nestedExtension = TestRequired.Single.Descriptor;
- Assert.AreEqual("optional_int32", primitiveField.Name);
- Assert.AreEqual("protobuf_unittest.TestAllTypes.optional_int32",
+ Assert.Equal("optional_int32", primitiveField.Name);
+ Assert.Equal("protobuf_unittest.TestAllTypes.optional_int32",
primitiveField.FullName);
- Assert.AreEqual(1, primitiveField.FieldNumber);
- Assert.AreEqual(messageType, primitiveField.ContainingType);
- Assert.AreEqual(Unittest.Descriptor, primitiveField.File);
- Assert.AreEqual(FieldType.Int32, primitiveField.FieldType);
- Assert.AreEqual(MappedType.Int32, primitiveField.MappedType);
- Assert.AreEqual(DescriptorProtos.FieldOptions.DefaultInstance, primitiveField.Options);
- Assert.IsFalse(primitiveField.IsExtension);
- Assert.AreEqual("optional_int32", primitiveField.Proto.Name);
-
- Assert.AreEqual("optional_nested_enum", enumField.Name);
- Assert.AreEqual(FieldType.Enum, enumField.FieldType);
- Assert.AreEqual(MappedType.Enum, enumField.MappedType);
- // Assert.AreEqual(TestAllTypes.Types.NestedEnum.DescriptorProtoFile, enumField.EnumType);
-
- Assert.AreEqual("optional_foreign_message", messageField.Name);
- Assert.AreEqual(FieldType.Message, messageField.FieldType);
- Assert.AreEqual(MappedType.Message, messageField.MappedType);
- Assert.AreEqual(ForeignMessage.Descriptor, messageField.MessageType);
-
- Assert.AreEqual("optional_cord", cordField.Name);
- Assert.AreEqual(FieldType.String, cordField.FieldType);
- Assert.AreEqual(MappedType.String, cordField.MappedType);
- Assert.AreEqual(DescriptorProtos.FieldOptions.Types.CType.CORD, cordField.Options.Ctype);
-
- Assert.AreEqual("optional_int32_extension", extension.Name);
- Assert.AreEqual("protobuf_unittest.optional_int32_extension", extension.FullName);
- Assert.AreEqual(1, extension.FieldNumber);
- Assert.AreEqual(TestAllExtensions.Descriptor, extension.ContainingType);
- Assert.AreEqual(Unittest.Descriptor, extension.File);
- Assert.AreEqual(FieldType.Int32, extension.FieldType);
- Assert.AreEqual(MappedType.Int32, extension.MappedType);
- Assert.AreEqual(DescriptorProtos.FieldOptions.DefaultInstance,
+ Assert.Equal(1, primitiveField.FieldNumber);
+ Assert.Equal(messageType, primitiveField.ContainingType);
+ Assert.Equal(Unittest.Descriptor, primitiveField.File);
+ Assert.Equal(FieldType.Int32, primitiveField.FieldType);
+ Assert.Equal(MappedType.Int32, primitiveField.MappedType);
+ Assert.Equal(DescriptorProtos.FieldOptions.DefaultInstance, primitiveField.Options);
+ Assert.False(primitiveField.IsExtension);
+ Assert.Equal("optional_int32", primitiveField.Proto.Name);
+
+ Assert.Equal("optional_nested_enum", enumField.Name);
+ Assert.Equal(FieldType.Enum, enumField.FieldType);
+ Assert.Equal(MappedType.Enum, enumField.MappedType);
+ // Assert.Equal(TestAllTypes.Types.NestedEnum.DescriptorProtoFile, enumField.EnumType);
+
+ Assert.Equal("optional_foreign_message", messageField.Name);
+ Assert.Equal(FieldType.Message, messageField.FieldType);
+ Assert.Equal(MappedType.Message, messageField.MappedType);
+ Assert.Equal(ForeignMessage.Descriptor, messageField.MessageType);
+
+ Assert.Equal("optional_cord", cordField.Name);
+ Assert.Equal(FieldType.String, cordField.FieldType);
+ Assert.Equal(MappedType.String, cordField.MappedType);
+ Assert.Equal(DescriptorProtos.FieldOptions.Types.CType.CORD, cordField.Options.Ctype);
+
+ Assert.Equal("optional_int32_extension", extension.Name);
+ Assert.Equal("protobuf_unittest.optional_int32_extension", extension.FullName);
+ Assert.Equal(1, extension.FieldNumber);
+ Assert.Equal(TestAllExtensions.Descriptor, extension.ContainingType);
+ Assert.Equal(Unittest.Descriptor, extension.File);
+ Assert.Equal(FieldType.Int32, extension.FieldType);
+ Assert.Equal(MappedType.Int32, extension.MappedType);
+ Assert.Equal(DescriptorProtos.FieldOptions.DefaultInstance,
extension.Options);
- Assert.IsTrue(extension.IsExtension);
- Assert.AreEqual(null, extension.ExtensionScope);
- Assert.AreEqual("optional_int32_extension", extension.Proto.Name);
+ Assert.True(extension.IsExtension);
+ Assert.Equal(null, extension.ExtensionScope);
+ Assert.Equal("optional_int32_extension", extension.Proto.Name);
- Assert.AreEqual("single", nestedExtension.Name);
- Assert.AreEqual("protobuf_unittest.TestRequired.single",
+ Assert.Equal("single", nestedExtension.Name);
+ Assert.Equal("protobuf_unittest.TestRequired.single",
nestedExtension.FullName);
- Assert.AreEqual(TestRequired.Descriptor,
+ Assert.Equal(TestRequired.Descriptor,
nestedExtension.ExtensionScope);
}
- [TestMethod]
+ [Fact]
public void FieldDescriptorLabel()
{
FieldDescriptor requiredField =
@@ -212,76 +210,76 @@ namespace Google.ProtocolBuffers FieldDescriptor repeatedField =
TestAllTypes.Descriptor.FindDescriptor<FieldDescriptor>("repeated_int32");
- Assert.IsTrue(requiredField.IsRequired);
- Assert.IsFalse(requiredField.IsRepeated);
- Assert.IsFalse(optionalField.IsRequired);
- Assert.IsFalse(optionalField.IsRepeated);
- Assert.IsFalse(repeatedField.IsRequired);
- Assert.IsTrue(repeatedField.IsRepeated);
+ Assert.True(requiredField.IsRequired);
+ Assert.False(requiredField.IsRepeated);
+ Assert.False(optionalField.IsRequired);
+ Assert.False(optionalField.IsRepeated);
+ Assert.False(repeatedField.IsRequired);
+ Assert.True(repeatedField.IsRepeated);
}
- [TestMethod]
+ [Fact]
public void FieldDescriptorDefault()
{
MessageDescriptor d = TestAllTypes.Descriptor;
- Assert.IsFalse(d.FindDescriptor<FieldDescriptor>("optional_int32").HasDefaultValue);
- Assert.AreEqual<object>(0, d.FindDescriptor<FieldDescriptor>("optional_int32").DefaultValue);
- Assert.IsTrue(d.FindDescriptor<FieldDescriptor>("default_int32").HasDefaultValue);
- Assert.AreEqual<object>(41, d.FindDescriptor<FieldDescriptor>("default_int32").DefaultValue);
+ Assert.False(d.FindDescriptor<FieldDescriptor>("optional_int32").HasDefaultValue);
+ Assert.Equal<object>(0, d.FindDescriptor<FieldDescriptor>("optional_int32").DefaultValue);
+ Assert.True(d.FindDescriptor<FieldDescriptor>("default_int32").HasDefaultValue);
+ Assert.Equal<object>(41, d.FindDescriptor<FieldDescriptor>("default_int32").DefaultValue);
d = TestExtremeDefaultValues.Descriptor;
- Assert.AreEqual<object>(TestExtremeDefaultValues.DefaultInstance.EscapedBytes,
+ Assert.Equal<object>(TestExtremeDefaultValues.DefaultInstance.EscapedBytes,
d.FindDescriptor<FieldDescriptor>("escaped_bytes").DefaultValue);
- Assert.AreEqual<object>(uint.MaxValue, d.FindDescriptor<FieldDescriptor>("large_uint32").DefaultValue);
- Assert.AreEqual<object>(ulong.MaxValue, d.FindDescriptor<FieldDescriptor>("large_uint64").DefaultValue);
+ Assert.Equal<object>(uint.MaxValue, d.FindDescriptor<FieldDescriptor>("large_uint32").DefaultValue);
+ Assert.Equal<object>(ulong.MaxValue, d.FindDescriptor<FieldDescriptor>("large_uint64").DefaultValue);
}
- [TestMethod]
+ [Fact]
public void EnumDescriptor()
{
// Note: this test is a bit different to the Java version because there's no static way of getting to the descriptor
EnumDescriptor enumType = Unittest.Descriptor.FindTypeByName<EnumDescriptor>("ForeignEnum");
EnumDescriptor nestedType = TestAllTypes.Descriptor.FindDescriptor<EnumDescriptor>("NestedEnum");
- Assert.AreEqual("ForeignEnum", enumType.Name);
- Assert.AreEqual("protobuf_unittest.ForeignEnum", enumType.FullName);
- Assert.AreEqual(Unittest.Descriptor, enumType.File);
- Assert.IsNull(enumType.ContainingType);
- Assert.AreEqual(DescriptorProtos.EnumOptions.DefaultInstance,
+ Assert.Equal("ForeignEnum", enumType.Name);
+ Assert.Equal("protobuf_unittest.ForeignEnum", enumType.FullName);
+ Assert.Equal(Unittest.Descriptor, enumType.File);
+ Assert.Null(enumType.ContainingType);
+ Assert.Equal(DescriptorProtos.EnumOptions.DefaultInstance,
enumType.Options);
- Assert.AreEqual("NestedEnum", nestedType.Name);
- Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedEnum",
+ Assert.Equal("NestedEnum", nestedType.Name);
+ Assert.Equal("protobuf_unittest.TestAllTypes.NestedEnum",
nestedType.FullName);
- Assert.AreEqual(Unittest.Descriptor, nestedType.File);
- Assert.AreEqual(TestAllTypes.Descriptor, nestedType.ContainingType);
+ Assert.Equal(Unittest.Descriptor, nestedType.File);
+ Assert.Equal(TestAllTypes.Descriptor, nestedType.ContainingType);
EnumValueDescriptor value = enumType.FindValueByName("FOREIGN_FOO");
- Assert.AreEqual(value, enumType.Values[0]);
- Assert.AreEqual("FOREIGN_FOO", value.Name);
- Assert.AreEqual(4, value.Number);
- Assert.AreEqual((int) ForeignEnum.FOREIGN_FOO, value.Number);
- Assert.AreEqual(value, enumType.FindValueByNumber(4));
- Assert.IsNull(enumType.FindValueByName("NO_SUCH_VALUE"));
+ Assert.Equal(value, enumType.Values[0]);
+ Assert.Equal("FOREIGN_FOO", value.Name);
+ Assert.Equal(4, value.Number);
+ Assert.Equal((int) ForeignEnum.FOREIGN_FOO, value.Number);
+ Assert.Equal(value, enumType.FindValueByNumber(4));
+ Assert.Null(enumType.FindValueByName("NO_SUCH_VALUE"));
for (int i = 0; i < enumType.Values.Count; i++)
{
- Assert.AreEqual(i, enumType.Values[i].Index);
+ Assert.Equal(i, enumType.Values[i].Index);
}
}
- [TestMethod]
+ [Fact]
public void CustomOptions()
{
MessageDescriptor descriptor = TestMessageWithCustomOptions.Descriptor;
- Assert.IsTrue(descriptor.Options.HasExtension(UnittestCustomOptions.MessageOpt1));
- Assert.AreEqual(-56, descriptor.Options.GetExtension(UnittestCustomOptions.MessageOpt1));
+ Assert.True(descriptor.Options.HasExtension(UnittestCustomOptions.MessageOpt1));
+ Assert.Equal(-56, descriptor.Options.GetExtension(UnittestCustomOptions.MessageOpt1));
FieldDescriptor field = descriptor.FindFieldByName("field1");
- Assert.IsNotNull(field);
+ Assert.NotNull(field);
- Assert.IsTrue(field.Options.HasExtension(UnittestCustomOptions.FieldOpt1));
- Assert.AreEqual(8765432109uL, field.Options.GetExtension(UnittestCustomOptions.FieldOpt1));
+ Assert.True(field.Options.HasExtension(UnittestCustomOptions.FieldOpt1));
+ Assert.Equal(8765432109uL, field.Options.GetExtension(UnittestCustomOptions.FieldOpt1));
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/DynamicMessageTest.cs b/csharp/src/ProtocolBuffers.Test/DynamicMessageTest.cs index 92515999..39f122aa 100644 --- a/csharp/src/ProtocolBuffers.Test/DynamicMessageTest.cs +++ b/csharp/src/ProtocolBuffers.Test/DynamicMessageTest.cs @@ -37,26 +37,24 @@ using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class DynamicMessageTest
{
private ReflectionTester reflectionTester;
private ReflectionTester extensionsReflectionTester;
private ReflectionTester packedReflectionTester;
- [TestInitialize]
- public void SetUp()
+ public DynamicMessageTest()
{
reflectionTester = ReflectionTester.CreateTestAllTypesInstance();
extensionsReflectionTester = ReflectionTester.CreateTestAllExtensionsInstance();
packedReflectionTester = ReflectionTester.CreateTestPackedTypesInstance();
}
- [TestMethod]
+ [Fact]
public void DynamicMessageAccessors()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
@@ -65,30 +63,22 @@ namespace Google.ProtocolBuffers reflectionTester.AssertAllFieldsSetViaReflection(message);
}
- [TestMethod]
+ [Fact]
public void DoubleBuildError()
{
DynamicMessage.Builder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
builder.Build();
- try
- {
- builder.Build();
- Assert.Fail("Should have thrown exception.");
- }
- catch (InvalidOperationException)
- {
- // Success.
- }
- }
-
- [TestMethod]
+ Assert.Throws<InvalidOperationException>(() => builder.Build());
+ }
+
+ [Fact]
public void DynamicMessageSettersRejectNull()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
reflectionTester.AssertReflectionSettersRejectNull(builder);
}
- [TestMethod]
+ [Fact]
public void DynamicMessageExtensionAccessors()
{
// We don't need to extensively test DynamicMessage's handling of
@@ -100,14 +90,14 @@ namespace Google.ProtocolBuffers extensionsReflectionTester.AssertAllFieldsSetViaReflection(message);
}
- [TestMethod]
+ [Fact]
public void DynamicMessageExtensionSettersRejectNull()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllExtensions.Descriptor);
extensionsReflectionTester.AssertReflectionSettersRejectNull(builder);
}
- [TestMethod]
+ [Fact]
public void DynamicMessageRepeatedSetters()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
@@ -117,21 +107,21 @@ namespace Google.ProtocolBuffers reflectionTester.AssertRepeatedFieldsModifiedViaReflection(message);
}
- [TestMethod]
+ [Fact]
public void DynamicMessageRepeatedSettersRejectNull()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
reflectionTester.AssertReflectionRepeatedSettersRejectNull(builder);
}
- [TestMethod]
+ [Fact]
public void DynamicMessageDefaults()
{
reflectionTester.AssertClearViaReflection(DynamicMessage.GetDefaultInstance(TestAllTypes.Descriptor));
reflectionTester.AssertClearViaReflection(DynamicMessage.CreateBuilder(TestAllTypes.Descriptor).Build());
}
- [TestMethod]
+ [Fact]
public void DynamicMessageSerializedSize()
{
TestAllTypes message = TestUtil.GetAllSet();
@@ -140,10 +130,10 @@ namespace Google.ProtocolBuffers reflectionTester.SetAllFieldsViaReflection(dynamicBuilder);
IMessage dynamicMessage = dynamicBuilder.WeakBuild();
- Assert.AreEqual(message.SerializedSize, dynamicMessage.SerializedSize);
+ Assert.Equal(message.SerializedSize, dynamicMessage.SerializedSize);
}
- [TestMethod]
+ [Fact]
public void DynamicMessageSerialization()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
@@ -156,10 +146,10 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllFieldsSet(message2);
// In fact, the serialized forms should be exactly the same, byte-for-byte.
- Assert.AreEqual(TestUtil.GetAllSet().ToByteString(), rawBytes);
+ Assert.Equal(TestUtil.GetAllSet().ToByteString(), rawBytes);
}
- [TestMethod]
+ [Fact]
public void DynamicMessageParsing()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -172,7 +162,7 @@ namespace Google.ProtocolBuffers reflectionTester.AssertAllFieldsSetViaReflection(message2);
}
- [TestMethod]
+ [Fact]
public void DynamicMessagePackedSerialization()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestPackedTypes.Descriptor);
@@ -185,11 +175,11 @@ namespace Google.ProtocolBuffers TestUtil.AssertPackedFieldsSet(message2);
// In fact, the serialized forms should be exactly the same, byte-for-byte.
- Assert.AreEqual(TestUtil.GetPackedSet().ToByteString(), rawBytes);
+ Assert.Equal(TestUtil.GetPackedSet().ToByteString(), rawBytes);
}
- [TestMethod]
- public void testDynamicMessagePackedParsing()
+ [Fact]
+ public void DynamicMessagePackedParsing()
{
TestPackedTypes.Builder builder = TestPackedTypes.CreateBuilder();
TestUtil.SetPackedFields(builder);
@@ -201,7 +191,7 @@ namespace Google.ProtocolBuffers packedReflectionTester.AssertPackedFieldsSetViaReflection(message2);
}
- [TestMethod]
+ [Fact]
public void DynamicMessageCopy()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -212,7 +202,7 @@ namespace Google.ProtocolBuffers reflectionTester.AssertAllFieldsSetViaReflection(copy);
}
- [TestMethod]
+ [Fact]
public void ToBuilder()
{
DynamicMessage.Builder builder =
@@ -230,8 +220,8 @@ namespace Google.ProtocolBuffers reflectionTester.AssertAllFieldsSetViaReflection(derived);
IList<ulong> values = derived.UnknownFields.FieldDictionary[unknownFieldNum].VarintList;
- Assert.AreEqual(1, values.Count);
- Assert.AreEqual(unknownFieldVal, values[0]);
+ Assert.Equal(1, values.Count);
+ Assert.Equal(unknownFieldVal, values[0]);
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/ExtendableMessageTest.cs b/csharp/src/ProtocolBuffers.Test/ExtendableMessageTest.cs index 4e0bf8e6..f329270b 100644 --- a/csharp/src/ProtocolBuffers.Test/ExtendableMessageTest.cs +++ b/csharp/src/ProtocolBuffers.Test/ExtendableMessageTest.cs @@ -35,24 +35,22 @@ #endregion
using System;
-using System.Collections.Generic;
-using Google.ProtocolBuffers;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class ExtendableMessageTest
{
- [TestMethod, ExpectedException(typeof(ArgumentException))]
+ [Fact]
public void ExtensionWriterInvalidExtension()
{
- TestPackedExtensions.CreateBuilder()[Unittest.OptionalForeignMessageExtension.Descriptor] =
- ForeignMessage.DefaultInstance;
+ Assert.Throws<ArgumentException>(() =>
+ TestPackedExtensions.CreateBuilder()[Unittest.OptionalForeignMessageExtension.Descriptor] =
+ ForeignMessage.DefaultInstance);
}
- [TestMethod]
+ [Fact]
public void ExtensionWriterTest()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder()
@@ -128,75 +126,75 @@ namespace Google.ProtocolBuffers registry);
TestAllExtensions copy = copyBuilder.Build();
- TestUtil.AssertBytesEqual(msg.ToByteArray(), copy.ToByteArray());
+ Assert.Equal(msg.ToByteArray(), copy.ToByteArray());
- Assert.AreEqual(true, copy.GetExtension(Unittest.DefaultBoolExtension));
- Assert.AreEqual(ByteString.CopyFromUtf8("123"), copy.GetExtension(Unittest.DefaultBytesExtension));
- Assert.AreEqual("123", copy.GetExtension(Unittest.DefaultCordExtension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.DefaultDoubleExtension));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.DefaultFixed32Extension));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.DefaultFixed64Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.DefaultFloatExtension));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ, copy.GetExtension(Unittest.DefaultForeignEnumExtension));
- Assert.AreEqual(ImportEnum.IMPORT_BAZ, copy.GetExtension(Unittest.DefaultImportEnumExtension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.DefaultInt32Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.DefaultInt64Extension));
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO,
+ Assert.Equal(true, copy.GetExtension(Unittest.DefaultBoolExtension));
+ Assert.Equal(ByteString.CopyFromUtf8("123"), copy.GetExtension(Unittest.DefaultBytesExtension));
+ Assert.Equal("123", copy.GetExtension(Unittest.DefaultCordExtension));
+ Assert.Equal(123, copy.GetExtension(Unittest.DefaultDoubleExtension));
+ Assert.Equal(123u, copy.GetExtension(Unittest.DefaultFixed32Extension));
+ Assert.Equal(123u, copy.GetExtension(Unittest.DefaultFixed64Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.DefaultFloatExtension));
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ, copy.GetExtension(Unittest.DefaultForeignEnumExtension));
+ Assert.Equal(ImportEnum.IMPORT_BAZ, copy.GetExtension(Unittest.DefaultImportEnumExtension));
+ Assert.Equal(123, copy.GetExtension(Unittest.DefaultInt32Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.DefaultInt64Extension));
+ Assert.Equal(TestAllTypes.Types.NestedEnum.FOO,
copy.GetExtension(Unittest.DefaultNestedEnumExtension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.DefaultSfixed32Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.DefaultSfixed64Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.DefaultSint32Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.DefaultSint64Extension));
- Assert.AreEqual("123", copy.GetExtension(Unittest.DefaultStringExtension));
- Assert.AreEqual("123", copy.GetExtension(Unittest.DefaultStringPieceExtension));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.DefaultUint32Extension));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.DefaultUint64Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.DefaultSfixed32Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.DefaultSfixed64Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.DefaultSint32Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.DefaultSint64Extension));
+ Assert.Equal("123", copy.GetExtension(Unittest.DefaultStringExtension));
+ Assert.Equal("123", copy.GetExtension(Unittest.DefaultStringPieceExtension));
+ Assert.Equal(123u, copy.GetExtension(Unittest.DefaultUint32Extension));
+ Assert.Equal(123u, copy.GetExtension(Unittest.DefaultUint64Extension));
- Assert.AreEqual(true, copy.GetExtension(Unittest.OptionalBoolExtension));
- Assert.AreEqual(ByteString.CopyFromUtf8("123"), copy.GetExtension(Unittest.OptionalBytesExtension));
- Assert.AreEqual("123", copy.GetExtension(Unittest.OptionalCordExtension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.OptionalDoubleExtension));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.OptionalFixed32Extension));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.OptionalFixed64Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.OptionalFloatExtension));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ, copy.GetExtension(Unittest.OptionalForeignEnumExtension));
- Assert.AreEqual(ImportEnum.IMPORT_BAZ, copy.GetExtension(Unittest.OptionalImportEnumExtension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.OptionalInt32Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.OptionalInt64Extension));
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO,
+ Assert.Equal(true, copy.GetExtension(Unittest.OptionalBoolExtension));
+ Assert.Equal(ByteString.CopyFromUtf8("123"), copy.GetExtension(Unittest.OptionalBytesExtension));
+ Assert.Equal("123", copy.GetExtension(Unittest.OptionalCordExtension));
+ Assert.Equal(123, copy.GetExtension(Unittest.OptionalDoubleExtension));
+ Assert.Equal(123u, copy.GetExtension(Unittest.OptionalFixed32Extension));
+ Assert.Equal(123u, copy.GetExtension(Unittest.OptionalFixed64Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.OptionalFloatExtension));
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ, copy.GetExtension(Unittest.OptionalForeignEnumExtension));
+ Assert.Equal(ImportEnum.IMPORT_BAZ, copy.GetExtension(Unittest.OptionalImportEnumExtension));
+ Assert.Equal(123, copy.GetExtension(Unittest.OptionalInt32Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.OptionalInt64Extension));
+ Assert.Equal(TestAllTypes.Types.NestedEnum.FOO,
copy.GetExtension(Unittest.OptionalNestedEnumExtension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.OptionalSfixed32Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.OptionalSfixed64Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.OptionalSint32Extension));
- Assert.AreEqual(123, copy.GetExtension(Unittest.OptionalSint64Extension));
- Assert.AreEqual("123", copy.GetExtension(Unittest.OptionalStringExtension));
- Assert.AreEqual("123", copy.GetExtension(Unittest.OptionalStringPieceExtension));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.OptionalUint32Extension));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.OptionalUint64Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.OptionalSfixed32Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.OptionalSfixed64Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.OptionalSint32Extension));
+ Assert.Equal(123, copy.GetExtension(Unittest.OptionalSint64Extension));
+ Assert.Equal("123", copy.GetExtension(Unittest.OptionalStringExtension));
+ Assert.Equal("123", copy.GetExtension(Unittest.OptionalStringPieceExtension));
+ Assert.Equal(123u, copy.GetExtension(Unittest.OptionalUint32Extension));
+ Assert.Equal(123u, copy.GetExtension(Unittest.OptionalUint64Extension));
- Assert.AreEqual(true, copy.GetExtension(Unittest.RepeatedBoolExtension, 0));
- Assert.AreEqual(ByteString.CopyFromUtf8("123"),
+ Assert.Equal(true, copy.GetExtension(Unittest.RepeatedBoolExtension, 0));
+ Assert.Equal(ByteString.CopyFromUtf8("123"),
copy.GetExtension(Unittest.RepeatedBytesExtension, 0));
- Assert.AreEqual("123", copy.GetExtension(Unittest.RepeatedCordExtension, 0));
- Assert.AreEqual(123, copy.GetExtension(Unittest.RepeatedDoubleExtension, 0));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.RepeatedFixed32Extension, 0));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.RepeatedFixed64Extension, 0));
- Assert.AreEqual(123, copy.GetExtension(Unittest.RepeatedFloatExtension, 0));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ,
+ Assert.Equal("123", copy.GetExtension(Unittest.RepeatedCordExtension, 0));
+ Assert.Equal(123, copy.GetExtension(Unittest.RepeatedDoubleExtension, 0));
+ Assert.Equal(123u, copy.GetExtension(Unittest.RepeatedFixed32Extension, 0));
+ Assert.Equal(123u, copy.GetExtension(Unittest.RepeatedFixed64Extension, 0));
+ Assert.Equal(123, copy.GetExtension(Unittest.RepeatedFloatExtension, 0));
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ,
copy.GetExtension(Unittest.RepeatedForeignEnumExtension, 0));
- Assert.AreEqual(ImportEnum.IMPORT_BAZ, copy.GetExtension(Unittest.RepeatedImportEnumExtension, 0));
- Assert.AreEqual(123, copy.GetExtension(Unittest.RepeatedInt32Extension, 0));
- Assert.AreEqual(123, copy.GetExtension(Unittest.RepeatedInt64Extension, 0));
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO,
+ Assert.Equal(ImportEnum.IMPORT_BAZ, copy.GetExtension(Unittest.RepeatedImportEnumExtension, 0));
+ Assert.Equal(123, copy.GetExtension(Unittest.RepeatedInt32Extension, 0));
+ Assert.Equal(123, copy.GetExtension(Unittest.RepeatedInt64Extension, 0));
+ Assert.Equal(TestAllTypes.Types.NestedEnum.FOO,
copy.GetExtension(Unittest.RepeatedNestedEnumExtension, 0));
- Assert.AreEqual(123, copy.GetExtension(Unittest.RepeatedSfixed32Extension, 0));
- Assert.AreEqual(123, copy.GetExtension(Unittest.RepeatedSfixed64Extension, 0));
- Assert.AreEqual(123, copy.GetExtension(Unittest.RepeatedSint32Extension, 0));
- Assert.AreEqual(123, copy.GetExtension(Unittest.RepeatedSint64Extension, 0));
- Assert.AreEqual("123", copy.GetExtension(Unittest.RepeatedStringExtension, 0));
- Assert.AreEqual("123", copy.GetExtension(Unittest.RepeatedStringPieceExtension, 0));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.RepeatedUint32Extension, 0));
- Assert.AreEqual(123u, copy.GetExtension(Unittest.RepeatedUint64Extension, 0));
+ Assert.Equal(123, copy.GetExtension(Unittest.RepeatedSfixed32Extension, 0));
+ Assert.Equal(123, copy.GetExtension(Unittest.RepeatedSfixed64Extension, 0));
+ Assert.Equal(123, copy.GetExtension(Unittest.RepeatedSint32Extension, 0));
+ Assert.Equal(123, copy.GetExtension(Unittest.RepeatedSint64Extension, 0));
+ Assert.Equal("123", copy.GetExtension(Unittest.RepeatedStringExtension, 0));
+ Assert.Equal("123", copy.GetExtension(Unittest.RepeatedStringPieceExtension, 0));
+ Assert.Equal(123u, copy.GetExtension(Unittest.RepeatedUint32Extension, 0));
+ Assert.Equal(123u, copy.GetExtension(Unittest.RepeatedUint64Extension, 0));
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs b/csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs index 1dcb1c21..692bfd11 100644 --- a/csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs +++ b/csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs @@ -1,12 +1,10 @@ using System;
using System.Collections.Generic;
-using System.Text;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class GeneratedBuilderTest
{
class OneTimeEnumerator<T> : IEnumerable<T>
@@ -19,107 +17,86 @@ namespace Google.ProtocolBuffers }
public IEnumerator<T> GetEnumerator()
{
- Assert.IsFalse(_enumerated, "The collection {0} has already been enumerated", GetType());
+ Assert.False(_enumerated);
_enumerated = true;
yield return _item;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- { return GetEnumerator(); }
+ {
+ return GetEnumerator();
+ }
}
- [TestMethod]
+ [Fact]
public void DoesNotEnumerateTwiceForMessageList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- b.AddRangeRepeatedForeignMessage(
- new OneTimeEnumerator<ForeignMessage>(
- ForeignMessage.DefaultInstance));
+ b.AddRangeRepeatedForeignMessage(new OneTimeEnumerator<ForeignMessage>(ForeignMessage.DefaultInstance));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotEnumerateTwiceForPrimitiveList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedInt32(new OneTimeEnumerator<int>(1));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotEnumerateTwiceForStringList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedString(new OneTimeEnumerator<string>("test"));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotEnumerateTwiceForEnumList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedForeignEnum(new OneTimeEnumerator<ForeignEnum>(ForeignEnum.FOREIGN_BAR));
}
-
- private delegate void TestMethod();
-
- private static void AssertThrows<T>(TestMethod method) where T : Exception
- {
- try
- {
- method();
- }
- catch (Exception error)
- {
- if (error is T)
- return;
- throw;
- }
- Assert.Fail("Expected exception of type " + typeof(T));
- }
-
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToMessageListByAddRange()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- AssertThrows<ArgumentNullException>(
- () => b.AddRangeRepeatedForeignMessage(new ForeignMessage[] { null })
- );
+ Assert.Throws<ArgumentNullException>(() => b.AddRangeRepeatedForeignMessage(new ForeignMessage[] { null }));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToMessageListByAdd()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- AssertThrows<ArgumentNullException>(
- () => b.AddRepeatedForeignMessage((ForeignMessage)null)
- );
+ Assert.Throws<ArgumentNullException>(() => b.AddRepeatedForeignMessage((ForeignMessage)null));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToMessageListBySet()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRepeatedForeignMessage(ForeignMessage.DefaultInstance);
- AssertThrows<ArgumentNullException>(
- () => b.SetRepeatedForeignMessage(0, (ForeignMessage)null)
- );
+ Assert.Throws<ArgumentNullException>(() => b.SetRepeatedForeignMessage(0, (ForeignMessage)null));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToStringListByAddRange()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- AssertThrows<ArgumentNullException>(
- () => b.AddRangeRepeatedString(new String[] { null })
- );
+ Assert.Throws<ArgumentNullException>(() => b.AddRangeRepeatedString(new String[] { null }));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToStringListByAdd()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- AssertThrows<ArgumentNullException>(
- () => b.AddRepeatedString(null)
- );
+ Assert.Throws<ArgumentNullException>(() => b.AddRepeatedString(null));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToStringListBySet()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRepeatedString("one");
- AssertThrows<ArgumentNullException>(
- () => b.SetRepeatedString(0, null)
- );
+ Assert.Throws<ArgumentNullException>(() => b.SetRepeatedString(0, null));
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/GeneratedMessageTest.cs b/csharp/src/ProtocolBuffers.Test/GeneratedMessageTest.cs index 0e8b9807..a9052954 100644 --- a/csharp/src/ProtocolBuffers.Test/GeneratedMessageTest.cs +++ b/csharp/src/ProtocolBuffers.Test/GeneratedMessageTest.cs @@ -38,31 +38,29 @@ using System; using System.Collections.Generic;
using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class GeneratedMessageTest
{
- private ReflectionTester reflectionTester;
- private ReflectionTester extensionsReflectionTester;
+ private readonly ReflectionTester reflectionTester;
+ private readonly ReflectionTester extensionsReflectionTester;
- [TestInitialize]
- public void SetUp()
+ public GeneratedMessageTest()
{
reflectionTester = ReflectionTester.CreateTestAllTypesInstance();
extensionsReflectionTester = ReflectionTester.CreateTestAllExtensionsInstance();
}
- [TestMethod]
+ [Fact]
public void RepeatedAddPrimitiveBeforeBuild()
{
TestAllTypes message = new TestAllTypes.Builder {RepeatedInt32List = {1, 2, 3}}.Build();
TestUtil.AssertEqual(new int[] {1, 2, 3}, message.RepeatedInt32List);
}
- [TestMethod]
+ [Fact]
public void AddPrimitiveFailsAfterBuild()
{
TestAllTypes.Builder builder = new TestAllTypes.Builder();
@@ -70,18 +68,10 @@ namespace Google.ProtocolBuffers list.Add(1); // Fine
builder.Build();
- try
- {
- list.Add(2);
- Assert.Fail("List should be frozen");
- }
- catch (NotSupportedException)
- {
- // Expected
- }
+ Assert.Throws<NotSupportedException>(() => list.Add(2));
}
- [TestMethod]
+ [Fact]
public void RepeatedAddMessageBeforeBuild()
{
TestAllTypes message = new TestAllTypes.Builder
@@ -89,36 +79,28 @@ namespace Google.ProtocolBuffers RepeatedNestedMessageList =
{new TestAllTypes.Types.NestedMessage.Builder {Bb = 10}.Build()}
}.Build();
- Assert.AreEqual(1, message.RepeatedNestedMessageCount);
- Assert.AreEqual(10, message.RepeatedNestedMessageList[0].Bb);
+ Assert.Equal(1, message.RepeatedNestedMessageCount);
+ Assert.Equal(10, message.RepeatedNestedMessageList[0].Bb);
}
- [TestMethod]
+ [Fact]
public void AddMessageFailsAfterBuild()
{
TestAllTypes.Builder builder = new TestAllTypes.Builder();
IList<TestAllTypes.Types.NestedMessage> list = builder.RepeatedNestedMessageList;
builder.Build();
- try
- {
- list.Add(new TestAllTypes.Types.NestedMessage.Builder {Bb = 10}.Build());
- Assert.Fail("List should be frozen");
- }
- catch (NotSupportedException)
- {
- // Expected
- }
+ Assert.Throws<NotSupportedException>(() => list.Add(new TestAllTypes.Types.NestedMessage.Builder { Bb = 10 }.Build()));
}
- [TestMethod]
+ [Fact]
public void DefaultInstance()
{
- Assert.AreSame(TestAllTypes.DefaultInstance, TestAllTypes.DefaultInstance.DefaultInstanceForType);
- Assert.AreSame(TestAllTypes.DefaultInstance, TestAllTypes.CreateBuilder().DefaultInstanceForType);
+ Assert.Same(TestAllTypes.DefaultInstance, TestAllTypes.DefaultInstance.DefaultInstanceForType);
+ Assert.Same(TestAllTypes.DefaultInstance, TestAllTypes.CreateBuilder().DefaultInstanceForType);
}
- [TestMethod]
+ [Fact]
public void Accessors()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -127,25 +109,25 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllFieldsSet(message);
}
- [TestMethod]
+ [Fact]
public void SettersRejectNull()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
- TestUtil.AssertArgumentNullException(() => builder.SetOptionalString(null));
- TestUtil.AssertArgumentNullException(() => builder.SetOptionalBytes(null));
- TestUtil.AssertArgumentNullException(
+ Assert.Throws<ArgumentNullException>(() => builder.SetOptionalString(null));
+ Assert.Throws<ArgumentNullException>(() => builder.SetOptionalBytes(null));
+ Assert.Throws<ArgumentNullException>(
() => builder.SetOptionalNestedMessage((TestAllTypes.Types.NestedMessage) null));
- TestUtil.AssertArgumentNullException(
+ Assert.Throws<ArgumentNullException>(
() => builder.SetOptionalNestedMessage((TestAllTypes.Types.NestedMessage.Builder) null));
- TestUtil.AssertArgumentNullException(() => builder.AddRepeatedString(null));
- TestUtil.AssertArgumentNullException(() => builder.AddRepeatedBytes(null));
- TestUtil.AssertArgumentNullException(
+ Assert.Throws<ArgumentNullException>(() => builder.AddRepeatedString(null));
+ Assert.Throws<ArgumentNullException>(() => builder.AddRepeatedBytes(null));
+ Assert.Throws<ArgumentNullException>(
() => builder.AddRepeatedNestedMessage((TestAllTypes.Types.NestedMessage) null));
- TestUtil.AssertArgumentNullException(
+ Assert.Throws<ArgumentNullException>(
() => builder.AddRepeatedNestedMessage((TestAllTypes.Types.NestedMessage.Builder) null));
}
- [TestMethod]
+ [Fact]
public void RepeatedSetters()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -155,7 +137,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertRepeatedFieldsModified(message);
}
- [TestMethod]
+ [Fact]
public void RepeatedAppend()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -169,26 +151,26 @@ namespace Google.ProtocolBuffers TestAllTypes message = builder.Build();
TestUtil.AssertEqual(message.RepeatedInt32List, new int[] {1, 2, 3, 4});
TestUtil.AssertEqual(message.RepeatedForeignEnumList, new ForeignEnum[] {ForeignEnum.FOREIGN_BAZ});
- Assert.AreEqual(1, message.RepeatedForeignMessageCount);
- Assert.AreEqual(12, message.GetRepeatedForeignMessage(0).C);
+ Assert.Equal(1, message.RepeatedForeignMessageCount);
+ Assert.Equal(12, message.GetRepeatedForeignMessage(0).C);
}
- [TestMethod]
+ [Fact]
public void RepeatedAppendRejectsNull()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
ForeignMessage foreignMessage = ForeignMessage.CreateBuilder().SetC(12).Build();
- TestUtil.AssertArgumentNullException(
+ Assert.Throws<ArgumentNullException>(
() => builder.AddRangeRepeatedForeignMessage(new[] {foreignMessage, null}));
- TestUtil.AssertArgumentNullException(() => builder.AddRangeRepeatedForeignMessage(null));
- TestUtil.AssertArgumentNullException(() => builder.AddRangeRepeatedForeignEnum(null));
- TestUtil.AssertArgumentNullException(() => builder.AddRangeRepeatedString(new[] {"one", null}));
- TestUtil.AssertArgumentNullException(
+ Assert.Throws<ArgumentNullException>(() => builder.AddRangeRepeatedForeignMessage(null));
+ Assert.Throws<ArgumentNullException>(() => builder.AddRangeRepeatedForeignEnum(null));
+ Assert.Throws<ArgumentNullException>(() => builder.AddRangeRepeatedString(new[] {"one", null}));
+ Assert.Throws<ArgumentNullException>(
() => builder.AddRangeRepeatedBytes(new[] {TestUtil.ToBytes("one"), null}));
}
- [TestMethod]
+ [Fact]
public void SettingForeignMessageUsingBuilder()
{
TestAllTypes message = TestAllTypes.CreateBuilder()
@@ -199,10 +181,10 @@ namespace Google.ProtocolBuffers // Create expected version passing foreign message instance explicitly.
.SetOptionalForeignMessage(ForeignMessage.CreateBuilder().SetC(123).Build())
.Build();
- Assert.AreEqual(expectedMessage, message);
+ Assert.Equal(expectedMessage, message);
}
- [TestMethod]
+ [Fact]
public void SettingRepeatedForeignMessageUsingBuilder()
{
TestAllTypes message = TestAllTypes.CreateBuilder()
@@ -213,10 +195,10 @@ namespace Google.ProtocolBuffers // Create expected version passing foreign message instance explicitly.
.AddRepeatedForeignMessage(ForeignMessage.CreateBuilder().SetC(456).Build())
.Build();
- Assert.AreEqual(expectedMessage, message);
+ Assert.Equal(expectedMessage, message);
}
- [TestMethod]
+ [Fact]
public void SettingRepeatedValuesUsingRangeInCollectionInitializer()
{
int[] values = {1, 2, 3};
@@ -224,29 +206,29 @@ namespace Google.ProtocolBuffers {
RepeatedSint32List = {values}
}.Build();
- Assert.IsTrue(Lists.Equals(values, message.RepeatedSint32List));
+ Assert.True(Lists.Equals(values, message.RepeatedSint32List));
}
- [TestMethod]
+ [Fact]
public void SettingRepeatedValuesUsingIndividualValuesInCollectionInitializer()
{
TestAllTypes message = new TestAllTypes.Builder
{
RepeatedSint32List = {6, 7}
}.Build();
- Assert.IsTrue(Lists.Equals(new int[] {6, 7}, message.RepeatedSint32List));
+ Assert.True(Lists.Equals(new int[] {6, 7}, message.RepeatedSint32List));
}
- [TestMethod]
+ [Fact]
public void Defaults()
{
TestUtil.AssertClear(TestAllTypes.DefaultInstance);
TestUtil.AssertClear(TestAllTypes.CreateBuilder().Build());
- Assert.AreEqual("\u1234", TestExtremeDefaultValues.DefaultInstance.Utf8String);
+ Assert.Equal("\u1234", TestExtremeDefaultValues.DefaultInstance.Utf8String);
}
- [TestMethod]
+ [Fact]
public void ReflectionGetters()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -255,7 +237,7 @@ namespace Google.ProtocolBuffers reflectionTester.AssertAllFieldsSetViaReflection(message);
}
- [TestMethod]
+ [Fact]
public void ReflectionSetters()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -264,7 +246,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllFieldsSet(message);
}
- [TestMethod]
+ [Fact]
public void ReflectionClear()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -274,14 +256,14 @@ namespace Google.ProtocolBuffers TestUtil.AssertClear(message);
}
- [TestMethod]
+ [Fact]
public void ReflectionSettersRejectNull()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
reflectionTester.AssertReflectionSettersRejectNull(builder);
}
- [TestMethod]
+ [Fact]
public void ReflectionRepeatedSetters()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -291,14 +273,14 @@ namespace Google.ProtocolBuffers TestUtil.AssertRepeatedFieldsModified(message);
}
- [TestMethod]
+ [Fact]
public void TestReflectionRepeatedSettersRejectNull()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
reflectionTester.AssertReflectionRepeatedSettersRejectNull(builder);
}
- [TestMethod]
+ [Fact]
public void ReflectionDefaults()
{
TestUtil.TestInMultipleCultures(() =>
@@ -313,7 +295,7 @@ namespace Google.ProtocolBuffers // =================================================================
// Extensions.
- [TestMethod]
+ [Fact]
public void ExtensionAccessors()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
@@ -322,7 +304,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllExtensionsSet(message);
}
- [TestMethod]
+ [Fact]
public void ExtensionRepeatedSetters()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
@@ -332,14 +314,14 @@ namespace Google.ProtocolBuffers TestUtil.AssertRepeatedExtensionsModified(message);
}
- [TestMethod]
+ [Fact]
public void ExtensionDefaults()
{
TestUtil.AssertExtensionsClear(TestAllExtensions.DefaultInstance);
TestUtil.AssertExtensionsClear(TestAllExtensions.CreateBuilder().Build());
}
- [TestMethod]
+ [Fact]
public void ExtensionReflectionGetters()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
@@ -348,7 +330,7 @@ namespace Google.ProtocolBuffers extensionsReflectionTester.AssertAllFieldsSetViaReflection(message);
}
- [TestMethod]
+ [Fact]
public void ExtensionReflectionSetters()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
@@ -357,14 +339,14 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllExtensionsSet(message);
}
- [TestMethod]
+ [Fact]
public void ExtensionReflectionSettersRejectNull()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
extensionsReflectionTester.AssertReflectionSettersRejectNull(builder);
}
- [TestMethod]
+ [Fact]
public void ExtensionReflectionRepeatedSetters()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
@@ -374,14 +356,14 @@ namespace Google.ProtocolBuffers TestUtil.AssertRepeatedExtensionsModified(message);
}
- [TestMethod]
+ [Fact]
public void ExtensionReflectionRepeatedSettersRejectNull()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
extensionsReflectionTester.AssertReflectionRepeatedSettersRejectNull(builder);
}
- [TestMethod]
+ [Fact]
public void ExtensionReflectionDefaults()
{
TestUtil.TestInMultipleCultures(() =>
@@ -393,33 +375,33 @@ namespace Google.ProtocolBuffers });
}
- [TestMethod]
+ [Fact]
public void ClearExtension()
{
// ClearExtension() is not actually used in TestUtil, so try it manually.
- Assert.IsFalse(TestAllExtensions.CreateBuilder()
+ Assert.False(TestAllExtensions.CreateBuilder()
.SetExtension(Unittest.OptionalInt32Extension, 1)
.ClearExtension(Unittest.OptionalInt32Extension)
.HasExtension(Unittest.OptionalInt32Extension));
- Assert.AreEqual(0, TestAllExtensions.CreateBuilder()
+ Assert.Equal(0, TestAllExtensions.CreateBuilder()
.AddExtension(Unittest.RepeatedInt32Extension, 1)
.ClearExtension(Unittest.RepeatedInt32Extension)
.GetExtensionCount(Unittest.RepeatedInt32Extension));
}
- [TestMethod]
+ [Fact]
public void ExtensionMergeFrom()
{
TestAllExtensions original = TestAllExtensions.CreateBuilder()
.SetExtension(Unittest.OptionalInt32Extension, 1).Build();
TestAllExtensions merged =
TestAllExtensions.CreateBuilder().MergeFrom(original).Build();
- Assert.IsTrue((merged.HasExtension(Unittest.OptionalInt32Extension)));
- Assert.AreEqual(1, (int) merged.GetExtension(Unittest.OptionalInt32Extension));
+ Assert.True((merged.HasExtension(Unittest.OptionalInt32Extension)));
+ Assert.Equal(1, (int) merged.GetExtension(Unittest.OptionalInt32Extension));
}
/* Removed multiple files option for the moment
- [TestMethod]
+ [Fact]
public void MultipleFilesOption() {
// We mostly just want to check that things compile.
MessageWithNoOuter message = MessageWithNoOuter.CreateBuilder()
@@ -428,63 +410,63 @@ namespace Google.ProtocolBuffers .SetNestedEnum(MessageWithNoOuter.Types.NestedEnum.BAZ)
.SetForeignEnum(EnumWithNoOuter.BAR)
.Build();
- Assert.AreEqual(message, MessageWithNoOuter.ParseFrom(message.ToByteString()));
+ Assert.Equal(message, MessageWithNoOuter.ParseFrom(message.ToByteString()));
- Assert.AreEqual(MultiFileProto.DescriptorProtoFile, MessageWithNoOuter.DescriptorProtoFile.File);
+ Assert.Equal(MultiFileProto.DescriptorProtoFile, MessageWithNoOuter.DescriptorProtoFile.File);
FieldDescriptor field = MessageWithNoOuter.DescriptorProtoFile.FindDescriptor<FieldDescriptor>("foreign_enum");
- Assert.AreEqual(MultiFileProto.DescriptorProtoFile.FindTypeByName<EnumDescriptor>("EnumWithNoOuter")
+ Assert.Equal(MultiFileProto.DescriptorProtoFile.FindTypeByName<EnumDescriptor>("EnumWithNoOuter")
.FindValueByNumber((int)EnumWithNoOuter.BAR), message[field]);
- Assert.AreEqual(MultiFileProto.DescriptorProtoFile, ServiceWithNoOuter.DescriptorProtoFile.File);
+ Assert.Equal(MultiFileProto.DescriptorProtoFile, ServiceWithNoOuter.DescriptorProtoFile.File);
- Assert.IsFalse(TestAllExtensions.DefaultInstance.HasExtension(MultiFileProto.ExtensionWithOuter));
+ Assert.False(TestAllExtensions.DefaultInstance.HasExtension(MultiFileProto.ExtensionWithOuter));
}*/
- [TestMethod]
+ [Fact]
public void OptionalFieldWithRequiredSubfieldsOptimizedForSize()
{
TestOptionalOptimizedForSize message = TestOptionalOptimizedForSize.DefaultInstance;
- Assert.IsTrue(message.IsInitialized);
+ Assert.True(message.IsInitialized);
message = TestOptionalOptimizedForSize.CreateBuilder().SetO(
TestRequiredOptimizedForSize.CreateBuilder().BuildPartial()
).BuildPartial();
- Assert.IsFalse(message.IsInitialized);
+ Assert.False(message.IsInitialized);
message = TestOptionalOptimizedForSize.CreateBuilder().SetO(
TestRequiredOptimizedForSize.CreateBuilder().SetX(5).BuildPartial()
).BuildPartial();
- Assert.IsTrue(message.IsInitialized);
+ Assert.True(message.IsInitialized);
}
- [TestMethod]
+ [Fact]
public void OptimizedForSizeMergeUsesAllFieldsFromTarget()
{
TestOptimizedForSize withFieldSet = new TestOptimizedForSize.Builder {I = 10}.Build();
TestOptimizedForSize.Builder builder = new TestOptimizedForSize.Builder();
builder.MergeFrom(withFieldSet);
TestOptimizedForSize built = builder.Build();
- Assert.AreEqual(10, built.I);
+ Assert.Equal(10, built.I);
}
- [TestMethod]
+ [Fact]
public void UninitializedExtensionInOptimizedForSizeMakesMessageUninitialized()
{
TestOptimizedForSize.Builder builder = new TestOptimizedForSize.Builder();
builder.SetExtension(TestOptimizedForSize.TestExtension2,
new TestRequiredOptimizedForSize.Builder().BuildPartial());
- Assert.IsFalse(builder.IsInitialized);
- Assert.IsFalse(builder.BuildPartial().IsInitialized);
+ Assert.False(builder.IsInitialized);
+ Assert.False(builder.BuildPartial().IsInitialized);
builder = new TestOptimizedForSize.Builder();
builder.SetExtension(TestOptimizedForSize.TestExtension2,
new TestRequiredOptimizedForSize.Builder {X = 10}.BuildPartial());
- Assert.IsTrue(builder.IsInitialized);
- Assert.IsTrue(builder.BuildPartial().IsInitialized);
+ Assert.True(builder.IsInitialized);
+ Assert.True(builder.BuildPartial().IsInitialized);
}
- [TestMethod]
+ [Fact]
public void ToBuilder()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -493,40 +475,40 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllFieldsSet(message.ToBuilder().Build());
}
- [TestMethod]
+ [Fact]
public void FieldConstantValues()
{
- Assert.AreEqual(TestAllTypes.Types.NestedMessage.BbFieldNumber, 1);
- Assert.AreEqual(TestAllTypes.OptionalInt32FieldNumber, 1);
- Assert.AreEqual(TestAllTypes.OptionalGroupFieldNumber, 16);
- Assert.AreEqual(TestAllTypes.OptionalNestedMessageFieldNumber, 18);
- Assert.AreEqual(TestAllTypes.OptionalNestedEnumFieldNumber, 21);
- Assert.AreEqual(TestAllTypes.RepeatedInt32FieldNumber, 31);
- Assert.AreEqual(TestAllTypes.RepeatedGroupFieldNumber, 46);
- Assert.AreEqual(TestAllTypes.RepeatedNestedMessageFieldNumber, 48);
- Assert.AreEqual(TestAllTypes.RepeatedNestedEnumFieldNumber, 51);
+ Assert.Equal(TestAllTypes.Types.NestedMessage.BbFieldNumber, 1);
+ Assert.Equal(TestAllTypes.OptionalInt32FieldNumber, 1);
+ Assert.Equal(TestAllTypes.OptionalGroupFieldNumber, 16);
+ Assert.Equal(TestAllTypes.OptionalNestedMessageFieldNumber, 18);
+ Assert.Equal(TestAllTypes.OptionalNestedEnumFieldNumber, 21);
+ Assert.Equal(TestAllTypes.RepeatedInt32FieldNumber, 31);
+ Assert.Equal(TestAllTypes.RepeatedGroupFieldNumber, 46);
+ Assert.Equal(TestAllTypes.RepeatedNestedMessageFieldNumber, 48);
+ Assert.Equal(TestAllTypes.RepeatedNestedEnumFieldNumber, 51);
}
- [TestMethod]
+ [Fact]
public void ExtensionConstantValues()
{
- Assert.AreEqual(TestRequired.SingleFieldNumber, 1000);
- Assert.AreEqual(TestRequired.MultiFieldNumber, 1001);
- Assert.AreEqual(Unittest.OptionalInt32ExtensionFieldNumber, 1);
- Assert.AreEqual(Unittest.OptionalGroupExtensionFieldNumber, 16);
- Assert.AreEqual(Unittest.OptionalNestedMessageExtensionFieldNumber, 18);
- Assert.AreEqual(Unittest.OptionalNestedEnumExtensionFieldNumber, 21);
- Assert.AreEqual(Unittest.RepeatedInt32ExtensionFieldNumber, 31);
- Assert.AreEqual(Unittest.RepeatedGroupExtensionFieldNumber, 46);
- Assert.AreEqual(Unittest.RepeatedNestedMessageExtensionFieldNumber, 48);
- Assert.AreEqual(Unittest.RepeatedNestedEnumExtensionFieldNumber, 51);
+ Assert.Equal(TestRequired.SingleFieldNumber, 1000);
+ Assert.Equal(TestRequired.MultiFieldNumber, 1001);
+ Assert.Equal(Unittest.OptionalInt32ExtensionFieldNumber, 1);
+ Assert.Equal(Unittest.OptionalGroupExtensionFieldNumber, 16);
+ Assert.Equal(Unittest.OptionalNestedMessageExtensionFieldNumber, 18);
+ Assert.Equal(Unittest.OptionalNestedEnumExtensionFieldNumber, 21);
+ Assert.Equal(Unittest.RepeatedInt32ExtensionFieldNumber, 31);
+ Assert.Equal(Unittest.RepeatedGroupExtensionFieldNumber, 46);
+ Assert.Equal(Unittest.RepeatedNestedMessageExtensionFieldNumber, 48);
+ Assert.Equal(Unittest.RepeatedNestedEnumExtensionFieldNumber, 51);
}
- [TestMethod]
+ [Fact]
public void EmptyPackedValue()
{
TestPackedTypes empty = new TestPackedTypes.Builder().Build();
- Assert.AreEqual(0, empty.SerializedSize);
+ Assert.Equal(0, empty.SerializedSize);
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/IssuesTest.cs b/csharp/src/ProtocolBuffers.Test/IssuesTest.cs index a80021c5..afd93f86 100644 --- a/csharp/src/ProtocolBuffers.Test/IssuesTest.cs +++ b/csharp/src/ProtocolBuffers.Test/IssuesTest.cs @@ -35,13 +35,9 @@ #endregion
-using System;
-using System.Collections.Generic;
-using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.Descriptors;
-using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitTest.Issues.TestProtos;
+using Xunit;
namespace Google.ProtocolBuffers
@@ -49,17 +45,16 @@ namespace Google.ProtocolBuffers /// <summary>
/// Tests for issues which aren't easily compartmentalized into other unit tests.
/// </summary>
- [TestClass]
public class IssuesTest
{
// Issue 45
- [TestMethod]
+ [Fact]
public void FieldCalledItem()
{
ItemField message = new ItemField.Builder { Item = 3 }.Build();
FieldDescriptor field = ItemField.Descriptor.FindFieldByName("item");
- Assert.IsNotNull(field);
- Assert.AreEqual(3, (int)message[field]);
+ Assert.NotNull(field);
+ Assert.Equal(3, (int)message[field]);
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs b/csharp/src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs index 78f059f7..7304861a 100644 --- a/csharp/src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs +++ b/csharp/src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs @@ -37,28 +37,27 @@ using System.Collections.Generic;
using System.IO;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class MessageStreamIteratorTest
{
- [TestMethod]
+ [Fact]
public void ThreeMessagesInMemory()
{
MemoryStream stream = new MemoryStream(MessageStreamWriterTest.ThreeMessageData);
IEnumerable<NestedMessage> iterator = MessageStreamIterator<NestedMessage>.FromStreamProvider(() => stream);
List<NestedMessage> messages = new List<NestedMessage>(iterator);
- Assert.AreEqual(3, messages.Count);
- Assert.AreEqual(5, messages[0].Bb);
- Assert.AreEqual(1500, messages[1].Bb);
- Assert.IsFalse(messages[2].HasBb);
+ Assert.Equal(3, messages.Count);
+ Assert.Equal(5, messages[0].Bb);
+ Assert.Equal(1500, messages[1].Bb);
+ Assert.False(messages[2].HasBb);
}
- [TestMethod]
+ [Fact]
public void ManyMessagesShouldNotTriggerSizeAlert()
{
int messageSize = TestUtil.GetAllSet().SerializedSize;
@@ -84,7 +83,7 @@ namespace Google.ProtocolBuffers count++;
TestUtil.AssertAllFieldsSet(message);
}
- Assert.AreEqual(correctCount, count);
+ Assert.Equal(correctCount, count);
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/MessageStreamWriterTest.cs b/csharp/src/ProtocolBuffers.Test/MessageStreamWriterTest.cs index 53772523..3bcc5ff6 100644 --- a/csharp/src/ProtocolBuffers.Test/MessageStreamWriterTest.cs +++ b/csharp/src/ProtocolBuffers.Test/MessageStreamWriterTest.cs @@ -35,12 +35,11 @@ #endregion
using System.IO;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class MessageStreamWriterTest
{
internal static readonly byte[] ThreeMessageData = new byte[]
@@ -55,7 +54,7 @@ namespace Google.ProtocolBuffers (1 << 3) | 2, 0, // Field 1, no data (third message)
};
- [TestMethod]
+ [Fact]
public void ThreeMessages()
{
NestedMessage message1 = new NestedMessage.Builder {Bb = 5}.Build();
diff --git a/csharp/src/ProtocolBuffers.Test/MessageTest.cs b/csharp/src/ProtocolBuffers.Test/MessageTest.cs index 8bb0fac7..8c8e6445 100644 --- a/csharp/src/ProtocolBuffers.Test/MessageTest.cs +++ b/csharp/src/ProtocolBuffers.Test/MessageTest.cs @@ -37,7 +37,7 @@ using System.IO;
using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
@@ -45,7 +45,6 @@ namespace Google.ProtocolBuffers /// Miscellaneous tests for message operations that apply to both
/// generated and dynamic messages.
/// </summary>
- [TestClass]
public class MessageTest
{
// =================================================================
@@ -77,12 +76,12 @@ namespace Google.ProtocolBuffers "repeated_string: \"qux\"\n" +
"repeated_string: \"bar\"\n";
- [TestMethod]
+ [Fact]
public void MergeFrom()
{
TestAllTypes result = TestAllTypes.CreateBuilder(MergeDest).MergeFrom(MergeSource).Build();
- Assert.AreEqual(MergeResultText, result.ToString());
+ Assert.Equal(MergeResultText, result.ToString());
}
/// <summary>
@@ -90,20 +89,20 @@ namespace Google.ProtocolBuffers /// As long as they have the same descriptor, this should work, but it is an
/// entirely different code path.
/// </summary>
- [TestMethod]
+ [Fact]
public void MergeFromDynamic()
{
TestAllTypes result = (TestAllTypes) TestAllTypes.CreateBuilder(MergeDest)
.MergeFrom(DynamicMessage.CreateBuilder(MergeSource).Build())
.Build();
- Assert.AreEqual(MergeResultText, result.ToString());
+ Assert.Equal(MergeResultText, result.ToString());
}
/// <summary>
/// Test merging two DynamicMessages.
/// </summary>
- [TestMethod]
+ [Fact]
public void DynamicMergeFrom()
{
DynamicMessage result = (DynamicMessage) DynamicMessage.CreateBuilder(MergeDest)
@@ -112,7 +111,7 @@ namespace Google.ProtocolBuffers DynamicMessage.CreateBuilder(MergeSource).Build())
.Build();
- Assert.AreEqual(MergeResultText, result.ToString());
+ Assert.Equal(MergeResultText, result.ToString());
}
// =================================================================
@@ -127,157 +126,143 @@ namespace Google.ProtocolBuffers C = 3
}.Build();
- [TestMethod]
+ [Fact]
public void Initialization()
{
TestRequired.Builder builder = TestRequired.CreateBuilder();
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder.A = 1;
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder.B = 1;
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder.C = 1;
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
}
- [TestMethod]
+ [Fact]
public void UninitializedBuilderToString()
{
TestRequired.Builder builder = TestRequired.CreateBuilder().SetA(1);
- Assert.AreEqual("a: 1\n", builder.ToString());
+ Assert.Equal("a: 1\n", builder.ToString());
}
- [TestMethod]
+ [Fact]
public void RequiredForeign()
{
TestRequiredForeign.Builder builder = TestRequiredForeign.CreateBuilder();
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
builder.SetOptionalMessage(TestRequiredUninitialized);
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder.SetOptionalMessage(TestRequiredInitialized);
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
builder.AddRepeatedMessage(TestRequiredUninitialized);
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder.SetRepeatedMessage(0, TestRequiredInitialized);
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
}
- [TestMethod]
+ [Fact]
public void RequiredExtension()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
builder.SetExtension(TestRequired.Single, TestRequiredUninitialized);
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder.SetExtension(TestRequired.Single, TestRequiredInitialized);
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
builder.AddExtension(TestRequired.Multi, TestRequiredUninitialized);
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder.SetExtension(TestRequired.Multi, 0, TestRequiredInitialized);
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
}
- [TestMethod]
+ [Fact]
public void RequiredDynamic()
{
MessageDescriptor descriptor = TestRequired.Descriptor;
DynamicMessage.Builder builder = DynamicMessage.CreateBuilder(descriptor);
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder[descriptor.FindDescriptor<FieldDescriptor>("a")] = 1;
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder[descriptor.FindDescriptor<FieldDescriptor>("b")] = 1;
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder[descriptor.FindDescriptor<FieldDescriptor>("c")] = 1;
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
}
- [TestMethod]
+ [Fact]
public void RequiredDynamicForeign()
{
MessageDescriptor descriptor = TestRequiredForeign.Descriptor;
DynamicMessage.Builder builder = DynamicMessage.CreateBuilder(descriptor);
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
builder[descriptor.FindDescriptor<FieldDescriptor>("optional_message")] = TestRequiredUninitialized;
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder[descriptor.FindDescriptor<FieldDescriptor>("optional_message")] = TestRequiredInitialized;
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
builder.AddRepeatedField(descriptor.FindDescriptor<FieldDescriptor>("repeated_message"),
TestRequiredUninitialized);
- Assert.IsFalse(builder.IsInitialized);
+ Assert.False(builder.IsInitialized);
builder.SetRepeatedField(descriptor.FindDescriptor<FieldDescriptor>("repeated_message"), 0,
TestRequiredInitialized);
- Assert.IsTrue(builder.IsInitialized);
+ Assert.True(builder.IsInitialized);
}
- [TestMethod]
+ [Fact]
public void UninitializedException()
{
- try
- {
- TestRequired.CreateBuilder().Build();
- Assert.Fail("Should have thrown an exception.");
- }
- catch (UninitializedMessageException e)
- {
- Assert.AreEqual("Message missing required fields: a, b, c", e.Message);
- }
+ var e = Assert.Throws<UninitializedMessageException>(() => TestRequired.CreateBuilder().Build());
+ Assert.Equal("Message missing required fields: a, b, c", e.Message);
}
- [TestMethod]
+ [Fact]
public void BuildPartial()
{
// We're mostly testing that no exception is thrown.
TestRequired message = TestRequired.CreateBuilder().BuildPartial();
- Assert.IsFalse(message.IsInitialized);
+ Assert.False(message.IsInitialized);
}
- [TestMethod]
+ [Fact]
public void NestedUninitializedException()
{
- try
- {
- TestRequiredForeign.CreateBuilder()
+ var e = Assert.Throws<UninitializedMessageException>(() => TestRequiredForeign.CreateBuilder()
.SetOptionalMessage(TestRequiredUninitialized)
.AddRepeatedMessage(TestRequiredUninitialized)
.AddRepeatedMessage(TestRequiredUninitialized)
- .Build();
- Assert.Fail("Should have thrown an exception.");
- }
- catch (UninitializedMessageException e)
- {
- Assert.AreEqual(
- "Message missing required fields: " +
- "optional_message.a, " +
- "optional_message.b, " +
- "optional_message.c, " +
- "repeated_message[0].a, " +
- "repeated_message[0].b, " +
- "repeated_message[0].c, " +
- "repeated_message[1].a, " +
- "repeated_message[1].b, " +
- "repeated_message[1].c",
- e.Message);
- }
+ .Build());
+ Assert.Equal(
+ "Message missing required fields: " +
+ "optional_message.a, " +
+ "optional_message.b, " +
+ "optional_message.c, " +
+ "repeated_message[0].a, " +
+ "repeated_message[0].b, " +
+ "repeated_message[0].c, " +
+ "repeated_message[1].a, " +
+ "repeated_message[1].b, " +
+ "repeated_message[1].c",
+ e.Message);
}
- [TestMethod]
+ [Fact]
public void BuildNestedPartial()
{
// We're mostly testing that no exception is thrown.
@@ -287,24 +272,17 @@ namespace Google.ProtocolBuffers .AddRepeatedMessage(TestRequiredUninitialized)
.AddRepeatedMessage(TestRequiredUninitialized)
.BuildPartial();
- Assert.IsFalse(message.IsInitialized);
+ Assert.False(message.IsInitialized);
}
- [TestMethod]
- public void ParseUnititialized()
+ [Fact]
+ public void ParseUninitialized()
{
- try
- {
- TestRequired.ParseFrom(ByteString.Empty);
- Assert.Fail("Should have thrown an exception.");
- }
- catch (InvalidProtocolBufferException e)
- {
- Assert.AreEqual("Message missing required fields: a, b, c", e.Message);
- }
+ var e = Assert.Throws<InvalidProtocolBufferException>(() => TestRequired.ParseFrom(ByteString.Empty));
+ Assert.Equal("Message missing required fields: a, b, c", e.Message);
}
- [TestMethod]
+ [Fact]
public void ParseNestedUnititialized()
{
ByteString data =
@@ -314,66 +292,45 @@ namespace Google.ProtocolBuffers .AddRepeatedMessage(TestRequiredUninitialized)
.BuildPartial().ToByteString();
- try
- {
- TestRequiredForeign.ParseFrom(data);
- Assert.Fail("Should have thrown an exception.");
- }
- catch (InvalidProtocolBufferException e)
- {
- Assert.AreEqual(
- "Message missing required fields: " +
- "optional_message.a, " +
- "optional_message.b, " +
- "optional_message.c, " +
- "repeated_message[0].a, " +
- "repeated_message[0].b, " +
- "repeated_message[0].c, " +
- "repeated_message[1].a, " +
- "repeated_message[1].b, " +
- "repeated_message[1].c",
- e.Message);
- }
+ var e = Assert.Throws<InvalidProtocolBufferException>(() => TestRequiredForeign.ParseFrom(data));
+ Assert.Equal(
+ "Message missing required fields: " +
+ "optional_message.a, " +
+ "optional_message.b, " +
+ "optional_message.c, " +
+ "repeated_message[0].a, " +
+ "repeated_message[0].b, " +
+ "repeated_message[0].c, " +
+ "repeated_message[1].a, " +
+ "repeated_message[1].b, " +
+ "repeated_message[1].c",
+ e.Message);
}
- [TestMethod]
+ [Fact]
public void DynamicUninitializedException()
{
- try
- {
- DynamicMessage.CreateBuilder(TestRequired.Descriptor).Build();
- Assert.Fail("Should have thrown an exception.");
- }
- catch (UninitializedMessageException e)
- {
- Assert.AreEqual("Message missing required fields: a, b, c", e.Message);
- }
+ var e = Assert.Throws<UninitializedMessageException>(() => DynamicMessage.CreateBuilder(TestRequired.Descriptor).Build());
+ Assert.Equal("Message missing required fields: a, b, c", e.Message);
}
- [TestMethod]
+ [Fact]
public void DynamicBuildPartial()
{
// We're mostly testing that no exception is thrown.
DynamicMessage message = DynamicMessage.CreateBuilder(TestRequired.Descriptor).BuildPartial();
- Assert.IsFalse(message.Initialized);
+ Assert.False(message.Initialized);
}
- [TestMethod]
+ [Fact]
public void DynamicParseUnititialized()
{
- try
- {
- MessageDescriptor descriptor = TestRequired.Descriptor;
- DynamicMessage.ParseFrom(descriptor, ByteString.Empty);
- Assert.Fail("Should have thrown an exception.");
- }
- catch (InvalidProtocolBufferException e)
- {
- Assert.AreEqual("Message missing required fields: a, b, c", e.Message);
- }
+ MessageDescriptor descriptor = TestRequired.Descriptor;
+ var e = Assert.Throws<InvalidProtocolBufferException>(() => DynamicMessage.ParseFrom(descriptor, ByteString.Empty));
+ Assert.Equal("Message missing required fields: a, b, c", e.Message);
}
- [TestMethod]
+ [Fact]
public void PackedTypesWrittenDirectlyToStream()
{
TestPackedTypes message = new TestPackedTypes.Builder {PackedInt32List = {0, 1, 2}}.Build();
@@ -381,7 +338,7 @@ namespace Google.ProtocolBuffers message.WriteTo(stream);
stream.Position = 0;
TestPackedTypes readMessage = TestPackedTypes.ParseFrom(stream);
- Assert.AreEqual(message, readMessage);
+ Assert.Equal(message, readMessage);
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/MessageUtilTest.cs b/csharp/src/ProtocolBuffers.Test/MessageUtilTest.cs index 4c33dbbd..186d9399 100644 --- a/csharp/src/ProtocolBuffers.Test/MessageUtilTest.cs +++ b/csharp/src/ProtocolBuffers.Test/MessageUtilTest.cs @@ -36,52 +36,47 @@ using System;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class MessageUtilTest
{
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
+ [Fact]
public void NullTypeName()
{
- MessageUtil.GetDefaultMessage((string) null);
+ Assert.Throws<ArgumentNullException>(() => MessageUtil.GetDefaultMessage((string) null));
}
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
+ [Fact]
public void InvalidTypeName()
{
- MessageUtil.GetDefaultMessage("invalidtypename");
+ Assert.Throws<ArgumentException>(() => MessageUtil.GetDefaultMessage("invalidtypename"));
}
- [TestMethod]
+ [Fact]
public void ValidTypeName()
{
- Assert.AreSame(TestAllTypes.DefaultInstance,
+ Assert.Same(TestAllTypes.DefaultInstance,
MessageUtil.GetDefaultMessage(typeof(TestAllTypes).AssemblyQualifiedName));
}
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
+ [Fact]
public void NullType()
{
- MessageUtil.GetDefaultMessage((Type) null);
+ Assert.Throws<ArgumentNullException>(() => MessageUtil.GetDefaultMessage((Type)null));
}
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
+ [Fact]
public void NonMessageType()
{
- MessageUtil.GetDefaultMessage(typeof(string));
+ Assert.Throws<ArgumentException>(() => MessageUtil.GetDefaultMessage(typeof(string)));
}
- [TestMethod]
+ [Fact]
public void ValidType()
{
- Assert.AreSame(TestAllTypes.DefaultInstance, MessageUtil.GetDefaultMessage(typeof(TestAllTypes)));
+ Assert.Same(TestAllTypes.DefaultInstance, MessageUtil.GetDefaultMessage(typeof(TestAllTypes)));
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/NameHelpersTest.cs b/csharp/src/ProtocolBuffers.Test/NameHelpersTest.cs index 50ab373d..034bbf1c 100644 --- a/csharp/src/ProtocolBuffers.Test/NameHelpersTest.cs +++ b/csharp/src/ProtocolBuffers.Test/NameHelpersTest.cs @@ -34,49 +34,48 @@ #endregion
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class NameHelpersTest
{
- [TestMethod]
+ [Fact]
public void UnderscoresToPascalCase()
{
- Assert.AreEqual("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_bar"));
- Assert.AreEqual("FooBar", NameHelpers.UnderscoresToPascalCase("foo_bar"));
- Assert.AreEqual("Foo0Bar", NameHelpers.UnderscoresToPascalCase("Foo0bar"));
- Assert.AreEqual("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_+_Bar"));
+ Assert.Equal("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_bar"));
+ Assert.Equal("FooBar", NameHelpers.UnderscoresToPascalCase("foo_bar"));
+ Assert.Equal("Foo0Bar", NameHelpers.UnderscoresToPascalCase("Foo0bar"));
+ Assert.Equal("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_+_Bar"));
- Assert.AreEqual("Bar", NameHelpers.UnderscoresToPascalCase("__+bar"));
- Assert.AreEqual("Bar", NameHelpers.UnderscoresToPascalCase("bar_"));
- Assert.AreEqual("_0Bar", NameHelpers.UnderscoresToPascalCase("_0bar"));
- Assert.AreEqual("_1Bar", NameHelpers.UnderscoresToPascalCase("_1_bar"));
+ Assert.Equal("Bar", NameHelpers.UnderscoresToPascalCase("__+bar"));
+ Assert.Equal("Bar", NameHelpers.UnderscoresToPascalCase("bar_"));
+ Assert.Equal("_0Bar", NameHelpers.UnderscoresToPascalCase("_0bar"));
+ Assert.Equal("_1Bar", NameHelpers.UnderscoresToPascalCase("_1_bar"));
}
- [TestMethod]
+ [Fact]
public void UnderscoresToCamelCase()
{
- Assert.AreEqual("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_bar"));
- Assert.AreEqual("fooBar", NameHelpers.UnderscoresToCamelCase("foo_bar"));
- Assert.AreEqual("foo0Bar", NameHelpers.UnderscoresToCamelCase("Foo0bar"));
- Assert.AreEqual("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_+_Bar"));
+ Assert.Equal("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_bar"));
+ Assert.Equal("fooBar", NameHelpers.UnderscoresToCamelCase("foo_bar"));
+ Assert.Equal("foo0Bar", NameHelpers.UnderscoresToCamelCase("Foo0bar"));
+ Assert.Equal("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_+_Bar"));
- Assert.AreEqual("bar", NameHelpers.UnderscoresToCamelCase("__+bar"));
- Assert.AreEqual("bar", NameHelpers.UnderscoresToCamelCase("bar_"));
- Assert.AreEqual("_0Bar", NameHelpers.UnderscoresToCamelCase("_0bar"));
- Assert.AreEqual("_1Bar", NameHelpers.UnderscoresToCamelCase("_1_bar"));
+ Assert.Equal("bar", NameHelpers.UnderscoresToCamelCase("__+bar"));
+ Assert.Equal("bar", NameHelpers.UnderscoresToCamelCase("bar_"));
+ Assert.Equal("_0Bar", NameHelpers.UnderscoresToCamelCase("_0bar"));
+ Assert.Equal("_1Bar", NameHelpers.UnderscoresToCamelCase("_1_bar"));
}
- [TestMethod]
+ [Fact]
public void StripSuffix()
{
string text = "FooBar";
- Assert.IsFalse(NameHelpers.StripSuffix(ref text, "Foo"));
- Assert.AreEqual("FooBar", text);
- Assert.IsTrue(NameHelpers.StripSuffix(ref text, "Bar"));
- Assert.AreEqual("Foo", text);
+ Assert.False(NameHelpers.StripSuffix(ref text, "Foo"));
+ Assert.Equal("FooBar", text);
+ Assert.True(NameHelpers.StripSuffix(ref text, "Bar"));
+ Assert.Equal("Foo", text);
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj b/csharp/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj index 8d900266..50c0b63e 100644 --- a/csharp/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj +++ b/csharp/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj @@ -1,9 +1,8 @@ <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
+ <Import Project="..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
<PropertyGroup>
- <EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
- <EnvironmentTemplate>NET35</EnvironmentTemplate>
- <EnvironmentProjectType>TEST</EnvironmentProjectType>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
@@ -13,12 +12,14 @@ <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Google.ProtocolBuffers</RootNamespace>
<AssemblyName>Google.ProtocolBuffers.Test</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
<OldToolsVersion>3.5</OldToolsVersion>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <NuGetPackageImportStamp>d37384c8</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -32,6 +33,7 @@ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -44,32 +46,23 @@ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup Condition=" '$(EnvironmentFlavor)' == 'CLIENTPROFILE' ">
- <Reference Include="nunit.framework">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\NUnit\lib\nunit.framework.dll</HintPath>
+ <Reference Include="xunit.abstractions">
+ <HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
- </ItemGroup>
- <ItemGroup Condition=" '$(EnvironmentFlavor)' != 'CLIENTPROFILE' ">
- <Reference Include="Microsoft.Silverlight.Testing, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\Microsoft.Silverlight.Testing\April2010\Microsoft.Silverlight.Testing.dll</HintPath>
+ <Reference Include="xunit.assert">
+ <HintPath>..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
</Reference>
- <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\Microsoft.Silverlight.Testing\April2010\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll</HintPath>
+ <Reference Include="xunit.core">
+ <HintPath>..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
- <Compile Include="..\..\lib\NUnit-config\Microsoft.VisualStudio.TestTools.cs">
- <Link>Microsoft.VisualStudio.TestTools.cs</Link>
- </Compile>
<Compile Include="AbstractMessageTest.cs" />
<Compile Include="ByteStringTest.cs" />
<Compile Include="CodedInputStreamTest.cs" />
@@ -132,27 +125,15 @@ </ProjectReference>
</ItemGroup>
<ItemGroup>
- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
- <Visible>False</Visible>
- <ProductName>Windows Installer 3.1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- </ItemGroup>
- <ItemGroup>
<EmbeddedResource Include="Compatibility\google_message1.dat" />
<EmbeddedResource Include="Compatibility\google_message2.dat" />
</ItemGroup>
- <ItemGroup />
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -161,10 +142,11 @@ <Target Name="AfterBuild">
</Target>
-->
- <PropertyGroup Condition=" '$(EnvironmentFlavor)' == 'CLIENTPROFILE' ">
- <StartAction>Program</StartAction>
- <StartProgram>$(ProjectDir)..\..\lib\NUnit\tools\nunit-console.exe</StartProgram>
- <StartArguments>/nologo /noshadow /labels /wait $(AssemblyName).dll</StartArguments>
- <StartWorkingDirectory>$(ProjectDir)$(OutputPath)</StartWorkingDirectory>
- </PropertyGroup>
+ <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+ <PropertyGroup>
+ <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
+ </PropertyGroup>
+ <Error Condition="!Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
+ <Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props'))" />
+ </Target>
</Project>
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/ReflectionTester.cs b/csharp/src/ProtocolBuffers.Test/ReflectionTester.cs index 5385d316..5fa22fef 100644 --- a/csharp/src/ProtocolBuffers.Test/ReflectionTester.cs +++ b/csharp/src/ProtocolBuffers.Test/ReflectionTester.cs @@ -37,7 +37,7 @@ using System;
using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
#pragma warning disable 618 // Disable warning about obsolete use miss-matched assert arguments
@@ -97,7 +97,7 @@ namespace Google.ProtocolBuffers this.extensionRegistry = extensionRegistry;
this.file = baseDescriptor.File;
- Assert.AreEqual(1, file.Dependencies.Count);
+ Assert.Equal(1, file.Dependencies.Count);
this.importFile = file.Dependencies[0];
MessageDescriptor testAllTypes;
@@ -108,7 +108,7 @@ namespace Google.ProtocolBuffers else
{
testAllTypes = file.FindTypeByName<MessageDescriptor>("TestAllTypes");
- Assert.IsNotNull(testAllTypes);
+ Assert.NotNull(testAllTypes);
}
if (extensionRegistry == null)
@@ -136,14 +136,14 @@ namespace Google.ProtocolBuffers this.foreignEnum = file.FindTypeByName<EnumDescriptor>("ForeignEnum");
this.importEnum = importFile.FindTypeByName<EnumDescriptor>("ImportEnum");
- Assert.IsNotNull(optionalGroup);
- Assert.IsNotNull(repeatedGroup);
- Assert.IsNotNull(nestedMessage);
- Assert.IsNotNull(foreignMessage);
- Assert.IsNotNull(importMessage);
- Assert.IsNotNull(nestedEnum);
- Assert.IsNotNull(foreignEnum);
- Assert.IsNotNull(importEnum);
+ Assert.NotNull(optionalGroup);
+ Assert.NotNull(repeatedGroup);
+ Assert.NotNull(nestedMessage);
+ Assert.NotNull(foreignMessage);
+ Assert.NotNull(importMessage);
+ Assert.NotNull(nestedEnum);
+ Assert.NotNull(foreignEnum);
+ Assert.NotNull(importEnum);
this.nestedB = nestedMessage.FindDescriptor<FieldDescriptor>("bb");
this.foreignC = foreignMessage.FindDescriptor<FieldDescriptor>("c");
@@ -161,20 +161,20 @@ namespace Google.ProtocolBuffers this.groupA = optionalGroup.FindDescriptor<FieldDescriptor>("a");
this.repeatedGroupA = repeatedGroup.FindDescriptor<FieldDescriptor>("a");
- Assert.IsNotNull(groupA);
- Assert.IsNotNull(repeatedGroupA);
- Assert.IsNotNull(nestedB);
- Assert.IsNotNull(foreignC);
- Assert.IsNotNull(importD);
- Assert.IsNotNull(nestedFoo);
- Assert.IsNotNull(nestedBar);
- Assert.IsNotNull(nestedBaz);
- Assert.IsNotNull(foreignFoo);
- Assert.IsNotNull(foreignBar);
- Assert.IsNotNull(foreignBaz);
- Assert.IsNotNull(importFoo);
- Assert.IsNotNull(importBar);
- Assert.IsNotNull(importBaz);
+ Assert.NotNull(groupA);
+ Assert.NotNull(repeatedGroupA);
+ Assert.NotNull(nestedB);
+ Assert.NotNull(foreignC);
+ Assert.NotNull(importD);
+ Assert.NotNull(nestedFoo);
+ Assert.NotNull(nestedBar);
+ Assert.NotNull(nestedBaz);
+ Assert.NotNull(foreignFoo);
+ Assert.NotNull(foreignBar);
+ Assert.NotNull(foreignBaz);
+ Assert.NotNull(importFoo);
+ Assert.NotNull(importBar);
+ Assert.NotNull(importBaz);
}
/// <summary>
@@ -216,7 +216,7 @@ namespace Google.ProtocolBuffers {
result = file.FindTypeByName<FieldDescriptor>(name + "_extension");
}
- Assert.IsNotNull(result);
+ Assert.NotNull(result);
return result;
}
@@ -233,8 +233,8 @@ namespace Google.ProtocolBuffers else
{
ExtensionInfo extension = extensionRegistry[field.ContainingType, field.FieldNumber];
- Assert.IsNotNull(extension);
- Assert.IsNotNull(extension.DefaultInstance);
+ Assert.NotNull(extension);
+ Assert.NotNull(extension.DefaultInstance);
return (IBuilder) extension.DefaultInstance.WeakCreateBuilderForType();
}
}
@@ -449,199 +449,199 @@ namespace Google.ProtocolBuffers /// </summary>
public void AssertAllFieldsSetViaReflection(IMessage message)
{
- Assert.IsTrue(message.HasField(f("optional_int32")));
- Assert.IsTrue(message.HasField(f("optional_int64")));
- Assert.IsTrue(message.HasField(f("optional_uint32")));
- Assert.IsTrue(message.HasField(f("optional_uint64")));
- Assert.IsTrue(message.HasField(f("optional_sint32")));
- Assert.IsTrue(message.HasField(f("optional_sint64")));
- Assert.IsTrue(message.HasField(f("optional_fixed32")));
- Assert.IsTrue(message.HasField(f("optional_fixed64")));
- Assert.IsTrue(message.HasField(f("optional_sfixed32")));
- Assert.IsTrue(message.HasField(f("optional_sfixed64")));
- Assert.IsTrue(message.HasField(f("optional_float")));
- Assert.IsTrue(message.HasField(f("optional_double")));
- Assert.IsTrue(message.HasField(f("optional_bool")));
- Assert.IsTrue(message.HasField(f("optional_string")));
- Assert.IsTrue(message.HasField(f("optional_bytes")));
-
- Assert.IsTrue(message.HasField(f("optionalgroup")));
- Assert.IsTrue(message.HasField(f("optional_nested_message")));
- Assert.IsTrue(message.HasField(f("optional_foreign_message")));
- Assert.IsTrue(message.HasField(f("optional_import_message")));
-
- Assert.IsTrue(((IMessage) message[f("optionalgroup")]).HasField(groupA));
- Assert.IsTrue(((IMessage) message[f("optional_nested_message")]).HasField(nestedB));
- Assert.IsTrue(((IMessage) message[f("optional_foreign_message")]).HasField(foreignC));
- Assert.IsTrue(((IMessage) message[f("optional_import_message")]).HasField(importD));
-
- Assert.IsTrue(message.HasField(f("optional_nested_enum")));
- Assert.IsTrue(message.HasField(f("optional_foreign_enum")));
- Assert.IsTrue(message.HasField(f("optional_import_enum")));
-
- Assert.IsTrue(message.HasField(f("optional_string_piece")));
- Assert.IsTrue(message.HasField(f("optional_cord")));
-
- Assert.AreEqual(101, message[f("optional_int32")]);
- Assert.AreEqual(102L, message[f("optional_int64")]);
- Assert.AreEqual(103u, message[f("optional_uint32")]);
- Assert.AreEqual(104UL, message[f("optional_uint64")]);
- Assert.AreEqual(105, message[f("optional_sint32")]);
- Assert.AreEqual(106L, message[f("optional_sint64")]);
- Assert.AreEqual(107U, message[f("optional_fixed32")]);
- Assert.AreEqual(108UL, message[f("optional_fixed64")]);
- Assert.AreEqual(109, message[f("optional_sfixed32")]);
- Assert.AreEqual(110L, message[f("optional_sfixed64")]);
- Assert.AreEqual(111F, message[f("optional_float")]);
- Assert.AreEqual(112D, message[f("optional_double")]);
- Assert.AreEqual(true, message[f("optional_bool")]);
- Assert.AreEqual("115", message[f("optional_string")]);
- Assert.AreEqual(TestUtil.ToBytes("116"), message[f("optional_bytes")]);
-
- Assert.AreEqual(117, ((IMessage) message[f("optionalgroup")])[groupA]);
- Assert.AreEqual(118, ((IMessage) message[f("optional_nested_message")])[nestedB]);
- Assert.AreEqual(119, ((IMessage) message[f("optional_foreign_message")])[foreignC]);
- Assert.AreEqual(120, ((IMessage) message[f("optional_import_message")])[importD]);
-
- Assert.AreEqual(nestedBaz, message[f("optional_nested_enum")]);
- Assert.AreEqual(foreignBaz, message[f("optional_foreign_enum")]);
- Assert.AreEqual(importBaz, message[f("optional_import_enum")]);
-
- Assert.AreEqual("124", message[f("optional_string_piece")]);
- Assert.AreEqual("125", message[f("optional_cord")]);
+ Assert.True(message.HasField(f("optional_int32")));
+ Assert.True(message.HasField(f("optional_int64")));
+ Assert.True(message.HasField(f("optional_uint32")));
+ Assert.True(message.HasField(f("optional_uint64")));
+ Assert.True(message.HasField(f("optional_sint32")));
+ Assert.True(message.HasField(f("optional_sint64")));
+ Assert.True(message.HasField(f("optional_fixed32")));
+ Assert.True(message.HasField(f("optional_fixed64")));
+ Assert.True(message.HasField(f("optional_sfixed32")));
+ Assert.True(message.HasField(f("optional_sfixed64")));
+ Assert.True(message.HasField(f("optional_float")));
+ Assert.True(message.HasField(f("optional_double")));
+ Assert.True(message.HasField(f("optional_bool")));
+ Assert.True(message.HasField(f("optional_string")));
+ Assert.True(message.HasField(f("optional_bytes")));
+
+ Assert.True(message.HasField(f("optionalgroup")));
+ Assert.True(message.HasField(f("optional_nested_message")));
+ Assert.True(message.HasField(f("optional_foreign_message")));
+ Assert.True(message.HasField(f("optional_import_message")));
+
+ Assert.True(((IMessage) message[f("optionalgroup")]).HasField(groupA));
+ Assert.True(((IMessage) message[f("optional_nested_message")]).HasField(nestedB));
+ Assert.True(((IMessage) message[f("optional_foreign_message")]).HasField(foreignC));
+ Assert.True(((IMessage) message[f("optional_import_message")]).HasField(importD));
+
+ Assert.True(message.HasField(f("optional_nested_enum")));
+ Assert.True(message.HasField(f("optional_foreign_enum")));
+ Assert.True(message.HasField(f("optional_import_enum")));
+
+ Assert.True(message.HasField(f("optional_string_piece")));
+ Assert.True(message.HasField(f("optional_cord")));
+
+ Assert.Equal(101, message[f("optional_int32")]);
+ Assert.Equal(102L, message[f("optional_int64")]);
+ Assert.Equal(103u, message[f("optional_uint32")]);
+ Assert.Equal(104UL, message[f("optional_uint64")]);
+ Assert.Equal(105, message[f("optional_sint32")]);
+ Assert.Equal(106L, message[f("optional_sint64")]);
+ Assert.Equal(107U, message[f("optional_fixed32")]);
+ Assert.Equal(108UL, message[f("optional_fixed64")]);
+ Assert.Equal(109, message[f("optional_sfixed32")]);
+ Assert.Equal(110L, message[f("optional_sfixed64")]);
+ Assert.Equal(111F, message[f("optional_float")]);
+ Assert.Equal(112D, message[f("optional_double")]);
+ Assert.Equal(true, message[f("optional_bool")]);
+ Assert.Equal("115", message[f("optional_string")]);
+ Assert.Equal(TestUtil.ToBytes("116"), message[f("optional_bytes")]);
+
+ Assert.Equal(117, ((IMessage) message[f("optionalgroup")])[groupA]);
+ Assert.Equal(118, ((IMessage) message[f("optional_nested_message")])[nestedB]);
+ Assert.Equal(119, ((IMessage) message[f("optional_foreign_message")])[foreignC]);
+ Assert.Equal(120, ((IMessage) message[f("optional_import_message")])[importD]);
+
+ Assert.Equal(nestedBaz, message[f("optional_nested_enum")]);
+ Assert.Equal(foreignBaz, message[f("optional_foreign_enum")]);
+ Assert.Equal(importBaz, message[f("optional_import_enum")]);
+
+ Assert.Equal("124", message[f("optional_string_piece")]);
+ Assert.Equal("125", message[f("optional_cord")]);
// -----------------------------------------------------------------
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_int32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_int64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_uint32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_uint64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sint32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sint64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_fixed32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_fixed64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sfixed32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sfixed64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_float")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_double")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_bool")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_string")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_bytes")));
-
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeatedgroup")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_nested_message")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_foreign_message")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_import_message")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_nested_enum")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_foreign_enum")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_import_enum")));
-
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_string_piece")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_cord")));
-
- Assert.AreEqual(201, message[f("repeated_int32"), 0]);
- Assert.AreEqual(202L, message[f("repeated_int64"), 0]);
- Assert.AreEqual(203U, message[f("repeated_uint32"), 0]);
- Assert.AreEqual(204UL, message[f("repeated_uint64"), 0]);
- Assert.AreEqual(205, message[f("repeated_sint32"), 0]);
- Assert.AreEqual(206L, message[f("repeated_sint64"), 0]);
- Assert.AreEqual(207U, message[f("repeated_fixed32"), 0]);
- Assert.AreEqual(208UL, message[f("repeated_fixed64"), 0]);
- Assert.AreEqual(209, message[f("repeated_sfixed32"), 0]);
- Assert.AreEqual(210L, message[f("repeated_sfixed64"), 0]);
- Assert.AreEqual(211F, message[f("repeated_float"), 0]);
- Assert.AreEqual(212D, message[f("repeated_double"), 0]);
- Assert.AreEqual(true, message[f("repeated_bool"), 0]);
- Assert.AreEqual("215", message[f("repeated_string"), 0]);
- Assert.AreEqual(TestUtil.ToBytes("216"), message[f("repeated_bytes"), 0]);
-
- Assert.AreEqual(217, ((IMessage) message[f("repeatedgroup"), 0])[repeatedGroupA]);
- Assert.AreEqual(218, ((IMessage) message[f("repeated_nested_message"), 0])[nestedB]);
- Assert.AreEqual(219, ((IMessage) message[f("repeated_foreign_message"), 0])[foreignC]);
- Assert.AreEqual(220, ((IMessage) message[f("repeated_import_message"), 0])[importD]);
-
- Assert.AreEqual(nestedBar, message[f("repeated_nested_enum"), 0]);
- Assert.AreEqual(foreignBar, message[f("repeated_foreign_enum"), 0]);
- Assert.AreEqual(importBar, message[f("repeated_import_enum"), 0]);
-
- Assert.AreEqual("224", message[f("repeated_string_piece"), 0]);
- Assert.AreEqual("225", message[f("repeated_cord"), 0]);
-
- Assert.AreEqual(301, message[f("repeated_int32"), 1]);
- Assert.AreEqual(302L, message[f("repeated_int64"), 1]);
- Assert.AreEqual(303U, message[f("repeated_uint32"), 1]);
- Assert.AreEqual(304UL, message[f("repeated_uint64"), 1]);
- Assert.AreEqual(305, message[f("repeated_sint32"), 1]);
- Assert.AreEqual(306L, message[f("repeated_sint64"), 1]);
- Assert.AreEqual(307U, message[f("repeated_fixed32"), 1]);
- Assert.AreEqual(308UL, message[f("repeated_fixed64"), 1]);
- Assert.AreEqual(309, message[f("repeated_sfixed32"), 1]);
- Assert.AreEqual(310L, message[f("repeated_sfixed64"), 1]);
- Assert.AreEqual(311F, message[f("repeated_float"), 1]);
- Assert.AreEqual(312D, message[f("repeated_double"), 1]);
- Assert.AreEqual(false, message[f("repeated_bool"), 1]);
- Assert.AreEqual("315", message[f("repeated_string"), 1]);
- Assert.AreEqual(TestUtil.ToBytes("316"), message[f("repeated_bytes"), 1]);
-
- Assert.AreEqual(317, ((IMessage) message[f("repeatedgroup"), 1])[repeatedGroupA]);
- Assert.AreEqual(318, ((IMessage) message[f("repeated_nested_message"), 1])[nestedB]);
- Assert.AreEqual(319, ((IMessage) message[f("repeated_foreign_message"), 1])[foreignC]);
- Assert.AreEqual(320, ((IMessage) message[f("repeated_import_message"), 1])[importD]);
-
- Assert.AreEqual(nestedBaz, message[f("repeated_nested_enum"), 1]);
- Assert.AreEqual(foreignBaz, message[f("repeated_foreign_enum"), 1]);
- Assert.AreEqual(importBaz, message[f("repeated_import_enum"), 1]);
-
- Assert.AreEqual("324", message[f("repeated_string_piece"), 1]);
- Assert.AreEqual("325", message[f("repeated_cord"), 1]);
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_int32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_int64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_uint32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_uint64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_sint32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_sint64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_fixed32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_fixed64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_sfixed32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_sfixed64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_float")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_double")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_bool")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_string")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_bytes")));
+
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeatedgroup")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_nested_message")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_foreign_message")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_import_message")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_nested_enum")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_foreign_enum")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_import_enum")));
+
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_string_piece")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_cord")));
+
+ Assert.Equal(201, message[f("repeated_int32"), 0]);
+ Assert.Equal(202L, message[f("repeated_int64"), 0]);
+ Assert.Equal(203U, message[f("repeated_uint32"), 0]);
+ Assert.Equal(204UL, message[f("repeated_uint64"), 0]);
+ Assert.Equal(205, message[f("repeated_sint32"), 0]);
+ Assert.Equal(206L, message[f("repeated_sint64"), 0]);
+ Assert.Equal(207U, message[f("repeated_fixed32"), 0]);
+ Assert.Equal(208UL, message[f("repeated_fixed64"), 0]);
+ Assert.Equal(209, message[f("repeated_sfixed32"), 0]);
+ Assert.Equal(210L, message[f("repeated_sfixed64"), 0]);
+ Assert.Equal(211F, message[f("repeated_float"), 0]);
+ Assert.Equal(212D, message[f("repeated_double"), 0]);
+ Assert.Equal(true, message[f("repeated_bool"), 0]);
+ Assert.Equal("215", message[f("repeated_string"), 0]);
+ Assert.Equal(TestUtil.ToBytes("216"), message[f("repeated_bytes"), 0]);
+
+ Assert.Equal(217, ((IMessage) message[f("repeatedgroup"), 0])[repeatedGroupA]);
+ Assert.Equal(218, ((IMessage) message[f("repeated_nested_message"), 0])[nestedB]);
+ Assert.Equal(219, ((IMessage) message[f("repeated_foreign_message"), 0])[foreignC]);
+ Assert.Equal(220, ((IMessage) message[f("repeated_import_message"), 0])[importD]);
+
+ Assert.Equal(nestedBar, message[f("repeated_nested_enum"), 0]);
+ Assert.Equal(foreignBar, message[f("repeated_foreign_enum"), 0]);
+ Assert.Equal(importBar, message[f("repeated_import_enum"), 0]);
+
+ Assert.Equal("224", message[f("repeated_string_piece"), 0]);
+ Assert.Equal("225", message[f("repeated_cord"), 0]);
+
+ Assert.Equal(301, message[f("repeated_int32"), 1]);
+ Assert.Equal(302L, message[f("repeated_int64"), 1]);
+ Assert.Equal(303U, message[f("repeated_uint32"), 1]);
+ Assert.Equal(304UL, message[f("repeated_uint64"), 1]);
+ Assert.Equal(305, message[f("repeated_sint32"), 1]);
+ Assert.Equal(306L, message[f("repeated_sint64"), 1]);
+ Assert.Equal(307U, message[f("repeated_fixed32"), 1]);
+ Assert.Equal(308UL, message[f("repeated_fixed64"), 1]);
+ Assert.Equal(309, message[f("repeated_sfixed32"), 1]);
+ Assert.Equal(310L, message[f("repeated_sfixed64"), 1]);
+ Assert.Equal(311F, message[f("repeated_float"), 1]);
+ Assert.Equal(312D, message[f("repeated_double"), 1]);
+ Assert.Equal(false, message[f("repeated_bool"), 1]);
+ Assert.Equal("315", message[f("repeated_string"), 1]);
+ Assert.Equal(TestUtil.ToBytes("316"), message[f("repeated_bytes"), 1]);
+
+ Assert.Equal(317, ((IMessage) message[f("repeatedgroup"), 1])[repeatedGroupA]);
+ Assert.Equal(318, ((IMessage) message[f("repeated_nested_message"), 1])[nestedB]);
+ Assert.Equal(319, ((IMessage) message[f("repeated_foreign_message"), 1])[foreignC]);
+ Assert.Equal(320, ((IMessage) message[f("repeated_import_message"), 1])[importD]);
+
+ Assert.Equal(nestedBaz, message[f("repeated_nested_enum"), 1]);
+ Assert.Equal(foreignBaz, message[f("repeated_foreign_enum"), 1]);
+ Assert.Equal(importBaz, message[f("repeated_import_enum"), 1]);
+
+ Assert.Equal("324", message[f("repeated_string_piece"), 1]);
+ Assert.Equal("325", message[f("repeated_cord"), 1]);
// -----------------------------------------------------------------
- Assert.IsTrue(message.HasField(f("default_int32")));
- Assert.IsTrue(message.HasField(f("default_int64")));
- Assert.IsTrue(message.HasField(f("default_uint32")));
- Assert.IsTrue(message.HasField(f("default_uint64")));
- Assert.IsTrue(message.HasField(f("default_sint32")));
- Assert.IsTrue(message.HasField(f("default_sint64")));
- Assert.IsTrue(message.HasField(f("default_fixed32")));
- Assert.IsTrue(message.HasField(f("default_fixed64")));
- Assert.IsTrue(message.HasField(f("default_sfixed32")));
- Assert.IsTrue(message.HasField(f("default_sfixed64")));
- Assert.IsTrue(message.HasField(f("default_float")));
- Assert.IsTrue(message.HasField(f("default_double")));
- Assert.IsTrue(message.HasField(f("default_bool")));
- Assert.IsTrue(message.HasField(f("default_string")));
- Assert.IsTrue(message.HasField(f("default_bytes")));
-
- Assert.IsTrue(message.HasField(f("default_nested_enum")));
- Assert.IsTrue(message.HasField(f("default_foreign_enum")));
- Assert.IsTrue(message.HasField(f("default_import_enum")));
-
- Assert.IsTrue(message.HasField(f("default_string_piece")));
- Assert.IsTrue(message.HasField(f("default_cord")));
-
- Assert.AreEqual(401, message[f("default_int32")]);
- Assert.AreEqual(402L, message[f("default_int64")]);
- Assert.AreEqual(403U, message[f("default_uint32")]);
- Assert.AreEqual(404UL, message[f("default_uint64")]);
- Assert.AreEqual(405, message[f("default_sint32")]);
- Assert.AreEqual(406L, message[f("default_sint64")]);
- Assert.AreEqual(407U, message[f("default_fixed32")]);
- Assert.AreEqual(408UL, message[f("default_fixed64")]);
- Assert.AreEqual(409, message[f("default_sfixed32")]);
- Assert.AreEqual(410L, message[f("default_sfixed64")]);
- Assert.AreEqual(411F, message[f("default_float")]);
- Assert.AreEqual(412D, message[f("default_double")]);
- Assert.AreEqual(false, message[f("default_bool")]);
- Assert.AreEqual("415", message[f("default_string")]);
- Assert.AreEqual(TestUtil.ToBytes("416"), message[f("default_bytes")]);
-
- Assert.AreEqual(nestedFoo, message[f("default_nested_enum")]);
- Assert.AreEqual(foreignFoo, message[f("default_foreign_enum")]);
- Assert.AreEqual(importFoo, message[f("default_import_enum")]);
-
- Assert.AreEqual("424", message[f("default_string_piece")]);
- Assert.AreEqual("425", message[f("default_cord")]);
+ Assert.True(message.HasField(f("default_int32")));
+ Assert.True(message.HasField(f("default_int64")));
+ Assert.True(message.HasField(f("default_uint32")));
+ Assert.True(message.HasField(f("default_uint64")));
+ Assert.True(message.HasField(f("default_sint32")));
+ Assert.True(message.HasField(f("default_sint64")));
+ Assert.True(message.HasField(f("default_fixed32")));
+ Assert.True(message.HasField(f("default_fixed64")));
+ Assert.True(message.HasField(f("default_sfixed32")));
+ Assert.True(message.HasField(f("default_sfixed64")));
+ Assert.True(message.HasField(f("default_float")));
+ Assert.True(message.HasField(f("default_double")));
+ Assert.True(message.HasField(f("default_bool")));
+ Assert.True(message.HasField(f("default_string")));
+ Assert.True(message.HasField(f("default_bytes")));
+
+ Assert.True(message.HasField(f("default_nested_enum")));
+ Assert.True(message.HasField(f("default_foreign_enum")));
+ Assert.True(message.HasField(f("default_import_enum")));
+
+ Assert.True(message.HasField(f("default_string_piece")));
+ Assert.True(message.HasField(f("default_cord")));
+
+ Assert.Equal(401, message[f("default_int32")]);
+ Assert.Equal(402L, message[f("default_int64")]);
+ Assert.Equal(403U, message[f("default_uint32")]);
+ Assert.Equal(404UL, message[f("default_uint64")]);
+ Assert.Equal(405, message[f("default_sint32")]);
+ Assert.Equal(406L, message[f("default_sint64")]);
+ Assert.Equal(407U, message[f("default_fixed32")]);
+ Assert.Equal(408UL, message[f("default_fixed64")]);
+ Assert.Equal(409, message[f("default_sfixed32")]);
+ Assert.Equal(410L, message[f("default_sfixed64")]);
+ Assert.Equal(411F, message[f("default_float")]);
+ Assert.Equal(412D, message[f("default_double")]);
+ Assert.Equal(false, message[f("default_bool")]);
+ Assert.Equal("415", message[f("default_string")]);
+ Assert.Equal(TestUtil.ToBytes("416"), message[f("default_bytes")]);
+
+ Assert.Equal(nestedFoo, message[f("default_nested_enum")]);
+ Assert.Equal(foreignFoo, message[f("default_foreign_enum")]);
+ Assert.Equal(importFoo, message[f("default_import_enum")]);
+
+ Assert.Equal("424", message[f("default_string_piece")]);
+ Assert.Equal("425", message[f("default_cord")]);
}
/// <summary>
@@ -651,148 +651,148 @@ namespace Google.ProtocolBuffers public void AssertClearViaReflection(IMessage message)
{
// has_blah() should initially be false for all optional fields.
- Assert.IsFalse(message.HasField(f("optional_int32")));
- Assert.IsFalse(message.HasField(f("optional_int64")));
- Assert.IsFalse(message.HasField(f("optional_uint32")));
- Assert.IsFalse(message.HasField(f("optional_uint64")));
- Assert.IsFalse(message.HasField(f("optional_sint32")));
- Assert.IsFalse(message.HasField(f("optional_sint64")));
- Assert.IsFalse(message.HasField(f("optional_fixed32")));
- Assert.IsFalse(message.HasField(f("optional_fixed64")));
- Assert.IsFalse(message.HasField(f("optional_sfixed32")));
- Assert.IsFalse(message.HasField(f("optional_sfixed64")));
- Assert.IsFalse(message.HasField(f("optional_float")));
- Assert.IsFalse(message.HasField(f("optional_double")));
- Assert.IsFalse(message.HasField(f("optional_bool")));
- Assert.IsFalse(message.HasField(f("optional_string")));
- Assert.IsFalse(message.HasField(f("optional_bytes")));
-
- Assert.IsFalse(message.HasField(f("optionalgroup")));
- Assert.IsFalse(message.HasField(f("optional_nested_message")));
- Assert.IsFalse(message.HasField(f("optional_foreign_message")));
- Assert.IsFalse(message.HasField(f("optional_import_message")));
-
- Assert.IsFalse(message.HasField(f("optional_nested_enum")));
- Assert.IsFalse(message.HasField(f("optional_foreign_enum")));
- Assert.IsFalse(message.HasField(f("optional_import_enum")));
-
- Assert.IsFalse(message.HasField(f("optional_string_piece")));
- Assert.IsFalse(message.HasField(f("optional_cord")));
+ Assert.False(message.HasField(f("optional_int32")));
+ Assert.False(message.HasField(f("optional_int64")));
+ Assert.False(message.HasField(f("optional_uint32")));
+ Assert.False(message.HasField(f("optional_uint64")));
+ Assert.False(message.HasField(f("optional_sint32")));
+ Assert.False(message.HasField(f("optional_sint64")));
+ Assert.False(message.HasField(f("optional_fixed32")));
+ Assert.False(message.HasField(f("optional_fixed64")));
+ Assert.False(message.HasField(f("optional_sfixed32")));
+ Assert.False(message.HasField(f("optional_sfixed64")));
+ Assert.False(message.HasField(f("optional_float")));
+ Assert.False(message.HasField(f("optional_double")));
+ Assert.False(message.HasField(f("optional_bool")));
+ Assert.False(message.HasField(f("optional_string")));
+ Assert.False(message.HasField(f("optional_bytes")));
+
+ Assert.False(message.HasField(f("optionalgroup")));
+ Assert.False(message.HasField(f("optional_nested_message")));
+ Assert.False(message.HasField(f("optional_foreign_message")));
+ Assert.False(message.HasField(f("optional_import_message")));
+
+ Assert.False(message.HasField(f("optional_nested_enum")));
+ Assert.False(message.HasField(f("optional_foreign_enum")));
+ Assert.False(message.HasField(f("optional_import_enum")));
+
+ Assert.False(message.HasField(f("optional_string_piece")));
+ Assert.False(message.HasField(f("optional_cord")));
// Optional fields without defaults are set to zero or something like it.
- Assert.AreEqual(0, message[f("optional_int32")]);
- Assert.AreEqual(0L, message[f("optional_int64")]);
- Assert.AreEqual(0U, message[f("optional_uint32")]);
- Assert.AreEqual(0UL, message[f("optional_uint64")]);
- Assert.AreEqual(0, message[f("optional_sint32")]);
- Assert.AreEqual(0L, message[f("optional_sint64")]);
- Assert.AreEqual(0U, message[f("optional_fixed32")]);
- Assert.AreEqual(0UL, message[f("optional_fixed64")]);
- Assert.AreEqual(0, message[f("optional_sfixed32")]);
- Assert.AreEqual(0L, message[f("optional_sfixed64")]);
- Assert.AreEqual(0F, message[f("optional_float")]);
- Assert.AreEqual(0D, message[f("optional_double")]);
- Assert.AreEqual(false, message[f("optional_bool")]);
- Assert.AreEqual("", message[f("optional_string")]);
- Assert.AreEqual(ByteString.Empty, message[f("optional_bytes")]);
+ Assert.Equal(0, message[f("optional_int32")]);
+ Assert.Equal(0L, message[f("optional_int64")]);
+ Assert.Equal(0U, message[f("optional_uint32")]);
+ Assert.Equal(0UL, message[f("optional_uint64")]);
+ Assert.Equal(0, message[f("optional_sint32")]);
+ Assert.Equal(0L, message[f("optional_sint64")]);
+ Assert.Equal(0U, message[f("optional_fixed32")]);
+ Assert.Equal(0UL, message[f("optional_fixed64")]);
+ Assert.Equal(0, message[f("optional_sfixed32")]);
+ Assert.Equal(0L, message[f("optional_sfixed64")]);
+ Assert.Equal(0F, message[f("optional_float")]);
+ Assert.Equal(0D, message[f("optional_double")]);
+ Assert.Equal(false, message[f("optional_bool")]);
+ Assert.Equal("", message[f("optional_string")]);
+ Assert.Equal(ByteString.Empty, message[f("optional_bytes")]);
// Embedded messages should also be clear.
- Assert.IsFalse(((IMessage) message[f("optionalgroup")]).HasField(groupA));
- Assert.IsFalse(((IMessage) message[f("optional_nested_message")])
+ Assert.False(((IMessage) message[f("optionalgroup")]).HasField(groupA));
+ Assert.False(((IMessage) message[f("optional_nested_message")])
.HasField(nestedB));
- Assert.IsFalse(((IMessage) message[f("optional_foreign_message")])
+ Assert.False(((IMessage) message[f("optional_foreign_message")])
.HasField(foreignC));
- Assert.IsFalse(((IMessage) message[f("optional_import_message")])
+ Assert.False(((IMessage) message[f("optional_import_message")])
.HasField(importD));
- Assert.AreEqual(0, ((IMessage) message[f("optionalgroup")])[groupA]);
- Assert.AreEqual(0, ((IMessage) message[f("optional_nested_message")])[nestedB]);
- Assert.AreEqual(0, ((IMessage) message[f("optional_foreign_message")])[foreignC]);
- Assert.AreEqual(0, ((IMessage) message[f("optional_import_message")])[importD]);
+ Assert.Equal(0, ((IMessage) message[f("optionalgroup")])[groupA]);
+ Assert.Equal(0, ((IMessage) message[f("optional_nested_message")])[nestedB]);
+ Assert.Equal(0, ((IMessage) message[f("optional_foreign_message")])[foreignC]);
+ Assert.Equal(0, ((IMessage) message[f("optional_import_message")])[importD]);
// Enums without defaults are set to the first value in the enum.
- Assert.AreEqual(nestedFoo, message[f("optional_nested_enum")]);
- Assert.AreEqual(foreignFoo, message[f("optional_foreign_enum")]);
- Assert.AreEqual(importFoo, message[f("optional_import_enum")]);
+ Assert.Equal(nestedFoo, message[f("optional_nested_enum")]);
+ Assert.Equal(foreignFoo, message[f("optional_foreign_enum")]);
+ Assert.Equal(importFoo, message[f("optional_import_enum")]);
- Assert.AreEqual("", message[f("optional_string_piece")]);
- Assert.AreEqual("", message[f("optional_cord")]);
+ Assert.Equal("", message[f("optional_string_piece")]);
+ Assert.Equal("", message[f("optional_cord")]);
// Repeated fields are empty.
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_int32")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_int64")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_uint32")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_uint64")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_sint32")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_sint64")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_fixed32")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_fixed64")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_sfixed32")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_sfixed64")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_float")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_double")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_bool")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_string")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_bytes")));
-
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeatedgroup")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_nested_message")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_foreign_message")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_import_message")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_nested_enum")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_foreign_enum")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_import_enum")));
-
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_string_piece")));
- Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_cord")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_int32")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_int64")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_uint32")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_uint64")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_sint32")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_sint64")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_fixed32")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_fixed64")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_sfixed32")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_sfixed64")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_float")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_double")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_bool")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_string")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_bytes")));
+
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeatedgroup")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_nested_message")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_foreign_message")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_import_message")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_nested_enum")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_foreign_enum")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_import_enum")));
+
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_string_piece")));
+ Assert.Equal(0, message.GetRepeatedFieldCount(f("repeated_cord")));
// has_blah() should also be false for all default fields.
- Assert.IsFalse(message.HasField(f("default_int32")));
- Assert.IsFalse(message.HasField(f("default_int64")));
- Assert.IsFalse(message.HasField(f("default_uint32")));
- Assert.IsFalse(message.HasField(f("default_uint64")));
- Assert.IsFalse(message.HasField(f("default_sint32")));
- Assert.IsFalse(message.HasField(f("default_sint64")));
- Assert.IsFalse(message.HasField(f("default_fixed32")));
- Assert.IsFalse(message.HasField(f("default_fixed64")));
- Assert.IsFalse(message.HasField(f("default_sfixed32")));
- Assert.IsFalse(message.HasField(f("default_sfixed64")));
- Assert.IsFalse(message.HasField(f("default_float")));
- Assert.IsFalse(message.HasField(f("default_double")));
- Assert.IsFalse(message.HasField(f("default_bool")));
- Assert.IsFalse(message.HasField(f("default_string")));
- Assert.IsFalse(message.HasField(f("default_bytes")));
-
- Assert.IsFalse(message.HasField(f("default_nested_enum")));
- Assert.IsFalse(message.HasField(f("default_foreign_enum")));
- Assert.IsFalse(message.HasField(f("default_import_enum")));
-
- Assert.IsFalse(message.HasField(f("default_string_piece")));
- Assert.IsFalse(message.HasField(f("default_cord")));
+ Assert.False(message.HasField(f("default_int32")));
+ Assert.False(message.HasField(f("default_int64")));
+ Assert.False(message.HasField(f("default_uint32")));
+ Assert.False(message.HasField(f("default_uint64")));
+ Assert.False(message.HasField(f("default_sint32")));
+ Assert.False(message.HasField(f("default_sint64")));
+ Assert.False(message.HasField(f("default_fixed32")));
+ Assert.False(message.HasField(f("default_fixed64")));
+ Assert.False(message.HasField(f("default_sfixed32")));
+ Assert.False(message.HasField(f("default_sfixed64")));
+ Assert.False(message.HasField(f("default_float")));
+ Assert.False(message.HasField(f("default_double")));
+ Assert.False(message.HasField(f("default_bool")));
+ Assert.False(message.HasField(f("default_string")));
+ Assert.False(message.HasField(f("default_bytes")));
+
+ Assert.False(message.HasField(f("default_nested_enum")));
+ Assert.False(message.HasField(f("default_foreign_enum")));
+ Assert.False(message.HasField(f("default_import_enum")));
+
+ Assert.False(message.HasField(f("default_string_piece")));
+ Assert.False(message.HasField(f("default_cord")));
// Fields with defaults have their default values (duh).
- Assert.AreEqual(41, message[f("default_int32")]);
- Assert.AreEqual(42L, message[f("default_int64")]);
- Assert.AreEqual(43U, message[f("default_uint32")]);
- Assert.AreEqual(44UL, message[f("default_uint64")]);
- Assert.AreEqual(-45, message[f("default_sint32")]);
- Assert.AreEqual(46L, message[f("default_sint64")]);
- Assert.AreEqual(47U, message[f("default_fixed32")]);
- Assert.AreEqual(48UL, message[f("default_fixed64")]);
- Assert.AreEqual(49, message[f("default_sfixed32")]);
- Assert.AreEqual(-50L, message[f("default_sfixed64")]);
- Assert.AreEqual(51.5F, message[f("default_float")]);
- Assert.AreEqual(52e3D, message[f("default_double")]);
- Assert.AreEqual(true, message[f("default_bool")]);
- Assert.AreEqual("hello", message[f("default_string")]);
- Assert.AreEqual(TestUtil.ToBytes("world"), message[f("default_bytes")]);
-
- Assert.AreEqual(nestedBar, message[f("default_nested_enum")]);
- Assert.AreEqual(foreignBar, message[f("default_foreign_enum")]);
- Assert.AreEqual(importBar, message[f("default_import_enum")]);
-
- Assert.AreEqual("abc", message[f("default_string_piece")]);
- Assert.AreEqual("123", message[f("default_cord")]);
+ Assert.Equal(41, message[f("default_int32")]);
+ Assert.Equal(42L, message[f("default_int64")]);
+ Assert.Equal(43U, message[f("default_uint32")]);
+ Assert.Equal(44UL, message[f("default_uint64")]);
+ Assert.Equal(-45, message[f("default_sint32")]);
+ Assert.Equal(46L, message[f("default_sint64")]);
+ Assert.Equal(47U, message[f("default_fixed32")]);
+ Assert.Equal(48UL, message[f("default_fixed64")]);
+ Assert.Equal(49, message[f("default_sfixed32")]);
+ Assert.Equal(-50L, message[f("default_sfixed64")]);
+ Assert.Equal(51.5F, message[f("default_float")]);
+ Assert.Equal(52e3D, message[f("default_double")]);
+ Assert.Equal(true, message[f("default_bool")]);
+ Assert.Equal("hello", message[f("default_string")]);
+ Assert.Equal(TestUtil.ToBytes("world"), message[f("default_bytes")]);
+
+ Assert.Equal(nestedBar, message[f("default_nested_enum")]);
+ Assert.Equal(foreignBar, message[f("default_foreign_enum")]);
+ Assert.Equal(importBar, message[f("default_import_enum")]);
+
+ Assert.Equal("abc", message[f("default_string_piece")]);
+ Assert.Equal("123", message[f("default_cord")]);
}
// ---------------------------------------------------------------
@@ -802,88 +802,88 @@ namespace Google.ProtocolBuffers // ModifyRepeatedFields only sets the second repeated element of each
// field. In addition to verifying this, we also verify that the first
// element and size were *not* modified.
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_int32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_int64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_uint32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_uint64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sint32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sint64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_fixed32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_fixed64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sfixed32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sfixed64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_float")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_double")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_bool")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_string")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_bytes")));
-
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeatedgroup")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_nested_message")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_foreign_message")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_import_message")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_nested_enum")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_foreign_enum")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_import_enum")));
-
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_string_piece")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_cord")));
-
- Assert.AreEqual(201, message[f("repeated_int32"), 0]);
- Assert.AreEqual(202L, message[f("repeated_int64"), 0]);
- Assert.AreEqual(203U, message[f("repeated_uint32"), 0]);
- Assert.AreEqual(204UL, message[f("repeated_uint64"), 0]);
- Assert.AreEqual(205, message[f("repeated_sint32"), 0]);
- Assert.AreEqual(206L, message[f("repeated_sint64"), 0]);
- Assert.AreEqual(207U, message[f("repeated_fixed32"), 0]);
- Assert.AreEqual(208UL, message[f("repeated_fixed64"), 0]);
- Assert.AreEqual(209, message[f("repeated_sfixed32"), 0]);
- Assert.AreEqual(210L, message[f("repeated_sfixed64"), 0]);
- Assert.AreEqual(211F, message[f("repeated_float"), 0]);
- Assert.AreEqual(212D, message[f("repeated_double"), 0]);
- Assert.AreEqual(true, message[f("repeated_bool"), 0]);
- Assert.AreEqual("215", message[f("repeated_string"), 0]);
- Assert.AreEqual(TestUtil.ToBytes("216"), message[f("repeated_bytes"), 0]);
-
- Assert.AreEqual(217, ((IMessage) message[f("repeatedgroup"), 0])[repeatedGroupA]);
- Assert.AreEqual(218, ((IMessage) message[f("repeated_nested_message"), 0])[nestedB]);
- Assert.AreEqual(219, ((IMessage) message[f("repeated_foreign_message"), 0])[foreignC]);
- Assert.AreEqual(220, ((IMessage) message[f("repeated_import_message"), 0])[importD]);
-
- Assert.AreEqual(nestedBar, message[f("repeated_nested_enum"), 0]);
- Assert.AreEqual(foreignBar, message[f("repeated_foreign_enum"), 0]);
- Assert.AreEqual(importBar, message[f("repeated_import_enum"), 0]);
-
- Assert.AreEqual("224", message[f("repeated_string_piece"), 0]);
- Assert.AreEqual("225", message[f("repeated_cord"), 0]);
-
- Assert.AreEqual(501, message[f("repeated_int32"), 1]);
- Assert.AreEqual(502L, message[f("repeated_int64"), 1]);
- Assert.AreEqual(503U, message[f("repeated_uint32"), 1]);
- Assert.AreEqual(504UL, message[f("repeated_uint64"), 1]);
- Assert.AreEqual(505, message[f("repeated_sint32"), 1]);
- Assert.AreEqual(506L, message[f("repeated_sint64"), 1]);
- Assert.AreEqual(507U, message[f("repeated_fixed32"), 1]);
- Assert.AreEqual(508UL, message[f("repeated_fixed64"), 1]);
- Assert.AreEqual(509, message[f("repeated_sfixed32"), 1]);
- Assert.AreEqual(510L, message[f("repeated_sfixed64"), 1]);
- Assert.AreEqual(511F, message[f("repeated_float"), 1]);
- Assert.AreEqual(512D, message[f("repeated_double"), 1]);
- Assert.AreEqual(true, message[f("repeated_bool"), 1]);
- Assert.AreEqual("515", message[f("repeated_string"), 1]);
- Assert.AreEqual(TestUtil.ToBytes("516"), message[f("repeated_bytes"), 1]);
-
- Assert.AreEqual(517, ((IMessage) message[f("repeatedgroup"), 1])[repeatedGroupA]);
- Assert.AreEqual(518, ((IMessage) message[f("repeated_nested_message"), 1])[nestedB]);
- Assert.AreEqual(519, ((IMessage) message[f("repeated_foreign_message"), 1])[foreignC]);
- Assert.AreEqual(520, ((IMessage) message[f("repeated_import_message"), 1])[importD]);
-
- Assert.AreEqual(nestedFoo, message[f("repeated_nested_enum"), 1]);
- Assert.AreEqual(foreignFoo, message[f("repeated_foreign_enum"), 1]);
- Assert.AreEqual(importFoo, message[f("repeated_import_enum"), 1]);
-
- Assert.AreEqual("524", message[f("repeated_string_piece"), 1]);
- Assert.AreEqual("525", message[f("repeated_cord"), 1]);
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_int32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_int64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_uint32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_uint64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_sint32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_sint64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_fixed32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_fixed64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_sfixed32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_sfixed64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_float")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_double")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_bool")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_string")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_bytes")));
+
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeatedgroup")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_nested_message")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_foreign_message")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_import_message")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_nested_enum")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_foreign_enum")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_import_enum")));
+
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_string_piece")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("repeated_cord")));
+
+ Assert.Equal(201, message[f("repeated_int32"), 0]);
+ Assert.Equal(202L, message[f("repeated_int64"), 0]);
+ Assert.Equal(203U, message[f("repeated_uint32"), 0]);
+ Assert.Equal(204UL, message[f("repeated_uint64"), 0]);
+ Assert.Equal(205, message[f("repeated_sint32"), 0]);
+ Assert.Equal(206L, message[f("repeated_sint64"), 0]);
+ Assert.Equal(207U, message[f("repeated_fixed32"), 0]);
+ Assert.Equal(208UL, message[f("repeated_fixed64"), 0]);
+ Assert.Equal(209, message[f("repeated_sfixed32"), 0]);
+ Assert.Equal(210L, message[f("repeated_sfixed64"), 0]);
+ Assert.Equal(211F, message[f("repeated_float"), 0]);
+ Assert.Equal(212D, message[f("repeated_double"), 0]);
+ Assert.Equal(true, message[f("repeated_bool"), 0]);
+ Assert.Equal("215", message[f("repeated_string"), 0]);
+ Assert.Equal(TestUtil.ToBytes("216"), message[f("repeated_bytes"), 0]);
+
+ Assert.Equal(217, ((IMessage) message[f("repeatedgroup"), 0])[repeatedGroupA]);
+ Assert.Equal(218, ((IMessage) message[f("repeated_nested_message"), 0])[nestedB]);
+ Assert.Equal(219, ((IMessage) message[f("repeated_foreign_message"), 0])[foreignC]);
+ Assert.Equal(220, ((IMessage) message[f("repeated_import_message"), 0])[importD]);
+
+ Assert.Equal(nestedBar, message[f("repeated_nested_enum"), 0]);
+ Assert.Equal(foreignBar, message[f("repeated_foreign_enum"), 0]);
+ Assert.Equal(importBar, message[f("repeated_import_enum"), 0]);
+
+ Assert.Equal("224", message[f("repeated_string_piece"), 0]);
+ Assert.Equal("225", message[f("repeated_cord"), 0]);
+
+ Assert.Equal(501, message[f("repeated_int32"), 1]);
+ Assert.Equal(502L, message[f("repeated_int64"), 1]);
+ Assert.Equal(503U, message[f("repeated_uint32"), 1]);
+ Assert.Equal(504UL, message[f("repeated_uint64"), 1]);
+ Assert.Equal(505, message[f("repeated_sint32"), 1]);
+ Assert.Equal(506L, message[f("repeated_sint64"), 1]);
+ Assert.Equal(507U, message[f("repeated_fixed32"), 1]);
+ Assert.Equal(508UL, message[f("repeated_fixed64"), 1]);
+ Assert.Equal(509, message[f("repeated_sfixed32"), 1]);
+ Assert.Equal(510L, message[f("repeated_sfixed64"), 1]);
+ Assert.Equal(511F, message[f("repeated_float"), 1]);
+ Assert.Equal(512D, message[f("repeated_double"), 1]);
+ Assert.Equal(true, message[f("repeated_bool"), 1]);
+ Assert.Equal("515", message[f("repeated_string"), 1]);
+ Assert.Equal(TestUtil.ToBytes("516"), message[f("repeated_bytes"), 1]);
+
+ Assert.Equal(517, ((IMessage) message[f("repeatedgroup"), 1])[repeatedGroupA]);
+ Assert.Equal(518, ((IMessage) message[f("repeated_nested_message"), 1])[nestedB]);
+ Assert.Equal(519, ((IMessage) message[f("repeated_foreign_message"), 1])[foreignC]);
+ Assert.Equal(520, ((IMessage) message[f("repeated_import_message"), 1])[importD]);
+
+ Assert.Equal(nestedFoo, message[f("repeated_nested_enum"), 1]);
+ Assert.Equal(foreignFoo, message[f("repeated_foreign_enum"), 1]);
+ Assert.Equal(importFoo, message[f("repeated_import_enum"), 1]);
+
+ Assert.Equal("524", message[f("repeated_string_piece"), 1]);
+ Assert.Equal("525", message[f("repeated_cord"), 1]);
}
/// <summary>
@@ -892,15 +892,15 @@ namespace Google.ProtocolBuffers /// </summary>
public void AssertReflectionSettersRejectNull(IBuilder builder)
{
- TestUtil.AssertArgumentNullException(() => builder[f("optional_string")] = null);
- TestUtil.AssertArgumentNullException(() => builder[f("optional_bytes")] = null);
- TestUtil.AssertArgumentNullException(() => builder[f("optional_nested_enum")] = null);
- TestUtil.AssertArgumentNullException(() => builder[f("optional_nested_message")] = null);
- TestUtil.AssertArgumentNullException(() => builder[f("optional_nested_message")] = null);
- TestUtil.AssertArgumentNullException(() => builder.WeakAddRepeatedField(f("repeated_string"), null));
- TestUtil.AssertArgumentNullException(() => builder.WeakAddRepeatedField(f("repeated_bytes"), null));
- TestUtil.AssertArgumentNullException(() => builder.WeakAddRepeatedField(f("repeated_nested_enum"), null));
- TestUtil.AssertArgumentNullException(() => builder.WeakAddRepeatedField(f("repeated_nested_message"), null));
+ Assert.Throws<ArgumentNullException>(() => builder[f("optional_string")] = null);
+ Assert.Throws<ArgumentNullException>(() => builder[f("optional_bytes")] = null);
+ Assert.Throws<ArgumentNullException>(() => builder[f("optional_nested_enum")] = null);
+ Assert.Throws<ArgumentNullException>(() => builder[f("optional_nested_message")] = null);
+ Assert.Throws<ArgumentNullException>(() => builder[f("optional_nested_message")] = null);
+ Assert.Throws<ArgumentNullException>(() => builder.WeakAddRepeatedField(f("repeated_string"), null));
+ Assert.Throws<ArgumentNullException>(() => builder.WeakAddRepeatedField(f("repeated_bytes"), null));
+ Assert.Throws<ArgumentNullException>(() => builder.WeakAddRepeatedField(f("repeated_nested_enum"), null));
+ Assert.Throws<ArgumentNullException>(() => builder.WeakAddRepeatedField(f("repeated_nested_message"), null));
}
/// <summary>
@@ -910,14 +910,14 @@ namespace Google.ProtocolBuffers public void AssertReflectionRepeatedSettersRejectNull(IBuilder builder)
{
builder.WeakAddRepeatedField(f("repeated_string"), "one");
- TestUtil.AssertArgumentNullException(() => builder.SetRepeatedField(f("repeated_string"), 0, null));
+ Assert.Throws<ArgumentNullException>(() => builder.SetRepeatedField(f("repeated_string"), 0, null));
builder.WeakAddRepeatedField(f("repeated_bytes"), TestUtil.ToBytes("one"));
- TestUtil.AssertArgumentNullException(() => builder.SetRepeatedField(f("repeated_bytes"), 0, null));
+ Assert.Throws<ArgumentNullException>(() => builder.SetRepeatedField(f("repeated_bytes"), 0, null));
builder.WeakAddRepeatedField(f("repeated_nested_enum"), nestedBaz);
- TestUtil.AssertArgumentNullException(() => builder.SetRepeatedField(f("repeated_nested_enum"), 0, null));
+ Assert.Throws<ArgumentNullException>(() => builder.SetRepeatedField(f("repeated_nested_enum"), 0, null));
builder.WeakAddRepeatedField(f("repeated_nested_message"),
new TestAllTypes.Types.NestedMessage.Builder {Bb = 218}.Build());
- TestUtil.AssertArgumentNullException(() => builder.SetRepeatedField(f("repeated_nested_message"), 0, null));
+ Assert.Throws<ArgumentNullException>(() => builder.SetRepeatedField(f("repeated_nested_message"), 0, null));
}
public void SetPackedFieldsViaReflection(IBuilder message)
@@ -955,50 +955,50 @@ namespace Google.ProtocolBuffers public void AssertPackedFieldsSetViaReflection(IMessage message)
{
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_int32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_int64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_uint32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_uint64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_sint32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_sint64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_fixed32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_fixed64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_sfixed32")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_sfixed64")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_float")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_double")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_bool")));
- Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_enum")));
-
- Assert.AreEqual(601, message[f("packed_int32"), 0]);
- Assert.AreEqual(602L, message[f("packed_int64"), 0]);
- Assert.AreEqual(603u, message[f("packed_uint32"), 0]);
- Assert.AreEqual(604uL, message[f("packed_uint64"), 0]);
- Assert.AreEqual(605, message[f("packed_sint32"), 0]);
- Assert.AreEqual(606L, message[f("packed_sint64"), 0]);
- Assert.AreEqual(607u, message[f("packed_fixed32"), 0]);
- Assert.AreEqual(608uL, message[f("packed_fixed64"), 0]);
- Assert.AreEqual(609, message[f("packed_sfixed32"), 0]);
- Assert.AreEqual(610L, message[f("packed_sfixed64"), 0]);
- Assert.AreEqual(611F, message[f("packed_float"), 0]);
- Assert.AreEqual(612D, message[f("packed_double"), 0]);
- Assert.AreEqual(true, message[f("packed_bool"), 0]);
- Assert.AreEqual(foreignBar, message[f("packed_enum"), 0]);
-
- Assert.AreEqual(701, message[f("packed_int32"), 1]);
- Assert.AreEqual(702L, message[f("packed_int64"), 1]);
- Assert.AreEqual(703u, message[f("packed_uint32"), 1]);
- Assert.AreEqual(704uL, message[f("packed_uint64"), 1]);
- Assert.AreEqual(705, message[f("packed_sint32"), 1]);
- Assert.AreEqual(706L, message[f("packed_sint64"), 1]);
- Assert.AreEqual(707u, message[f("packed_fixed32"), 1]);
- Assert.AreEqual(708uL, message[f("packed_fixed64"), 1]);
- Assert.AreEqual(709, message[f("packed_sfixed32"), 1]);
- Assert.AreEqual(710L, message[f("packed_sfixed64"), 1]);
- Assert.AreEqual(711F, message[f("packed_float"), 1]);
- Assert.AreEqual(712D, message[f("packed_double"), 1]);
- Assert.AreEqual(false, message[f("packed_bool"), 1]);
- Assert.AreEqual(foreignBaz, message[f("packed_enum"), 1]);
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_int32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_int64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_uint32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_uint64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_sint32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_sint64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_fixed32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_fixed64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_sfixed32")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_sfixed64")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_float")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_double")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_bool")));
+ Assert.Equal(2, message.GetRepeatedFieldCount(f("packed_enum")));
+
+ Assert.Equal(601, message[f("packed_int32"), 0]);
+ Assert.Equal(602L, message[f("packed_int64"), 0]);
+ Assert.Equal(603u, message[f("packed_uint32"), 0]);
+ Assert.Equal(604uL, message[f("packed_uint64"), 0]);
+ Assert.Equal(605, message[f("packed_sint32"), 0]);
+ Assert.Equal(606L, message[f("packed_sint64"), 0]);
+ Assert.Equal(607u, message[f("packed_fixed32"), 0]);
+ Assert.Equal(608uL, message[f("packed_fixed64"), 0]);
+ Assert.Equal(609, message[f("packed_sfixed32"), 0]);
+ Assert.Equal(610L, message[f("packed_sfixed64"), 0]);
+ Assert.Equal(611F, message[f("packed_float"), 0]);
+ Assert.Equal(612D, message[f("packed_double"), 0]);
+ Assert.Equal(true, message[f("packed_bool"), 0]);
+ Assert.Equal(foreignBar, message[f("packed_enum"), 0]);
+
+ Assert.Equal(701, message[f("packed_int32"), 1]);
+ Assert.Equal(702L, message[f("packed_int64"), 1]);
+ Assert.Equal(703u, message[f("packed_uint32"), 1]);
+ Assert.Equal(704uL, message[f("packed_uint64"), 1]);
+ Assert.Equal(705, message[f("packed_sint32"), 1]);
+ Assert.Equal(706L, message[f("packed_sint64"), 1]);
+ Assert.Equal(707u, message[f("packed_fixed32"), 1]);
+ Assert.Equal(708uL, message[f("packed_fixed64"), 1]);
+ Assert.Equal(709, message[f("packed_sfixed32"), 1]);
+ Assert.Equal(710L, message[f("packed_sfixed64"), 1]);
+ Assert.Equal(711F, message[f("packed_float"), 1]);
+ Assert.Equal(712D, message[f("packed_double"), 1]);
+ Assert.Equal(false, message[f("packed_bool"), 1]);
+ Assert.Equal(foreignBaz, message[f("packed_enum"), 1]);
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/ReusableBuilderTest.cs b/csharp/src/ProtocolBuffers.Test/ReusableBuilderTest.cs index a63f6575..e6b6a1b3 100644 --- a/csharp/src/ProtocolBuffers.Test/ReusableBuilderTest.cs +++ b/csharp/src/ProtocolBuffers.Test/ReusableBuilderTest.cs @@ -1,48 +1,43 @@ using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Text;
using Google.ProtocolBuffers.Collections;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Google.ProtocolBuffers.TestProtos;
-using Google.ProtocolBuffers.Serialization;
using UnitTest.Issues.TestProtos;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class ReusableBuilderTest
{
//Issue 28: Circular message dependencies result in null defaults for DefaultInstance
- [TestMethod]
+ [Fact]
public void EnsureStaticCicularReference()
{
MyMessageAReferenceB ab = MyMessageAReferenceB.DefaultInstance;
- Assert.IsNotNull(ab);
- Assert.IsNotNull(ab.Value);
+ Assert.NotNull(ab);
+ Assert.NotNull(ab.Value);
MyMessageBReferenceA ba = MyMessageBReferenceA.DefaultInstance;
- Assert.IsNotNull(ba);
- Assert.IsNotNull(ba.Value);
+ Assert.NotNull(ba);
+ Assert.NotNull(ba.Value);
}
- [TestMethod]
+ [Fact]
public void TestModifyDefaultInstance()
{
//verify that the default instance has correctly been marked as read-only
- Assert.AreEqual(typeof(PopsicleList<bool>), TestAllTypes.DefaultInstance.RepeatedBoolList.GetType());
+ Assert.Equal(typeof(PopsicleList<bool>), TestAllTypes.DefaultInstance.RepeatedBoolList.GetType());
PopsicleList<bool> list = (PopsicleList<bool>)TestAllTypes.DefaultInstance.RepeatedBoolList;
- Assert.IsTrue(list.IsReadOnly);
+ Assert.True(list.IsReadOnly);
}
- [TestMethod]
+ [Fact]
public void TestUnmodifiedDefaultInstance()
{
//Simply calling ToBuilder().Build() no longer creates a copy of the message
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
- [TestMethod]
+ [Fact]
public void BuildMultipleWithoutChange()
{
//Calling Build() or BuildPartial() does not require a copy of the message
@@ -51,31 +46,31 @@ namespace Google.ProtocolBuffers TestAllTypes first = builder.BuildPartial();
//Still the same instance?
- Assert.IsTrue(ReferenceEquals(first, builder.Build()));
+ Assert.True(ReferenceEquals(first, builder.Build()));
//Still the same instance?
- Assert.IsTrue(ReferenceEquals(first, builder.BuildPartial().ToBuilder().Build()));
+ Assert.True(ReferenceEquals(first, builder.BuildPartial().ToBuilder().Build()));
}
- [TestMethod]
+ [Fact]
public void MergeFromDefaultInstance()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.MergeFrom(TestAllTypes.DefaultInstance);
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
- [TestMethod]
+ [Fact]
public void BuildNewBuilderIsDefaultInstance()
{
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, new TestAllTypes.Builder().Build()));
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, TestAllTypes.CreateBuilder().Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, new TestAllTypes.Builder().Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, TestAllTypes.CreateBuilder().Build()));
//last test, if you clear a builder it reverts to default instance
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance,
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance,
TestAllTypes.CreateBuilder().SetOptionalBool(true).Build().ToBuilder().Clear().Build()));
}
- [TestMethod]
+ [Fact]
public void BuildModifyAndRebuild()
{
TestAllTypes.Builder b1 = new TestAllTypes.Builder();
@@ -91,80 +86,80 @@ namespace Google.ProtocolBuffers TestAllTypes m2 = b1.Build();
- Assert.AreEqual("{\"optional_foreign_message\":{},\"repeated_int32\":[2],\"default_int32\":1}", Extensions.ToJson(m1));
- Assert.AreEqual("{\"optional_foreign_message\":{\"c\":7},\"repeated_int32\":[2,6],\"default_int32\":5}", Extensions.ToJson(m2));
+ Assert.Equal("{\"optional_foreign_message\":{},\"repeated_int32\":[2],\"default_int32\":1}", Extensions.ToJson(m1));
+ Assert.Equal("{\"optional_foreign_message\":{\"c\":7},\"repeated_int32\":[2,6],\"default_int32\":5}", Extensions.ToJson(m2));
}
- [TestMethod]
+ [Fact]
public void CloneOnChangePrimitive()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.SetDefaultBool(true);
- Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
- [TestMethod]
+ [Fact]
public void CloneOnAddRepeatedBool()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.AddRepeatedBool(true);
- Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
- [TestMethod]
+ [Fact]
public void CloneOnGetRepeatedBoolList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedBoolList);
- Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
- [TestMethod]
+ [Fact]
public void CloneOnChangeMessage()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.SetOptionalForeignMessage(new ForeignMessage.Builder());
- Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
- [TestMethod]
+ [Fact]
public void CloneOnClearMessage()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.ClearOptionalForeignMessage();
- Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
- [TestMethod]
+ [Fact]
public void CloneOnGetRepeatedForeignMessageList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedForeignMessageList);
- Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
- [TestMethod]
+ [Fact]
public void CloneOnChangeEnumValue()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.SetOptionalForeignEnum(ForeignEnum.FOREIGN_BAR);
- Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
- [TestMethod]
+ [Fact]
public void CloneOnGetRepeatedForeignEnumList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
- Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedForeignEnumList);
- Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
+ Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/TestCornerCases.cs b/csharp/src/ProtocolBuffers.Test/TestCornerCases.cs index 0be4e1d4..5bec24f1 100644 --- a/csharp/src/ProtocolBuffers.Test/TestCornerCases.cs +++ b/csharp/src/ProtocolBuffers.Test/TestCornerCases.cs @@ -1,15 +1,11 @@ -using System;
-using System.Collections.Generic;
-using System.Text;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using UnitTest.Issues.TestProtos;
+using UnitTest.Issues.TestProtos;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class TestCornerCases
{
- [TestMethod]
+ [Fact]
public void TestRoundTripNegativeEnums()
{
NegativeEnumMessage msg = NegativeEnumMessage.CreateBuilder()
@@ -23,16 +19,16 @@ namespace Google.ProtocolBuffers .AddPackedValues(NegativeEnum.FiveBelow) //10
.Build();
- Assert.AreEqual(58, msg.SerializedSize);
+ Assert.Equal(58, msg.SerializedSize);
byte[] bytes = new byte[58];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
msg.WriteTo(output);
- Assert.AreEqual(0, output.SpaceLeft);
+ Assert.Equal(0, output.SpaceLeft);
NegativeEnumMessage copy = NegativeEnumMessage.ParseFrom(bytes);
- Assert.AreEqual(msg, copy);
+ Assert.Equal(msg, copy);
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/TestMimeMessageFormats.cs b/csharp/src/ProtocolBuffers.Test/TestMimeMessageFormats.cs index c16f567f..5caa2e23 100644 --- a/csharp/src/ProtocolBuffers.Test/TestMimeMessageFormats.cs +++ b/csharp/src/ProtocolBuffers.Test/TestMimeMessageFormats.cs @@ -5,11 +5,10 @@ using System.Text; using Google.ProtocolBuffers.Serialization;
using Google.ProtocolBuffers.Serialization.Http;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class TestMimeMessageFormats
{
// There is a whole host of various json mime types in use around the net, this is the set we accept...
@@ -17,85 +16,91 @@ namespace Google.ProtocolBuffers readonly IEnumerable<string> XmlTypes = new string[] { "text/xml", "application/xml" };
readonly IEnumerable<string> ProtobufTypes = new string[] { "application/binary", "application/x-protobuf", "application/vnd.google.protobuf" };
- [TestMethod]
+ [Fact]
public void TestReadJsonMimeTypes()
{
foreach (string type in JsonTypes)
{
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateInputStream(new MessageFormatOptions(), type, Stream.Null)
is JsonFormatReader);
}
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateInputStream(new MessageFormatOptions() { DefaultContentType = "application/json" }, null, Stream.Null)
is JsonFormatReader);
}
- [TestMethod]
+
+ [Fact]
public void TestWriteJsonMimeTypes()
{
foreach (string type in JsonTypes)
{
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateOutputStream(new MessageFormatOptions(), type, Stream.Null)
is JsonFormatWriter);
}
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateOutputStream(new MessageFormatOptions() { DefaultContentType = "application/json" }, null, Stream.Null)
is JsonFormatWriter);
}
- [TestMethod]
+
+ [Fact]
public void TestReadXmlMimeTypes()
{
foreach (string type in XmlTypes)
{
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateInputStream(new MessageFormatOptions(), type, Stream.Null)
is XmlFormatReader);
}
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateInputStream(new MessageFormatOptions() { DefaultContentType = "application/xml" }, null, Stream.Null)
is XmlFormatReader);
}
- [TestMethod]
+
+ [Fact]
public void TestWriteXmlMimeTypes()
{
foreach (string type in XmlTypes)
{
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateOutputStream(new MessageFormatOptions(), type, Stream.Null)
is XmlFormatWriter);
}
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateOutputStream(new MessageFormatOptions() { DefaultContentType = "application/xml" }, null, Stream.Null)
is XmlFormatWriter);
}
- [TestMethod]
+
+ [Fact]
public void TestReadProtoMimeTypes()
{
foreach (string type in ProtobufTypes)
{
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateInputStream(new MessageFormatOptions(), type, Stream.Null)
is CodedInputStream);
}
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateInputStream(new MessageFormatOptions() { DefaultContentType = "application/vnd.google.protobuf" }, null, Stream.Null)
is CodedInputStream);
}
- [TestMethod]
+
+ [Fact]
public void TestWriteProtoMimeTypes()
{
foreach (string type in ProtobufTypes)
{
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateOutputStream(new MessageFormatOptions(), type, Stream.Null)
is CodedOutputStream);
}
- Assert.IsTrue(
+ Assert.True(
MessageFormatFactory.CreateOutputStream(new MessageFormatOptions() { DefaultContentType = "application/vnd.google.protobuf" }, null, Stream.Null)
is CodedOutputStream);
}
- [TestMethod]
+
+ [Fact]
public void TestMergeFromJsonType()
{
TestXmlMessage msg = Extensions.MergeFrom(new TestXmlMessage.Builder(),
@@ -103,10 +108,11 @@ namespace Google.ProtocolBuffers Extensions.ToJson(TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build())
)))
.Build();
- Assert.AreEqual("a", msg.Text);
- Assert.AreEqual(1, msg.Number);
+ Assert.Equal("a", msg.Text);
+ Assert.Equal(1, msg.Number);
}
- [TestMethod]
+
+ [Fact]
public void TestMergeFromXmlType()
{
TestXmlMessage msg = Extensions.MergeFrom(new TestXmlMessage.Builder(),
@@ -114,10 +120,10 @@ namespace Google.ProtocolBuffers Extensions.ToXml(TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build())
)))
.Build();
- Assert.AreEqual("a", msg.Text);
- Assert.AreEqual(1, msg.Number);
+ Assert.Equal("a", msg.Text);
+ Assert.Equal(1, msg.Number);
}
- [TestMethod]
+ [Fact]
public void TestMergeFromProtoType()
{
TestXmlMessage msg = Extensions.MergeFrom(new TestXmlMessage.Builder(),
@@ -125,28 +131,30 @@ namespace Google.ProtocolBuffers TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build().ToByteArray()
))
.Build();
- Assert.AreEqual("a", msg.Text);
- Assert.AreEqual(1, msg.Number);
+ Assert.Equal("a", msg.Text);
+ Assert.Equal(1, msg.Number);
}
- [TestMethod]
+
+ [Fact]
public void TestWriteToJsonType()
{
MemoryStream ms = new MemoryStream();
Extensions.WriteTo(TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build(),
new MessageFormatOptions(), "application/json", ms);
- Assert.AreEqual(@"{""text"":""a"",""number"":1}", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
+ Assert.Equal(@"{""text"":""a"",""number"":1}", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
}
- [TestMethod]
+
+ [Fact]
public void TestWriteToXmlType()
{
MemoryStream ms = new MemoryStream();
Extensions.WriteTo(TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build(),
new MessageFormatOptions(), "application/xml", ms);
- Assert.AreEqual("<root><text>a</text><number>1</number></root>", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
+ Assert.Equal("<root><text>a</text><number>1</number></root>", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
}
- [TestMethod]
+ [Fact]
public void TestWriteToProtoType()
{
MemoryStream ms = new MemoryStream();
@@ -154,9 +162,10 @@ namespace Google.ProtocolBuffers new MessageFormatOptions(), "application/vnd.google.protobuf", ms);
byte[] bytes = TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build().ToByteArray();
- TestUtil.AssertBytesEqual(bytes, ms.ToArray());
+ Assert.Equal(bytes, ms.ToArray());
}
- [TestMethod]
+
+ [Fact]
public void TestXmlReaderOptions()
{
MemoryStream ms = new MemoryStream();
@@ -175,12 +184,13 @@ namespace Google.ProtocolBuffers options, "application/xml", ms)
.Build();
- Assert.AreEqual("a", msg.Text);
- Assert.AreEqual(1, msg.NumbersList[0]);
- Assert.AreEqual(2, msg.NumbersList[1]);
+ Assert.Equal("a", msg.Text);
+ Assert.Equal(1, msg.NumbersList[0]);
+ Assert.Equal(2, msg.NumbersList[1]);
}
- [TestMethod]
+
+ [Fact]
public void TestXmlWriterOptions()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder().SetText("a").AddNumbers(1).AddNumbers(2).Build();
@@ -199,30 +209,32 @@ namespace Google.ProtocolBuffers .SetOptions(XmlReaderOptions.ReadNestedArrays)
.Merge("root-node", builder);
- Assert.AreEqual("a", builder.Text);
- Assert.AreEqual(1, builder.NumbersList[0]);
- Assert.AreEqual(2, builder.NumbersList[1]);
+ Assert.Equal("a", builder.Text);
+ Assert.Equal(1, builder.NumbersList[0]);
+ Assert.Equal(2, builder.NumbersList[1]);
}
- [TestMethod]
+
+ [Fact]
public void TestJsonFormatted()
{
MemoryStream ms = new MemoryStream();
Extensions.WriteTo(TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build(),
new MessageFormatOptions() { FormattedOutput = true }, "application/json", ms);
- Assert.AreEqual("{\r\n \"text\": \"a\",\r\n \"number\": 1\r\n}", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
+ Assert.Equal("{\r\n \"text\": \"a\",\r\n \"number\": 1\r\n}", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
}
- [TestMethod]
+
+ [Fact]
public void TestXmlFormatted()
{
MemoryStream ms = new MemoryStream();
Extensions.WriteTo(TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build(),
new MessageFormatOptions() { FormattedOutput = true }, "application/xml", ms);
- Assert.AreEqual("<root>\r\n <text>a</text>\r\n <number>1</number>\r\n</root>", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
+ Assert.Equal("<root>\r\n <text>a</text>\r\n <number>1</number>\r\n</root>", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
}
- [TestMethod]
+ [Fact]
public void TestReadCustomMimeTypes()
{
var options = new MessageFormatOptions();
@@ -230,7 +242,7 @@ namespace Google.ProtocolBuffers options.MimeInputTypes.Clear();
//Add our own
options.MimeInputTypes.Add("-custom-XML-mime-type-", XmlFormatReader.CreateInstance);
- Assert.AreEqual(1, options.MimeInputTypes.Count);
+ Assert.Equal(1, options.MimeInputTypes.Count);
Stream xmlStream = new MemoryStream(Encoding.UTF8.GetBytes(
Extensions.ToXml(TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build())
@@ -239,11 +251,11 @@ namespace Google.ProtocolBuffers TestXmlMessage msg = Extensions.MergeFrom(new TestXmlMessage.Builder(),
options, "-custom-XML-mime-type-", xmlStream)
.Build();
- Assert.AreEqual("a", msg.Text);
- Assert.AreEqual(1, msg.Number);
+ Assert.Equal("a", msg.Text);
+ Assert.Equal(1, msg.Number);
}
- [TestMethod]
+ [Fact]
public void TestWriteToCustomType()
{
var options = new MessageFormatOptions();
@@ -252,13 +264,13 @@ namespace Google.ProtocolBuffers //Add our own
options.MimeOutputTypes.Add("-custom-XML-mime-type-", XmlFormatWriter.CreateInstance);
- Assert.AreEqual(1, options.MimeOutputTypes.Count);
+ Assert.Equal(1, options.MimeOutputTypes.Count);
MemoryStream ms = new MemoryStream();
Extensions.WriteTo(TestXmlMessage.CreateBuilder().SetText("a").SetNumber(1).Build(),
options, "-custom-XML-mime-type-", ms);
- Assert.AreEqual("<root><text>a</text><number>1</number></root>", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
+ Assert.Equal("<root><text>a</text><number>1</number></root>", Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
}
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/TestReaderForUrlEncoded.cs b/csharp/src/ProtocolBuffers.Test/TestReaderForUrlEncoded.cs index 1c43e24d..b262667a 100644 --- a/csharp/src/ProtocolBuffers.Test/TestReaderForUrlEncoded.cs +++ b/csharp/src/ProtocolBuffers.Test/TestReaderForUrlEncoded.cs @@ -1,16 +1,15 @@ using System;
using System.IO;
using System.Text;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Google.ProtocolBuffers.TestProtos;
using Google.ProtocolBuffers.Serialization.Http;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class TestReaderForUrlEncoded
{
- [TestMethod]
+ [Fact]
public void Example_FromQueryString()
{
Uri sampleUri = new Uri("http://sample.com/Path/File.ext?text=two+three%20four&valid=true&numbers=1&numbers=2", UriKind.Absolute);
@@ -21,14 +20,14 @@ namespace Google.ProtocolBuffers builder.MergeFrom(input);
TestXmlMessage message = builder.Build();
- Assert.AreEqual(true, message.Valid);
- Assert.AreEqual("two three four", message.Text);
- Assert.AreEqual(2, message.NumbersCount);
- Assert.AreEqual(1, message.NumbersList[0]);
- Assert.AreEqual(2, message.NumbersList[1]);
+ Assert.Equal(true, message.Valid);
+ Assert.Equal("two three four", message.Text);
+ Assert.Equal(2, message.NumbersCount);
+ Assert.Equal(1, message.NumbersList[0]);
+ Assert.Equal(2, message.NumbersList[1]);
}
- [TestMethod]
+ [Fact]
public void Example_FromFormData()
{
Stream rawPost = new MemoryStream(Encoding.UTF8.GetBytes("text=two+three%20four&valid=true&numbers=1&numbers=2"), false);
@@ -39,46 +38,46 @@ namespace Google.ProtocolBuffers builder.MergeFrom(input);
TestXmlMessage message = builder.Build();
- Assert.AreEqual(true, message.Valid);
- Assert.AreEqual("two three four", message.Text);
- Assert.AreEqual(2, message.NumbersCount);
- Assert.AreEqual(1, message.NumbersList[0]);
- Assert.AreEqual(2, message.NumbersList[1]);
+ Assert.Equal(true, message.Valid);
+ Assert.Equal("two three four", message.Text);
+ Assert.Equal(2, message.NumbersCount);
+ Assert.Equal(1, message.NumbersList[0]);
+ Assert.Equal(2, message.NumbersList[1]);
}
- [TestMethod]
+ [Fact]
public void TestEmptyValues()
{
ICodedInputStream input = FormUrlEncodedReader.CreateInstance("valid=true&text=&numbers=1");
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
builder.MergeFrom(input);
- Assert.IsTrue(builder.Valid);
- Assert.IsTrue(builder.HasText);
- Assert.AreEqual("", builder.Text);
- Assert.AreEqual(1, builder.NumbersCount);
- Assert.AreEqual(1, builder.NumbersList[0]);
+ Assert.True(builder.Valid);
+ Assert.True(builder.HasText);
+ Assert.Equal("", builder.Text);
+ Assert.Equal(1, builder.NumbersCount);
+ Assert.Equal(1, builder.NumbersList[0]);
}
- [TestMethod]
+ [Fact]
public void TestNoValue()
{
ICodedInputStream input = FormUrlEncodedReader.CreateInstance("valid=true&text&numbers=1");
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
builder.MergeFrom(input);
- Assert.IsTrue(builder.Valid);
- Assert.IsTrue(builder.HasText);
- Assert.AreEqual("", builder.Text);
- Assert.AreEqual(1, builder.NumbersCount);
- Assert.AreEqual(1, builder.NumbersList[0]);
+ Assert.True(builder.Valid);
+ Assert.True(builder.HasText);
+ Assert.Equal("", builder.Text);
+ Assert.Equal(1, builder.NumbersCount);
+ Assert.Equal(1, builder.NumbersList[0]);
}
- [TestMethod, ExpectedException(typeof(NotSupportedException))]
+ [Fact]
public void FormUrlEncodedReaderDoesNotSupportChildren()
{
ICodedInputStream input = FormUrlEncodedReader.CreateInstance("child=uh0");
- TestXmlMessage.CreateBuilder().MergeFrom(input);
+ Assert.Throws<NotSupportedException>(() => TestXmlMessage.CreateBuilder().MergeFrom(input));
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/TestUtil.cs b/csharp/src/ProtocolBuffers.Test/TestUtil.cs index ec30cbcd..83509c18 100644 --- a/csharp/src/ProtocolBuffers.Test/TestUtil.cs +++ b/csharp/src/ProtocolBuffers.Test/TestUtil.cs @@ -41,7 +41,7 @@ using System.IO; using System.Text;
using System.Threading;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
@@ -324,343 +324,343 @@ namespace Google.ProtocolBuffers /// </summary>
internal static void AssertAllFieldsSet(TestAllTypes message)
{
- Assert.IsTrue(message.HasOptionalInt32);
- Assert.IsTrue(message.HasOptionalInt64);
- Assert.IsTrue(message.HasOptionalUint32);
- Assert.IsTrue(message.HasOptionalUint64);
- Assert.IsTrue(message.HasOptionalSint32);
- Assert.IsTrue(message.HasOptionalSint64);
- Assert.IsTrue(message.HasOptionalFixed32);
- Assert.IsTrue(message.HasOptionalFixed64);
- Assert.IsTrue(message.HasOptionalSfixed32);
- Assert.IsTrue(message.HasOptionalSfixed64);
- Assert.IsTrue(message.HasOptionalFloat);
- Assert.IsTrue(message.HasOptionalDouble);
- Assert.IsTrue(message.HasOptionalBool);
- Assert.IsTrue(message.HasOptionalString);
- Assert.IsTrue(message.HasOptionalBytes);
-
- Assert.IsTrue(message.HasOptionalGroup);
- Assert.IsTrue(message.HasOptionalNestedMessage);
- Assert.IsTrue(message.HasOptionalForeignMessage);
- Assert.IsTrue(message.HasOptionalImportMessage);
-
- Assert.IsTrue(message.OptionalGroup.HasA);
- Assert.IsTrue(message.OptionalNestedMessage.HasBb);
- Assert.IsTrue(message.OptionalForeignMessage.HasC);
- Assert.IsTrue(message.OptionalImportMessage.HasD);
-
- Assert.IsTrue(message.HasOptionalNestedEnum);
- Assert.IsTrue(message.HasOptionalForeignEnum);
- Assert.IsTrue(message.HasOptionalImportEnum);
-
- Assert.IsTrue(message.HasOptionalStringPiece);
- Assert.IsTrue(message.HasOptionalCord);
-
- Assert.AreEqual(101, message.OptionalInt32);
- Assert.AreEqual(102, message.OptionalInt64);
- Assert.AreEqual(103u, message.OptionalUint32);
- Assert.AreEqual(104u, message.OptionalUint64);
- Assert.AreEqual(105, message.OptionalSint32);
- Assert.AreEqual(106, message.OptionalSint64);
- Assert.AreEqual(107u, message.OptionalFixed32);
- Assert.AreEqual(108u, message.OptionalFixed64);
- Assert.AreEqual(109, message.OptionalSfixed32);
- Assert.AreEqual(110, message.OptionalSfixed64);
- Assert.AreEqual(111, message.OptionalFloat);
- Assert.AreEqual(112, message.OptionalDouble);
- Assert.AreEqual(true, message.OptionalBool);
- Assert.AreEqual("115", message.OptionalString);
- Assert.AreEqual(ToBytes("116"), message.OptionalBytes);
-
- Assert.AreEqual(117, message.OptionalGroup.A);
- Assert.AreEqual(118, message.OptionalNestedMessage.Bb);
- Assert.AreEqual(119, message.OptionalForeignMessage.C);
- Assert.AreEqual(120, message.OptionalImportMessage.D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAZ, message.OptionalNestedEnum);
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ, message.OptionalForeignEnum);
- Assert.AreEqual(ImportEnum.IMPORT_BAZ, message.OptionalImportEnum);
-
- Assert.AreEqual("124", message.OptionalStringPiece);
- Assert.AreEqual("125", message.OptionalCord);
+ Assert.True(message.HasOptionalInt32);
+ Assert.True(message.HasOptionalInt64);
+ Assert.True(message.HasOptionalUint32);
+ Assert.True(message.HasOptionalUint64);
+ Assert.True(message.HasOptionalSint32);
+ Assert.True(message.HasOptionalSint64);
+ Assert.True(message.HasOptionalFixed32);
+ Assert.True(message.HasOptionalFixed64);
+ Assert.True(message.HasOptionalSfixed32);
+ Assert.True(message.HasOptionalSfixed64);
+ Assert.True(message.HasOptionalFloat);
+ Assert.True(message.HasOptionalDouble);
+ Assert.True(message.HasOptionalBool);
+ Assert.True(message.HasOptionalString);
+ Assert.True(message.HasOptionalBytes);
+
+ Assert.True(message.HasOptionalGroup);
+ Assert.True(message.HasOptionalNestedMessage);
+ Assert.True(message.HasOptionalForeignMessage);
+ Assert.True(message.HasOptionalImportMessage);
+
+ Assert.True(message.OptionalGroup.HasA);
+ Assert.True(message.OptionalNestedMessage.HasBb);
+ Assert.True(message.OptionalForeignMessage.HasC);
+ Assert.True(message.OptionalImportMessage.HasD);
+
+ Assert.True(message.HasOptionalNestedEnum);
+ Assert.True(message.HasOptionalForeignEnum);
+ Assert.True(message.HasOptionalImportEnum);
+
+ Assert.True(message.HasOptionalStringPiece);
+ Assert.True(message.HasOptionalCord);
+
+ Assert.Equal(101, message.OptionalInt32);
+ Assert.Equal(102, message.OptionalInt64);
+ Assert.Equal(103u, message.OptionalUint32);
+ Assert.Equal(104u, message.OptionalUint64);
+ Assert.Equal(105, message.OptionalSint32);
+ Assert.Equal(106, message.OptionalSint64);
+ Assert.Equal(107u, message.OptionalFixed32);
+ Assert.Equal(108u, message.OptionalFixed64);
+ Assert.Equal(109, message.OptionalSfixed32);
+ Assert.Equal(110, message.OptionalSfixed64);
+ Assert.Equal(111, message.OptionalFloat);
+ Assert.Equal(112, message.OptionalDouble);
+ Assert.Equal(true, message.OptionalBool);
+ Assert.Equal("115", message.OptionalString);
+ Assert.Equal(ToBytes("116"), message.OptionalBytes);
+
+ Assert.Equal(117, message.OptionalGroup.A);
+ Assert.Equal(118, message.OptionalNestedMessage.Bb);
+ Assert.Equal(119, message.OptionalForeignMessage.C);
+ Assert.Equal(120, message.OptionalImportMessage.D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAZ, message.OptionalNestedEnum);
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ, message.OptionalForeignEnum);
+ Assert.Equal(ImportEnum.IMPORT_BAZ, message.OptionalImportEnum);
+
+ Assert.Equal("124", message.OptionalStringPiece);
+ Assert.Equal("125", message.OptionalCord);
// -----------------------------------------------------------------
- Assert.AreEqual(2, message.RepeatedInt32Count);
- Assert.AreEqual(2, message.RepeatedInt64Count);
- Assert.AreEqual(2, message.RepeatedUint32Count);
- Assert.AreEqual(2, message.RepeatedUint64Count);
- Assert.AreEqual(2, message.RepeatedSint32Count);
- Assert.AreEqual(2, message.RepeatedSint64Count);
- Assert.AreEqual(2, message.RepeatedFixed32Count);
- Assert.AreEqual(2, message.RepeatedFixed64Count);
- Assert.AreEqual(2, message.RepeatedSfixed32Count);
- Assert.AreEqual(2, message.RepeatedSfixed64Count);
- Assert.AreEqual(2, message.RepeatedFloatCount);
- Assert.AreEqual(2, message.RepeatedDoubleCount);
- Assert.AreEqual(2, message.RepeatedBoolCount);
- Assert.AreEqual(2, message.RepeatedStringCount);
- Assert.AreEqual(2, message.RepeatedBytesCount);
-
- Assert.AreEqual(2, message.RepeatedGroupCount);
- Assert.AreEqual(2, message.RepeatedNestedMessageCount);
- Assert.AreEqual(2, message.RepeatedForeignMessageCount);
- Assert.AreEqual(2, message.RepeatedImportMessageCount);
- Assert.AreEqual(2, message.RepeatedNestedEnumCount);
- Assert.AreEqual(2, message.RepeatedForeignEnumCount);
- Assert.AreEqual(2, message.RepeatedImportEnumCount);
-
- Assert.AreEqual(2, message.RepeatedStringPieceCount);
- Assert.AreEqual(2, message.RepeatedCordCount);
-
- Assert.AreEqual(201, message.GetRepeatedInt32(0));
- Assert.AreEqual(202, message.GetRepeatedInt64(0));
- Assert.AreEqual(203u, message.GetRepeatedUint32(0));
- Assert.AreEqual(204u, message.GetRepeatedUint64(0));
- Assert.AreEqual(205, message.GetRepeatedSint32(0));
- Assert.AreEqual(206, message.GetRepeatedSint64(0));
- Assert.AreEqual(207u, message.GetRepeatedFixed32(0));
- Assert.AreEqual(208u, message.GetRepeatedFixed64(0));
- Assert.AreEqual(209, message.GetRepeatedSfixed32(0));
- Assert.AreEqual(210, message.GetRepeatedSfixed64(0));
- Assert.AreEqual(211, message.GetRepeatedFloat(0));
- Assert.AreEqual(212, message.GetRepeatedDouble(0));
- Assert.AreEqual(true, message.GetRepeatedBool(0));
- Assert.AreEqual("215", message.GetRepeatedString(0));
- Assert.AreEqual(ToBytes("216"), message.GetRepeatedBytes(0));
-
- Assert.AreEqual(217, message.GetRepeatedGroup(0).A);
- Assert.AreEqual(218, message.GetRepeatedNestedMessage(0).Bb);
- Assert.AreEqual(219, message.GetRepeatedForeignMessage(0).C);
- Assert.AreEqual(220, message.GetRepeatedImportMessage(0).D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR, message.GetRepeatedNestedEnum(0));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR, message.GetRepeatedForeignEnum(0));
- Assert.AreEqual(ImportEnum.IMPORT_BAR, message.GetRepeatedImportEnum(0));
-
- Assert.AreEqual("224", message.GetRepeatedStringPiece(0));
- Assert.AreEqual("225", message.GetRepeatedCord(0));
-
- Assert.AreEqual(301, message.GetRepeatedInt32(1));
- Assert.AreEqual(302, message.GetRepeatedInt64(1));
- Assert.AreEqual(303u, message.GetRepeatedUint32(1));
- Assert.AreEqual(304u, message.GetRepeatedUint64(1));
- Assert.AreEqual(305, message.GetRepeatedSint32(1));
- Assert.AreEqual(306, message.GetRepeatedSint64(1));
- Assert.AreEqual(307u, message.GetRepeatedFixed32(1));
- Assert.AreEqual(308u, message.GetRepeatedFixed64(1));
- Assert.AreEqual(309, message.GetRepeatedSfixed32(1));
- Assert.AreEqual(310, message.GetRepeatedSfixed64(1));
- Assert.AreEqual(311, message.GetRepeatedFloat(1), 0.0);
- Assert.AreEqual(312, message.GetRepeatedDouble(1), 0.0);
- Assert.AreEqual(false, message.GetRepeatedBool(1));
- Assert.AreEqual("315", message.GetRepeatedString(1));
- Assert.AreEqual(ToBytes("316"), message.GetRepeatedBytes(1));
-
- Assert.AreEqual(317, message.GetRepeatedGroup(1).A);
- Assert.AreEqual(318, message.GetRepeatedNestedMessage(1).Bb);
- Assert.AreEqual(319, message.GetRepeatedForeignMessage(1).C);
- Assert.AreEqual(320, message.GetRepeatedImportMessage(1).D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAZ, message.GetRepeatedNestedEnum(1));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ, message.GetRepeatedForeignEnum(1));
- Assert.AreEqual(ImportEnum.IMPORT_BAZ, message.GetRepeatedImportEnum(1));
-
- Assert.AreEqual("324", message.GetRepeatedStringPiece(1));
- Assert.AreEqual("325", message.GetRepeatedCord(1));
+ Assert.Equal(2, message.RepeatedInt32Count);
+ Assert.Equal(2, message.RepeatedInt64Count);
+ Assert.Equal(2, message.RepeatedUint32Count);
+ Assert.Equal(2, message.RepeatedUint64Count);
+ Assert.Equal(2, message.RepeatedSint32Count);
+ Assert.Equal(2, message.RepeatedSint64Count);
+ Assert.Equal(2, message.RepeatedFixed32Count);
+ Assert.Equal(2, message.RepeatedFixed64Count);
+ Assert.Equal(2, message.RepeatedSfixed32Count);
+ Assert.Equal(2, message.RepeatedSfixed64Count);
+ Assert.Equal(2, message.RepeatedFloatCount);
+ Assert.Equal(2, message.RepeatedDoubleCount);
+ Assert.Equal(2, message.RepeatedBoolCount);
+ Assert.Equal(2, message.RepeatedStringCount);
+ Assert.Equal(2, message.RepeatedBytesCount);
+
+ Assert.Equal(2, message.RepeatedGroupCount);
+ Assert.Equal(2, message.RepeatedNestedMessageCount);
+ Assert.Equal(2, message.RepeatedForeignMessageCount);
+ Assert.Equal(2, message.RepeatedImportMessageCount);
+ Assert.Equal(2, message.RepeatedNestedEnumCount);
+ Assert.Equal(2, message.RepeatedForeignEnumCount);
+ Assert.Equal(2, message.RepeatedImportEnumCount);
+
+ Assert.Equal(2, message.RepeatedStringPieceCount);
+ Assert.Equal(2, message.RepeatedCordCount);
+
+ Assert.Equal(201, message.GetRepeatedInt32(0));
+ Assert.Equal(202, message.GetRepeatedInt64(0));
+ Assert.Equal(203u, message.GetRepeatedUint32(0));
+ Assert.Equal(204u, message.GetRepeatedUint64(0));
+ Assert.Equal(205, message.GetRepeatedSint32(0));
+ Assert.Equal(206, message.GetRepeatedSint64(0));
+ Assert.Equal(207u, message.GetRepeatedFixed32(0));
+ Assert.Equal(208u, message.GetRepeatedFixed64(0));
+ Assert.Equal(209, message.GetRepeatedSfixed32(0));
+ Assert.Equal(210, message.GetRepeatedSfixed64(0));
+ Assert.Equal(211, message.GetRepeatedFloat(0));
+ Assert.Equal(212, message.GetRepeatedDouble(0));
+ Assert.Equal(true, message.GetRepeatedBool(0));
+ Assert.Equal("215", message.GetRepeatedString(0));
+ Assert.Equal(ToBytes("216"), message.GetRepeatedBytes(0));
+
+ Assert.Equal(217, message.GetRepeatedGroup(0).A);
+ Assert.Equal(218, message.GetRepeatedNestedMessage(0).Bb);
+ Assert.Equal(219, message.GetRepeatedForeignMessage(0).C);
+ Assert.Equal(220, message.GetRepeatedImportMessage(0).D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAR, message.GetRepeatedNestedEnum(0));
+ Assert.Equal(ForeignEnum.FOREIGN_BAR, message.GetRepeatedForeignEnum(0));
+ Assert.Equal(ImportEnum.IMPORT_BAR, message.GetRepeatedImportEnum(0));
+
+ Assert.Equal("224", message.GetRepeatedStringPiece(0));
+ Assert.Equal("225", message.GetRepeatedCord(0));
+
+ Assert.Equal(301, message.GetRepeatedInt32(1));
+ Assert.Equal(302, message.GetRepeatedInt64(1));
+ Assert.Equal(303u, message.GetRepeatedUint32(1));
+ Assert.Equal(304u, message.GetRepeatedUint64(1));
+ Assert.Equal(305, message.GetRepeatedSint32(1));
+ Assert.Equal(306, message.GetRepeatedSint64(1));
+ Assert.Equal(307u, message.GetRepeatedFixed32(1));
+ Assert.Equal(308u, message.GetRepeatedFixed64(1));
+ Assert.Equal(309, message.GetRepeatedSfixed32(1));
+ Assert.Equal(310, message.GetRepeatedSfixed64(1));
+ Assert.Equal(311f, message.GetRepeatedFloat(1));
+ Assert.Equal(312d, message.GetRepeatedDouble(1));
+ Assert.Equal(false, message.GetRepeatedBool(1));
+ Assert.Equal("315", message.GetRepeatedString(1));
+ Assert.Equal(ToBytes("316"), message.GetRepeatedBytes(1));
+
+ Assert.Equal(317, message.GetRepeatedGroup(1).A);
+ Assert.Equal(318, message.GetRepeatedNestedMessage(1).Bb);
+ Assert.Equal(319, message.GetRepeatedForeignMessage(1).C);
+ Assert.Equal(320, message.GetRepeatedImportMessage(1).D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAZ, message.GetRepeatedNestedEnum(1));
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ, message.GetRepeatedForeignEnum(1));
+ Assert.Equal(ImportEnum.IMPORT_BAZ, message.GetRepeatedImportEnum(1));
+
+ Assert.Equal("324", message.GetRepeatedStringPiece(1));
+ Assert.Equal("325", message.GetRepeatedCord(1));
// -----------------------------------------------------------------
- Assert.IsTrue(message.HasDefaultInt32);
- Assert.IsTrue(message.HasDefaultInt64);
- Assert.IsTrue(message.HasDefaultUint32);
- Assert.IsTrue(message.HasDefaultUint64);
- Assert.IsTrue(message.HasDefaultSint32);
- Assert.IsTrue(message.HasDefaultSint64);
- Assert.IsTrue(message.HasDefaultFixed32);
- Assert.IsTrue(message.HasDefaultFixed64);
- Assert.IsTrue(message.HasDefaultSfixed32);
- Assert.IsTrue(message.HasDefaultSfixed64);
- Assert.IsTrue(message.HasDefaultFloat);
- Assert.IsTrue(message.HasDefaultDouble);
- Assert.IsTrue(message.HasDefaultBool);
- Assert.IsTrue(message.HasDefaultString);
- Assert.IsTrue(message.HasDefaultBytes);
-
- Assert.IsTrue(message.HasDefaultNestedEnum);
- Assert.IsTrue(message.HasDefaultForeignEnum);
- Assert.IsTrue(message.HasDefaultImportEnum);
-
- Assert.IsTrue(message.HasDefaultStringPiece);
- Assert.IsTrue(message.HasDefaultCord);
-
- Assert.AreEqual(401, message.DefaultInt32);
- Assert.AreEqual(402, message.DefaultInt64);
- Assert.AreEqual(403u, message.DefaultUint32);
- Assert.AreEqual(404u, message.DefaultUint64);
- Assert.AreEqual(405, message.DefaultSint32);
- Assert.AreEqual(406, message.DefaultSint64);
- Assert.AreEqual(407u, message.DefaultFixed32);
- Assert.AreEqual(408u, message.DefaultFixed64);
- Assert.AreEqual(409, message.DefaultSfixed32);
- Assert.AreEqual(410, message.DefaultSfixed64);
- Assert.AreEqual(411, message.DefaultFloat);
- Assert.AreEqual(412, message.DefaultDouble);
- Assert.AreEqual(false, message.DefaultBool);
- Assert.AreEqual("415", message.DefaultString);
- Assert.AreEqual(ToBytes("416"), message.DefaultBytes);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO, message.DefaultNestedEnum);
- Assert.AreEqual(ForeignEnum.FOREIGN_FOO, message.DefaultForeignEnum);
- Assert.AreEqual(ImportEnum.IMPORT_FOO, message.DefaultImportEnum);
-
- Assert.AreEqual("424", message.DefaultStringPiece);
- Assert.AreEqual("425", message.DefaultCord);
+ Assert.True(message.HasDefaultInt32);
+ Assert.True(message.HasDefaultInt64);
+ Assert.True(message.HasDefaultUint32);
+ Assert.True(message.HasDefaultUint64);
+ Assert.True(message.HasDefaultSint32);
+ Assert.True(message.HasDefaultSint64);
+ Assert.True(message.HasDefaultFixed32);
+ Assert.True(message.HasDefaultFixed64);
+ Assert.True(message.HasDefaultSfixed32);
+ Assert.True(message.HasDefaultSfixed64);
+ Assert.True(message.HasDefaultFloat);
+ Assert.True(message.HasDefaultDouble);
+ Assert.True(message.HasDefaultBool);
+ Assert.True(message.HasDefaultString);
+ Assert.True(message.HasDefaultBytes);
+
+ Assert.True(message.HasDefaultNestedEnum);
+ Assert.True(message.HasDefaultForeignEnum);
+ Assert.True(message.HasDefaultImportEnum);
+
+ Assert.True(message.HasDefaultStringPiece);
+ Assert.True(message.HasDefaultCord);
+
+ Assert.Equal(401, message.DefaultInt32);
+ Assert.Equal(402, message.DefaultInt64);
+ Assert.Equal(403u, message.DefaultUint32);
+ Assert.Equal(404u, message.DefaultUint64);
+ Assert.Equal(405, message.DefaultSint32);
+ Assert.Equal(406, message.DefaultSint64);
+ Assert.Equal(407u, message.DefaultFixed32);
+ Assert.Equal(408u, message.DefaultFixed64);
+ Assert.Equal(409, message.DefaultSfixed32);
+ Assert.Equal(410, message.DefaultSfixed64);
+ Assert.Equal(411, message.DefaultFloat);
+ Assert.Equal(412, message.DefaultDouble);
+ Assert.Equal(false, message.DefaultBool);
+ Assert.Equal("415", message.DefaultString);
+ Assert.Equal(ToBytes("416"), message.DefaultBytes);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.FOO, message.DefaultNestedEnum);
+ Assert.Equal(ForeignEnum.FOREIGN_FOO, message.DefaultForeignEnum);
+ Assert.Equal(ImportEnum.IMPORT_FOO, message.DefaultImportEnum);
+
+ Assert.Equal("424", message.DefaultStringPiece);
+ Assert.Equal("425", message.DefaultCord);
}
internal static void AssertClear(TestAllTypes message)
{
// HasBlah() should initially be false for all optional fields.
- Assert.IsFalse(message.HasOptionalInt32);
- Assert.IsFalse(message.HasOptionalInt64);
- Assert.IsFalse(message.HasOptionalUint32);
- Assert.IsFalse(message.HasOptionalUint64);
- Assert.IsFalse(message.HasOptionalSint32);
- Assert.IsFalse(message.HasOptionalSint64);
- Assert.IsFalse(message.HasOptionalFixed32);
- Assert.IsFalse(message.HasOptionalFixed64);
- Assert.IsFalse(message.HasOptionalSfixed32);
- Assert.IsFalse(message.HasOptionalSfixed64);
- Assert.IsFalse(message.HasOptionalFloat);
- Assert.IsFalse(message.HasOptionalDouble);
- Assert.IsFalse(message.HasOptionalBool);
- Assert.IsFalse(message.HasOptionalString);
- Assert.IsFalse(message.HasOptionalBytes);
-
- Assert.IsFalse(message.HasOptionalGroup);
- Assert.IsFalse(message.HasOptionalNestedMessage);
- Assert.IsFalse(message.HasOptionalForeignMessage);
- Assert.IsFalse(message.HasOptionalImportMessage);
-
- Assert.IsFalse(message.HasOptionalNestedEnum);
- Assert.IsFalse(message.HasOptionalForeignEnum);
- Assert.IsFalse(message.HasOptionalImportEnum);
-
- Assert.IsFalse(message.HasOptionalStringPiece);
- Assert.IsFalse(message.HasOptionalCord);
+ Assert.False(message.HasOptionalInt32);
+ Assert.False(message.HasOptionalInt64);
+ Assert.False(message.HasOptionalUint32);
+ Assert.False(message.HasOptionalUint64);
+ Assert.False(message.HasOptionalSint32);
+ Assert.False(message.HasOptionalSint64);
+ Assert.False(message.HasOptionalFixed32);
+ Assert.False(message.HasOptionalFixed64);
+ Assert.False(message.HasOptionalSfixed32);
+ Assert.False(message.HasOptionalSfixed64);
+ Assert.False(message.HasOptionalFloat);
+ Assert.False(message.HasOptionalDouble);
+ Assert.False(message.HasOptionalBool);
+ Assert.False(message.HasOptionalString);
+ Assert.False(message.HasOptionalBytes);
+
+ Assert.False(message.HasOptionalGroup);
+ Assert.False(message.HasOptionalNestedMessage);
+ Assert.False(message.HasOptionalForeignMessage);
+ Assert.False(message.HasOptionalImportMessage);
+
+ Assert.False(message.HasOptionalNestedEnum);
+ Assert.False(message.HasOptionalForeignEnum);
+ Assert.False(message.HasOptionalImportEnum);
+
+ Assert.False(message.HasOptionalStringPiece);
+ Assert.False(message.HasOptionalCord);
// Optional fields without defaults are set to zero or something like it.
- Assert.AreEqual(0, message.OptionalInt32);
- Assert.AreEqual(0, message.OptionalInt64);
- Assert.AreEqual(0u, message.OptionalUint32);
- Assert.AreEqual(0u, message.OptionalUint64);
- Assert.AreEqual(0, message.OptionalSint32);
- Assert.AreEqual(0, message.OptionalSint64);
- Assert.AreEqual(0u, message.OptionalFixed32);
- Assert.AreEqual(0u, message.OptionalFixed64);
- Assert.AreEqual(0, message.OptionalSfixed32);
- Assert.AreEqual(0, message.OptionalSfixed64);
- Assert.AreEqual(0, message.OptionalFloat);
- Assert.AreEqual(0, message.OptionalDouble);
- Assert.AreEqual(false, message.OptionalBool);
- Assert.AreEqual("", message.OptionalString);
- Assert.AreEqual(ByteString.Empty, message.OptionalBytes);
+ Assert.Equal(0, message.OptionalInt32);
+ Assert.Equal(0, message.OptionalInt64);
+ Assert.Equal(0u, message.OptionalUint32);
+ Assert.Equal(0u, message.OptionalUint64);
+ Assert.Equal(0, message.OptionalSint32);
+ Assert.Equal(0, message.OptionalSint64);
+ Assert.Equal(0u, message.OptionalFixed32);
+ Assert.Equal(0u, message.OptionalFixed64);
+ Assert.Equal(0, message.OptionalSfixed32);
+ Assert.Equal(0, message.OptionalSfixed64);
+ Assert.Equal(0, message.OptionalFloat);
+ Assert.Equal(0, message.OptionalDouble);
+ Assert.Equal(false, message.OptionalBool);
+ Assert.Equal("", message.OptionalString);
+ Assert.Equal(ByteString.Empty, message.OptionalBytes);
// Embedded messages should also be clear.
- Assert.IsFalse(message.OptionalGroup.HasA);
- Assert.IsFalse(message.OptionalNestedMessage.HasBb);
- Assert.IsFalse(message.OptionalForeignMessage.HasC);
- Assert.IsFalse(message.OptionalImportMessage.HasD);
+ Assert.False(message.OptionalGroup.HasA);
+ Assert.False(message.OptionalNestedMessage.HasBb);
+ Assert.False(message.OptionalForeignMessage.HasC);
+ Assert.False(message.OptionalImportMessage.HasD);
- Assert.AreEqual(0, message.OptionalGroup.A);
- Assert.AreEqual(0, message.OptionalNestedMessage.Bb);
- Assert.AreEqual(0, message.OptionalForeignMessage.C);
- Assert.AreEqual(0, message.OptionalImportMessage.D);
+ Assert.Equal(0, message.OptionalGroup.A);
+ Assert.Equal(0, message.OptionalNestedMessage.Bb);
+ Assert.Equal(0, message.OptionalForeignMessage.C);
+ Assert.Equal(0, message.OptionalImportMessage.D);
// Enums without defaults are set to the first value in the enum.
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO, message.OptionalNestedEnum);
- Assert.AreEqual(ForeignEnum.FOREIGN_FOO, message.OptionalForeignEnum);
- Assert.AreEqual(ImportEnum.IMPORT_FOO, message.OptionalImportEnum);
+ Assert.Equal(TestAllTypes.Types.NestedEnum.FOO, message.OptionalNestedEnum);
+ Assert.Equal(ForeignEnum.FOREIGN_FOO, message.OptionalForeignEnum);
+ Assert.Equal(ImportEnum.IMPORT_FOO, message.OptionalImportEnum);
- Assert.AreEqual("", message.OptionalStringPiece);
- Assert.AreEqual("", message.OptionalCord);
+ Assert.Equal("", message.OptionalStringPiece);
+ Assert.Equal("", message.OptionalCord);
// Repeated fields are empty.
- Assert.AreEqual(0, message.RepeatedInt32Count);
- Assert.AreEqual(0, message.RepeatedInt64Count);
- Assert.AreEqual(0, message.RepeatedUint32Count);
- Assert.AreEqual(0, message.RepeatedUint64Count);
- Assert.AreEqual(0, message.RepeatedSint32Count);
- Assert.AreEqual(0, message.RepeatedSint64Count);
- Assert.AreEqual(0, message.RepeatedFixed32Count);
- Assert.AreEqual(0, message.RepeatedFixed64Count);
- Assert.AreEqual(0, message.RepeatedSfixed32Count);
- Assert.AreEqual(0, message.RepeatedSfixed64Count);
- Assert.AreEqual(0, message.RepeatedFloatCount);
- Assert.AreEqual(0, message.RepeatedDoubleCount);
- Assert.AreEqual(0, message.RepeatedBoolCount);
- Assert.AreEqual(0, message.RepeatedStringCount);
- Assert.AreEqual(0, message.RepeatedBytesCount);
-
- Assert.AreEqual(0, message.RepeatedGroupCount);
- Assert.AreEqual(0, message.RepeatedNestedMessageCount);
- Assert.AreEqual(0, message.RepeatedForeignMessageCount);
- Assert.AreEqual(0, message.RepeatedImportMessageCount);
- Assert.AreEqual(0, message.RepeatedNestedEnumCount);
- Assert.AreEqual(0, message.RepeatedForeignEnumCount);
- Assert.AreEqual(0, message.RepeatedImportEnumCount);
-
- Assert.AreEqual(0, message.RepeatedStringPieceCount);
- Assert.AreEqual(0, message.RepeatedCordCount);
+ Assert.Equal(0, message.RepeatedInt32Count);
+ Assert.Equal(0, message.RepeatedInt64Count);
+ Assert.Equal(0, message.RepeatedUint32Count);
+ Assert.Equal(0, message.RepeatedUint64Count);
+ Assert.Equal(0, message.RepeatedSint32Count);
+ Assert.Equal(0, message.RepeatedSint64Count);
+ Assert.Equal(0, message.RepeatedFixed32Count);
+ Assert.Equal(0, message.RepeatedFixed64Count);
+ Assert.Equal(0, message.RepeatedSfixed32Count);
+ Assert.Equal(0, message.RepeatedSfixed64Count);
+ Assert.Equal(0, message.RepeatedFloatCount);
+ Assert.Equal(0, message.RepeatedDoubleCount);
+ Assert.Equal(0, message.RepeatedBoolCount);
+ Assert.Equal(0, message.RepeatedStringCount);
+ Assert.Equal(0, message.RepeatedBytesCount);
+
+ Assert.Equal(0, message.RepeatedGroupCount);
+ Assert.Equal(0, message.RepeatedNestedMessageCount);
+ Assert.Equal(0, message.RepeatedForeignMessageCount);
+ Assert.Equal(0, message.RepeatedImportMessageCount);
+ Assert.Equal(0, message.RepeatedNestedEnumCount);
+ Assert.Equal(0, message.RepeatedForeignEnumCount);
+ Assert.Equal(0, message.RepeatedImportEnumCount);
+
+ Assert.Equal(0, message.RepeatedStringPieceCount);
+ Assert.Equal(0, message.RepeatedCordCount);
// HasBlah() should also be false for all default fields.
- Assert.IsFalse(message.HasDefaultInt32);
- Assert.IsFalse(message.HasDefaultInt64);
- Assert.IsFalse(message.HasDefaultUint32);
- Assert.IsFalse(message.HasDefaultUint64);
- Assert.IsFalse(message.HasDefaultSint32);
- Assert.IsFalse(message.HasDefaultSint64);
- Assert.IsFalse(message.HasDefaultFixed32);
- Assert.IsFalse(message.HasDefaultFixed64);
- Assert.IsFalse(message.HasDefaultSfixed32);
- Assert.IsFalse(message.HasDefaultSfixed64);
- Assert.IsFalse(message.HasDefaultFloat);
- Assert.IsFalse(message.HasDefaultDouble);
- Assert.IsFalse(message.HasDefaultBool);
- Assert.IsFalse(message.HasDefaultString);
- Assert.IsFalse(message.HasDefaultBytes);
-
- Assert.IsFalse(message.HasDefaultNestedEnum);
- Assert.IsFalse(message.HasDefaultForeignEnum);
- Assert.IsFalse(message.HasDefaultImportEnum);
-
- Assert.IsFalse(message.HasDefaultStringPiece);
- Assert.IsFalse(message.HasDefaultCord);
+ Assert.False(message.HasDefaultInt32);
+ Assert.False(message.HasDefaultInt64);
+ Assert.False(message.HasDefaultUint32);
+ Assert.False(message.HasDefaultUint64);
+ Assert.False(message.HasDefaultSint32);
+ Assert.False(message.HasDefaultSint64);
+ Assert.False(message.HasDefaultFixed32);
+ Assert.False(message.HasDefaultFixed64);
+ Assert.False(message.HasDefaultSfixed32);
+ Assert.False(message.HasDefaultSfixed64);
+ Assert.False(message.HasDefaultFloat);
+ Assert.False(message.HasDefaultDouble);
+ Assert.False(message.HasDefaultBool);
+ Assert.False(message.HasDefaultString);
+ Assert.False(message.HasDefaultBytes);
+
+ Assert.False(message.HasDefaultNestedEnum);
+ Assert.False(message.HasDefaultForeignEnum);
+ Assert.False(message.HasDefaultImportEnum);
+
+ Assert.False(message.HasDefaultStringPiece);
+ Assert.False(message.HasDefaultCord);
// Fields with defaults have their default values (duh).
- Assert.AreEqual(41, message.DefaultInt32);
- Assert.AreEqual(42, message.DefaultInt64);
- Assert.AreEqual(43u, message.DefaultUint32);
- Assert.AreEqual(44u, message.DefaultUint64);
- Assert.AreEqual(-45, message.DefaultSint32);
- Assert.AreEqual(46, message.DefaultSint64);
- Assert.AreEqual(47u, message.DefaultFixed32);
- Assert.AreEqual(48u, message.DefaultFixed64);
- Assert.AreEqual(49, message.DefaultSfixed32);
- Assert.AreEqual(-50, message.DefaultSfixed64);
- Assert.AreEqual(51.5, message.DefaultFloat, 0.0);
- Assert.AreEqual(52e3, message.DefaultDouble, 0.0);
- Assert.AreEqual(true, message.DefaultBool);
- Assert.AreEqual("hello", message.DefaultString);
- Assert.AreEqual(ToBytes("world"), message.DefaultBytes);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR, message.DefaultNestedEnum);
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR, message.DefaultForeignEnum);
- Assert.AreEqual(ImportEnum.IMPORT_BAR, message.DefaultImportEnum);
-
- Assert.AreEqual("abc", message.DefaultStringPiece);
- Assert.AreEqual("123", message.DefaultCord);
+ Assert.Equal(41, message.DefaultInt32);
+ Assert.Equal(42, message.DefaultInt64);
+ Assert.Equal(43u, message.DefaultUint32);
+ Assert.Equal(44u, message.DefaultUint64);
+ Assert.Equal(-45, message.DefaultSint32);
+ Assert.Equal(46, message.DefaultSint64);
+ Assert.Equal(47u, message.DefaultFixed32);
+ Assert.Equal(48u, message.DefaultFixed64);
+ Assert.Equal(49, message.DefaultSfixed32);
+ Assert.Equal(-50, message.DefaultSfixed64);
+ Assert.Equal(51.5f, message.DefaultFloat);
+ Assert.Equal(52e3d, message.DefaultDouble);
+ Assert.Equal(true, message.DefaultBool);
+ Assert.Equal("hello", message.DefaultString);
+ Assert.Equal(ToBytes("world"), message.DefaultBytes);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAR, message.DefaultNestedEnum);
+ Assert.Equal(ForeignEnum.FOREIGN_BAR, message.DefaultForeignEnum);
+ Assert.Equal(ImportEnum.IMPORT_BAR, message.DefaultImportEnum);
+
+ Assert.Equal("abc", message.DefaultStringPiece);
+ Assert.Equal("123", message.DefaultCord);
}
/// <summary>
@@ -855,89 +855,89 @@ namespace Google.ProtocolBuffers // ModifyRepeatedFields only sets the second repeated element of each
// field. In addition to verifying this, we also verify that the first
// element and size were *not* modified.
- Assert.AreEqual(2, message.RepeatedInt32Count);
- Assert.AreEqual(2, message.RepeatedInt64Count);
- Assert.AreEqual(2, message.RepeatedUint32Count);
- Assert.AreEqual(2, message.RepeatedUint64Count);
- Assert.AreEqual(2, message.RepeatedSint32Count);
- Assert.AreEqual(2, message.RepeatedSint64Count);
- Assert.AreEqual(2, message.RepeatedFixed32Count);
- Assert.AreEqual(2, message.RepeatedFixed64Count);
- Assert.AreEqual(2, message.RepeatedSfixed32Count);
- Assert.AreEqual(2, message.RepeatedSfixed64Count);
- Assert.AreEqual(2, message.RepeatedFloatCount);
- Assert.AreEqual(2, message.RepeatedDoubleCount);
- Assert.AreEqual(2, message.RepeatedBoolCount);
- Assert.AreEqual(2, message.RepeatedStringCount);
- Assert.AreEqual(2, message.RepeatedBytesCount);
-
- Assert.AreEqual(2, message.RepeatedGroupCount);
- Assert.AreEqual(2, message.RepeatedNestedMessageCount);
- Assert.AreEqual(2, message.RepeatedForeignMessageCount);
- Assert.AreEqual(2, message.RepeatedImportMessageCount);
- Assert.AreEqual(2, message.RepeatedNestedEnumCount);
- Assert.AreEqual(2, message.RepeatedForeignEnumCount);
- Assert.AreEqual(2, message.RepeatedImportEnumCount);
-
- Assert.AreEqual(2, message.RepeatedStringPieceCount);
- Assert.AreEqual(2, message.RepeatedCordCount);
-
- Assert.AreEqual(201, message.GetRepeatedInt32(0));
- Assert.AreEqual(202L, message.GetRepeatedInt64(0));
- Assert.AreEqual(203U, message.GetRepeatedUint32(0));
- Assert.AreEqual(204UL, message.GetRepeatedUint64(0));
- Assert.AreEqual(205, message.GetRepeatedSint32(0));
- Assert.AreEqual(206L, message.GetRepeatedSint64(0));
- Assert.AreEqual(207U, message.GetRepeatedFixed32(0));
- Assert.AreEqual(208UL, message.GetRepeatedFixed64(0));
- Assert.AreEqual(209, message.GetRepeatedSfixed32(0));
- Assert.AreEqual(210L, message.GetRepeatedSfixed64(0));
- Assert.AreEqual(211F, message.GetRepeatedFloat(0));
- Assert.AreEqual(212D, message.GetRepeatedDouble(0));
- Assert.AreEqual(true, message.GetRepeatedBool(0));
- Assert.AreEqual("215", message.GetRepeatedString(0));
- Assert.AreEqual(ToBytes("216"), message.GetRepeatedBytes(0));
-
- Assert.AreEqual(217, message.GetRepeatedGroup(0).A);
- Assert.AreEqual(218, message.GetRepeatedNestedMessage(0).Bb);
- Assert.AreEqual(219, message.GetRepeatedForeignMessage(0).C);
- Assert.AreEqual(220, message.GetRepeatedImportMessage(0).D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR, message.GetRepeatedNestedEnum(0));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR, message.GetRepeatedForeignEnum(0));
- Assert.AreEqual(ImportEnum.IMPORT_BAR, message.GetRepeatedImportEnum(0));
-
- Assert.AreEqual("224", message.GetRepeatedStringPiece(0));
- Assert.AreEqual("225", message.GetRepeatedCord(0));
+ Assert.Equal(2, message.RepeatedInt32Count);
+ Assert.Equal(2, message.RepeatedInt64Count);
+ Assert.Equal(2, message.RepeatedUint32Count);
+ Assert.Equal(2, message.RepeatedUint64Count);
+ Assert.Equal(2, message.RepeatedSint32Count);
+ Assert.Equal(2, message.RepeatedSint64Count);
+ Assert.Equal(2, message.RepeatedFixed32Count);
+ Assert.Equal(2, message.RepeatedFixed64Count);
+ Assert.Equal(2, message.RepeatedSfixed32Count);
+ Assert.Equal(2, message.RepeatedSfixed64Count);
+ Assert.Equal(2, message.RepeatedFloatCount);
+ Assert.Equal(2, message.RepeatedDoubleCount);
+ Assert.Equal(2, message.RepeatedBoolCount);
+ Assert.Equal(2, message.RepeatedStringCount);
+ Assert.Equal(2, message.RepeatedBytesCount);
+
+ Assert.Equal(2, message.RepeatedGroupCount);
+ Assert.Equal(2, message.RepeatedNestedMessageCount);
+ Assert.Equal(2, message.RepeatedForeignMessageCount);
+ Assert.Equal(2, message.RepeatedImportMessageCount);
+ Assert.Equal(2, message.RepeatedNestedEnumCount);
+ Assert.Equal(2, message.RepeatedForeignEnumCount);
+ Assert.Equal(2, message.RepeatedImportEnumCount);
+
+ Assert.Equal(2, message.RepeatedStringPieceCount);
+ Assert.Equal(2, message.RepeatedCordCount);
+
+ Assert.Equal(201, message.GetRepeatedInt32(0));
+ Assert.Equal(202L, message.GetRepeatedInt64(0));
+ Assert.Equal(203U, message.GetRepeatedUint32(0));
+ Assert.Equal(204UL, message.GetRepeatedUint64(0));
+ Assert.Equal(205, message.GetRepeatedSint32(0));
+ Assert.Equal(206L, message.GetRepeatedSint64(0));
+ Assert.Equal(207U, message.GetRepeatedFixed32(0));
+ Assert.Equal(208UL, message.GetRepeatedFixed64(0));
+ Assert.Equal(209, message.GetRepeatedSfixed32(0));
+ Assert.Equal(210L, message.GetRepeatedSfixed64(0));
+ Assert.Equal(211F, message.GetRepeatedFloat(0));
+ Assert.Equal(212D, message.GetRepeatedDouble(0));
+ Assert.Equal(true, message.GetRepeatedBool(0));
+ Assert.Equal("215", message.GetRepeatedString(0));
+ Assert.Equal(ToBytes("216"), message.GetRepeatedBytes(0));
+
+ Assert.Equal(217, message.GetRepeatedGroup(0).A);
+ Assert.Equal(218, message.GetRepeatedNestedMessage(0).Bb);
+ Assert.Equal(219, message.GetRepeatedForeignMessage(0).C);
+ Assert.Equal(220, message.GetRepeatedImportMessage(0).D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAR, message.GetRepeatedNestedEnum(0));
+ Assert.Equal(ForeignEnum.FOREIGN_BAR, message.GetRepeatedForeignEnum(0));
+ Assert.Equal(ImportEnum.IMPORT_BAR, message.GetRepeatedImportEnum(0));
+
+ Assert.Equal("224", message.GetRepeatedStringPiece(0));
+ Assert.Equal("225", message.GetRepeatedCord(0));
// Actually verify the second (modified) elements now.
- Assert.AreEqual(501, message.GetRepeatedInt32(1));
- Assert.AreEqual(502L, message.GetRepeatedInt64(1));
- Assert.AreEqual(503U, message.GetRepeatedUint32(1));
- Assert.AreEqual(504UL, message.GetRepeatedUint64(1));
- Assert.AreEqual(505, message.GetRepeatedSint32(1));
- Assert.AreEqual(506L, message.GetRepeatedSint64(1));
- Assert.AreEqual(507U, message.GetRepeatedFixed32(1));
- Assert.AreEqual(508UL, message.GetRepeatedFixed64(1));
- Assert.AreEqual(509, message.GetRepeatedSfixed32(1));
- Assert.AreEqual(510L, message.GetRepeatedSfixed64(1));
- Assert.AreEqual(511F, message.GetRepeatedFloat(1));
- Assert.AreEqual(512D, message.GetRepeatedDouble(1));
- Assert.AreEqual(true, message.GetRepeatedBool(1));
- Assert.AreEqual("515", message.GetRepeatedString(1));
- Assert.AreEqual(ToBytes("516"), message.GetRepeatedBytes(1));
-
- Assert.AreEqual(517, message.GetRepeatedGroup(1).A);
- Assert.AreEqual(518, message.GetRepeatedNestedMessage(1).Bb);
- Assert.AreEqual(519, message.GetRepeatedForeignMessage(1).C);
- Assert.AreEqual(520, message.GetRepeatedImportMessage(1).D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO, message.GetRepeatedNestedEnum(1));
- Assert.AreEqual(ForeignEnum.FOREIGN_FOO, message.GetRepeatedForeignEnum(1));
- Assert.AreEqual(ImportEnum.IMPORT_FOO, message.GetRepeatedImportEnum(1));
-
- Assert.AreEqual("524", message.GetRepeatedStringPiece(1));
- Assert.AreEqual("525", message.GetRepeatedCord(1));
+ Assert.Equal(501, message.GetRepeatedInt32(1));
+ Assert.Equal(502L, message.GetRepeatedInt64(1));
+ Assert.Equal(503U, message.GetRepeatedUint32(1));
+ Assert.Equal(504UL, message.GetRepeatedUint64(1));
+ Assert.Equal(505, message.GetRepeatedSint32(1));
+ Assert.Equal(506L, message.GetRepeatedSint64(1));
+ Assert.Equal(507U, message.GetRepeatedFixed32(1));
+ Assert.Equal(508UL, message.GetRepeatedFixed64(1));
+ Assert.Equal(509, message.GetRepeatedSfixed32(1));
+ Assert.Equal(510L, message.GetRepeatedSfixed64(1));
+ Assert.Equal(511F, message.GetRepeatedFloat(1));
+ Assert.Equal(512D, message.GetRepeatedDouble(1));
+ Assert.Equal(true, message.GetRepeatedBool(1));
+ Assert.Equal("515", message.GetRepeatedString(1));
+ Assert.Equal(ToBytes("516"), message.GetRepeatedBytes(1));
+
+ Assert.Equal(517, message.GetRepeatedGroup(1).A);
+ Assert.Equal(518, message.GetRepeatedNestedMessage(1).Bb);
+ Assert.Equal(519, message.GetRepeatedForeignMessage(1).C);
+ Assert.Equal(520, message.GetRepeatedImportMessage(1).D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.FOO, message.GetRepeatedNestedEnum(1));
+ Assert.Equal(ForeignEnum.FOREIGN_FOO, message.GetRepeatedForeignEnum(1));
+ Assert.Equal(ImportEnum.IMPORT_FOO, message.GetRepeatedImportEnum(1));
+
+ Assert.Equal("524", message.GetRepeatedStringPiece(1));
+ Assert.Equal("525", message.GetRepeatedCord(1));
}
/// <summary>
@@ -949,222 +949,222 @@ namespace Google.ProtocolBuffers {
foreach (T secondElement in second)
{
- Assert.IsTrue(firstEnumerator.MoveNext(), "First enumerator ran out of elements too early.");
- Assert.AreEqual(firstEnumerator.Current, secondElement);
+ Assert.True(firstEnumerator.MoveNext(), "First enumerator ran out of elements too early.");
+ Assert.Equal(firstEnumerator.Current, secondElement);
}
- Assert.IsFalse(firstEnumerator.MoveNext(), "Second enumerator ran out of elements too early.");
+ Assert.False(firstEnumerator.MoveNext(), "Second enumerator ran out of elements too early.");
}
}
internal static void AssertEqualBytes(byte[] expected, byte[] actual)
{
- Assert.AreEqual(ByteString.CopyFrom(expected), ByteString.CopyFrom(actual));
+ Assert.Equal(ByteString.CopyFrom(expected), ByteString.CopyFrom(actual));
}
internal static void AssertAllExtensionsSet(TestAllExtensions message)
{
- Assert.IsTrue(message.HasExtension(Unittest.OptionalInt32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalInt64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalUint32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalUint64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalSint32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalSint64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalFixed32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalFixed64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalSfixed32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalSfixed64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalFloatExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalDoubleExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalBoolExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalStringExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalBytesExtension));
-
- Assert.IsTrue(message.HasExtension(Unittest.OptionalGroupExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalNestedMessageExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalForeignMessageExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalImportMessageExtension));
-
- Assert.IsTrue(message.GetExtension(Unittest.OptionalGroupExtension).HasA);
- Assert.IsTrue(message.GetExtension(Unittest.OptionalNestedMessageExtension).HasBb);
- Assert.IsTrue(message.GetExtension(Unittest.OptionalForeignMessageExtension).HasC);
- Assert.IsTrue(message.GetExtension(Unittest.OptionalImportMessageExtension).HasD);
-
- Assert.IsTrue(message.HasExtension(Unittest.OptionalNestedEnumExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalForeignEnumExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalImportEnumExtension));
-
- Assert.IsTrue(message.HasExtension(Unittest.OptionalStringPieceExtension));
- Assert.IsTrue(message.HasExtension(Unittest.OptionalCordExtension));
-
- Assert.AreEqual(101, message.GetExtension(Unittest.OptionalInt32Extension));
- Assert.AreEqual(102L, message.GetExtension(Unittest.OptionalInt64Extension));
- Assert.AreEqual(103U, message.GetExtension(Unittest.OptionalUint32Extension));
- Assert.AreEqual(104UL, message.GetExtension(Unittest.OptionalUint64Extension));
- Assert.AreEqual(105, message.GetExtension(Unittest.OptionalSint32Extension));
- Assert.AreEqual(106L, message.GetExtension(Unittest.OptionalSint64Extension));
- Assert.AreEqual(107U, message.GetExtension(Unittest.OptionalFixed32Extension));
- Assert.AreEqual(108UL, message.GetExtension(Unittest.OptionalFixed64Extension));
- Assert.AreEqual(109, message.GetExtension(Unittest.OptionalSfixed32Extension));
- Assert.AreEqual(110L, message.GetExtension(Unittest.OptionalSfixed64Extension));
- Assert.AreEqual(111F, message.GetExtension(Unittest.OptionalFloatExtension));
- Assert.AreEqual(112D, message.GetExtension(Unittest.OptionalDoubleExtension));
- Assert.AreEqual(true, message.GetExtension(Unittest.OptionalBoolExtension));
- Assert.AreEqual("115", message.GetExtension(Unittest.OptionalStringExtension));
- Assert.AreEqual(ToBytes("116"), message.GetExtension(Unittest.OptionalBytesExtension));
-
- Assert.AreEqual(117, message.GetExtension(Unittest.OptionalGroupExtension).A);
- Assert.AreEqual(118, message.GetExtension(Unittest.OptionalNestedMessageExtension).Bb);
- Assert.AreEqual(119, message.GetExtension(Unittest.OptionalForeignMessageExtension).C);
- Assert.AreEqual(120, message.GetExtension(Unittest.OptionalImportMessageExtension).D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAZ,
+ Assert.True(message.HasExtension(Unittest.OptionalInt32Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalInt64Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalUint32Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalUint64Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalSint32Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalSint64Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalFixed32Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalFixed64Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalSfixed32Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalSfixed64Extension));
+ Assert.True(message.HasExtension(Unittest.OptionalFloatExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalDoubleExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalBoolExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalStringExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalBytesExtension));
+
+ Assert.True(message.HasExtension(Unittest.OptionalGroupExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalNestedMessageExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalForeignMessageExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalImportMessageExtension));
+
+ Assert.True(message.GetExtension(Unittest.OptionalGroupExtension).HasA);
+ Assert.True(message.GetExtension(Unittest.OptionalNestedMessageExtension).HasBb);
+ Assert.True(message.GetExtension(Unittest.OptionalForeignMessageExtension).HasC);
+ Assert.True(message.GetExtension(Unittest.OptionalImportMessageExtension).HasD);
+
+ Assert.True(message.HasExtension(Unittest.OptionalNestedEnumExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalForeignEnumExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalImportEnumExtension));
+
+ Assert.True(message.HasExtension(Unittest.OptionalStringPieceExtension));
+ Assert.True(message.HasExtension(Unittest.OptionalCordExtension));
+
+ Assert.Equal(101, message.GetExtension(Unittest.OptionalInt32Extension));
+ Assert.Equal(102L, message.GetExtension(Unittest.OptionalInt64Extension));
+ Assert.Equal(103U, message.GetExtension(Unittest.OptionalUint32Extension));
+ Assert.Equal(104UL, message.GetExtension(Unittest.OptionalUint64Extension));
+ Assert.Equal(105, message.GetExtension(Unittest.OptionalSint32Extension));
+ Assert.Equal(106L, message.GetExtension(Unittest.OptionalSint64Extension));
+ Assert.Equal(107U, message.GetExtension(Unittest.OptionalFixed32Extension));
+ Assert.Equal(108UL, message.GetExtension(Unittest.OptionalFixed64Extension));
+ Assert.Equal(109, message.GetExtension(Unittest.OptionalSfixed32Extension));
+ Assert.Equal(110L, message.GetExtension(Unittest.OptionalSfixed64Extension));
+ Assert.Equal(111F, message.GetExtension(Unittest.OptionalFloatExtension));
+ Assert.Equal(112D, message.GetExtension(Unittest.OptionalDoubleExtension));
+ Assert.Equal(true, message.GetExtension(Unittest.OptionalBoolExtension));
+ Assert.Equal("115", message.GetExtension(Unittest.OptionalStringExtension));
+ Assert.Equal(ToBytes("116"), message.GetExtension(Unittest.OptionalBytesExtension));
+
+ Assert.Equal(117, message.GetExtension(Unittest.OptionalGroupExtension).A);
+ Assert.Equal(118, message.GetExtension(Unittest.OptionalNestedMessageExtension).Bb);
+ Assert.Equal(119, message.GetExtension(Unittest.OptionalForeignMessageExtension).C);
+ Assert.Equal(120, message.GetExtension(Unittest.OptionalImportMessageExtension).D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAZ,
message.GetExtension(Unittest.OptionalNestedEnumExtension));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ,
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ,
message.GetExtension(Unittest.OptionalForeignEnumExtension));
- Assert.AreEqual(ImportEnum.IMPORT_BAZ, message.GetExtension(Unittest.OptionalImportEnumExtension));
+ Assert.Equal(ImportEnum.IMPORT_BAZ, message.GetExtension(Unittest.OptionalImportEnumExtension));
- Assert.AreEqual("124", message.GetExtension(Unittest.OptionalStringPieceExtension));
- Assert.AreEqual("125", message.GetExtension(Unittest.OptionalCordExtension));
+ Assert.Equal("124", message.GetExtension(Unittest.OptionalStringPieceExtension));
+ Assert.Equal("125", message.GetExtension(Unittest.OptionalCordExtension));
// -----------------------------------------------------------------
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedInt32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedInt64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedUint32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedUint64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedSint32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedSint64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedFixed32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedFixed64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedSfixed32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedSfixed64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedFloatExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedDoubleExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedBoolExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedStringExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedBytesExtension));
-
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedGroupExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedNestedMessageExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedForeignMessageExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedImportMessageExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedNestedEnumExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedForeignEnumExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedImportEnumExtension));
-
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedStringPieceExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedCordExtension));
-
- Assert.AreEqual(201, message.GetExtension(Unittest.RepeatedInt32Extension, 0));
- Assert.AreEqual(202L, message.GetExtension(Unittest.RepeatedInt64Extension, 0));
- Assert.AreEqual(203U, message.GetExtension(Unittest.RepeatedUint32Extension, 0));
- Assert.AreEqual(204UL, message.GetExtension(Unittest.RepeatedUint64Extension, 0));
- Assert.AreEqual(205, message.GetExtension(Unittest.RepeatedSint32Extension, 0));
- Assert.AreEqual(206L, message.GetExtension(Unittest.RepeatedSint64Extension, 0));
- Assert.AreEqual(207U, message.GetExtension(Unittest.RepeatedFixed32Extension, 0));
- Assert.AreEqual(208UL, message.GetExtension(Unittest.RepeatedFixed64Extension, 0));
- Assert.AreEqual(209, message.GetExtension(Unittest.RepeatedSfixed32Extension, 0));
- Assert.AreEqual(210L, message.GetExtension(Unittest.RepeatedSfixed64Extension, 0));
- Assert.AreEqual(211F, message.GetExtension(Unittest.RepeatedFloatExtension, 0));
- Assert.AreEqual(212D, message.GetExtension(Unittest.RepeatedDoubleExtension, 0));
- Assert.AreEqual(true, message.GetExtension(Unittest.RepeatedBoolExtension, 0));
- Assert.AreEqual("215", message.GetExtension(Unittest.RepeatedStringExtension, 0));
- Assert.AreEqual(ToBytes("216"), message.GetExtension(Unittest.RepeatedBytesExtension, 0));
-
- Assert.AreEqual(217, message.GetExtension(Unittest.RepeatedGroupExtension, 0).A);
- Assert.AreEqual(218, message.GetExtension(Unittest.RepeatedNestedMessageExtension, 0).Bb);
- Assert.AreEqual(219, message.GetExtension(Unittest.RepeatedForeignMessageExtension, 0).C);
- Assert.AreEqual(220, message.GetExtension(Unittest.RepeatedImportMessageExtension, 0).D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR,
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedInt32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedInt64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedUint32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedUint64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedSint32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedSint64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedFixed32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedFixed64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedSfixed32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedSfixed64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedFloatExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedDoubleExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedBoolExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedStringExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedBytesExtension));
+
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedGroupExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedNestedMessageExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedForeignMessageExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedImportMessageExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedNestedEnumExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedForeignEnumExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedImportEnumExtension));
+
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedStringPieceExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedCordExtension));
+
+ Assert.Equal(201, message.GetExtension(Unittest.RepeatedInt32Extension, 0));
+ Assert.Equal(202L, message.GetExtension(Unittest.RepeatedInt64Extension, 0));
+ Assert.Equal(203U, message.GetExtension(Unittest.RepeatedUint32Extension, 0));
+ Assert.Equal(204UL, message.GetExtension(Unittest.RepeatedUint64Extension, 0));
+ Assert.Equal(205, message.GetExtension(Unittest.RepeatedSint32Extension, 0));
+ Assert.Equal(206L, message.GetExtension(Unittest.RepeatedSint64Extension, 0));
+ Assert.Equal(207U, message.GetExtension(Unittest.RepeatedFixed32Extension, 0));
+ Assert.Equal(208UL, message.GetExtension(Unittest.RepeatedFixed64Extension, 0));
+ Assert.Equal(209, message.GetExtension(Unittest.RepeatedSfixed32Extension, 0));
+ Assert.Equal(210L, message.GetExtension(Unittest.RepeatedSfixed64Extension, 0));
+ Assert.Equal(211F, message.GetExtension(Unittest.RepeatedFloatExtension, 0));
+ Assert.Equal(212D, message.GetExtension(Unittest.RepeatedDoubleExtension, 0));
+ Assert.Equal(true, message.GetExtension(Unittest.RepeatedBoolExtension, 0));
+ Assert.Equal("215", message.GetExtension(Unittest.RepeatedStringExtension, 0));
+ Assert.Equal(ToBytes("216"), message.GetExtension(Unittest.RepeatedBytesExtension, 0));
+
+ Assert.Equal(217, message.GetExtension(Unittest.RepeatedGroupExtension, 0).A);
+ Assert.Equal(218, message.GetExtension(Unittest.RepeatedNestedMessageExtension, 0).Bb);
+ Assert.Equal(219, message.GetExtension(Unittest.RepeatedForeignMessageExtension, 0).C);
+ Assert.Equal(220, message.GetExtension(Unittest.RepeatedImportMessageExtension, 0).D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAR,
message.GetExtension(Unittest.RepeatedNestedEnumExtension, 0));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR,
+ Assert.Equal(ForeignEnum.FOREIGN_BAR,
message.GetExtension(Unittest.RepeatedForeignEnumExtension, 0));
- Assert.AreEqual(ImportEnum.IMPORT_BAR,
+ Assert.Equal(ImportEnum.IMPORT_BAR,
message.GetExtension(Unittest.RepeatedImportEnumExtension, 0));
- Assert.AreEqual("224", message.GetExtension(Unittest.RepeatedStringPieceExtension, 0));
- Assert.AreEqual("225", message.GetExtension(Unittest.RepeatedCordExtension, 0));
-
- Assert.AreEqual(301, message.GetExtension(Unittest.RepeatedInt32Extension, 1));
- Assert.AreEqual(302L, message.GetExtension(Unittest.RepeatedInt64Extension, 1));
- Assert.AreEqual(303U, message.GetExtension(Unittest.RepeatedUint32Extension, 1));
- Assert.AreEqual(304UL, message.GetExtension(Unittest.RepeatedUint64Extension, 1));
- Assert.AreEqual(305, message.GetExtension(Unittest.RepeatedSint32Extension, 1));
- Assert.AreEqual(306L, message.GetExtension(Unittest.RepeatedSint64Extension, 1));
- Assert.AreEqual(307U, message.GetExtension(Unittest.RepeatedFixed32Extension, 1));
- Assert.AreEqual(308UL, message.GetExtension(Unittest.RepeatedFixed64Extension, 1));
- Assert.AreEqual(309, message.GetExtension(Unittest.RepeatedSfixed32Extension, 1));
- Assert.AreEqual(310L, message.GetExtension(Unittest.RepeatedSfixed64Extension, 1));
- Assert.AreEqual(311F, message.GetExtension(Unittest.RepeatedFloatExtension, 1));
- Assert.AreEqual(312D, message.GetExtension(Unittest.RepeatedDoubleExtension, 1));
- Assert.AreEqual(false, message.GetExtension(Unittest.RepeatedBoolExtension, 1));
- Assert.AreEqual("315", message.GetExtension(Unittest.RepeatedStringExtension, 1));
- Assert.AreEqual(ToBytes("316"), message.GetExtension(Unittest.RepeatedBytesExtension, 1));
-
- Assert.AreEqual(317, message.GetExtension(Unittest.RepeatedGroupExtension, 1).A);
- Assert.AreEqual(318, message.GetExtension(Unittest.RepeatedNestedMessageExtension, 1).Bb);
- Assert.AreEqual(319, message.GetExtension(Unittest.RepeatedForeignMessageExtension, 1).C);
- Assert.AreEqual(320, message.GetExtension(Unittest.RepeatedImportMessageExtension, 1).D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAZ,
+ Assert.Equal("224", message.GetExtension(Unittest.RepeatedStringPieceExtension, 0));
+ Assert.Equal("225", message.GetExtension(Unittest.RepeatedCordExtension, 0));
+
+ Assert.Equal(301, message.GetExtension(Unittest.RepeatedInt32Extension, 1));
+ Assert.Equal(302L, message.GetExtension(Unittest.RepeatedInt64Extension, 1));
+ Assert.Equal(303U, message.GetExtension(Unittest.RepeatedUint32Extension, 1));
+ Assert.Equal(304UL, message.GetExtension(Unittest.RepeatedUint64Extension, 1));
+ Assert.Equal(305, message.GetExtension(Unittest.RepeatedSint32Extension, 1));
+ Assert.Equal(306L, message.GetExtension(Unittest.RepeatedSint64Extension, 1));
+ Assert.Equal(307U, message.GetExtension(Unittest.RepeatedFixed32Extension, 1));
+ Assert.Equal(308UL, message.GetExtension(Unittest.RepeatedFixed64Extension, 1));
+ Assert.Equal(309, message.GetExtension(Unittest.RepeatedSfixed32Extension, 1));
+ Assert.Equal(310L, message.GetExtension(Unittest.RepeatedSfixed64Extension, 1));
+ Assert.Equal(311F, message.GetExtension(Unittest.RepeatedFloatExtension, 1));
+ Assert.Equal(312D, message.GetExtension(Unittest.RepeatedDoubleExtension, 1));
+ Assert.Equal(false, message.GetExtension(Unittest.RepeatedBoolExtension, 1));
+ Assert.Equal("315", message.GetExtension(Unittest.RepeatedStringExtension, 1));
+ Assert.Equal(ToBytes("316"), message.GetExtension(Unittest.RepeatedBytesExtension, 1));
+
+ Assert.Equal(317, message.GetExtension(Unittest.RepeatedGroupExtension, 1).A);
+ Assert.Equal(318, message.GetExtension(Unittest.RepeatedNestedMessageExtension, 1).Bb);
+ Assert.Equal(319, message.GetExtension(Unittest.RepeatedForeignMessageExtension, 1).C);
+ Assert.Equal(320, message.GetExtension(Unittest.RepeatedImportMessageExtension, 1).D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAZ,
message.GetExtension(Unittest.RepeatedNestedEnumExtension, 1));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ,
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ,
message.GetExtension(Unittest.RepeatedForeignEnumExtension, 1));
- Assert.AreEqual(ImportEnum.IMPORT_BAZ,
+ Assert.Equal(ImportEnum.IMPORT_BAZ,
message.GetExtension(Unittest.RepeatedImportEnumExtension, 1));
- Assert.AreEqual("324", message.GetExtension(Unittest.RepeatedStringPieceExtension, 1));
- Assert.AreEqual("325", message.GetExtension(Unittest.RepeatedCordExtension, 1));
+ Assert.Equal("324", message.GetExtension(Unittest.RepeatedStringPieceExtension, 1));
+ Assert.Equal("325", message.GetExtension(Unittest.RepeatedCordExtension, 1));
// -----------------------------------------------------------------
- Assert.IsTrue(message.HasExtension(Unittest.DefaultInt32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultInt64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultUint32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultUint64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultSint32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultSint64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultFixed32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultFixed64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultSfixed32Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultSfixed64Extension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultFloatExtension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultDoubleExtension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultBoolExtension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultStringExtension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultBytesExtension));
-
- Assert.IsTrue(message.HasExtension(Unittest.DefaultNestedEnumExtension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultForeignEnumExtension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultImportEnumExtension));
-
- Assert.IsTrue(message.HasExtension(Unittest.DefaultStringPieceExtension));
- Assert.IsTrue(message.HasExtension(Unittest.DefaultCordExtension));
-
- Assert.AreEqual(401, message.GetExtension(Unittest.DefaultInt32Extension));
- Assert.AreEqual(402L, message.GetExtension(Unittest.DefaultInt64Extension));
- Assert.AreEqual(403U, message.GetExtension(Unittest.DefaultUint32Extension));
- Assert.AreEqual(404UL, message.GetExtension(Unittest.DefaultUint64Extension));
- Assert.AreEqual(405, message.GetExtension(Unittest.DefaultSint32Extension));
- Assert.AreEqual(406L, message.GetExtension(Unittest.DefaultSint64Extension));
- Assert.AreEqual(407U, message.GetExtension(Unittest.DefaultFixed32Extension));
- Assert.AreEqual(408UL, message.GetExtension(Unittest.DefaultFixed64Extension));
- Assert.AreEqual(409, message.GetExtension(Unittest.DefaultSfixed32Extension));
- Assert.AreEqual(410L, message.GetExtension(Unittest.DefaultSfixed64Extension));
- Assert.AreEqual(411F, message.GetExtension(Unittest.DefaultFloatExtension));
- Assert.AreEqual(412D, message.GetExtension(Unittest.DefaultDoubleExtension));
- Assert.AreEqual(false, message.GetExtension(Unittest.DefaultBoolExtension));
- Assert.AreEqual("415", message.GetExtension(Unittest.DefaultStringExtension));
- Assert.AreEqual(ToBytes("416"), message.GetExtension(Unittest.DefaultBytesExtension));
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO,
+ Assert.True(message.HasExtension(Unittest.DefaultInt32Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultInt64Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultUint32Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultUint64Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultSint32Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultSint64Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultFixed32Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultFixed64Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultSfixed32Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultSfixed64Extension));
+ Assert.True(message.HasExtension(Unittest.DefaultFloatExtension));
+ Assert.True(message.HasExtension(Unittest.DefaultDoubleExtension));
+ Assert.True(message.HasExtension(Unittest.DefaultBoolExtension));
+ Assert.True(message.HasExtension(Unittest.DefaultStringExtension));
+ Assert.True(message.HasExtension(Unittest.DefaultBytesExtension));
+
+ Assert.True(message.HasExtension(Unittest.DefaultNestedEnumExtension));
+ Assert.True(message.HasExtension(Unittest.DefaultForeignEnumExtension));
+ Assert.True(message.HasExtension(Unittest.DefaultImportEnumExtension));
+
+ Assert.True(message.HasExtension(Unittest.DefaultStringPieceExtension));
+ Assert.True(message.HasExtension(Unittest.DefaultCordExtension));
+
+ Assert.Equal(401, message.GetExtension(Unittest.DefaultInt32Extension));
+ Assert.Equal(402L, message.GetExtension(Unittest.DefaultInt64Extension));
+ Assert.Equal(403U, message.GetExtension(Unittest.DefaultUint32Extension));
+ Assert.Equal(404UL, message.GetExtension(Unittest.DefaultUint64Extension));
+ Assert.Equal(405, message.GetExtension(Unittest.DefaultSint32Extension));
+ Assert.Equal(406L, message.GetExtension(Unittest.DefaultSint64Extension));
+ Assert.Equal(407U, message.GetExtension(Unittest.DefaultFixed32Extension));
+ Assert.Equal(408UL, message.GetExtension(Unittest.DefaultFixed64Extension));
+ Assert.Equal(409, message.GetExtension(Unittest.DefaultSfixed32Extension));
+ Assert.Equal(410L, message.GetExtension(Unittest.DefaultSfixed64Extension));
+ Assert.Equal(411F, message.GetExtension(Unittest.DefaultFloatExtension));
+ Assert.Equal(412D, message.GetExtension(Unittest.DefaultDoubleExtension));
+ Assert.Equal(false, message.GetExtension(Unittest.DefaultBoolExtension));
+ Assert.Equal("415", message.GetExtension(Unittest.DefaultStringExtension));
+ Assert.Equal(ToBytes("416"), message.GetExtension(Unittest.DefaultBytesExtension));
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.FOO,
message.GetExtension(Unittest.DefaultNestedEnumExtension));
- Assert.AreEqual(ForeignEnum.FOREIGN_FOO, message.GetExtension(Unittest.DefaultForeignEnumExtension));
- Assert.AreEqual(ImportEnum.IMPORT_FOO, message.GetExtension(Unittest.DefaultImportEnumExtension));
+ Assert.Equal(ForeignEnum.FOREIGN_FOO, message.GetExtension(Unittest.DefaultForeignEnumExtension));
+ Assert.Equal(ImportEnum.IMPORT_FOO, message.GetExtension(Unittest.DefaultImportEnumExtension));
- Assert.AreEqual("424", message.GetExtension(Unittest.DefaultStringPieceExtension));
- Assert.AreEqual("425", message.GetExtension(Unittest.DefaultCordExtension));
+ Assert.Equal("424", message.GetExtension(Unittest.DefaultStringPieceExtension));
+ Assert.Equal("425", message.GetExtension(Unittest.DefaultCordExtension));
}
/// <summary>
@@ -1215,242 +1215,242 @@ namespace Google.ProtocolBuffers // ModifyRepeatedFields only sets the second repeated element of each
// field. In addition to verifying this, we also verify that the first
// element and size were *not* modified.
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedInt32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedInt64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedUint32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedUint64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedSint32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedSint64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedFixed32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedFixed64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedSfixed32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedSfixed64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedFloatExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedDoubleExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedBoolExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedStringExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedBytesExtension));
-
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedGroupExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedNestedMessageExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedForeignMessageExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedImportMessageExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedNestedEnumExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedForeignEnumExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedImportEnumExtension));
-
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedStringPieceExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.RepeatedCordExtension));
-
- Assert.AreEqual(201, message.GetExtension(Unittest.RepeatedInt32Extension, 0));
- Assert.AreEqual(202L, message.GetExtension(Unittest.RepeatedInt64Extension, 0));
- Assert.AreEqual(203U, message.GetExtension(Unittest.RepeatedUint32Extension, 0));
- Assert.AreEqual(204UL, message.GetExtension(Unittest.RepeatedUint64Extension, 0));
- Assert.AreEqual(205, message.GetExtension(Unittest.RepeatedSint32Extension, 0));
- Assert.AreEqual(206L, message.GetExtension(Unittest.RepeatedSint64Extension, 0));
- Assert.AreEqual(207U, message.GetExtension(Unittest.RepeatedFixed32Extension, 0));
- Assert.AreEqual(208UL, message.GetExtension(Unittest.RepeatedFixed64Extension, 0));
- Assert.AreEqual(209, message.GetExtension(Unittest.RepeatedSfixed32Extension, 0));
- Assert.AreEqual(210L, message.GetExtension(Unittest.RepeatedSfixed64Extension, 0));
- Assert.AreEqual(211F, message.GetExtension(Unittest.RepeatedFloatExtension, 0));
- Assert.AreEqual(212D, message.GetExtension(Unittest.RepeatedDoubleExtension, 0));
- Assert.AreEqual(true, message.GetExtension(Unittest.RepeatedBoolExtension, 0));
- Assert.AreEqual("215", message.GetExtension(Unittest.RepeatedStringExtension, 0));
- Assert.AreEqual(ToBytes("216"), message.GetExtension(Unittest.RepeatedBytesExtension, 0));
-
- Assert.AreEqual(217, message.GetExtension(Unittest.RepeatedGroupExtension, 0).A);
- Assert.AreEqual(218, message.GetExtension(Unittest.RepeatedNestedMessageExtension, 0).Bb);
- Assert.AreEqual(219, message.GetExtension(Unittest.RepeatedForeignMessageExtension, 0).C);
- Assert.AreEqual(220, message.GetExtension(Unittest.RepeatedImportMessageExtension, 0).D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR,
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedInt32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedInt64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedUint32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedUint64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedSint32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedSint64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedFixed32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedFixed64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedSfixed32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedSfixed64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedFloatExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedDoubleExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedBoolExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedStringExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedBytesExtension));
+
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedGroupExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedNestedMessageExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedForeignMessageExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedImportMessageExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedNestedEnumExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedForeignEnumExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedImportEnumExtension));
+
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedStringPieceExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.RepeatedCordExtension));
+
+ Assert.Equal(201, message.GetExtension(Unittest.RepeatedInt32Extension, 0));
+ Assert.Equal(202L, message.GetExtension(Unittest.RepeatedInt64Extension, 0));
+ Assert.Equal(203U, message.GetExtension(Unittest.RepeatedUint32Extension, 0));
+ Assert.Equal(204UL, message.GetExtension(Unittest.RepeatedUint64Extension, 0));
+ Assert.Equal(205, message.GetExtension(Unittest.RepeatedSint32Extension, 0));
+ Assert.Equal(206L, message.GetExtension(Unittest.RepeatedSint64Extension, 0));
+ Assert.Equal(207U, message.GetExtension(Unittest.RepeatedFixed32Extension, 0));
+ Assert.Equal(208UL, message.GetExtension(Unittest.RepeatedFixed64Extension, 0));
+ Assert.Equal(209, message.GetExtension(Unittest.RepeatedSfixed32Extension, 0));
+ Assert.Equal(210L, message.GetExtension(Unittest.RepeatedSfixed64Extension, 0));
+ Assert.Equal(211F, message.GetExtension(Unittest.RepeatedFloatExtension, 0));
+ Assert.Equal(212D, message.GetExtension(Unittest.RepeatedDoubleExtension, 0));
+ Assert.Equal(true, message.GetExtension(Unittest.RepeatedBoolExtension, 0));
+ Assert.Equal("215", message.GetExtension(Unittest.RepeatedStringExtension, 0));
+ Assert.Equal(ToBytes("216"), message.GetExtension(Unittest.RepeatedBytesExtension, 0));
+
+ Assert.Equal(217, message.GetExtension(Unittest.RepeatedGroupExtension, 0).A);
+ Assert.Equal(218, message.GetExtension(Unittest.RepeatedNestedMessageExtension, 0).Bb);
+ Assert.Equal(219, message.GetExtension(Unittest.RepeatedForeignMessageExtension, 0).C);
+ Assert.Equal(220, message.GetExtension(Unittest.RepeatedImportMessageExtension, 0).D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAR,
message.GetExtension(Unittest.RepeatedNestedEnumExtension, 0));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR,
+ Assert.Equal(ForeignEnum.FOREIGN_BAR,
message.GetExtension(Unittest.RepeatedForeignEnumExtension, 0));
- Assert.AreEqual(ImportEnum.IMPORT_BAR,
+ Assert.Equal(ImportEnum.IMPORT_BAR,
message.GetExtension(Unittest.RepeatedImportEnumExtension, 0));
- Assert.AreEqual("224", message.GetExtension(Unittest.RepeatedStringPieceExtension, 0));
- Assert.AreEqual("225", message.GetExtension(Unittest.RepeatedCordExtension, 0));
+ Assert.Equal("224", message.GetExtension(Unittest.RepeatedStringPieceExtension, 0));
+ Assert.Equal("225", message.GetExtension(Unittest.RepeatedCordExtension, 0));
// Actually verify the second (modified) elements now.
- Assert.AreEqual(501, message.GetExtension(Unittest.RepeatedInt32Extension, 1));
- Assert.AreEqual(502L, message.GetExtension(Unittest.RepeatedInt64Extension, 1));
- Assert.AreEqual(503U, message.GetExtension(Unittest.RepeatedUint32Extension, 1));
- Assert.AreEqual(504UL, message.GetExtension(Unittest.RepeatedUint64Extension, 1));
- Assert.AreEqual(505, message.GetExtension(Unittest.RepeatedSint32Extension, 1));
- Assert.AreEqual(506L, message.GetExtension(Unittest.RepeatedSint64Extension, 1));
- Assert.AreEqual(507U, message.GetExtension(Unittest.RepeatedFixed32Extension, 1));
- Assert.AreEqual(508UL, message.GetExtension(Unittest.RepeatedFixed64Extension, 1));
- Assert.AreEqual(509, message.GetExtension(Unittest.RepeatedSfixed32Extension, 1));
- Assert.AreEqual(510L, message.GetExtension(Unittest.RepeatedSfixed64Extension, 1));
- Assert.AreEqual(511F, message.GetExtension(Unittest.RepeatedFloatExtension, 1));
- Assert.AreEqual(512D, message.GetExtension(Unittest.RepeatedDoubleExtension, 1));
- Assert.AreEqual(true, message.GetExtension(Unittest.RepeatedBoolExtension, 1));
- Assert.AreEqual("515", message.GetExtension(Unittest.RepeatedStringExtension, 1));
- Assert.AreEqual(ToBytes("516"), message.GetExtension(Unittest.RepeatedBytesExtension, 1));
-
- Assert.AreEqual(517, message.GetExtension(Unittest.RepeatedGroupExtension, 1).A);
- Assert.AreEqual(518, message.GetExtension(Unittest.RepeatedNestedMessageExtension, 1).Bb);
- Assert.AreEqual(519, message.GetExtension(Unittest.RepeatedForeignMessageExtension, 1).C);
- Assert.AreEqual(520, message.GetExtension(Unittest.RepeatedImportMessageExtension, 1).D);
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO,
+ Assert.Equal(501, message.GetExtension(Unittest.RepeatedInt32Extension, 1));
+ Assert.Equal(502L, message.GetExtension(Unittest.RepeatedInt64Extension, 1));
+ Assert.Equal(503U, message.GetExtension(Unittest.RepeatedUint32Extension, 1));
+ Assert.Equal(504UL, message.GetExtension(Unittest.RepeatedUint64Extension, 1));
+ Assert.Equal(505, message.GetExtension(Unittest.RepeatedSint32Extension, 1));
+ Assert.Equal(506L, message.GetExtension(Unittest.RepeatedSint64Extension, 1));
+ Assert.Equal(507U, message.GetExtension(Unittest.RepeatedFixed32Extension, 1));
+ Assert.Equal(508UL, message.GetExtension(Unittest.RepeatedFixed64Extension, 1));
+ Assert.Equal(509, message.GetExtension(Unittest.RepeatedSfixed32Extension, 1));
+ Assert.Equal(510L, message.GetExtension(Unittest.RepeatedSfixed64Extension, 1));
+ Assert.Equal(511F, message.GetExtension(Unittest.RepeatedFloatExtension, 1));
+ Assert.Equal(512D, message.GetExtension(Unittest.RepeatedDoubleExtension, 1));
+ Assert.Equal(true, message.GetExtension(Unittest.RepeatedBoolExtension, 1));
+ Assert.Equal("515", message.GetExtension(Unittest.RepeatedStringExtension, 1));
+ Assert.Equal(ToBytes("516"), message.GetExtension(Unittest.RepeatedBytesExtension, 1));
+
+ Assert.Equal(517, message.GetExtension(Unittest.RepeatedGroupExtension, 1).A);
+ Assert.Equal(518, message.GetExtension(Unittest.RepeatedNestedMessageExtension, 1).Bb);
+ Assert.Equal(519, message.GetExtension(Unittest.RepeatedForeignMessageExtension, 1).C);
+ Assert.Equal(520, message.GetExtension(Unittest.RepeatedImportMessageExtension, 1).D);
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.FOO,
message.GetExtension(Unittest.RepeatedNestedEnumExtension, 1));
- Assert.AreEqual(ForeignEnum.FOREIGN_FOO,
+ Assert.Equal(ForeignEnum.FOREIGN_FOO,
message.GetExtension(Unittest.RepeatedForeignEnumExtension, 1));
- Assert.AreEqual(ImportEnum.IMPORT_FOO,
+ Assert.Equal(ImportEnum.IMPORT_FOO,
message.GetExtension(Unittest.RepeatedImportEnumExtension, 1));
- Assert.AreEqual("524", message.GetExtension(Unittest.RepeatedStringPieceExtension, 1));
- Assert.AreEqual("525", message.GetExtension(Unittest.RepeatedCordExtension, 1));
+ Assert.Equal("524", message.GetExtension(Unittest.RepeatedStringPieceExtension, 1));
+ Assert.Equal("525", message.GetExtension(Unittest.RepeatedCordExtension, 1));
}
internal static void AssertExtensionsClear(TestAllExtensions message)
{
// HasBlah() should initially be false for all optional fields.
- Assert.IsFalse(message.HasExtension(Unittest.OptionalInt32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalInt64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalUint32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalUint64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalSint32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalSint64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalFixed32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalFixed64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalSfixed32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalSfixed64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalFloatExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalDoubleExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalBoolExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalStringExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalBytesExtension));
-
- Assert.IsFalse(message.HasExtension(Unittest.OptionalGroupExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalNestedMessageExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalForeignMessageExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalImportMessageExtension));
-
- Assert.IsFalse(message.HasExtension(Unittest.OptionalNestedEnumExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalForeignEnumExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalImportEnumExtension));
-
- Assert.IsFalse(message.HasExtension(Unittest.OptionalStringPieceExtension));
- Assert.IsFalse(message.HasExtension(Unittest.OptionalCordExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalInt32Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalInt64Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalUint32Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalUint64Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalSint32Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalSint64Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalFixed32Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalFixed64Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalSfixed32Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalSfixed64Extension));
+ Assert.False(message.HasExtension(Unittest.OptionalFloatExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalDoubleExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalBoolExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalStringExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalBytesExtension));
+
+ Assert.False(message.HasExtension(Unittest.OptionalGroupExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalNestedMessageExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalForeignMessageExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalImportMessageExtension));
+
+ Assert.False(message.HasExtension(Unittest.OptionalNestedEnumExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalForeignEnumExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalImportEnumExtension));
+
+ Assert.False(message.HasExtension(Unittest.OptionalStringPieceExtension));
+ Assert.False(message.HasExtension(Unittest.OptionalCordExtension));
// Optional fields without defaults are set to zero or something like it.
- Assert.AreEqual(0, message.GetExtension(Unittest.OptionalInt32Extension));
- Assert.AreEqual(0L, message.GetExtension(Unittest.OptionalInt64Extension));
- Assert.AreEqual(0U, message.GetExtension(Unittest.OptionalUint32Extension));
- Assert.AreEqual(0UL, message.GetExtension(Unittest.OptionalUint64Extension));
- Assert.AreEqual(0, message.GetExtension(Unittest.OptionalSint32Extension));
- Assert.AreEqual(0L, message.GetExtension(Unittest.OptionalSint64Extension));
- Assert.AreEqual(0U, message.GetExtension(Unittest.OptionalFixed32Extension));
- Assert.AreEqual(0UL, message.GetExtension(Unittest.OptionalFixed64Extension));
- Assert.AreEqual(0, message.GetExtension(Unittest.OptionalSfixed32Extension));
- Assert.AreEqual(0L, message.GetExtension(Unittest.OptionalSfixed64Extension));
- Assert.AreEqual(0F, message.GetExtension(Unittest.OptionalFloatExtension));
- Assert.AreEqual(0D, message.GetExtension(Unittest.OptionalDoubleExtension));
- Assert.AreEqual(false, message.GetExtension(Unittest.OptionalBoolExtension));
- Assert.AreEqual("", message.GetExtension(Unittest.OptionalStringExtension));
- Assert.AreEqual(ByteString.Empty, message.GetExtension(Unittest.OptionalBytesExtension));
+ Assert.Equal(0, message.GetExtension(Unittest.OptionalInt32Extension));
+ Assert.Equal(0L, message.GetExtension(Unittest.OptionalInt64Extension));
+ Assert.Equal(0U, message.GetExtension(Unittest.OptionalUint32Extension));
+ Assert.Equal(0UL, message.GetExtension(Unittest.OptionalUint64Extension));
+ Assert.Equal(0, message.GetExtension(Unittest.OptionalSint32Extension));
+ Assert.Equal(0L, message.GetExtension(Unittest.OptionalSint64Extension));
+ Assert.Equal(0U, message.GetExtension(Unittest.OptionalFixed32Extension));
+ Assert.Equal(0UL, message.GetExtension(Unittest.OptionalFixed64Extension));
+ Assert.Equal(0, message.GetExtension(Unittest.OptionalSfixed32Extension));
+ Assert.Equal(0L, message.GetExtension(Unittest.OptionalSfixed64Extension));
+ Assert.Equal(0F, message.GetExtension(Unittest.OptionalFloatExtension));
+ Assert.Equal(0D, message.GetExtension(Unittest.OptionalDoubleExtension));
+ Assert.Equal(false, message.GetExtension(Unittest.OptionalBoolExtension));
+ Assert.Equal("", message.GetExtension(Unittest.OptionalStringExtension));
+ Assert.Equal(ByteString.Empty, message.GetExtension(Unittest.OptionalBytesExtension));
// Embedded messages should also be clear.
- Assert.IsFalse(message.GetExtension(Unittest.OptionalGroupExtension).HasA);
- Assert.IsFalse(message.GetExtension(Unittest.OptionalNestedMessageExtension).HasBb);
- Assert.IsFalse(message.GetExtension(Unittest.OptionalForeignMessageExtension).HasC);
- Assert.IsFalse(message.GetExtension(Unittest.OptionalImportMessageExtension).HasD);
+ Assert.False(message.GetExtension(Unittest.OptionalGroupExtension).HasA);
+ Assert.False(message.GetExtension(Unittest.OptionalNestedMessageExtension).HasBb);
+ Assert.False(message.GetExtension(Unittest.OptionalForeignMessageExtension).HasC);
+ Assert.False(message.GetExtension(Unittest.OptionalImportMessageExtension).HasD);
- Assert.AreEqual(0, message.GetExtension(Unittest.OptionalGroupExtension).A);
- Assert.AreEqual(0, message.GetExtension(Unittest.OptionalNestedMessageExtension).Bb);
- Assert.AreEqual(0, message.GetExtension(Unittest.OptionalForeignMessageExtension).C);
- Assert.AreEqual(0, message.GetExtension(Unittest.OptionalImportMessageExtension).D);
+ Assert.Equal(0, message.GetExtension(Unittest.OptionalGroupExtension).A);
+ Assert.Equal(0, message.GetExtension(Unittest.OptionalNestedMessageExtension).Bb);
+ Assert.Equal(0, message.GetExtension(Unittest.OptionalForeignMessageExtension).C);
+ Assert.Equal(0, message.GetExtension(Unittest.OptionalImportMessageExtension).D);
// Enums without defaults are set to the first value in the enum.
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO,
+ Assert.Equal(TestAllTypes.Types.NestedEnum.FOO,
message.GetExtension(Unittest.OptionalNestedEnumExtension));
- Assert.AreEqual(ForeignEnum.FOREIGN_FOO,
+ Assert.Equal(ForeignEnum.FOREIGN_FOO,
message.GetExtension(Unittest.OptionalForeignEnumExtension));
- Assert.AreEqual(ImportEnum.IMPORT_FOO, message.GetExtension(Unittest.OptionalImportEnumExtension));
+ Assert.Equal(ImportEnum.IMPORT_FOO, message.GetExtension(Unittest.OptionalImportEnumExtension));
- Assert.AreEqual("", message.GetExtension(Unittest.OptionalStringPieceExtension));
- Assert.AreEqual("", message.GetExtension(Unittest.OptionalCordExtension));
+ Assert.Equal("", message.GetExtension(Unittest.OptionalStringPieceExtension));
+ Assert.Equal("", message.GetExtension(Unittest.OptionalCordExtension));
// Repeated fields are empty.
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedInt32Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedInt64Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedUint32Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedUint64Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedSint32Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedSint64Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedFixed32Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedFixed64Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedSfixed32Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedSfixed64Extension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedFloatExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedDoubleExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedBoolExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedStringExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedBytesExtension));
-
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedGroupExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedNestedMessageExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedForeignMessageExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedImportMessageExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedNestedEnumExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedForeignEnumExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedImportEnumExtension));
-
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedStringPieceExtension));
- Assert.AreEqual(0, message.GetExtensionCount(Unittest.RepeatedCordExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedInt32Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedInt64Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedUint32Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedUint64Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedSint32Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedSint64Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedFixed32Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedFixed64Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedSfixed32Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedSfixed64Extension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedFloatExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedDoubleExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedBoolExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedStringExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedBytesExtension));
+
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedGroupExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedNestedMessageExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedForeignMessageExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedImportMessageExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedNestedEnumExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedForeignEnumExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedImportEnumExtension));
+
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedStringPieceExtension));
+ Assert.Equal(0, message.GetExtensionCount(Unittest.RepeatedCordExtension));
// HasBlah() should also be false for all default fields.
- Assert.IsFalse(message.HasExtension(Unittest.DefaultInt32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultInt64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultUint32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultUint64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultSint32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultSint64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultFixed32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultFixed64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultSfixed32Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultSfixed64Extension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultFloatExtension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultDoubleExtension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultBoolExtension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultStringExtension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultBytesExtension));
-
- Assert.IsFalse(message.HasExtension(Unittest.DefaultNestedEnumExtension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultForeignEnumExtension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultImportEnumExtension));
-
- Assert.IsFalse(message.HasExtension(Unittest.DefaultStringPieceExtension));
- Assert.IsFalse(message.HasExtension(Unittest.DefaultCordExtension));
+ Assert.False(message.HasExtension(Unittest.DefaultInt32Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultInt64Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultUint32Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultUint64Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultSint32Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultSint64Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultFixed32Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultFixed64Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultSfixed32Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultSfixed64Extension));
+ Assert.False(message.HasExtension(Unittest.DefaultFloatExtension));
+ Assert.False(message.HasExtension(Unittest.DefaultDoubleExtension));
+ Assert.False(message.HasExtension(Unittest.DefaultBoolExtension));
+ Assert.False(message.HasExtension(Unittest.DefaultStringExtension));
+ Assert.False(message.HasExtension(Unittest.DefaultBytesExtension));
+
+ Assert.False(message.HasExtension(Unittest.DefaultNestedEnumExtension));
+ Assert.False(message.HasExtension(Unittest.DefaultForeignEnumExtension));
+ Assert.False(message.HasExtension(Unittest.DefaultImportEnumExtension));
+
+ Assert.False(message.HasExtension(Unittest.DefaultStringPieceExtension));
+ Assert.False(message.HasExtension(Unittest.DefaultCordExtension));
// Fields with defaults have their default values (duh).
- Assert.AreEqual(41, message.GetExtension(Unittest.DefaultInt32Extension));
- Assert.AreEqual(42L, message.GetExtension(Unittest.DefaultInt64Extension));
- Assert.AreEqual(43U, message.GetExtension(Unittest.DefaultUint32Extension));
- Assert.AreEqual(44UL, message.GetExtension(Unittest.DefaultUint64Extension));
- Assert.AreEqual(-45, message.GetExtension(Unittest.DefaultSint32Extension));
- Assert.AreEqual(46L, message.GetExtension(Unittest.DefaultSint64Extension));
- Assert.AreEqual(47U, message.GetExtension(Unittest.DefaultFixed32Extension));
- Assert.AreEqual(48UL, message.GetExtension(Unittest.DefaultFixed64Extension));
- Assert.AreEqual(49, message.GetExtension(Unittest.DefaultSfixed32Extension));
- Assert.AreEqual(-50L, message.GetExtension(Unittest.DefaultSfixed64Extension));
- Assert.AreEqual(51.5F, message.GetExtension(Unittest.DefaultFloatExtension));
- Assert.AreEqual(52e3D, message.GetExtension(Unittest.DefaultDoubleExtension));
- Assert.AreEqual(true, message.GetExtension(Unittest.DefaultBoolExtension));
- Assert.AreEqual("hello", message.GetExtension(Unittest.DefaultStringExtension));
- Assert.AreEqual(ToBytes("world"), message.GetExtension(Unittest.DefaultBytesExtension));
-
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR,
+ Assert.Equal(41, message.GetExtension(Unittest.DefaultInt32Extension));
+ Assert.Equal(42L, message.GetExtension(Unittest.DefaultInt64Extension));
+ Assert.Equal(43U, message.GetExtension(Unittest.DefaultUint32Extension));
+ Assert.Equal(44UL, message.GetExtension(Unittest.DefaultUint64Extension));
+ Assert.Equal(-45, message.GetExtension(Unittest.DefaultSint32Extension));
+ Assert.Equal(46L, message.GetExtension(Unittest.DefaultSint64Extension));
+ Assert.Equal(47U, message.GetExtension(Unittest.DefaultFixed32Extension));
+ Assert.Equal(48UL, message.GetExtension(Unittest.DefaultFixed64Extension));
+ Assert.Equal(49, message.GetExtension(Unittest.DefaultSfixed32Extension));
+ Assert.Equal(-50L, message.GetExtension(Unittest.DefaultSfixed64Extension));
+ Assert.Equal(51.5F, message.GetExtension(Unittest.DefaultFloatExtension));
+ Assert.Equal(52e3D, message.GetExtension(Unittest.DefaultDoubleExtension));
+ Assert.Equal(true, message.GetExtension(Unittest.DefaultBoolExtension));
+ Assert.Equal("hello", message.GetExtension(Unittest.DefaultStringExtension));
+ Assert.Equal(ToBytes("world"), message.GetExtension(Unittest.DefaultBytesExtension));
+
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAR,
message.GetExtension(Unittest.DefaultNestedEnumExtension));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR, message.GetExtension(Unittest.DefaultForeignEnumExtension));
- Assert.AreEqual(ImportEnum.IMPORT_BAR, message.GetExtension(Unittest.DefaultImportEnumExtension));
+ Assert.Equal(ForeignEnum.FOREIGN_BAR, message.GetExtension(Unittest.DefaultForeignEnumExtension));
+ Assert.Equal(ImportEnum.IMPORT_BAR, message.GetExtension(Unittest.DefaultImportEnumExtension));
- Assert.AreEqual("abc", message.GetExtension(Unittest.DefaultStringPieceExtension));
- Assert.AreEqual("123", message.GetExtension(Unittest.DefaultCordExtension));
+ Assert.Equal("abc", message.GetExtension(Unittest.DefaultStringPieceExtension));
+ Assert.Equal("123", message.GetExtension(Unittest.DefaultCordExtension));
}
/// <summary>
@@ -1495,48 +1495,48 @@ namespace Google.ProtocolBuffers /// </summary>
public static void AssertPackedFieldsSet(TestPackedTypes message)
{
- Assert.AreEqual(2, message.PackedInt32Count);
- Assert.AreEqual(2, message.PackedInt64Count);
- Assert.AreEqual(2, message.PackedUint32Count);
- Assert.AreEqual(2, message.PackedUint64Count);
- Assert.AreEqual(2, message.PackedSint32Count);
- Assert.AreEqual(2, message.PackedSint64Count);
- Assert.AreEqual(2, message.PackedFixed32Count);
- Assert.AreEqual(2, message.PackedFixed64Count);
- Assert.AreEqual(2, message.PackedSfixed32Count);
- Assert.AreEqual(2, message.PackedSfixed64Count);
- Assert.AreEqual(2, message.PackedFloatCount);
- Assert.AreEqual(2, message.PackedDoubleCount);
- Assert.AreEqual(2, message.PackedBoolCount);
- Assert.AreEqual(2, message.PackedEnumCount);
- Assert.AreEqual(601, message.GetPackedInt32(0));
- Assert.AreEqual(602, message.GetPackedInt64(0));
- Assert.AreEqual(603u, message.GetPackedUint32(0));
- Assert.AreEqual(604u, message.GetPackedUint64(0));
- Assert.AreEqual(605, message.GetPackedSint32(0));
- Assert.AreEqual(606, message.GetPackedSint64(0));
- Assert.AreEqual(607u, message.GetPackedFixed32(0));
- Assert.AreEqual(608u, message.GetPackedFixed64(0));
- Assert.AreEqual(609, message.GetPackedSfixed32(0));
- Assert.AreEqual(610, message.GetPackedSfixed64(0));
- Assert.AreEqual(611, message.GetPackedFloat(0), 0.0);
- Assert.AreEqual(612, message.GetPackedDouble(0), 0.0);
- Assert.AreEqual(true, message.GetPackedBool(0));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR, message.GetPackedEnum(0));
- Assert.AreEqual(701, message.GetPackedInt32(1));
- Assert.AreEqual(702, message.GetPackedInt64(1));
- Assert.AreEqual(703u, message.GetPackedUint32(1));
- Assert.AreEqual(704u, message.GetPackedUint64(1));
- Assert.AreEqual(705, message.GetPackedSint32(1));
- Assert.AreEqual(706, message.GetPackedSint64(1));
- Assert.AreEqual(707u, message.GetPackedFixed32(1));
- Assert.AreEqual(708u, message.GetPackedFixed64(1));
- Assert.AreEqual(709, message.GetPackedSfixed32(1));
- Assert.AreEqual(710, message.GetPackedSfixed64(1));
- Assert.AreEqual(711, message.GetPackedFloat(1), 0.0);
- Assert.AreEqual(712, message.GetPackedDouble(1), 0.0);
- Assert.AreEqual(false, message.GetPackedBool(1));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ, message.GetPackedEnum(1));
+ Assert.Equal(2, message.PackedInt32Count);
+ Assert.Equal(2, message.PackedInt64Count);
+ Assert.Equal(2, message.PackedUint32Count);
+ Assert.Equal(2, message.PackedUint64Count);
+ Assert.Equal(2, message.PackedSint32Count);
+ Assert.Equal(2, message.PackedSint64Count);
+ Assert.Equal(2, message.PackedFixed32Count);
+ Assert.Equal(2, message.PackedFixed64Count);
+ Assert.Equal(2, message.PackedSfixed32Count);
+ Assert.Equal(2, message.PackedSfixed64Count);
+ Assert.Equal(2, message.PackedFloatCount);
+ Assert.Equal(2, message.PackedDoubleCount);
+ Assert.Equal(2, message.PackedBoolCount);
+ Assert.Equal(2, message.PackedEnumCount);
+ Assert.Equal(601, message.GetPackedInt32(0));
+ Assert.Equal(602, message.GetPackedInt64(0));
+ Assert.Equal(603u, message.GetPackedUint32(0));
+ Assert.Equal(604u, message.GetPackedUint64(0));
+ Assert.Equal(605, message.GetPackedSint32(0));
+ Assert.Equal(606, message.GetPackedSint64(0));
+ Assert.Equal(607u, message.GetPackedFixed32(0));
+ Assert.Equal(608u, message.GetPackedFixed64(0));
+ Assert.Equal(609, message.GetPackedSfixed32(0));
+ Assert.Equal(610, message.GetPackedSfixed64(0));
+ Assert.Equal(611f, message.GetPackedFloat(0));
+ Assert.Equal(612d, message.GetPackedDouble(0));
+ Assert.Equal(true, message.GetPackedBool(0));
+ Assert.Equal(ForeignEnum.FOREIGN_BAR, message.GetPackedEnum(0));
+ Assert.Equal(701, message.GetPackedInt32(1));
+ Assert.Equal(702, message.GetPackedInt64(1));
+ Assert.Equal(703u, message.GetPackedUint32(1));
+ Assert.Equal(704u, message.GetPackedUint64(1));
+ Assert.Equal(705, message.GetPackedSint32(1));
+ Assert.Equal(706, message.GetPackedSint64(1));
+ Assert.Equal(707u, message.GetPackedFixed32(1));
+ Assert.Equal(708u, message.GetPackedFixed64(1));
+ Assert.Equal(709, message.GetPackedSfixed32(1));
+ Assert.Equal(710, message.GetPackedSfixed64(1));
+ Assert.Equal(711f, message.GetPackedFloat(1));
+ Assert.Equal(712d, message.GetPackedDouble(1));
+ Assert.Equal(false, message.GetPackedBool(1));
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ, message.GetPackedEnum(1));
}
/// <summary>
/// Asserts that all the fields of the specified message are set to the values assigned
@@ -1544,48 +1544,48 @@ namespace Google.ProtocolBuffers /// </summary>
public static void AssertUnpackedFieldsSet(TestUnpackedTypes message)
{
- Assert.AreEqual(2, message.UnpackedInt32Count);
- Assert.AreEqual(2, message.UnpackedInt64Count);
- Assert.AreEqual(2, message.UnpackedUint32Count);
- Assert.AreEqual(2, message.UnpackedUint64Count);
- Assert.AreEqual(2, message.UnpackedSint32Count);
- Assert.AreEqual(2, message.UnpackedSint64Count);
- Assert.AreEqual(2, message.UnpackedFixed32Count);
- Assert.AreEqual(2, message.UnpackedFixed64Count);
- Assert.AreEqual(2, message.UnpackedSfixed32Count);
- Assert.AreEqual(2, message.UnpackedSfixed64Count);
- Assert.AreEqual(2, message.UnpackedFloatCount);
- Assert.AreEqual(2, message.UnpackedDoubleCount);
- Assert.AreEqual(2, message.UnpackedBoolCount);
- Assert.AreEqual(2, message.UnpackedEnumCount);
- Assert.AreEqual(601, message.GetUnpackedInt32(0));
- Assert.AreEqual(602, message.GetUnpackedInt64(0));
- Assert.AreEqual(603u, message.GetUnpackedUint32(0));
- Assert.AreEqual(604u, message.GetUnpackedUint64(0));
- Assert.AreEqual(605, message.GetUnpackedSint32(0));
- Assert.AreEqual(606, message.GetUnpackedSint64(0));
- Assert.AreEqual(607u, message.GetUnpackedFixed32(0));
- Assert.AreEqual(608u, message.GetUnpackedFixed64(0));
- Assert.AreEqual(609, message.GetUnpackedSfixed32(0));
- Assert.AreEqual(610, message.GetUnpackedSfixed64(0));
- Assert.AreEqual(611, message.GetUnpackedFloat(0), 0.0);
- Assert.AreEqual(612, message.GetUnpackedDouble(0), 0.0);
- Assert.AreEqual(true, message.GetUnpackedBool(0));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR, message.GetUnpackedEnum(0));
- Assert.AreEqual(701, message.GetUnpackedInt32(1));
- Assert.AreEqual(702, message.GetUnpackedInt64(1));
- Assert.AreEqual(703u, message.GetUnpackedUint32(1));
- Assert.AreEqual(704u, message.GetUnpackedUint64(1));
- Assert.AreEqual(705, message.GetUnpackedSint32(1));
- Assert.AreEqual(706, message.GetUnpackedSint64(1));
- Assert.AreEqual(707u, message.GetUnpackedFixed32(1));
- Assert.AreEqual(708u, message.GetUnpackedFixed64(1));
- Assert.AreEqual(709, message.GetUnpackedSfixed32(1));
- Assert.AreEqual(710, message.GetUnpackedSfixed64(1));
- Assert.AreEqual(711, message.GetUnpackedFloat(1), 0.0);
- Assert.AreEqual(712, message.GetUnpackedDouble(1), 0.0);
- Assert.AreEqual(false, message.GetUnpackedBool(1));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ, message.GetUnpackedEnum(1));
+ Assert.Equal(2, message.UnpackedInt32Count);
+ Assert.Equal(2, message.UnpackedInt64Count);
+ Assert.Equal(2, message.UnpackedUint32Count);
+ Assert.Equal(2, message.UnpackedUint64Count);
+ Assert.Equal(2, message.UnpackedSint32Count);
+ Assert.Equal(2, message.UnpackedSint64Count);
+ Assert.Equal(2, message.UnpackedFixed32Count);
+ Assert.Equal(2, message.UnpackedFixed64Count);
+ Assert.Equal(2, message.UnpackedSfixed32Count);
+ Assert.Equal(2, message.UnpackedSfixed64Count);
+ Assert.Equal(2, message.UnpackedFloatCount);
+ Assert.Equal(2, message.UnpackedDoubleCount);
+ Assert.Equal(2, message.UnpackedBoolCount);
+ Assert.Equal(2, message.UnpackedEnumCount);
+ Assert.Equal(601, message.GetUnpackedInt32(0));
+ Assert.Equal(602, message.GetUnpackedInt64(0));
+ Assert.Equal(603u, message.GetUnpackedUint32(0));
+ Assert.Equal(604u, message.GetUnpackedUint64(0));
+ Assert.Equal(605, message.GetUnpackedSint32(0));
+ Assert.Equal(606, message.GetUnpackedSint64(0));
+ Assert.Equal(607u, message.GetUnpackedFixed32(0));
+ Assert.Equal(608u, message.GetUnpackedFixed64(0));
+ Assert.Equal(609, message.GetUnpackedSfixed32(0));
+ Assert.Equal(610, message.GetUnpackedSfixed64(0));
+ Assert.Equal(611f, message.GetUnpackedFloat(0));
+ Assert.Equal(612d, message.GetUnpackedDouble(0));
+ Assert.Equal(true, message.GetUnpackedBool(0));
+ Assert.Equal(ForeignEnum.FOREIGN_BAR, message.GetUnpackedEnum(0));
+ Assert.Equal(701, message.GetUnpackedInt32(1));
+ Assert.Equal(702, message.GetUnpackedInt64(1));
+ Assert.Equal(703u, message.GetUnpackedUint32(1));
+ Assert.Equal(704u, message.GetUnpackedUint64(1));
+ Assert.Equal(705, message.GetUnpackedSint32(1));
+ Assert.Equal(706, message.GetUnpackedSint64(1));
+ Assert.Equal(707u, message.GetUnpackedFixed32(1));
+ Assert.Equal(708u, message.GetUnpackedFixed64(1));
+ Assert.Equal(709, message.GetUnpackedSfixed32(1));
+ Assert.Equal(710, message.GetUnpackedSfixed64(1));
+ Assert.Equal(711f, message.GetUnpackedFloat(1));
+ Assert.Equal(712d, message.GetUnpackedDouble(1));
+ Assert.Equal(false, message.GetUnpackedBool(1));
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ, message.GetUnpackedEnum(1));
}
public static void SetPackedExtensions(TestPackedExtensions.Builder message)
@@ -1623,95 +1623,95 @@ namespace Google.ProtocolBuffers public static void AssertPackedExtensionsSet(TestPackedExtensions message)
{
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedInt32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedInt64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedUint32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedUint64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedSint32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedSint64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedFixed32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedFixed64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedSfixed32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedSfixed64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedFloatExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedDoubleExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedBoolExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.PackedEnumExtension));
- Assert.AreEqual(601, message.GetExtension(Unittest.PackedInt32Extension, 0));
- Assert.AreEqual(602L, message.GetExtension(Unittest.PackedInt64Extension, 0));
- Assert.AreEqual(603u, message.GetExtension(Unittest.PackedUint32Extension, 0));
- Assert.AreEqual(604uL, message.GetExtension(Unittest.PackedUint64Extension, 0));
- Assert.AreEqual(605, message.GetExtension(Unittest.PackedSint32Extension, 0));
- Assert.AreEqual(606L, message.GetExtension(Unittest.PackedSint64Extension, 0));
- Assert.AreEqual(607u, message.GetExtension(Unittest.PackedFixed32Extension, 0));
- Assert.AreEqual(608uL, message.GetExtension(Unittest.PackedFixed64Extension, 0));
- Assert.AreEqual(609, message.GetExtension(Unittest.PackedSfixed32Extension, 0));
- Assert.AreEqual(610L, message.GetExtension(Unittest.PackedSfixed64Extension, 0));
- Assert.AreEqual(611F, message.GetExtension(Unittest.PackedFloatExtension, 0));
- Assert.AreEqual(612D, message.GetExtension(Unittest.PackedDoubleExtension, 0));
- Assert.AreEqual(true, message.GetExtension(Unittest.PackedBoolExtension, 0));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR,
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedInt32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedInt64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedUint32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedUint64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedSint32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedSint64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedFixed32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedFixed64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedSfixed32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedSfixed64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedFloatExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedDoubleExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedBoolExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.PackedEnumExtension));
+ Assert.Equal(601, message.GetExtension(Unittest.PackedInt32Extension, 0));
+ Assert.Equal(602L, message.GetExtension(Unittest.PackedInt64Extension, 0));
+ Assert.Equal(603u, message.GetExtension(Unittest.PackedUint32Extension, 0));
+ Assert.Equal(604uL, message.GetExtension(Unittest.PackedUint64Extension, 0));
+ Assert.Equal(605, message.GetExtension(Unittest.PackedSint32Extension, 0));
+ Assert.Equal(606L, message.GetExtension(Unittest.PackedSint64Extension, 0));
+ Assert.Equal(607u, message.GetExtension(Unittest.PackedFixed32Extension, 0));
+ Assert.Equal(608uL, message.GetExtension(Unittest.PackedFixed64Extension, 0));
+ Assert.Equal(609, message.GetExtension(Unittest.PackedSfixed32Extension, 0));
+ Assert.Equal(610L, message.GetExtension(Unittest.PackedSfixed64Extension, 0));
+ Assert.Equal(611F, message.GetExtension(Unittest.PackedFloatExtension, 0));
+ Assert.Equal(612D, message.GetExtension(Unittest.PackedDoubleExtension, 0));
+ Assert.Equal(true, message.GetExtension(Unittest.PackedBoolExtension, 0));
+ Assert.Equal(ForeignEnum.FOREIGN_BAR,
message.GetExtension(Unittest.PackedEnumExtension, 0));
- Assert.AreEqual(701, message.GetExtension(Unittest.PackedInt32Extension, 1));
- Assert.AreEqual(702L, message.GetExtension(Unittest.PackedInt64Extension, 1));
- Assert.AreEqual(703u, message.GetExtension(Unittest.PackedUint32Extension, 1));
- Assert.AreEqual(704uL, message.GetExtension(Unittest.PackedUint64Extension, 1));
- Assert.AreEqual(705, message.GetExtension(Unittest.PackedSint32Extension, 1));
- Assert.AreEqual(706L, message.GetExtension(Unittest.PackedSint64Extension, 1));
- Assert.AreEqual(707u, message.GetExtension(Unittest.PackedFixed32Extension, 1));
- Assert.AreEqual(708uL, message.GetExtension(Unittest.PackedFixed64Extension, 1));
- Assert.AreEqual(709, message.GetExtension(Unittest.PackedSfixed32Extension, 1));
- Assert.AreEqual(710L, message.GetExtension(Unittest.PackedSfixed64Extension, 1));
- Assert.AreEqual(711F, message.GetExtension(Unittest.PackedFloatExtension, 1));
- Assert.AreEqual(712D, message.GetExtension(Unittest.PackedDoubleExtension, 1));
- Assert.AreEqual(false, message.GetExtension(Unittest.PackedBoolExtension, 1));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ, message.GetExtension(Unittest.PackedEnumExtension, 1));
+ Assert.Equal(701, message.GetExtension(Unittest.PackedInt32Extension, 1));
+ Assert.Equal(702L, message.GetExtension(Unittest.PackedInt64Extension, 1));
+ Assert.Equal(703u, message.GetExtension(Unittest.PackedUint32Extension, 1));
+ Assert.Equal(704uL, message.GetExtension(Unittest.PackedUint64Extension, 1));
+ Assert.Equal(705, message.GetExtension(Unittest.PackedSint32Extension, 1));
+ Assert.Equal(706L, message.GetExtension(Unittest.PackedSint64Extension, 1));
+ Assert.Equal(707u, message.GetExtension(Unittest.PackedFixed32Extension, 1));
+ Assert.Equal(708uL, message.GetExtension(Unittest.PackedFixed64Extension, 1));
+ Assert.Equal(709, message.GetExtension(Unittest.PackedSfixed32Extension, 1));
+ Assert.Equal(710L, message.GetExtension(Unittest.PackedSfixed64Extension, 1));
+ Assert.Equal(711F, message.GetExtension(Unittest.PackedFloatExtension, 1));
+ Assert.Equal(712D, message.GetExtension(Unittest.PackedDoubleExtension, 1));
+ Assert.Equal(false, message.GetExtension(Unittest.PackedBoolExtension, 1));
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ, message.GetExtension(Unittest.PackedEnumExtension, 1));
}
public static void AssertUnpackedExtensionsSet(TestUnpackedExtensions message)
{
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedInt32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedInt64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedUint32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedUint64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedSint32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedSint64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedFixed32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedFixed64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedSfixed32Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedSfixed64Extension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedFloatExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedDoubleExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedBoolExtension));
- Assert.AreEqual(2, message.GetExtensionCount(Unittest.UnpackedEnumExtension));
- Assert.AreEqual(601, message.GetExtension(Unittest.UnpackedInt32Extension, 0));
- Assert.AreEqual(602L, message.GetExtension(Unittest.UnpackedInt64Extension, 0));
- Assert.AreEqual(603u, message.GetExtension(Unittest.UnpackedUint32Extension, 0));
- Assert.AreEqual(604uL, message.GetExtension(Unittest.UnpackedUint64Extension, 0));
- Assert.AreEqual(605, message.GetExtension(Unittest.UnpackedSint32Extension, 0));
- Assert.AreEqual(606L, message.GetExtension(Unittest.UnpackedSint64Extension, 0));
- Assert.AreEqual(607u, message.GetExtension(Unittest.UnpackedFixed32Extension, 0));
- Assert.AreEqual(608uL, message.GetExtension(Unittest.UnpackedFixed64Extension, 0));
- Assert.AreEqual(609, message.GetExtension(Unittest.UnpackedSfixed32Extension, 0));
- Assert.AreEqual(610L, message.GetExtension(Unittest.UnpackedSfixed64Extension, 0));
- Assert.AreEqual(611F, message.GetExtension(Unittest.UnpackedFloatExtension, 0));
- Assert.AreEqual(612D, message.GetExtension(Unittest.UnpackedDoubleExtension, 0));
- Assert.AreEqual(true, message.GetExtension(Unittest.UnpackedBoolExtension, 0));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAR, message.GetExtension(Unittest.UnpackedEnumExtension, 0));
- Assert.AreEqual(701, message.GetExtension(Unittest.UnpackedInt32Extension, 1));
- Assert.AreEqual(702L, message.GetExtension(Unittest.UnpackedInt64Extension, 1));
- Assert.AreEqual(703u, message.GetExtension(Unittest.UnpackedUint32Extension, 1));
- Assert.AreEqual(704uL, message.GetExtension(Unittest.UnpackedUint64Extension, 1));
- Assert.AreEqual(705, message.GetExtension(Unittest.UnpackedSint32Extension, 1));
- Assert.AreEqual(706L, message.GetExtension(Unittest.UnpackedSint64Extension, 1));
- Assert.AreEqual(707u, message.GetExtension(Unittest.UnpackedFixed32Extension, 1));
- Assert.AreEqual(708uL, message.GetExtension(Unittest.UnpackedFixed64Extension, 1));
- Assert.AreEqual(709, message.GetExtension(Unittest.UnpackedSfixed32Extension, 1));
- Assert.AreEqual(710L, message.GetExtension(Unittest.UnpackedSfixed64Extension, 1));
- Assert.AreEqual(711F, message.GetExtension(Unittest.UnpackedFloatExtension, 1));
- Assert.AreEqual(712D, message.GetExtension(Unittest.UnpackedDoubleExtension, 1));
- Assert.AreEqual(false, message.GetExtension(Unittest.UnpackedBoolExtension, 1));
- Assert.AreEqual(ForeignEnum.FOREIGN_BAZ, message.GetExtension(Unittest.UnpackedEnumExtension, 1));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedInt32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedInt64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedUint32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedUint64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedSint32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedSint64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedFixed32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedFixed64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedSfixed32Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedSfixed64Extension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedFloatExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedDoubleExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedBoolExtension));
+ Assert.Equal(2, message.GetExtensionCount(Unittest.UnpackedEnumExtension));
+ Assert.Equal(601, message.GetExtension(Unittest.UnpackedInt32Extension, 0));
+ Assert.Equal(602L, message.GetExtension(Unittest.UnpackedInt64Extension, 0));
+ Assert.Equal(603u, message.GetExtension(Unittest.UnpackedUint32Extension, 0));
+ Assert.Equal(604uL, message.GetExtension(Unittest.UnpackedUint64Extension, 0));
+ Assert.Equal(605, message.GetExtension(Unittest.UnpackedSint32Extension, 0));
+ Assert.Equal(606L, message.GetExtension(Unittest.UnpackedSint64Extension, 0));
+ Assert.Equal(607u, message.GetExtension(Unittest.UnpackedFixed32Extension, 0));
+ Assert.Equal(608uL, message.GetExtension(Unittest.UnpackedFixed64Extension, 0));
+ Assert.Equal(609, message.GetExtension(Unittest.UnpackedSfixed32Extension, 0));
+ Assert.Equal(610L, message.GetExtension(Unittest.UnpackedSfixed64Extension, 0));
+ Assert.Equal(611F, message.GetExtension(Unittest.UnpackedFloatExtension, 0));
+ Assert.Equal(612D, message.GetExtension(Unittest.UnpackedDoubleExtension, 0));
+ Assert.Equal(true, message.GetExtension(Unittest.UnpackedBoolExtension, 0));
+ Assert.Equal(ForeignEnum.FOREIGN_BAR, message.GetExtension(Unittest.UnpackedEnumExtension, 0));
+ Assert.Equal(701, message.GetExtension(Unittest.UnpackedInt32Extension, 1));
+ Assert.Equal(702L, message.GetExtension(Unittest.UnpackedInt64Extension, 1));
+ Assert.Equal(703u, message.GetExtension(Unittest.UnpackedUint32Extension, 1));
+ Assert.Equal(704uL, message.GetExtension(Unittest.UnpackedUint64Extension, 1));
+ Assert.Equal(705, message.GetExtension(Unittest.UnpackedSint32Extension, 1));
+ Assert.Equal(706L, message.GetExtension(Unittest.UnpackedSint64Extension, 1));
+ Assert.Equal(707u, message.GetExtension(Unittest.UnpackedFixed32Extension, 1));
+ Assert.Equal(708uL, message.GetExtension(Unittest.UnpackedFixed64Extension, 1));
+ Assert.Equal(709, message.GetExtension(Unittest.UnpackedSfixed32Extension, 1));
+ Assert.Equal(710L, message.GetExtension(Unittest.UnpackedSfixed64Extension, 1));
+ Assert.Equal(711F, message.GetExtension(Unittest.UnpackedFloatExtension, 1));
+ Assert.Equal(712D, message.GetExtension(Unittest.UnpackedDoubleExtension, 1));
+ Assert.Equal(false, message.GetExtension(Unittest.UnpackedBoolExtension, 1));
+ Assert.Equal(ForeignEnum.FOREIGN_BAZ, message.GetExtension(Unittest.UnpackedEnumExtension, 1));
}
private static readonly string[] TestCultures = {"en-US", "en-GB", "fr-FR", "de-DE"};
@@ -1751,61 +1751,5 @@ namespace Google.ProtocolBuffers }
return bytes;
}
-
-
- internal delegate void Action();
-
- internal static void AssertNotSupported(Action action)
- {
- try
- {
- action();
- Assert.Fail("Expected NotSupportedException");
- }
- catch (NotSupportedException)
- {
- // Expected
- }
- }
-
- internal static void AssertArgumentNullException(Action action)
- {
- try
- {
- action();
- Assert.Fail("Exception was not thrown");
- }
- // Not a general case, however, Compact Framework v2 does use Invoke
- catch (System.Reflection.TargetInvocationException te)
- {
- if (te.InnerException.GetType() != typeof(ArgumentNullException))
- throw;
- }
- // Normally expected exception
- catch (ArgumentNullException)
- {
- // We expect this exception.
- }
- }
-
- internal static void AssertBytesEqual(byte[] a, byte[]b)
- {
- if (a == null || b == null)
- {
- Assert.AreEqual<object>(a, b);
- }
- else
- {
- Assert.AreEqual(a.Length, b.Length, "The byte[] is not of the expected length.");
-
- for (int i = 0; i < a.Length; i++)
- {
- if (a[i] != b[i])
- {
- Assert.AreEqual(a[i], b[i], "Byte[] differs at index " + i);
- }
- }
- }
- }
}
}
\ No newline at end of file diff --git a/csharp/src/ProtocolBuffers.Test/TestWriterFormatJson.cs b/csharp/src/ProtocolBuffers.Test/TestWriterFormatJson.cs index b4472a60..ad5c052e 100644 --- a/csharp/src/ProtocolBuffers.Test/TestWriterFormatJson.cs +++ b/csharp/src/ProtocolBuffers.Test/TestWriterFormatJson.cs @@ -1,18 +1,18 @@ using System;
using System.IO;
+using System.Runtime.InteropServices;
using System.Text;
+using EnumOptions = Google.ProtocolBuffers.TestProtos.EnumOptions;
using Google.ProtocolBuffers.DescriptorProtos;
using Google.ProtocolBuffers.Serialization;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Google.ProtocolBuffers.TestProtos;
-using EnumOptions = Google.ProtocolBuffers.TestProtos.EnumOptions;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class TestWriterFormatJson
{
- [TestMethod]
+ [Fact]
public void Example_FromJson()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
@@ -21,10 +21,10 @@ namespace Google.ProtocolBuffers Extensions.MergeFromJson(builder, @"{""valid"":true}");
TestXmlMessage message = builder.Build();
- Assert.AreEqual(true, message.Valid);
+ Assert.Equal(true, message.Valid);
}
- [TestMethod]
+ [Fact]
public void Example_ToJson()
{
TestXmlMessage message =
@@ -35,10 +35,10 @@ namespace Google.ProtocolBuffers //3.5: string json = message.ToJson();
string json = Extensions.ToJson(message);
- Assert.AreEqual(@"{""valid"":true}", json);
+ Assert.Equal(@"{""valid"":true}", json);
}
- [TestMethod]
+ [Fact]
public void Example_WriteJsonUsingICodedOutputStream()
{
TestXmlMessage message =
@@ -52,20 +52,20 @@ namespace Google.ProtocolBuffers writer.WriteMessageStart(); //manually begin the message, output is '{'
writer.Flush();
- Assert.AreEqual("{", output.ToString());
+ Assert.Equal("{", output.ToString());
ICodedOutputStream stream = writer;
message.WriteTo(stream); //write the message normally
writer.Flush();
- Assert.AreEqual(@"{""valid"":true", output.ToString());
+ Assert.Equal(@"{""valid"":true", output.ToString());
writer.WriteMessageEnd(); //manually write the end message '}'
- Assert.AreEqual(@"{""valid"":true}", output.ToString());
+ Assert.Equal(@"{""valid"":true}", output.ToString());
}
}
- [TestMethod]
+ [Fact]
public void Example_ReadJsonUsingICodedInputStream()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
@@ -94,35 +94,37 @@ namespace Google.ProtocolBuffers JsonFormatReader.CreateInstance(Content)
.Merge(message.WeakCreateBuilderForType(), registry).WeakBuild();
- Assert.AreEqual(typeof(TMessage), copy.GetType());
- Assert.AreEqual(message, copy);
+ Assert.Equal(typeof(TMessage), copy.GetType());
+ Assert.Equal(message, copy);
foreach (string expect in expecting)
- Assert.IsTrue(Content.IndexOf(expect) >= 0, "Expected to find content '{0}' in: \r\n{1}", expect, Content);
+ {
+ Assert.True(Content.IndexOf(expect) >= 0);
+ }
}
- [TestMethod]
+ [Fact]
public void TestToJsonParseFromJson()
{
TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
string json = Extensions.ToJson(msg);
- Assert.AreEqual("{\"default_bool\":true}", json);
+ Assert.Equal("{\"default_bool\":true}", json);
TestAllTypes copy = Extensions.MergeFromJson(new TestAllTypes.Builder(), json).Build();
- Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
- Assert.AreEqual(msg, copy);
+ Assert.True(copy.HasDefaultBool && copy.DefaultBool);
+ Assert.Equal(msg, copy);
}
- [TestMethod]
+ [Fact]
public void TestToJsonParseFromJsonReader()
{
TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
string json = Extensions.ToJson(msg);
- Assert.AreEqual("{\"default_bool\":true}", json);
+ Assert.Equal("{\"default_bool\":true}", json);
TestAllTypes copy = Extensions.MergeFromJson(new TestAllTypes.Builder(), new StringReader(json)).Build();
- Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
- Assert.AreEqual(msg, copy);
+ Assert.True(copy.HasDefaultBool && copy.DefaultBool);
+ Assert.Equal(msg, copy);
}
- [TestMethod]
+ [Fact]
public void TestJsonFormatted()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -142,10 +144,10 @@ namespace Google.ProtocolBuffers TestXmlMessage copy = JsonFormatReader.CreateInstance(json)
.Merge(TestXmlMessage.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+ [Fact]
public void TestEmptyMessage()
{
FormatterAssert(
@@ -155,7 +157,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestRepeatedField()
{
FormatterAssert(
@@ -167,7 +169,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestNestedEmptyMessage()
{
FormatterAssert(
@@ -178,7 +180,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestNestedMessage()
{
FormatterAssert(
@@ -189,7 +191,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestBooleanTypes()
{
FormatterAssert(
@@ -200,7 +202,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestFullMessage()
{
FormatterAssert(
@@ -230,7 +232,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestMessageWithXmlText()
{
FormatterAssert(
@@ -241,7 +243,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestWithEscapeChars()
{
FormatterAssert(
@@ -252,7 +254,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestWithExtensionText()
{
FormatterAssert(
@@ -264,7 +266,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestWithExtensionNumber()
{
FormatterAssert(
@@ -276,7 +278,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestWithExtensionArray()
{
FormatterAssert(
@@ -289,7 +291,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestWithExtensionEnum()
{
FormatterAssert(
@@ -300,7 +302,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestMessageWithExtensions()
{
FormatterAssert(
@@ -323,7 +325,7 @@ namespace Google.ProtocolBuffers );
}
- [TestMethod]
+ [Fact]
public void TestMessageMissingExtensions()
{
TestXmlMessage original = TestXmlMessage.CreateBuilder()
@@ -351,23 +353,23 @@ namespace Google.ProtocolBuffers IMessageLite copy = JsonFormatReader.CreateInstance(Content)
.Merge(message.CreateBuilderForType()).Build();
- Assert.AreNotEqual(original, message);
- Assert.AreNotEqual(original, copy);
- Assert.AreEqual(message, copy);
+ Assert.NotEqual(original, message);
+ Assert.NotEqual(original, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+ [Fact]
public void TestMergeFields()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
builder.MergeFrom(JsonFormatReader.CreateInstance("\"valid\": true"));
builder.MergeFrom(JsonFormatReader.CreateInstance("\"text\": \"text\", \"number\": \"411\""));
- Assert.AreEqual(true, builder.Valid);
- Assert.AreEqual("text", builder.Text);
- Assert.AreEqual(411, builder.Number);
+ Assert.Equal(true, builder.Valid);
+ Assert.Equal("text", builder.Text);
+ Assert.Equal(411, builder.Number);
}
- [TestMethod]
+ [Fact]
public void TestMessageArray()
{
JsonFormatWriter writer = JsonFormatWriter.CreateInstance().Formatted();
@@ -386,13 +388,13 @@ namespace Google.ProtocolBuffers foreach (JsonFormatReader r in reader.EnumerateArray())
{
r.Merge(builder);
- Assert.AreEqual(++ordinal, builder.Number);
+ Assert.Equal(++ordinal, builder.Number);
}
- Assert.AreEqual(3, ordinal);
- Assert.AreEqual(3, builder.TextlinesCount);
+ Assert.Equal(3, ordinal);
+ Assert.Equal(3, builder.TextlinesCount);
}
- [TestMethod]
+ [Fact]
public void TestNestedMessageArray()
{
JsonFormatWriter writer = JsonFormatWriter.CreateInstance();
@@ -416,13 +418,13 @@ namespace Google.ProtocolBuffers foreach (JsonFormatReader r2 in r.EnumerateArray())
{
r2.Merge(builder);
- Assert.AreEqual(++ordinal, builder.Number);
+ Assert.Equal(++ordinal, builder.Number);
}
- Assert.AreEqual(3, ordinal);
- Assert.AreEqual(3, builder.TextlinesCount);
+ Assert.Equal(3, ordinal);
+ Assert.Equal(3, builder.TextlinesCount);
}
- [TestMethod]
+ [Fact]
public void TestReadWriteJsonWithoutRoot()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
@@ -437,53 +439,51 @@ namespace Google.ProtocolBuffers output.Flush();
Json = sw.ToString();
}
- Assert.AreEqual(@"""text"":""abc"",""number"":123", Json);
+ Assert.Equal(@"""text"":""abc"",""number"":123", Json);
ICodedInputStream input = JsonFormatReader.CreateInstance(Json);
TestXmlMessage copy = TestXmlMessage.CreateBuilder().MergeFrom(input).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod,ExpectedException(typeof(RecursionLimitExceededException))]
+ [Fact]
public void TestRecursiveLimit()
{
StringBuilder sb = new StringBuilder(8192);
for (int i = 0; i < 80; i++)
+ {
sb.Append("{\"child\":");
- TestXmlRescursive msg = Extensions.MergeFromJson(new TestXmlRescursive.Builder(), sb.ToString()).Build();
+ }
+ Assert.Throws<RecursionLimitExceededException>(() => Extensions.MergeFromJson(new TestXmlRescursive.Builder(), sb.ToString()).Build());
}
- [TestMethod, ExpectedException(typeof(FormatException))]
+ [Fact]
public void FailWithEmptyText()
{
- JsonFormatReader.CreateInstance("")
- .Merge(TestXmlMessage.CreateBuilder());
+ Assert.Throws<FormatException>(() => JsonFormatReader.CreateInstance("").Merge(TestXmlMessage.CreateBuilder()));
}
- [TestMethod, ExpectedException(typeof(FormatException))]
+ [Fact]
public void FailWithUnexpectedValue()
{
- JsonFormatReader.CreateInstance("{{}}")
- .Merge(TestXmlMessage.CreateBuilder());
+ Assert.Throws<FormatException>(() => JsonFormatReader.CreateInstance("{{}}").Merge(TestXmlMessage.CreateBuilder()));
}
- [TestMethod, ExpectedException(typeof(FormatException))]
+ [Fact]
public void FailWithUnQuotedName()
{
- JsonFormatReader.CreateInstance("{name:{}}")
- .Merge(TestXmlMessage.CreateBuilder());
+ Assert.Throws<FormatException>(() => JsonFormatReader.CreateInstance("{name:{}}").Merge(TestXmlMessage.CreateBuilder()));
}
- [TestMethod, ExpectedException(typeof(FormatException))]
+ [Fact]
public void FailWithUnexpectedType()
{
- JsonFormatReader.CreateInstance("{\"valid\":{}}")
- .Merge(TestXmlMessage.CreateBuilder());
+ Assert.Throws<FormatException>(() => JsonFormatReader.CreateInstance("{\"valid\":{}}").Merge(TestXmlMessage.CreateBuilder()));
}
// See issue 64 for background.
- [TestMethod]
+ [Fact]
public void ToJsonRequiringBufferExpansion()
{
string s = new string('.', 4086);
@@ -492,7 +492,7 @@ namespace Google.ProtocolBuffers .SetPackage("package")
.BuildPartial();
- Assert.IsNotNull(Extensions.ToJson(opts));
+ Assert.NotNull(Extensions.ToJson(opts));
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/TestWriterFormatXml.cs b/csharp/src/ProtocolBuffers.Test/TestWriterFormatXml.cs index 695daa84..78e6bb27 100644 --- a/csharp/src/ProtocolBuffers.Test/TestWriterFormatXml.cs +++ b/csharp/src/ProtocolBuffers.Test/TestWriterFormatXml.cs @@ -1,18 +1,16 @@ using System;
-using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using Google.ProtocolBuffers.Serialization;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Google.ProtocolBuffers.TestProtos;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class TestWriterFormatXml
{
- [TestMethod]
+ [Fact]
public void Example_FromXml()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
@@ -22,10 +20,10 @@ namespace Google.ProtocolBuffers Extensions.MergeFromXml(builder, rdr);
TestXmlMessage message = builder.Build();
- Assert.AreEqual(true, message.Valid);
+ Assert.Equal(true, message.Valid);
}
- [TestMethod]
+ [Fact]
public void Example_ToXml()
{
TestXmlMessage message =
@@ -36,10 +34,10 @@ namespace Google.ProtocolBuffers //3.5: string Xml = message.ToXml();
string Xml = Extensions.ToXml(message);
- Assert.AreEqual(@"<root><valid>true</valid></root>", Xml);
+ Assert.Equal(@"<root><valid>true</valid></root>", Xml);
}
- [TestMethod]
+ [Fact]
public void Example_WriteXmlUsingICodedOutputStream()
{
TestXmlMessage message =
@@ -56,11 +54,11 @@ namespace Google.ProtocolBuffers message.WriteTo(stream); //write the message normally
writer.WriteMessageEnd(); //manually write the end message '}'
- Assert.AreEqual(@"<root><valid>true</valid></root>", output.ToString());
+ Assert.Equal(@"<root><valid>true</valid></root>", output.ToString());
}
}
- [TestMethod]
+ [Fact]
public void Example_ReadXmlUsingICodedInputStream()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
@@ -73,29 +71,29 @@ namespace Google.ProtocolBuffers reader.ReadMessageEnd(); //manually read the end message '}'
}
- [TestMethod]
+ [Fact]
public void TestToXmlParseFromXml()
{
TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
string xml = Extensions.ToXml(msg);
- Assert.AreEqual("<root><default_bool>true</default_bool></root>", xml);
+ Assert.Equal("<root><default_bool>true</default_bool></root>", xml);
TestAllTypes copy = Extensions.MergeFromXml(new TestAllTypes.Builder(), XmlReader.Create(new StringReader(xml))).Build();
- Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
- Assert.AreEqual(msg, copy);
+ Assert.True(copy.HasDefaultBool && copy.DefaultBool);
+ Assert.Equal(msg, copy);
}
- [TestMethod]
+ [Fact]
public void TestToXmlParseFromXmlWithRootName()
{
TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
string xml = Extensions.ToXml(msg, "message");
- Assert.AreEqual("<message><default_bool>true</default_bool></message>", xml);
+ Assert.Equal("<message><default_bool>true</default_bool></message>", xml);
TestAllTypes copy = Extensions.MergeFromXml(new TestAllTypes.Builder(), "message", XmlReader.Create(new StringReader(xml))).Build();
- Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
- Assert.AreEqual(msg, copy);
+ Assert.True(copy.HasDefaultBool && copy.DefaultBool);
+ Assert.Equal(msg, copy);
}
- [TestMethod]
+ [Fact]
public void TestEmptyMessage()
{
TestXmlChild message = TestXmlChild.CreateBuilder()
@@ -113,9 +111,9 @@ namespace Google.ProtocolBuffers string xml = sw.ToString();
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlChild copy = rdr.Merge(TestXmlChild.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+ [Fact]
public void TestRepeatedField()
{
TestXmlChild message = TestXmlChild.CreateBuilder()
@@ -130,9 +128,10 @@ namespace Google.ProtocolBuffers string xml = sw.ToString();
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlChild copy = rdr.Merge(TestXmlChild.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestNestedEmptyMessage()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -145,9 +144,10 @@ namespace Google.ProtocolBuffers string xml = sw.ToString();
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestNestedMessage()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -160,9 +160,10 @@ namespace Google.ProtocolBuffers string xml = sw.ToString();
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestBooleanTypes()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -175,9 +176,10 @@ namespace Google.ProtocolBuffers string xml = sw.ToString();
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestFullMessage()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -204,9 +206,10 @@ namespace Google.ProtocolBuffers XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestFullMessageWithRichTypes()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -236,9 +239,10 @@ namespace Google.ProtocolBuffers XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
rdr.Options = XmlReaderOptions.ReadNestedArrays;
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestFullMessageWithUnknownFields()
{
TestXmlMessage origial = TestXmlMessage.CreateBuilder()
@@ -257,7 +261,7 @@ namespace Google.ProtocolBuffers .Build();
TestXmlNoFields message = TestXmlNoFields.CreateBuilder().MergeFrom(origial.ToByteArray()).Build();
- Assert.AreEqual(0, message.AllFields.Count);
+ Assert.Equal(0, message.AllFields.Count);
StringWriter sw = new StringWriter();
XmlFormatWriter.CreateInstance(sw)
@@ -269,9 +273,9 @@ namespace Google.ProtocolBuffers using (XmlReader x = XmlReader.Create(new StringReader(xml)))
{
x.MoveToContent();
- Assert.AreEqual(XmlNodeType.Element, x.NodeType);
+ Assert.Equal(XmlNodeType.Element, x.NodeType);
//should always be empty
- Assert.IsTrue(x.IsEmptyElement ||
+ Assert.True(x.IsEmptyElement ||
(x.Read() && x.NodeType == XmlNodeType.EndElement)
);
}
@@ -279,9 +283,10 @@ namespace Google.ProtocolBuffers XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
rdr.Options = XmlReaderOptions.ReadNestedArrays;
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder()).Build();
- Assert.AreEqual(TestXmlMessage.DefaultInstance, copy);
+ Assert.Equal(TestXmlMessage.DefaultInstance, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestMessageWithXmlText()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -294,9 +299,10 @@ namespace Google.ProtocolBuffers XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestXmlWithWhitespace()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -309,9 +315,10 @@ namespace Google.ProtocolBuffers XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder()).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestXmlWithExtensionText()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -328,9 +335,10 @@ namespace Google.ProtocolBuffers XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestXmlWithExtensionMessage()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -347,9 +355,10 @@ namespace Google.ProtocolBuffers XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestXmlWithExtensionArray()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -368,9 +377,10 @@ namespace Google.ProtocolBuffers XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestXmlWithExtensionEnum()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
@@ -387,9 +397,10 @@ namespace Google.ProtocolBuffers XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod]
+
+ [Fact]
public void TestXmlReadEmptyRoot()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
@@ -402,7 +413,7 @@ namespace Google.ProtocolBuffers reader.ReadMessageEnd(); //manually read the end message '}'
}
- [TestMethod]
+ [Fact]
public void TestXmlReadEmptyChild()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
@@ -411,11 +422,11 @@ namespace Google.ProtocolBuffers reader.ReadMessageStart(); //manually read the begin the message '{'
builder.MergeFrom(reader); //write the message normally
- Assert.IsTrue(builder.HasText);
- Assert.AreEqual(String.Empty, builder.Text);
+ Assert.True(builder.HasText);
+ Assert.Equal(String.Empty, builder.Text);
}
- [TestMethod]
+ [Fact]
public void TestXmlReadWriteWithoutRoot()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
@@ -431,7 +442,7 @@ namespace Google.ProtocolBuffers output.Flush();
xml = sw.ToString();
}
- Assert.AreEqual("<text>abc</text><number>123</number>", xml);
+ Assert.Equal("<text>abc</text><number>123</number>", xml);
TestXmlMessage copy;
using (XmlReader xr = XmlReader.Create(new StringReader(xml), new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Fragment }))
@@ -440,16 +451,18 @@ namespace Google.ProtocolBuffers copy = TestXmlMessage.CreateBuilder().MergeFrom(input).Build();
}
- Assert.AreEqual(message, copy);
+ Assert.Equal(message, copy);
}
- [TestMethod, ExpectedException(typeof(RecursionLimitExceededException))]
+ [Fact]
public void TestRecursiveLimit()
{
StringBuilder sb = new StringBuilder(8192);
for (int i = 0; i < 80; i++)
+ {
sb.Append("<child>");
- TestXmlRescursive msg = Extensions.MergeFromXml(new TestXmlRescursive.Builder(), "child", XmlReader.Create(new StringReader(sb.ToString()))).Build();
+ }
+ Assert.Throws<RecursionLimitExceededException>(() => Extensions.MergeFromXml(new TestXmlRescursive.Builder(), "child", XmlReader.Create(new StringReader(sb.ToString()))).Build());
}
}
}
diff --git a/csharp/src/ProtocolBuffers.Test/TextFormatTest.cs b/csharp/src/ProtocolBuffers.Test/TextFormatTest.cs index 37a4192a..1e083c6b 100644 --- a/csharp/src/ProtocolBuffers.Test/TextFormatTest.cs +++ b/csharp/src/ProtocolBuffers.Test/TextFormatTest.cs @@ -36,15 +36,11 @@ using System;
using System.IO;
-using System.Text;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Globalization;
-using System.Threading;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class TextFormatTest
{
private static readonly string AllFieldsSetText = TestResources.text_format_unittest_data;
@@ -88,46 +84,46 @@ namespace Google.ProtocolBuffers /// <summary>
/// Print TestAllTypes and compare with golden file.
/// </summary>
- [TestMethod]
+ [Fact]
public void PrintMessage()
{
TestUtil.TestInMultipleCultures(() =>
- {
- string text = TextFormat.PrintToString(TestUtil.GetAllSet());
- Assert.AreEqual(AllFieldsSetText.Replace("\r\n", "\n").Trim(),
- text.Replace("\r\n", "\n").Trim());
- });
+ {
+ string text = TextFormat.PrintToString(TestUtil.GetAllSet());
+ Assert.Equal(AllFieldsSetText.Replace("\r\n", "\n").Trim(),
+ text.Replace("\r\n", "\n").Trim());
+ });
}
/// <summary>
/// Tests that a builder prints the same way as a message.
/// </summary>
- [TestMethod]
+ [Fact]
public void PrintBuilder()
{
TestUtil.TestInMultipleCultures(() =>
{
string messageText = TextFormat.PrintToString(TestUtil.GetAllSet());
string builderText = TextFormat.PrintToString(TestUtil.GetAllSet().ToBuilder());
- Assert.AreEqual(messageText, builderText);
+ Assert.Equal(messageText, builderText);
});
}
/// <summary>
/// Print TestAllExtensions and compare with golden file.
/// </summary>
- [TestMethod]
+ [Fact]
public void PrintExtensions()
{
string text = TextFormat.PrintToString(TestUtil.GetAllExtensionsSet());
- Assert.AreEqual(AllExtensionsSetText.Replace("\r\n", "\n").Trim(), text.Replace("\r\n", "\n").Trim());
+ Assert.Equal(AllExtensionsSetText.Replace("\r\n", "\n").Trim(), text.Replace("\r\n", "\n").Trim());
}
/// <summary>
/// Test printing of unknown fields in a message.
/// </summary>
- [TestMethod]
+ [Fact]
public void PrintUnknownFields()
{
TestEmptyMessage message =
@@ -163,7 +159,7 @@ namespace Google.ProtocolBuffers .Build())
.Build();
- Assert.AreEqual(
+ Assert.Equal(
"5: 1\n" +
"5: 0x00000002\n" +
"5: 0x0000000000000003\n" +
@@ -193,7 +189,7 @@ namespace Google.ProtocolBuffers return ByteString.CopyFrom(bytes);
}
- [TestMethod]
+ [Fact]
public void PrintExotic()
{
IMessage message = TestAllTypes.CreateBuilder()
@@ -224,10 +220,10 @@ namespace Google.ProtocolBuffers .AddRepeatedBytes(Bytes("\0\u0001\u0007\b\f\n\r\t\v\\\'\"\u00fe"))
.Build();
- Assert.AreEqual(ExoticText, message.ToString());
+ Assert.Equal(ExoticText, message.ToString());
}
- [TestMethod]
+ [Fact]
public void PrintMessageSet()
{
TestMessageSet messageSet =
@@ -240,12 +236,12 @@ namespace Google.ProtocolBuffers TestMessageSetExtension2.CreateBuilder().SetStr("foo").Build())
.Build();
- Assert.AreEqual(MessageSetText, messageSet.ToString());
+ Assert.Equal(MessageSetText, messageSet.ToString());
}
// =================================================================
- [TestMethod]
+ [Fact]
public void Parse()
{
TestUtil.TestInMultipleCultures(() =>
@@ -256,7 +252,7 @@ namespace Google.ProtocolBuffers });
}
- [TestMethod]
+ [Fact]
public void ParseReader()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -264,7 +260,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllFieldsSet(builder.Build());
}
- [TestMethod]
+ [Fact]
public void ParseExtensions()
{
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
@@ -274,7 +270,7 @@ namespace Google.ProtocolBuffers TestUtil.AssertAllExtensionsSet(builder.Build());
}
- [TestMethod]
+ [Fact]
public void ParseCompatibility()
{
string original = "repeated_float: inf\n" +
@@ -303,10 +299,10 @@ namespace Google.ProtocolBuffers "repeated_double: NaN\n";
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
TextFormat.Merge(original, builder);
- Assert.AreEqual(canonical, builder.Build().ToString());
+ Assert.Equal(canonical, builder.Build().ToString());
}
- [TestMethod]
+ [Fact]
public void ParseExotic()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -314,10 +310,10 @@ namespace Google.ProtocolBuffers // Too lazy to check things individually. Don't try to debug this
// if testPrintExotic() is Assert.Failing.
- Assert.AreEqual(ExoticText, builder.Build().ToString());
+ Assert.Equal(ExoticText, builder.Build().ToString());
}
- [TestMethod]
+ [Fact]
public void ParseMessageSet()
{
ExtensionRegistry extensionRegistry = ExtensionRegistry.CreateInstance();
@@ -328,30 +324,30 @@ namespace Google.ProtocolBuffers TextFormat.Merge(MessageSetText, extensionRegistry, builder);
TestMessageSet messageSet = builder.Build();
- Assert.IsTrue(messageSet.HasExtension(TestMessageSetExtension1.MessageSetExtension));
- Assert.AreEqual(123, messageSet.GetExtension(TestMessageSetExtension1.MessageSetExtension).I);
- Assert.IsTrue(messageSet.HasExtension(TestMessageSetExtension2.MessageSetExtension));
- Assert.AreEqual("foo", messageSet.GetExtension(TestMessageSetExtension2.MessageSetExtension).Str);
+ Assert.True(messageSet.HasExtension(TestMessageSetExtension1.MessageSetExtension));
+ Assert.Equal(123, messageSet.GetExtension(TestMessageSetExtension1.MessageSetExtension).I);
+ Assert.True(messageSet.HasExtension(TestMessageSetExtension2.MessageSetExtension));
+ Assert.Equal("foo", messageSet.GetExtension(TestMessageSetExtension2.MessageSetExtension).Str);
}
- [TestMethod]
+ [Fact]
public void ParseNumericEnum()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
TextFormat.Merge("optional_nested_enum: 2", builder);
- Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR, builder.OptionalNestedEnum);
+ Assert.Equal(TestAllTypes.Types.NestedEnum.BAR, builder.OptionalNestedEnum);
}
- [TestMethod]
+ [Fact]
public void ParseAngleBrackets()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
TextFormat.Merge("OptionalGroup: < a: 1 >", builder);
- Assert.IsTrue(builder.HasOptionalGroup);
- Assert.AreEqual(1, builder.OptionalGroup.A);
+ Assert.True(builder.HasOptionalGroup);
+ Assert.Equal(1, builder.OptionalGroup.A);
}
- [TestMethod]
+ [Fact]
public void ParseComment()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
@@ -360,26 +356,19 @@ namespace Google.ProtocolBuffers "optional_int32: 1 # another comment\n" +
"optional_int64: 2\n" +
"# EOF comment", builder);
- Assert.AreEqual(1, builder.OptionalInt32);
- Assert.AreEqual(2, builder.OptionalInt64);
+ Assert.Equal(1, builder.OptionalInt32);
+ Assert.Equal(2, builder.OptionalInt64);
}
private static void AssertParseError(string error, string text)
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
- try
- {
- TextFormat.Merge(text, TestUtil.CreateExtensionRegistry(), builder);
- Assert.Fail("Expected parse exception.");
- }
- catch (FormatException e)
- {
- Assert.AreEqual(error, e.Message);
- }
+ Exception exception = Assert.Throws<FormatException>(() => TextFormat.Merge(text, TestUtil.CreateExtensionRegistry(), builder));
+ Assert.Equal(error, exception.Message);
}
- [TestMethod]
+ [Fact]
public void ParseErrors()
{
AssertParseError(
@@ -454,111 +443,96 @@ namespace Google.ProtocolBuffers return ByteString.CopyFrom(bytes);
}
- private delegate void FormattingAction();
-
- private static void AssertFormatException(FormattingAction action)
- {
- try
- {
- action();
- Assert.Fail("Should have thrown an exception.");
- }
- catch (FormatException)
- {
- // success
- }
- }
-
- [TestMethod]
+ [Fact]
public void Escape()
{
// Escape sequences.
- Assert.AreEqual("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"",
+ Assert.Equal("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"",
TextFormat.EscapeBytes(Bytes("\0\u0001\u0007\b\f\n\r\t\v\\\'\"")));
- Assert.AreEqual("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"",
+ Assert.Equal("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"",
TextFormat.EscapeText("\0\u0001\u0007\b\f\n\r\t\v\\\'\""));
- Assert.AreEqual(Bytes("\0\u0001\u0007\b\f\n\r\t\v\\\'\""),
+ Assert.Equal(Bytes("\0\u0001\u0007\b\f\n\r\t\v\\\'\""),
TextFormat.UnescapeBytes("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\""));
- Assert.AreEqual("\0\u0001\u0007\b\f\n\r\t\v\\\'\"",
+ Assert.Equal("\0\u0001\u0007\b\f\n\r\t\v\\\'\"",
TextFormat.UnescapeText("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\""));
// Unicode handling.
- Assert.AreEqual("\\341\\210\\264", TextFormat.EscapeText("\u1234"));
- Assert.AreEqual("\\341\\210\\264", TextFormat.EscapeBytes(Bytes(0xe1, 0x88, 0xb4)));
- Assert.AreEqual("\u1234", TextFormat.UnescapeText("\\341\\210\\264"));
- Assert.AreEqual(Bytes(0xe1, 0x88, 0xb4), TextFormat.UnescapeBytes("\\341\\210\\264"));
- Assert.AreEqual("\u1234", TextFormat.UnescapeText("\\xe1\\x88\\xb4"));
- Assert.AreEqual(Bytes(0xe1, 0x88, 0xb4), TextFormat.UnescapeBytes("\\xe1\\x88\\xb4"));
+ Assert.Equal("\\341\\210\\264", TextFormat.EscapeText("\u1234"));
+ Assert.Equal("\\341\\210\\264", TextFormat.EscapeBytes(Bytes(0xe1, 0x88, 0xb4)));
+ Assert.Equal("\u1234", TextFormat.UnescapeText("\\341\\210\\264"));
+ Assert.Equal(Bytes(0xe1, 0x88, 0xb4), TextFormat.UnescapeBytes("\\341\\210\\264"));
+ Assert.Equal("\u1234", TextFormat.UnescapeText("\\xe1\\x88\\xb4"));
+ Assert.Equal(Bytes(0xe1, 0x88, 0xb4), TextFormat.UnescapeBytes("\\xe1\\x88\\xb4"));
// Errors.
- AssertFormatException(() => TextFormat.UnescapeText("\\x"));
- AssertFormatException(() => TextFormat.UnescapeText("\\z"));
- AssertFormatException(() => TextFormat.UnescapeText("\\"));
+ Assert.Throws<FormatException>(() => TextFormat.UnescapeText("\\x"));
+ Assert.Throws<FormatException>(() => TextFormat.UnescapeText("\\z"));
+ Assert.Throws<FormatException>(() => TextFormat.UnescapeText("\\"));
}
- [TestMethod]
+ [Fact]
public void ParseInteger()
{
- Assert.AreEqual(0, TextFormat.ParseInt32("0"));
- Assert.AreEqual(1, TextFormat.ParseInt32("1"));
- Assert.AreEqual(-1, TextFormat.ParseInt32("-1"));
- Assert.AreEqual(12345, TextFormat.ParseInt32("12345"));
- Assert.AreEqual(-12345, TextFormat.ParseInt32("-12345"));
- Assert.AreEqual(2147483647, TextFormat.ParseInt32("2147483647"));
- Assert.AreEqual(-2147483648, TextFormat.ParseInt32("-2147483648"));
-
- Assert.AreEqual(0u, TextFormat.ParseUInt32("0"));
- Assert.AreEqual(1u, TextFormat.ParseUInt32("1"));
- Assert.AreEqual(12345u, TextFormat.ParseUInt32("12345"));
- Assert.AreEqual(2147483647u, TextFormat.ParseUInt32("2147483647"));
- Assert.AreEqual(2147483648U, TextFormat.ParseUInt32("2147483648"));
- Assert.AreEqual(4294967295U, TextFormat.ParseUInt32("4294967295"));
-
- Assert.AreEqual(0L, TextFormat.ParseInt64("0"));
- Assert.AreEqual(1L, TextFormat.ParseInt64("1"));
- Assert.AreEqual(-1L, TextFormat.ParseInt64("-1"));
- Assert.AreEqual(12345L, TextFormat.ParseInt64("12345"));
- Assert.AreEqual(-12345L, TextFormat.ParseInt64("-12345"));
- Assert.AreEqual(2147483647L, TextFormat.ParseInt64("2147483647"));
- Assert.AreEqual(-2147483648L, TextFormat.ParseInt64("-2147483648"));
- Assert.AreEqual(4294967295L, TextFormat.ParseInt64("4294967295"));
- Assert.AreEqual(4294967296L, TextFormat.ParseInt64("4294967296"));
- Assert.AreEqual(9223372036854775807L, TextFormat.ParseInt64("9223372036854775807"));
- Assert.AreEqual(-9223372036854775808L, TextFormat.ParseInt64("-9223372036854775808"));
-
- Assert.AreEqual(0uL, TextFormat.ParseUInt64("0"));
- Assert.AreEqual(1uL, TextFormat.ParseUInt64("1"));
- Assert.AreEqual(12345uL, TextFormat.ParseUInt64("12345"));
- Assert.AreEqual(2147483647uL, TextFormat.ParseUInt64("2147483647"));
- Assert.AreEqual(4294967295uL, TextFormat.ParseUInt64("4294967295"));
- Assert.AreEqual(4294967296uL, TextFormat.ParseUInt64("4294967296"));
- Assert.AreEqual(9223372036854775807UL, TextFormat.ParseUInt64("9223372036854775807"));
- Assert.AreEqual(9223372036854775808UL, TextFormat.ParseUInt64("9223372036854775808"));
- Assert.AreEqual(18446744073709551615UL, TextFormat.ParseUInt64("18446744073709551615"));
+ Assert.Equal(0, TextFormat.ParseInt32("0"));
+ Assert.Equal(1, TextFormat.ParseInt32("1"));
+ Assert.Equal(-1, TextFormat.ParseInt32("-1"));
+ Assert.Equal(12345, TextFormat.ParseInt32("12345"));
+ Assert.Equal(-12345, TextFormat.ParseInt32("-12345"));
+ Assert.Equal(2147483647, TextFormat.ParseInt32("2147483647"));
+ Assert.Equal(-2147483648, TextFormat.ParseInt32("-2147483648"));
+
+ Assert.Equal(0u, TextFormat.ParseUInt32("0"));
+ Assert.Equal(1u, TextFormat.ParseUInt32("1"));
+ Assert.Equal(12345u, TextFormat.ParseUInt32("12345"));
+ Assert.Equal(2147483647u, TextFormat.ParseUInt32("2147483647"));
+ Assert.Equal(2147483648U, TextFormat.ParseUInt32("2147483648"));
+ Assert.Equal(4294967295U, TextFormat.ParseUInt32("4294967295"));
+
+ Assert.Equal(0L, TextFormat.ParseInt64("0"));
+ Assert.Equal(1L, TextFormat.ParseInt64("1"));
+ Assert.Equal(-1L, TextFormat.ParseInt64("-1"));
+ Assert.Equal(12345L, TextFormat.ParseInt64("12345"));
+ Assert.Equal(-12345L, TextFormat.ParseInt64("-12345"));
+ Assert.Equal(2147483647L, TextFormat.ParseInt64("2147483647"));
+ Assert.Equal(-2147483648L, TextFormat.ParseInt64("-2147483648"));
+ Assert.Equal(4294967295L, TextFormat.ParseInt64("4294967295"));
+ Assert.Equal(4294967296L, TextFormat.ParseInt64("4294967296"));
+ Assert.Equal(9223372036854775807L, TextFormat.ParseInt64("9223372036854775807"));
+ Assert.Equal(-9223372036854775808L, TextFormat.ParseInt64("-9223372036854775808"));
+
+ Assert.Equal(0uL, TextFormat.ParseUInt64("0"));
+ Assert.Equal(1uL, TextFormat.ParseUInt64("1"));
+ Assert.Equal(12345uL, TextFormat.ParseUInt64("12345"));
+ Assert.Equal(2147483647uL, TextFormat.ParseUInt64("2147483647"));
+ Assert.Equal(4294967295uL, TextFormat.ParseUInt64("4294967295"));
+ Assert.Equal(4294967296uL, TextFormat.ParseUInt64("4294967296"));
+ Assert.Equal(9223372036854775807UL, TextFormat.ParseUInt64("9223372036854775807"));
+ Assert.Equal(9223372036854775808UL, TextFormat.ParseUInt64("9223372036854775808"));
+ Assert.Equal(18446744073709551615UL, TextFormat.ParseUInt64("18446744073709551615"));
// Hex
- Assert.AreEqual(0x1234abcd, TextFormat.ParseInt32("0x1234abcd"));
- Assert.AreEqual(-0x1234abcd, TextFormat.ParseInt32("-0x1234abcd"));
- Assert.AreEqual(0xffffffffffffffffUL, TextFormat.ParseUInt64("0xffffffffffffffff"));
- Assert.AreEqual(0x7fffffffffffffffL,
+ Assert.Equal(0x1234abcd, TextFormat.ParseInt32("0x1234abcd"));
+ Assert.Equal(-0x1234abcd, TextFormat.ParseInt32("-0x1234abcd"));
+ Assert.Equal(0xffffffffffffffffUL, TextFormat.ParseUInt64("0xffffffffffffffff"));
+ Assert.Equal(0x7fffffffffffffffL,
TextFormat.ParseInt64("0x7fffffffffffffff"));
// Octal
- Assert.AreEqual(342391, TextFormat.ParseInt32("01234567"));
+ Assert.Equal(342391, TextFormat.ParseInt32("01234567"));
// Out-of-range
- AssertFormatException(() => TextFormat.ParseInt32("2147483648"));
- AssertFormatException(() => TextFormat.ParseInt32("-2147483649"));
- AssertFormatException(() => TextFormat.ParseUInt32("4294967296"));
- AssertFormatException(() => TextFormat.ParseUInt32("-1"));
- AssertFormatException(() => TextFormat.ParseInt64("9223372036854775808"));
- AssertFormatException(() => TextFormat.ParseInt64("-9223372036854775809"));
- AssertFormatException(() => TextFormat.ParseUInt64("18446744073709551616"));
- AssertFormatException(() => TextFormat.ParseUInt64("-1"));
- AssertFormatException(() => TextFormat.ParseInt32("abcd"));
+ Assert.Throws<FormatException>(() => TextFormat.ParseInt32("2147483648"));
+ Assert.Throws<FormatException>(() => TextFormat.ParseInt32("-2147483649"));
+ Assert.Throws<FormatException>(() => TextFormat.ParseUInt32("4294967296"));
+ Assert.Throws<FormatException>(() => TextFormat.ParseUInt32("-1"));
+ Assert.Throws<FormatException>(() => TextFormat.ParseInt64("9223372036854775808"));
+ Assert.Throws<FormatException>(() => TextFormat.ParseInt64("-9223372036854775809"));
+ Assert.Throws<FormatException>(() => TextFormat.ParseUInt64("18446744073709551616"));
+ Assert.Throws<FormatException>(() => TextFormat.ParseUInt64("-1"));
+ Assert.Throws<FormatException>(() => TextFormat.ParseInt32("abcd"));
}
- [TestMethod]
+ [Fact]
public void ParseLongString()
{
string longText =
@@ -580,7 +554,7 @@ namespace Google.ProtocolBuffers "123456789012345678901234567890123456789012345678901234567890";
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
TextFormat.Merge("optional_string: \"" + longText + "\"", builder);
- Assert.AreEqual(longText, builder.OptionalString);
+ Assert.Equal(longText, builder.OptionalString);
}
}
}
\ No newline at end of file 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 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 diff --git a/csharp/src/ProtocolBuffers.Test/packages.config b/csharp/src/ProtocolBuffers.Test/packages.config new file mode 100644 index 00000000..6f1fb7f5 --- /dev/null +++ b/csharp/src/ProtocolBuffers.Test/packages.config @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="xunit" version="2.0.0" targetFramework="net45" /> + <package id="xunit.abstractions" version="2.0.0" targetFramework="net45" /> + <package id="xunit.assert" version="2.0.0" targetFramework="net45" /> + <package id="xunit.core" version="2.0.0" targetFramework="net45" /> + <package id="xunit.extensibility.core" version="2.0.0" targetFramework="net45" /> + <package id="xunit.runner.visualstudio" version="2.0.0" targetFramework="net45" /> +</packages>
\ No newline at end of file |