aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs')
-rw-r--r--csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs139
1 files changed, 68 insertions, 71 deletions
diff --git a/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs b/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs
index b70635d5..b9680e68 100644
--- a/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs
+++ b/csharp/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs
@@ -34,17 +34,14 @@
#endregion
-using System.IO;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Collections.Generic;
using Google.ProtocolBuffers.TestProtos;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class MissingFieldAndExtensionTest
{
- [TestMethod]
+ [Fact]
public void TestRecoverMissingExtensions()
{
const int optionalInt32 = 12345678;
@@ -55,42 +52,42 @@ namespace Google.ProtocolBuffers
builder.AddExtension(Unittest.RepeatedDoubleExtension, 1.3);
TestAllExtensions msg = builder.Build();
- Assert.IsTrue(msg.HasExtension(Unittest.OptionalInt32Extension));
- Assert.AreEqual(3, msg.GetExtensionCount(Unittest.RepeatedDoubleExtension));
+ Assert.True(msg.HasExtension(Unittest.OptionalInt32Extension));
+ Assert.Equal(3, msg.GetExtensionCount(Unittest.RepeatedDoubleExtension));
byte[] bits = msg.ToByteArray();
TestAllExtensions copy = TestAllExtensions.ParseFrom(bits);
- Assert.IsFalse(copy.HasExtension(Unittest.OptionalInt32Extension));
- Assert.AreEqual(0, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
- Assert.AreNotEqual(msg, copy);
+ Assert.False(copy.HasExtension(Unittest.OptionalInt32Extension));
+ Assert.Equal(0, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
+ Assert.NotEqual(msg, copy);
//Even though copy does not understand the typees they serialize correctly
byte[] copybits = copy.ToByteArray();
- TestUtil.AssertBytesEqual(bits, copybits);
+ Assert.Equal(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.IsTrue(copy.HasExtension(Unittest.OptionalInt32Extension));
- Assert.AreEqual(3, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
+ Assert.True(copy.HasExtension(Unittest.OptionalInt32Extension));
+ Assert.Equal(3, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
- Assert.AreEqual(msg, copy);
- TestUtil.AssertBytesEqual(bits, copy.ToByteArray());
+ Assert.Equal(msg, copy);
+ Assert.Equal(bits, copy.ToByteArray());
//If we modify the object this should all continue to work as before
copybits = copy.ToBuilder().Build().ToByteArray();
- TestUtil.AssertBytesEqual(bits, copybits);
+ Assert.Equal(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();
- TestUtil.AssertBytesEqual(bits, copybits);
+ Assert.Equal(bits, copybits);
}
- [TestMethod]
+ [Fact]
public void TestRecoverMissingFields()
{
TestMissingFieldsA msga = TestMissingFieldsA.CreateBuilder()
@@ -101,53 +98,53 @@ namespace Google.ProtocolBuffers
//serialize to type B and verify all fields exist
TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray());
- 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",
+ 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",
msgb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8());
//serializes exactly the same (at least for this simple example)
- TestUtil.AssertBytesEqual(msga.ToByteArray(), msgb.ToByteArray());
- Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
+ Assert.Equal(msga.ToByteArray(), msgb.ToByteArray());
+ Assert.Equal(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
//now re-create an exact copy of A from serialized B
TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
- Assert.AreEqual(msga, copya);
- Assert.AreEqual(1001, copya.Id);
- Assert.AreEqual("Name", copya.Name);
- Assert.AreEqual("missing@field.value", copya.Email);
+ Assert.Equal(msga, copya);
+ Assert.Equal(1001, copya.Id);
+ Assert.Equal("Name", copya.Name);
+ Assert.Equal("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.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
+ Assert.Equal(1, msgb.UnknownFields.FieldDictionary.Count);
//Convert back to A and see if all fields are there?
copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
- 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",
+ 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",
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.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",
+ 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",
copyb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8
());
}
- [TestMethod]
+ [Fact]
public void TestRecoverMissingMessage()
{
TestMissingFieldsA.Types.SubA suba =
@@ -161,52 +158,52 @@ namespace Google.ProtocolBuffers
//serialize to type B and verify all fields exist
TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray());
- Assert.AreEqual(1001, msgb.Id);
- Assert.AreEqual("Name", msgb.Name);
- Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
- Assert.AreEqual(suba.ToString(),
+ Assert.Equal(1001, msgb.Id);
+ Assert.Equal("Name", msgb.Name);
+ Assert.Equal(1, msgb.UnknownFields.FieldDictionary.Count);
+ Assert.Equal(suba.ToString(),
TestMissingFieldsA.Types.SubA.ParseFrom(
msgb.UnknownFields[TestMissingFieldsA.TestAFieldNumber].LengthDelimitedList[0]).ToString
());
//serializes exactly the same (at least for this simple example)
- TestUtil.AssertBytesEqual(msga.ToByteArray(), msgb.ToByteArray());
- Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
+ Assert.Equal(msga.ToByteArray(), msgb.ToByteArray());
+ Assert.Equal(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
//now re-create an exact copy of A from serialized B
TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
- Assert.AreEqual(msga, copya);
- Assert.AreEqual(1001, copya.Id);
- Assert.AreEqual("Name", copya.Name);
- Assert.AreEqual(suba, copya.TestA);
+ Assert.Equal(msga, copya);
+ Assert.Equal(1001, copya.Id);
+ Assert.Equal("Name", copya.Name);
+ Assert.Equal(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.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
+ Assert.Equal(1, msgb.UnknownFields.FieldDictionary.Count);
//Convert back to A and see if all fields are there?
copya = TestMissingFieldsA.ParseFrom(msgb.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);
- TestUtil.AssertBytesEqual(subb.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(),
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.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);
+ 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);
}
- [TestMethod]
+ [Fact]
public void TestRestoreFromOtherType()
{
TestInteropPerson person = TestInteropPerson.CreateBuilder()
@@ -222,19 +219,19 @@ namespace Google.ProtocolBuffers
.SetExtension(UnittestExtrasFull.EmployeeId,
TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build())
.Build();
- Assert.IsTrue(person.IsInitialized);
+ Assert.True(person.IsInitialized);
TestEmptyMessage temp = TestEmptyMessage.ParseFrom(person.ToByteArray());
- Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);
+ Assert.Equal(7, temp.UnknownFields.FieldDictionary.Count);
temp = temp.ToBuilder().Build();
- Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);
+ Assert.Equal(7, temp.UnknownFields.FieldDictionary.Count);
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnittestExtrasFull.RegisterAllExtensions(registry);
TestInteropPerson copy = TestInteropPerson.ParseFrom(temp.ToByteArray(), registry);
- Assert.AreEqual(person, copy);
- TestUtil.AssertBytesEqual(person.ToByteArray(), copy.ToByteArray());
+ Assert.Equal(person, copy);
+ Assert.Equal(person.ToByteArray(), copy.ToByteArray());
}
}
} \ No newline at end of file