aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-05-12 09:47:19 +0100
committerJon Skeet <jonskeet@google.com>2015-05-12 09:48:02 +0100
commit90c8932fc7316b5afaae350395624b6fd2e73a97 (patch)
tree080924d0a9fd8f52d88b1ee4fb76f9aa3bd802cd /csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs
parentc58b2c66448f83c25da0251fe6cf5b12299fa581 (diff)
downloadprotobuf-90c8932fc7316b5afaae350395624b6fd2e73a97.tar.gz
protobuf-90c8932fc7316b5afaae350395624b6fd2e73a97.tar.bz2
protobuf-90c8932fc7316b5afaae350395624b6fd2e73a97.zip
Convert back to using NUnit, which is now loaded via NuGet.
This includes the NUnit test adapter which allows NUnit tests to be run under VS without any extra plugins. Unfortunate the compatibility tests using the abstract test fixture class show up as "external" tests, and aren't well presented - but they do run.
Diffstat (limited to 'csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs')
-rw-r--r--csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs136
1 files changed, 68 insertions, 68 deletions
diff --git a/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs b/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs
index b9680e68..2385bde5 100644
--- a/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs
+++ b/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs
@@ -35,13 +35,13 @@
#endregion
using Google.ProtocolBuffers.TestProtos;
-using Xunit;
+using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class MissingFieldAndExtensionTest
{
- [Fact]
+ [Test]
public void TestRecoverMissingExtensions()
{
const int optionalInt32 = 12345678;
@@ -52,42 +52,42 @@ namespace Google.ProtocolBuffers
builder.AddExtension(Unittest.RepeatedDoubleExtension, 1.3);
TestAllExtensions msg = builder.Build();
- Assert.True(msg.HasExtension(Unittest.OptionalInt32Extension));
- Assert.Equal(3, msg.GetExtensionCount(Unittest.RepeatedDoubleExtension));
+ Assert.IsTrue(msg.HasExtension(Unittest.OptionalInt32Extension));
+ Assert.AreEqual(3, msg.GetExtensionCount(Unittest.RepeatedDoubleExtension));
byte[] bits = msg.ToByteArray();
TestAllExtensions copy = TestAllExtensions.ParseFrom(bits);
- Assert.False(copy.HasExtension(Unittest.OptionalInt32Extension));
- Assert.Equal(0, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
- Assert.NotEqual(msg, copy);
+ Assert.IsFalse(copy.HasExtension(Unittest.OptionalInt32Extension));
+ Assert.AreEqual(0, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
+ Assert.AreNotEqual(msg, copy);
//Even though copy does not understand the typees they serialize correctly
byte[] copybits = copy.ToByteArray();
- Assert.Equal(bits, copybits);
+ Assert.AreEqual(bits, copybits);
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
Unittest.RegisterAllExtensions(registry);
//Now we can take those copy bits and restore the full message with extensions
copy = TestAllExtensions.ParseFrom(copybits, registry);
- Assert.True(copy.HasExtension(Unittest.OptionalInt32Extension));
- Assert.Equal(3, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
+ Assert.IsTrue(copy.HasExtension(Unittest.OptionalInt32Extension));
+ Assert.AreEqual(3, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
- Assert.Equal(msg, copy);
- Assert.Equal(bits, copy.ToByteArray());
+ Assert.AreEqual(msg, copy);
+ Assert.AreEqual(bits, copy.ToByteArray());
//If we modify the object this should all continue to work as before
copybits = copy.ToBuilder().Build().ToByteArray();
- Assert.Equal(bits, copybits);
+ Assert.AreEqual(bits, copybits);
//If we replace extension the object this should all continue to work as before
copybits = copy.ToBuilder()
.SetExtension(Unittest.OptionalInt32Extension, optionalInt32)
.Build().ToByteArray();
- Assert.Equal(bits, copybits);
+ Assert.AreEqual(bits, copybits);
}
- [Fact]
+ [Test]
public void TestRecoverMissingFields()
{
TestMissingFieldsA msga = TestMissingFieldsA.CreateBuilder()
@@ -98,53 +98,53 @@ namespace Google.ProtocolBuffers
//serialize to type B and verify all fields exist
TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray());
- Assert.Equal(1001, msgb.Id);
- Assert.Equal("Name", msgb.Name);
- Assert.False(msgb.HasWebsite);
- Assert.Equal(1, msgb.UnknownFields.FieldDictionary.Count);
- Assert.Equal("missing@field.value",
+ Assert.AreEqual(1001, msgb.Id);
+ Assert.AreEqual("Name", msgb.Name);
+ Assert.IsFalse(msgb.HasWebsite);
+ Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual("missing@field.value",
msgb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8());
//serializes exactly the same (at least for this simple example)
- Assert.Equal(msga.ToByteArray(), msgb.ToByteArray());
- Assert.Equal(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
+ Assert.AreEqual(msga.ToByteArray(), msgb.ToByteArray());
+ Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
//now re-create an exact copy of A from serialized B
TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
- Assert.Equal(msga, copya);
- Assert.Equal(1001, copya.Id);
- Assert.Equal("Name", copya.Name);
- Assert.Equal("missing@field.value", copya.Email);
+ Assert.AreEqual(msga, copya);
+ Assert.AreEqual(1001, copya.Id);
+ Assert.AreEqual("Name", copya.Name);
+ Assert.AreEqual("missing@field.value", copya.Email);
//Now we modify B... and try again
msgb = msgb.ToBuilder().SetWebsite("http://new.missing.field").Build();
//Does B still have the missing field?
- Assert.Equal(1, msgb.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
//Convert back to A and see if all fields are there?
copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
- Assert.NotEqual(msga, copya);
- Assert.Equal(1001, copya.Id);
- Assert.Equal("Name", copya.Name);
- Assert.Equal("missing@field.value", copya.Email);
- Assert.Equal(1, copya.UnknownFields.FieldDictionary.Count);
- Assert.Equal("http://new.missing.field",
+ Assert.AreNotEqual(msga, copya);
+ Assert.AreEqual(1001, copya.Id);
+ Assert.AreEqual("Name", copya.Name);
+ Assert.AreEqual("missing@field.value", copya.Email);
+ Assert.AreEqual(1, copya.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual("http://new.missing.field",
copya.UnknownFields[TestMissingFieldsB.WebsiteFieldNumber].LengthDelimitedList[0].
ToStringUtf8());
//Lastly we can even still trip back to type B and see all fields:
TestMissingFieldsB copyb = TestMissingFieldsB.ParseFrom(copya.ToByteArray());
- Assert.Equal(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order.
- Assert.Equal(1001, copyb.Id);
- Assert.Equal("Name", copyb.Name);
- Assert.Equal("http://new.missing.field", copyb.Website);
- Assert.Equal(1, copyb.UnknownFields.FieldDictionary.Count);
- Assert.Equal("missing@field.value",
+ Assert.AreEqual(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order.
+ Assert.AreEqual(1001, copyb.Id);
+ Assert.AreEqual("Name", copyb.Name);
+ Assert.AreEqual("http://new.missing.field", copyb.Website);
+ Assert.AreEqual(1, copyb.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual("missing@field.value",
copyb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8
());
}
- [Fact]
+ [Test]
public void TestRecoverMissingMessage()
{
TestMissingFieldsA.Types.SubA suba =
@@ -158,52 +158,52 @@ namespace Google.ProtocolBuffers
//serialize to type B and verify all fields exist
TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray());
- Assert.Equal(1001, msgb.Id);
- Assert.Equal("Name", msgb.Name);
- Assert.Equal(1, msgb.UnknownFields.FieldDictionary.Count);
- Assert.Equal(suba.ToString(),
+ Assert.AreEqual(1001, msgb.Id);
+ Assert.AreEqual("Name", msgb.Name);
+ Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual(suba.ToString(),
TestMissingFieldsA.Types.SubA.ParseFrom(
msgb.UnknownFields[TestMissingFieldsA.TestAFieldNumber].LengthDelimitedList[0]).ToString
());
//serializes exactly the same (at least for this simple example)
- Assert.Equal(msga.ToByteArray(), msgb.ToByteArray());
- Assert.Equal(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
+ Assert.AreEqual(msga.ToByteArray(), msgb.ToByteArray());
+ Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
//now re-create an exact copy of A from serialized B
TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
- Assert.Equal(msga, copya);
- Assert.Equal(1001, copya.Id);
- Assert.Equal("Name", copya.Name);
- Assert.Equal(suba, copya.TestA);
+ Assert.AreEqual(msga, copya);
+ Assert.AreEqual(1001, copya.Id);
+ Assert.AreEqual("Name", copya.Name);
+ Assert.AreEqual(suba, copya.TestA);
//Now we modify B... and try again
TestMissingFieldsB.Types.SubB subb =
TestMissingFieldsB.Types.SubB.CreateBuilder().AddValues("test-b").Build();
msgb = msgb.ToBuilder().SetTestB(subb).Build();
//Does B still have the missing field?
- Assert.Equal(1, msgb.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
//Convert back to A and see if all fields are there?
copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
- Assert.NotEqual(msga, copya);
- Assert.Equal(1001, copya.Id);
- Assert.Equal("Name", copya.Name);
- Assert.Equal(suba, copya.TestA);
- Assert.Equal(1, copya.UnknownFields.FieldDictionary.Count);
- Assert.Equal(subb.ToByteArray(),
+ Assert.AreNotEqual(msga, copya);
+ Assert.AreEqual(1001, copya.Id);
+ Assert.AreEqual("Name", copya.Name);
+ Assert.AreEqual(suba, copya.TestA);
+ Assert.AreEqual(1, copya.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual(subb.ToByteArray(),
copya.UnknownFields[TestMissingFieldsB.TestBFieldNumber].LengthDelimitedList[0].ToByteArray());
//Lastly we can even still trip back to type B and see all fields:
TestMissingFieldsB copyb = TestMissingFieldsB.ParseFrom(copya.ToByteArray());
- Assert.Equal(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order.
- Assert.Equal(1001, copyb.Id);
- Assert.Equal("Name", copyb.Name);
- Assert.Equal(subb, copyb.TestB);
- Assert.Equal(1, copyb.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order.
+ Assert.AreEqual(1001, copyb.Id);
+ Assert.AreEqual("Name", copyb.Name);
+ Assert.AreEqual(subb, copyb.TestB);
+ Assert.AreEqual(1, copyb.UnknownFields.FieldDictionary.Count);
}
- [Fact]
+ [Test]
public void TestRestoreFromOtherType()
{
TestInteropPerson person = TestInteropPerson.CreateBuilder()
@@ -219,19 +219,19 @@ namespace Google.ProtocolBuffers
.SetExtension(UnittestExtrasFull.EmployeeId,
TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build())
.Build();
- Assert.True(person.IsInitialized);
+ Assert.IsTrue(person.IsInitialized);
TestEmptyMessage temp = TestEmptyMessage.ParseFrom(person.ToByteArray());
- Assert.Equal(7, temp.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);
temp = temp.ToBuilder().Build();
- Assert.Equal(7, temp.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnittestExtrasFull.RegisterAllExtensions(registry);
TestInteropPerson copy = TestInteropPerson.ParseFrom(temp.ToByteArray(), registry);
- Assert.Equal(person, copy);
- Assert.Equal(person.ToByteArray(), copy.ToByteArray());
+ Assert.AreEqual(person, copy);
+ Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
}
}
} \ No newline at end of file