Commit 0884b779 authored by Jon Skeet's avatar Jon Skeet

Merge pull request #324 from jskeet/csharp

Change to using xUnit for all unit tests, and fetch that via NuGet.
parents 151018e8 c5647508
...@@ -79,3 +79,6 @@ javanano/target ...@@ -79,3 +79,6 @@ javanano/target
vsprojects/Debug vsprojects/Debug
vsprojects/Release vsprojects/Release
# NuGet packages: we want the repository configuration, but not the
# packages themselves.
/csharp/src/packages/*/

using System;
#if CLIENTPROFILE
namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
public sealed class TestClassAttribute : NUnit.Framework.TestFixtureAttribute
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public sealed class TestMethodAttribute : NUnit.Framework.TestAttribute
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public sealed class TestInitializeAttribute : NUnit.Framework.SetUpAttribute
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public sealed class IgnoreAttribute : NUnit.Framework.IgnoreAttribute
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public sealed class ExpectedExceptionAttribute : NUnit.Framework.ExpectedExceptionAttribute
{
public ExpectedExceptionAttribute(Type type) : base(type)
{ }
}
public class Assert : NUnit.Framework.Assert
{
[Obsolete("Do not use AreEqual on Byte[], use TestUtil.AssertBytesEqual(,)")]
public static void AreEqual(byte[] b1, byte[] b2)
{
NUnit.Framework.Assert.AreEqual(b1, b2);
}
[Obsolete("No not use assert with miss-matched types.")]
public static new void AreEqual(object b1, object b2)
{
NUnit.Framework.Assert.AreEqual(b1, b2);
}
//Allowed if the types match
public static void AreEqual<T>(T b1, T b2)
{
NUnit.Framework.Assert.AreEqual(b1, b2);
}
}
}
#endif
\ No newline at end of file
<?xml version="1.0" encoding="Windows-1252"?>
<configuration>
<startup>
<requiredRuntime version="v2.0.50727" />
</startup>
<runtime>
<!-- We need this so test exceptions don't crash NUnit -->
<legacyUnhandledExceptionPolicy enabled="1" />
<!-- Look for addins in the addins directory for now -->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib;addins"/>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="Windows-1252"?>
<configuration>
<startup>
<requiredRuntime version="v2.0.50727" />
</startup>
<runtime>
<!-- We need this so test exceptions don't crash NUnit -->
<legacyUnhandledExceptionPolicy enabled="1" />
<!-- Look for addins in the addins directory for now -->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib;addins"/>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="Windows-1252"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime version="v4.0.30319" safemode="true"/>
</startup>
<runtime>
<!-- We need this so test exceptions don't crash NUnit -->
<legacyUnhandledExceptionPolicy enabled="1" />
<!-- Look for addins in the addins directory for now -->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib;addins"/>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
...@@ -36,113 +36,112 @@ ...@@ -36,113 +36,112 @@
using System; using System;
using System.Text; using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class ByteStringTest public class ByteStringTest
{ {
[TestMethod] [Fact]
public void EmptyByteStringHasZeroSize() public void EmptyByteStringHasZeroSize()
{ {
Assert.AreEqual(0, ByteString.Empty.Length); Assert.Equal(0, ByteString.Empty.Length);
} }
[TestMethod] [Fact]
public void CopyFromStringWithExplicitEncoding() public void CopyFromStringWithExplicitEncoding()
{ {
ByteString bs = ByteString.CopyFrom("AB", Encoding.Unicode); ByteString bs = ByteString.CopyFrom("AB", Encoding.Unicode);
Assert.AreEqual(4, bs.Length); Assert.Equal(4, bs.Length);
Assert.AreEqual(65, bs[0]); Assert.Equal(65, bs[0]);
Assert.AreEqual(0, bs[1]); Assert.Equal(0, bs[1]);
Assert.AreEqual(66, bs[2]); Assert.Equal(66, bs[2]);
Assert.AreEqual(0, bs[3]); Assert.Equal(0, bs[3]);
} }
[TestMethod] [Fact]
public void IsEmptyWhenEmpty() public void IsEmptyWhenEmpty()
{ {
Assert.IsTrue(ByteString.CopyFromUtf8("").IsEmpty); Assert.True(ByteString.CopyFromUtf8("").IsEmpty);
} }
[TestMethod] [Fact]
public void IsEmptyWhenNotEmpty() public void IsEmptyWhenNotEmpty()
{ {
Assert.IsFalse(ByteString.CopyFromUtf8("X").IsEmpty); Assert.False(ByteString.CopyFromUtf8("X").IsEmpty);
} }
[TestMethod] [Fact]
public void CopyFromByteArrayCopiesContents() public void CopyFromByteArrayCopiesContents()
{ {
byte[] data = new byte[1]; byte[] data = new byte[1];
data[0] = 10; data[0] = 10;
ByteString bs = ByteString.CopyFrom(data); ByteString bs = ByteString.CopyFrom(data);
Assert.AreEqual(10, bs[0]); Assert.Equal(10, bs[0]);
data[0] = 5; data[0] = 5;
Assert.AreEqual(10, bs[0]); Assert.Equal(10, bs[0]);
} }
[TestMethod] [Fact]
public void ToByteArrayCopiesContents() public void ToByteArrayCopiesContents()
{ {
ByteString bs = ByteString.CopyFromUtf8("Hello"); ByteString bs = ByteString.CopyFromUtf8("Hello");
byte[] data = bs.ToByteArray(); byte[] data = bs.ToByteArray();
Assert.AreEqual((byte)'H', data[0]); Assert.Equal((byte)'H', data[0]);
Assert.AreEqual((byte)'H', bs[0]); Assert.Equal((byte)'H', bs[0]);
data[0] = 0; data[0] = 0;
Assert.AreEqual(0, data[0]); Assert.Equal(0, data[0]);
Assert.AreEqual((byte)'H', bs[0]); Assert.Equal((byte)'H', bs[0]);
} }
[TestMethod] [Fact]
public void CopyFromUtf8UsesUtf8() public void CopyFromUtf8UsesUtf8()
{ {
ByteString bs = ByteString.CopyFromUtf8("\u20ac"); ByteString bs = ByteString.CopyFromUtf8("\u20ac");
Assert.AreEqual(3, bs.Length); Assert.Equal(3, bs.Length);
Assert.AreEqual(0xe2, bs[0]); Assert.Equal(0xe2, bs[0]);
Assert.AreEqual(0x82, bs[1]); Assert.Equal(0x82, bs[1]);
Assert.AreEqual(0xac, bs[2]); Assert.Equal(0xac, bs[2]);
} }
[TestMethod] [Fact]
public void CopyFromPortion() public void CopyFromPortion()
{ {
byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6}; byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
ByteString bs = ByteString.CopyFrom(data, 2, 3); ByteString bs = ByteString.CopyFrom(data, 2, 3);
Assert.AreEqual(3, bs.Length); Assert.Equal(3, bs.Length);
Assert.AreEqual(2, bs[0]); Assert.Equal(2, bs[0]);
Assert.AreEqual(3, bs[1]); Assert.Equal(3, bs[1]);
} }
[TestMethod] [Fact]
public void ToStringUtf8() public void ToStringUtf8()
{ {
ByteString bs = ByteString.CopyFromUtf8("\u20ac"); ByteString bs = ByteString.CopyFromUtf8("\u20ac");
Assert.AreEqual("\u20ac", bs.ToStringUtf8()); Assert.Equal("\u20ac", bs.ToStringUtf8());
} }
[TestMethod] [Fact]
public void ToStringWithExplicitEncoding() public void ToStringWithExplicitEncoding()
{ {
ByteString bs = ByteString.CopyFrom("\u20ac", Encoding.Unicode); 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() public void FromBase64_WithText()
{ {
byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6}; byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
string base64 = Convert.ToBase64String(data); string base64 = Convert.ToBase64String(data);
ByteString bs = ByteString.FromBase64(base64); ByteString bs = ByteString.FromBase64(base64);
TestUtil.AssertBytesEqual(data, bs.ToByteArray()); Assert.Equal(data, bs.ToByteArray());
} }
[TestMethod] [Fact]
public void FromBase64_Empty() public void FromBase64_Empty()
{ {
// Optimization which also fixes issue 61. // Optimization which also fixes issue 61.
Assert.AreSame(ByteString.Empty, ByteString.FromBase64("")); Assert.Same(ByteString.Empty, ByteString.FromBase64(""));
} }
} }
} }
\ No newline at end of file
...@@ -36,40 +36,39 @@ ...@@ -36,40 +36,39 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers.Collections namespace Google.ProtocolBuffers.Collections
{ {
[TestClass]
public class PopsicleListTest public class PopsicleListTest
{ {
[TestMethod] [Fact]
public void MutatingOperationsOnFrozenList() public void MutatingOperationsOnFrozenList()
{ {
PopsicleList<string> list = new PopsicleList<string>(); PopsicleList<string> list = new PopsicleList<string>();
list.MakeReadOnly(); list.MakeReadOnly();
TestUtil.AssertNotSupported(() => list.Add("")); Assert.Throws<NotSupportedException>(() => list.Add(""));
TestUtil.AssertNotSupported(() => list.Clear()); Assert.Throws<NotSupportedException>(() => list.Clear());
TestUtil.AssertNotSupported(() => list.Insert(0, "")); Assert.Throws<NotSupportedException>(() => list.Insert(0, ""));
TestUtil.AssertNotSupported(() => list.Remove("")); Assert.Throws<NotSupportedException>(() => list.Remove(""));
TestUtil.AssertNotSupported(() => list.RemoveAt(0)); Assert.Throws<NotSupportedException>(() => list.RemoveAt(0));
TestUtil.AssertNotSupported(() => list.Add(new[] { "", "" })); Assert.Throws<NotSupportedException>(() => list.Add(new[] { "", "" }));
} }
[TestMethod] [Fact]
public void NonMutatingOperationsOnFrozenList() public void NonMutatingOperationsOnFrozenList()
{ {
PopsicleList<string> list = new PopsicleList<string>(); PopsicleList<string> list = new PopsicleList<string>();
list.MakeReadOnly(); list.MakeReadOnly();
Assert.IsFalse(list.Contains("")); Assert.False(list.Contains(""));
Assert.AreEqual(0, list.Count); Assert.Equal(0, list.Count);
list.CopyTo(new string[5], 0); list.CopyTo(new string[5], 0);
list.GetEnumerator(); list.GetEnumerator();
Assert.AreEqual(-1, list.IndexOf("")); Assert.Equal(-1, list.IndexOf(""));
Assert.IsTrue(list.IsReadOnly); Assert.True(list.IsReadOnly);
} }
[TestMethod] [Fact]
public void MutatingOperationsOnFluidList() public void MutatingOperationsOnFluidList()
{ {
PopsicleList<string> list = new PopsicleList<string>(); PopsicleList<string> list = new PopsicleList<string>();
...@@ -81,73 +80,46 @@ namespace Google.ProtocolBuffers.Collections ...@@ -81,73 +80,46 @@ namespace Google.ProtocolBuffers.Collections
list.RemoveAt(0); list.RemoveAt(0);
} }
[TestMethod] [Fact]
public void NonMutatingOperationsOnFluidList() public void NonMutatingOperationsOnFluidList()
{ {
PopsicleList<string> list = new PopsicleList<string>(); PopsicleList<string> list = new PopsicleList<string>();
Assert.IsFalse(list.Contains("")); Assert.False(list.Contains(""));
Assert.AreEqual(0, list.Count); Assert.Equal(0, list.Count);
list.CopyTo(new string[5], 0); list.CopyTo(new string[5], 0);
list.GetEnumerator(); list.GetEnumerator();
Assert.AreEqual(-1, list.IndexOf("")); Assert.Equal(-1, list.IndexOf(""));
Assert.IsFalse(list.IsReadOnly); Assert.False(list.IsReadOnly);
} }
[TestMethod] [Fact]
public void DoesNotAddNullEnumerable() public void DoesNotAddNullEnumerable()
{ {
PopsicleList<string> list = new PopsicleList<string>(); PopsicleList<string> list = new PopsicleList<string>();
try Assert.Throws<ArgumentNullException>(() => list.Add((IEnumerable<string>) null));
{
list.Add((IEnumerable<string>)null);
}
catch (ArgumentNullException)
{ return; }
Assert.Fail("List should not allow nulls.");
} }
[TestMethod] [Fact]
public void DoesNotAddRangeWithNull() public void DoesNotAddRangeWithNull()
{ {
PopsicleList<string> list = new PopsicleList<string>(); PopsicleList<string> list = new PopsicleList<string>();
try // TODO(jonskeet): Change to ArgumentException? The argument isn't null...
{ Assert.Throws<ArgumentNullException>(() => list.Add(new[] {"a", "b", null}));
list.Add(new[] { "a", "b", null });
}
catch (ArgumentNullException)
{ return; }
Assert.Fail("List should not allow nulls.");
} }
[TestMethod] [Fact]
public void DoesNotAddNull() public void DoesNotAddNull()
{ {
PopsicleList<string> list = new PopsicleList<string>(); PopsicleList<string> list = new PopsicleList<string>();
try Assert.Throws<ArgumentNullException>(() => list.Add((string) null));
{
list.Add((string)null);
}
catch (ArgumentNullException)
{ return; }
Assert.Fail("List should not allow nulls.");
} }
[TestMethod] [Fact]
public void DoesNotSetNull() public void DoesNotSetNull()
{ {
PopsicleList<string> list = new PopsicleList<string>(); PopsicleList<string> list = new PopsicleList<string>();
list.Add("a"); list.Add("a");
try Assert.Throws<ArgumentNullException>(() => list[0] = null);
{
list[0] = null;
}
catch (ArgumentNullException)
{ return; }
Assert.Fail("List should not allow nulls.");
} }
} }
} }
\ No newline at end of file
using System; using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers.Compatibility namespace Google.ProtocolBuffers.Compatibility
{ {
[TestClass]
public class BinaryCompatibilityTests : CompatibilityTests public class BinaryCompatibilityTests : CompatibilityTests
{ {
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message) protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
......
using System; using System;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers.Compatibility namespace Google.ProtocolBuffers.Compatibility
...@@ -22,10 +22,10 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -22,10 +22,10 @@ namespace Google.ProtocolBuffers.Compatibility
protected virtual void AssertOutputEquals(object lhs, object rhs) protected virtual void AssertOutputEquals(object lhs, object rhs)
{ {
Assert.AreEqual<object>(lhs, rhs); Assert.Equal<object>(lhs, rhs);
} }
[TestMethod] [Fact]
public virtual void RoundTripWithEmptyChildMessageSize() public virtual void RoundTripWithEmptyChildMessageSize()
{ {
SizeMessage1 msg = SizeMessage1.CreateBuilder() SizeMessage1 msg = SizeMessage1.CreateBuilder()
...@@ -37,12 +37,12 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -37,12 +37,12 @@ namespace Google.ProtocolBuffers.Compatibility
SizeMessage1 copy = DeserializeMessage<SizeMessage1, SizeMessage1.Builder>(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).BuildPartial(); 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)); 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() public virtual void RoundTripWithEmptyChildMessageSpeed()
{ {
SpeedMessage1 msg = SpeedMessage1.CreateBuilder() SpeedMessage1 msg = SpeedMessage1.CreateBuilder()
...@@ -54,12 +54,12 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -54,12 +54,12 @@ namespace Google.ProtocolBuffers.Compatibility
SpeedMessage1 copy = DeserializeMessage<SpeedMessage1, SpeedMessage1.Builder>(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).BuildPartial(); 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)); 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() public virtual void RoundTripMessage1OptimizeSize()
{ {
SizeMessage1 msg = SizeMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build(); SizeMessage1 msg = SizeMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
...@@ -67,12 +67,12 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -67,12 +67,12 @@ namespace Google.ProtocolBuffers.Compatibility
SizeMessage1 copy = DeserializeMessage<SizeMessage1, SizeMessage1.Builder>(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build(); 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)); 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() public virtual void RoundTripMessage2OptimizeSize()
{ {
SizeMessage2 msg = SizeMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build(); SizeMessage2 msg = SizeMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
...@@ -80,12 +80,12 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -80,12 +80,12 @@ namespace Google.ProtocolBuffers.Compatibility
SizeMessage2 copy = DeserializeMessage<SizeMessage2, SizeMessage2.Builder>(content, SizeMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build(); 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)); 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() public virtual void RoundTripMessage1OptimizeSpeed()
{ {
SpeedMessage1 msg = SpeedMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build(); SpeedMessage1 msg = SpeedMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
...@@ -93,12 +93,12 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -93,12 +93,12 @@ namespace Google.ProtocolBuffers.Compatibility
SpeedMessage1 copy = DeserializeMessage<SpeedMessage1, SpeedMessage1.Builder>(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build(); 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)); 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() public virtual void RoundTripMessage2OptimizeSpeed()
{ {
SpeedMessage2 msg = SpeedMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build(); SpeedMessage2 msg = SpeedMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
...@@ -106,9 +106,9 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -106,9 +106,9 @@ namespace Google.ProtocolBuffers.Compatibility
SpeedMessage2 copy = DeserializeMessage<SpeedMessage2, SpeedMessage2.Builder>(content, SpeedMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build(); 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)); 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 #region Test message builders
...@@ -185,7 +185,7 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -185,7 +185,7 @@ namespace Google.ProtocolBuffers.Compatibility
#endregion #endregion
[TestMethod] [Fact]
public void TestRoundTripAllTypes() public void TestRoundTripAllTypes()
{ {
TestAllTypes msg = AddAllTypes(new TestAllTypes.Builder()).Build(); TestAllTypes msg = AddAllTypes(new TestAllTypes.Builder()).Build();
...@@ -193,12 +193,12 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -193,12 +193,12 @@ namespace Google.ProtocolBuffers.Compatibility
TestAllTypes copy = DeserializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build(); 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)); 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() public void TestRoundTripRepeatedTypes()
{ {
TestAllTypes msg = AddRepeatedTypes(new TestAllTypes.Builder(), 5).Build(); TestAllTypes msg = AddRepeatedTypes(new TestAllTypes.Builder(), 5).Build();
...@@ -206,12 +206,12 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -206,12 +206,12 @@ namespace Google.ProtocolBuffers.Compatibility
TestAllTypes copy = DeserializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build(); 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)); 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() public void TestRoundTripPackedTypes()
{ {
TestPackedTypes msg = AddPackedTypes(new TestPackedTypes.Builder(), 5).Build(); TestPackedTypes msg = AddPackedTypes(new TestPackedTypes.Builder(), 5).Build();
...@@ -219,9 +219,9 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -219,9 +219,9 @@ namespace Google.ProtocolBuffers.Compatibility
TestPackedTypes copy = DeserializeMessage<TestPackedTypes, TestPackedTypes.Builder>(content, TestPackedTypes.CreateBuilder(), ExtensionRegistry.Empty).Build(); 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)); 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()));
} }
} }
} }
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Text;
using Google.ProtocolBuffers.Serialization; using Google.ProtocolBuffers.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers.Compatibility namespace Google.ProtocolBuffers.Compatibility
{ {
[TestClass]
public class DictionaryCompatibilityTests : CompatibilityTests public class DictionaryCompatibilityTests : CompatibilityTests
{ {
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message) protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
...@@ -28,7 +25,7 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -28,7 +25,7 @@ namespace Google.ProtocolBuffers.Compatibility
IDictionary<string, object> left = (IDictionary<string, object>)lhs; IDictionary<string, object> left = (IDictionary<string, object>)lhs;
IDictionary<string, object> right = (IDictionary<string, object>)rhs; 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>(left.Keys).ToArray()),
String.Join(",", new List<string>(right.Keys).ToArray()) String.Join(",", new List<string>(right.Keys).ToArray())
); );
......
using System.IO; using System.IO;
using System.Text;
using Google.ProtocolBuffers.Serialization; using Google.ProtocolBuffers.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers.Compatibility namespace Google.ProtocolBuffers.Compatibility
{ {
[TestClass]
public class JsonCompatibilityTests : CompatibilityTests public class JsonCompatibilityTests : CompatibilityTests
{ {
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message) protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
...@@ -23,7 +20,6 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -23,7 +20,6 @@ namespace Google.ProtocolBuffers.Compatibility
} }
} }
[TestClass]
public class JsonCompatibilityFormattedTests : CompatibilityTests public class JsonCompatibilityFormattedTests : CompatibilityTests
{ {
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message) protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
......
using System; using System.IO;
using System.Collections.Generic; using Xunit;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers.Compatibility namespace Google.ProtocolBuffers.Compatibility
{ {
...@@ -15,11 +12,11 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -15,11 +12,11 @@ namespace Google.ProtocolBuffers.Compatibility
Stream resource = typeof(TestResources).Assembly.GetManifestResourceStream( Stream resource = typeof(TestResources).Assembly.GetManifestResourceStream(
typeof(TestResources).Namespace + ".google_message1.dat"); 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]; byte[] bytes = new byte[resource.Length];
int amtRead = resource.Read(bytes, 0, bytes.Length); int amtRead = resource.Read(bytes, 0, bytes.Length);
Assert.AreEqual(bytes.Length, amtRead); Assert.Equal(bytes.Length, amtRead);
return bytes; return bytes;
} }
} }
...@@ -30,11 +27,10 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -30,11 +27,10 @@ namespace Google.ProtocolBuffers.Compatibility
Stream resource = typeof(TestResources).Assembly.GetManifestResourceStream( Stream resource = typeof(TestResources).Assembly.GetManifestResourceStream(
typeof(TestResources).Namespace + ".google_message2.dat"); 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]; byte[] bytes = new byte[resource.Length];
int amtRead = resource.Read(bytes, 0, bytes.Length); int amtRead = resource.Read(bytes, 0, bytes.Length);
Assert.AreEqual(bytes.Length, amtRead); Assert.Equal(bytes.Length, amtRead);
return bytes; return bytes;
} }
} }
......
using System.ComponentModel;
using System.IO; using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers.Compatibility namespace Google.ProtocolBuffers.Compatibility
{ {
[TestClass]
public class TextCompatibilityTests : CompatibilityTests public class TextCompatibilityTests : CompatibilityTests
{ {
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message) protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
...@@ -20,14 +18,14 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -20,14 +18,14 @@ namespace Google.ProtocolBuffers.Compatibility
return builder; return builder;
} }
//This test can take a very long time to run. //This test can take a very long time to run.
[TestMethod] [Fact]
public override void RoundTripMessage2OptimizeSize() public override void RoundTripMessage2OptimizeSize()
{ {
//base.RoundTripMessage2OptimizeSize(); //base.RoundTripMessage2OptimizeSize();
} }
//This test can take a very long time to run. //This test can take a very long time to run.
[TestMethod] [Fact]
public override void RoundTripMessage2OptimizeSpeed() public override void RoundTripMessage2OptimizeSpeed()
{ {
//base.RoundTripMessage2OptimizeSpeed(); //base.RoundTripMessage2OptimizeSpeed();
......
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using Google.ProtocolBuffers.Serialization; using Google.ProtocolBuffers.Serialization;
using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers.Compatibility namespace Google.ProtocolBuffers.Compatibility
{ {
[TestClass]
public class XmlCompatibilityTests : CompatibilityTests public class XmlCompatibilityTests : CompatibilityTests
{ {
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message) protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
...@@ -24,7 +21,6 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -24,7 +21,6 @@ namespace Google.ProtocolBuffers.Compatibility
} }
} }
[TestClass]
public class XmlCompatibilityFormattedTests : CompatibilityTests public class XmlCompatibilityFormattedTests : CompatibilityTests
{ {
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message) protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
......
using System; using System;
using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitTest.Issues.TestProtos; using UnitTest.Issues.TestProtos;
using Xunit;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class DeprecatedMemberTest public class DeprecatedMemberTest
{ {
private static void AssertIsDeprecated(MemberInfo member) private static void AssertIsDeprecated(MemberInfo member)
{ {
Assert.IsNotNull(member); Assert.NotNull(member);
Assert.IsTrue(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member); Assert.True(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
} }
[TestMethod] [Fact]
public void TestDepreatedPrimitiveValue() public void TestDepreatedPrimitiveValue()
{ {
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasPrimitiveValue")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasPrimitiveValue"));
...@@ -27,7 +24,7 @@ namespace Google.ProtocolBuffers ...@@ -27,7 +24,7 @@ namespace Google.ProtocolBuffers
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveValue")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetPrimitiveValue")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetPrimitiveValue"));
} }
[TestMethod] [Fact]
public void TestDepreatedPrimitiveArray() public void TestDepreatedPrimitiveArray()
{ {
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("PrimitiveArrayList")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("PrimitiveArrayList"));
...@@ -42,7 +39,7 @@ namespace Google.ProtocolBuffers ...@@ -42,7 +39,7 @@ namespace Google.ProtocolBuffers
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangePrimitiveArray")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangePrimitiveArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveArray")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveArray"));
} }
[TestMethod] [Fact]
public void TestDepreatedMessageValue() public void TestDepreatedMessageValue()
{ {
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasMessageValue")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasMessageValue"));
...@@ -55,7 +52,7 @@ namespace Google.ProtocolBuffers ...@@ -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) }));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageValue", new[] { typeof(DeprecatedChild.Builder) })); AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageValue", new[] { typeof(DeprecatedChild.Builder) }));
} }
[TestMethod] [Fact]
public void TestDepreatedMessageArray() public void TestDepreatedMessageArray()
{ {
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("MessageArrayList")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("MessageArrayList"));
...@@ -72,7 +69,7 @@ namespace Google.ProtocolBuffers ...@@ -72,7 +69,7 @@ namespace Google.ProtocolBuffers
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangeMessageArray")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangeMessageArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearMessageArray")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearMessageArray"));
} }
[TestMethod] [Fact]
public void TestDepreatedEnumValue() public void TestDepreatedEnumValue()
{ {
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasEnumValue")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasEnumValue"));
...@@ -83,7 +80,7 @@ namespace Google.ProtocolBuffers ...@@ -83,7 +80,7 @@ namespace Google.ProtocolBuffers
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearEnumValue")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearEnumValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetEnumValue")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetEnumValue"));
} }
[TestMethod] [Fact]
public void TestDepreatedEnumArray() public void TestDepreatedEnumArray()
{ {
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("EnumArrayList")); AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("EnumArrayList"));
......
...@@ -37,26 +37,24 @@ ...@@ -37,26 +37,24 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class DynamicMessageTest public class DynamicMessageTest
{ {
private ReflectionTester reflectionTester; private ReflectionTester reflectionTester;
private ReflectionTester extensionsReflectionTester; private ReflectionTester extensionsReflectionTester;
private ReflectionTester packedReflectionTester; private ReflectionTester packedReflectionTester;
[TestInitialize] public DynamicMessageTest()
public void SetUp()
{ {
reflectionTester = ReflectionTester.CreateTestAllTypesInstance(); reflectionTester = ReflectionTester.CreateTestAllTypesInstance();
extensionsReflectionTester = ReflectionTester.CreateTestAllExtensionsInstance(); extensionsReflectionTester = ReflectionTester.CreateTestAllExtensionsInstance();
packedReflectionTester = ReflectionTester.CreateTestPackedTypesInstance(); packedReflectionTester = ReflectionTester.CreateTestPackedTypesInstance();
} }
[TestMethod] [Fact]
public void DynamicMessageAccessors() public void DynamicMessageAccessors()
{ {
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor); IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
...@@ -65,30 +63,22 @@ namespace Google.ProtocolBuffers ...@@ -65,30 +63,22 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertAllFieldsSetViaReflection(message); reflectionTester.AssertAllFieldsSetViaReflection(message);
} }
[TestMethod] [Fact]
public void DoubleBuildError() public void DoubleBuildError()
{ {
DynamicMessage.Builder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor); DynamicMessage.Builder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
builder.Build(); builder.Build();
try Assert.Throws<InvalidOperationException>(() => builder.Build());
{ }
builder.Build();
Assert.Fail("Should have thrown exception."); [Fact]
}
catch (InvalidOperationException)
{
// Success.
}
}
[TestMethod]
public void DynamicMessageSettersRejectNull() public void DynamicMessageSettersRejectNull()
{ {
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor); IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
reflectionTester.AssertReflectionSettersRejectNull(builder); reflectionTester.AssertReflectionSettersRejectNull(builder);
} }
[TestMethod] [Fact]
public void DynamicMessageExtensionAccessors() public void DynamicMessageExtensionAccessors()
{ {
// We don't need to extensively test DynamicMessage's handling of // We don't need to extensively test DynamicMessage's handling of
...@@ -100,14 +90,14 @@ namespace Google.ProtocolBuffers ...@@ -100,14 +90,14 @@ namespace Google.ProtocolBuffers
extensionsReflectionTester.AssertAllFieldsSetViaReflection(message); extensionsReflectionTester.AssertAllFieldsSetViaReflection(message);
} }
[TestMethod] [Fact]
public void DynamicMessageExtensionSettersRejectNull() public void DynamicMessageExtensionSettersRejectNull()
{ {
IBuilder builder = DynamicMessage.CreateBuilder(TestAllExtensions.Descriptor); IBuilder builder = DynamicMessage.CreateBuilder(TestAllExtensions.Descriptor);
extensionsReflectionTester.AssertReflectionSettersRejectNull(builder); extensionsReflectionTester.AssertReflectionSettersRejectNull(builder);
} }
[TestMethod] [Fact]
public void DynamicMessageRepeatedSetters() public void DynamicMessageRepeatedSetters()
{ {
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor); IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
...@@ -117,21 +107,21 @@ namespace Google.ProtocolBuffers ...@@ -117,21 +107,21 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertRepeatedFieldsModifiedViaReflection(message); reflectionTester.AssertRepeatedFieldsModifiedViaReflection(message);
} }
[TestMethod] [Fact]
public void DynamicMessageRepeatedSettersRejectNull() public void DynamicMessageRepeatedSettersRejectNull()
{ {
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor); IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
reflectionTester.AssertReflectionRepeatedSettersRejectNull(builder); reflectionTester.AssertReflectionRepeatedSettersRejectNull(builder);
} }
[TestMethod] [Fact]
public void DynamicMessageDefaults() public void DynamicMessageDefaults()
{ {
reflectionTester.AssertClearViaReflection(DynamicMessage.GetDefaultInstance(TestAllTypes.Descriptor)); reflectionTester.AssertClearViaReflection(DynamicMessage.GetDefaultInstance(TestAllTypes.Descriptor));
reflectionTester.AssertClearViaReflection(DynamicMessage.CreateBuilder(TestAllTypes.Descriptor).Build()); reflectionTester.AssertClearViaReflection(DynamicMessage.CreateBuilder(TestAllTypes.Descriptor).Build());
} }
[TestMethod] [Fact]
public void DynamicMessageSerializedSize() public void DynamicMessageSerializedSize()
{ {
TestAllTypes message = TestUtil.GetAllSet(); TestAllTypes message = TestUtil.GetAllSet();
...@@ -140,10 +130,10 @@ namespace Google.ProtocolBuffers ...@@ -140,10 +130,10 @@ namespace Google.ProtocolBuffers
reflectionTester.SetAllFieldsViaReflection(dynamicBuilder); reflectionTester.SetAllFieldsViaReflection(dynamicBuilder);
IMessage dynamicMessage = dynamicBuilder.WeakBuild(); IMessage dynamicMessage = dynamicBuilder.WeakBuild();
Assert.AreEqual(message.SerializedSize, dynamicMessage.SerializedSize); Assert.Equal(message.SerializedSize, dynamicMessage.SerializedSize);
} }
[TestMethod] [Fact]
public void DynamicMessageSerialization() public void DynamicMessageSerialization()
{ {
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor); IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
...@@ -156,10 +146,10 @@ namespace Google.ProtocolBuffers ...@@ -156,10 +146,10 @@ namespace Google.ProtocolBuffers
TestUtil.AssertAllFieldsSet(message2); TestUtil.AssertAllFieldsSet(message2);
// In fact, the serialized forms should be exactly the same, byte-for-byte. // 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() public void DynamicMessageParsing()
{ {
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder(); TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
...@@ -172,7 +162,7 @@ namespace Google.ProtocolBuffers ...@@ -172,7 +162,7 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertAllFieldsSetViaReflection(message2); reflectionTester.AssertAllFieldsSetViaReflection(message2);
} }
[TestMethod] [Fact]
public void DynamicMessagePackedSerialization() public void DynamicMessagePackedSerialization()
{ {
IBuilder builder = DynamicMessage.CreateBuilder(TestPackedTypes.Descriptor); IBuilder builder = DynamicMessage.CreateBuilder(TestPackedTypes.Descriptor);
...@@ -185,11 +175,11 @@ namespace Google.ProtocolBuffers ...@@ -185,11 +175,11 @@ namespace Google.ProtocolBuffers
TestUtil.AssertPackedFieldsSet(message2); TestUtil.AssertPackedFieldsSet(message2);
// In fact, the serialized forms should be exactly the same, byte-for-byte. // 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] [Fact]
public void testDynamicMessagePackedParsing() public void DynamicMessagePackedParsing()
{ {
TestPackedTypes.Builder builder = TestPackedTypes.CreateBuilder(); TestPackedTypes.Builder builder = TestPackedTypes.CreateBuilder();
TestUtil.SetPackedFields(builder); TestUtil.SetPackedFields(builder);
...@@ -201,7 +191,7 @@ namespace Google.ProtocolBuffers ...@@ -201,7 +191,7 @@ namespace Google.ProtocolBuffers
packedReflectionTester.AssertPackedFieldsSetViaReflection(message2); packedReflectionTester.AssertPackedFieldsSetViaReflection(message2);
} }
[TestMethod] [Fact]
public void DynamicMessageCopy() public void DynamicMessageCopy()
{ {
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder(); TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
...@@ -212,7 +202,7 @@ namespace Google.ProtocolBuffers ...@@ -212,7 +202,7 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertAllFieldsSetViaReflection(copy); reflectionTester.AssertAllFieldsSetViaReflection(copy);
} }
[TestMethod] [Fact]
public void ToBuilder() public void ToBuilder()
{ {
DynamicMessage.Builder builder = DynamicMessage.Builder builder =
...@@ -230,8 +220,8 @@ namespace Google.ProtocolBuffers ...@@ -230,8 +220,8 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertAllFieldsSetViaReflection(derived); reflectionTester.AssertAllFieldsSetViaReflection(derived);
IList<ulong> values = derived.UnknownFields.FieldDictionary[unknownFieldNum].VarintList; IList<ulong> values = derived.UnknownFields.FieldDictionary[unknownFieldNum].VarintList;
Assert.AreEqual(1, values.Count); Assert.Equal(1, values.Count);
Assert.AreEqual(unknownFieldVal, values[0]); Assert.Equal(unknownFieldVal, values[0]);
} }
} }
} }
\ No newline at end of file
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class GeneratedBuilderTest public class GeneratedBuilderTest
{ {
class OneTimeEnumerator<T> : IEnumerable<T> class OneTimeEnumerator<T> : IEnumerable<T>
...@@ -19,107 +17,86 @@ namespace Google.ProtocolBuffers ...@@ -19,107 +17,86 @@ namespace Google.ProtocolBuffers
} }
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
Assert.IsFalse(_enumerated, "The collection {0} has already been enumerated", GetType()); Assert.False(_enumerated);
_enumerated = true; _enumerated = true;
yield return _item; yield return _item;
} }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{ return GetEnumerator(); } {
return GetEnumerator();
}
} }
[TestMethod] [Fact]
public void DoesNotEnumerateTwiceForMessageList() public void DoesNotEnumerateTwiceForMessageList()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedForeignMessage( b.AddRangeRepeatedForeignMessage(new OneTimeEnumerator<ForeignMessage>(ForeignMessage.DefaultInstance));
new OneTimeEnumerator<ForeignMessage>(
ForeignMessage.DefaultInstance));
} }
[TestMethod]
[Fact]
public void DoesNotEnumerateTwiceForPrimitiveList() public void DoesNotEnumerateTwiceForPrimitiveList()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedInt32(new OneTimeEnumerator<int>(1)); b.AddRangeRepeatedInt32(new OneTimeEnumerator<int>(1));
} }
[TestMethod]
[Fact]
public void DoesNotEnumerateTwiceForStringList() public void DoesNotEnumerateTwiceForStringList()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedString(new OneTimeEnumerator<string>("test")); b.AddRangeRepeatedString(new OneTimeEnumerator<string>("test"));
} }
[TestMethod]
[Fact]
public void DoesNotEnumerateTwiceForEnumList() public void DoesNotEnumerateTwiceForEnumList()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedForeignEnum(new OneTimeEnumerator<ForeignEnum>(ForeignEnum.FOREIGN_BAR)); b.AddRangeRepeatedForeignEnum(new OneTimeEnumerator<ForeignEnum>(ForeignEnum.FOREIGN_BAR));
} }
private delegate void TestMethod(); [Fact]
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]
public void DoesNotAddNullToMessageListByAddRange() public void DoesNotAddNullToMessageListByAddRange()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
AssertThrows<ArgumentNullException>( Assert.Throws<ArgumentNullException>(() => b.AddRangeRepeatedForeignMessage(new ForeignMessage[] { null }));
() => b.AddRangeRepeatedForeignMessage(new ForeignMessage[] { null })
);
} }
[TestMethod]
[Fact]
public void DoesNotAddNullToMessageListByAdd() public void DoesNotAddNullToMessageListByAdd()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
AssertThrows<ArgumentNullException>( Assert.Throws<ArgumentNullException>(() => b.AddRepeatedForeignMessage((ForeignMessage)null));
() => b.AddRepeatedForeignMessage((ForeignMessage)null)
);
} }
[TestMethod]
[Fact]
public void DoesNotAddNullToMessageListBySet() public void DoesNotAddNullToMessageListBySet()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRepeatedForeignMessage(ForeignMessage.DefaultInstance); b.AddRepeatedForeignMessage(ForeignMessage.DefaultInstance);
AssertThrows<ArgumentNullException>( Assert.Throws<ArgumentNullException>(() => b.SetRepeatedForeignMessage(0, (ForeignMessage)null));
() => b.SetRepeatedForeignMessage(0, (ForeignMessage)null)
);
} }
[TestMethod]
[Fact]
public void DoesNotAddNullToStringListByAddRange() public void DoesNotAddNullToStringListByAddRange()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
AssertThrows<ArgumentNullException>( Assert.Throws<ArgumentNullException>(() => b.AddRangeRepeatedString(new String[] { null }));
() => b.AddRangeRepeatedString(new String[] { null })
);
} }
[TestMethod]
[Fact]
public void DoesNotAddNullToStringListByAdd() public void DoesNotAddNullToStringListByAdd()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
AssertThrows<ArgumentNullException>( Assert.Throws<ArgumentNullException>(() => b.AddRepeatedString(null));
() => b.AddRepeatedString(null)
);
} }
[TestMethod]
[Fact]
public void DoesNotAddNullToStringListBySet() public void DoesNotAddNullToStringListBySet()
{ {
TestAllTypes.Builder b = new TestAllTypes.Builder(); TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRepeatedString("one"); b.AddRepeatedString("one");
AssertThrows<ArgumentNullException>( Assert.Throws<ArgumentNullException>(() => b.SetRepeatedString(0, null));
() => b.SetRepeatedString(0, null)
);
} }
} }
} }
...@@ -35,13 +35,9 @@ ...@@ -35,13 +35,9 @@
#endregion #endregion
using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.Descriptors; using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitTest.Issues.TestProtos; using UnitTest.Issues.TestProtos;
using Xunit;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
...@@ -49,17 +45,16 @@ namespace Google.ProtocolBuffers ...@@ -49,17 +45,16 @@ namespace Google.ProtocolBuffers
/// <summary> /// <summary>
/// Tests for issues which aren't easily compartmentalized into other unit tests. /// Tests for issues which aren't easily compartmentalized into other unit tests.
/// </summary> /// </summary>
[TestClass]
public class IssuesTest public class IssuesTest
{ {
// Issue 45 // Issue 45
[TestMethod] [Fact]
public void FieldCalledItem() public void FieldCalledItem()
{ {
ItemField message = new ItemField.Builder { Item = 3 }.Build(); ItemField message = new ItemField.Builder { Item = 3 }.Build();
FieldDescriptor field = ItemField.Descriptor.FindFieldByName("item"); FieldDescriptor field = ItemField.Descriptor.FindFieldByName("item");
Assert.IsNotNull(field); Assert.NotNull(field);
Assert.AreEqual(3, (int)message[field]); Assert.Equal(3, (int)message[field]);
} }
} }
} }
...@@ -37,28 +37,27 @@ ...@@ -37,28 +37,27 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage; using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class MessageStreamIteratorTest public class MessageStreamIteratorTest
{ {
[TestMethod] [Fact]
public void ThreeMessagesInMemory() public void ThreeMessagesInMemory()
{ {
MemoryStream stream = new MemoryStream(MessageStreamWriterTest.ThreeMessageData); MemoryStream stream = new MemoryStream(MessageStreamWriterTest.ThreeMessageData);
IEnumerable<NestedMessage> iterator = MessageStreamIterator<NestedMessage>.FromStreamProvider(() => stream); IEnumerable<NestedMessage> iterator = MessageStreamIterator<NestedMessage>.FromStreamProvider(() => stream);
List<NestedMessage> messages = new List<NestedMessage>(iterator); List<NestedMessage> messages = new List<NestedMessage>(iterator);
Assert.AreEqual(3, messages.Count); Assert.Equal(3, messages.Count);
Assert.AreEqual(5, messages[0].Bb); Assert.Equal(5, messages[0].Bb);
Assert.AreEqual(1500, messages[1].Bb); Assert.Equal(1500, messages[1].Bb);
Assert.IsFalse(messages[2].HasBb); Assert.False(messages[2].HasBb);
} }
[TestMethod] [Fact]
public void ManyMessagesShouldNotTriggerSizeAlert() public void ManyMessagesShouldNotTriggerSizeAlert()
{ {
int messageSize = TestUtil.GetAllSet().SerializedSize; int messageSize = TestUtil.GetAllSet().SerializedSize;
...@@ -84,7 +83,7 @@ namespace Google.ProtocolBuffers ...@@ -84,7 +83,7 @@ namespace Google.ProtocolBuffers
count++; count++;
TestUtil.AssertAllFieldsSet(message); TestUtil.AssertAllFieldsSet(message);
} }
Assert.AreEqual(correctCount, count); Assert.Equal(correctCount, count);
} }
} }
} }
......
...@@ -35,12 +35,11 @@ ...@@ -35,12 +35,11 @@
#endregion #endregion
using System.IO; using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage; using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class MessageStreamWriterTest public class MessageStreamWriterTest
{ {
internal static readonly byte[] ThreeMessageData = new byte[] internal static readonly byte[] ThreeMessageData = new byte[]
...@@ -55,7 +54,7 @@ namespace Google.ProtocolBuffers ...@@ -55,7 +54,7 @@ namespace Google.ProtocolBuffers
(1 << 3) | 2, 0, // Field 1, no data (third message) (1 << 3) | 2, 0, // Field 1, no data (third message)
}; };
[TestMethod] [Fact]
public void ThreeMessages() public void ThreeMessages()
{ {
NestedMessage message1 = new NestedMessage.Builder {Bb = 5}.Build(); NestedMessage message1 = new NestedMessage.Builder {Bb = 5}.Build();
......
...@@ -36,52 +36,47 @@ ...@@ -36,52 +36,47 @@
using System; using System;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class MessageUtilTest public class MessageUtilTest
{ {
[TestMethod] [Fact]
[ExpectedException(typeof(ArgumentNullException))]
public void NullTypeName() public void NullTypeName()
{ {
MessageUtil.GetDefaultMessage((string) null); Assert.Throws<ArgumentNullException>(() => MessageUtil.GetDefaultMessage((string) null));
} }
[TestMethod] [Fact]
[ExpectedException(typeof(ArgumentException))]
public void InvalidTypeName() public void InvalidTypeName()
{ {
MessageUtil.GetDefaultMessage("invalidtypename"); Assert.Throws<ArgumentException>(() => MessageUtil.GetDefaultMessage("invalidtypename"));
} }
[TestMethod] [Fact]
public void ValidTypeName() public void ValidTypeName()
{ {
Assert.AreSame(TestAllTypes.DefaultInstance, Assert.Same(TestAllTypes.DefaultInstance,
MessageUtil.GetDefaultMessage(typeof(TestAllTypes).AssemblyQualifiedName)); MessageUtil.GetDefaultMessage(typeof(TestAllTypes).AssemblyQualifiedName));
} }
[TestMethod] [Fact]
[ExpectedException(typeof(ArgumentNullException))]
public void NullType() public void NullType()
{ {
MessageUtil.GetDefaultMessage((Type) null); Assert.Throws<ArgumentNullException>(() => MessageUtil.GetDefaultMessage((Type)null));
} }
[TestMethod] [Fact]
[ExpectedException(typeof(ArgumentException))]
public void NonMessageType() public void NonMessageType()
{ {
MessageUtil.GetDefaultMessage(typeof(string)); Assert.Throws<ArgumentException>(() => MessageUtil.GetDefaultMessage(typeof(string)));
} }
[TestMethod] [Fact]
public void ValidType() 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
...@@ -34,49 +34,48 @@ ...@@ -34,49 +34,48 @@
#endregion #endregion
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class NameHelpersTest public class NameHelpersTest
{ {
[TestMethod] [Fact]
public void UnderscoresToPascalCase() public void UnderscoresToPascalCase()
{ {
Assert.AreEqual("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_bar")); Assert.Equal("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_bar"));
Assert.AreEqual("FooBar", NameHelpers.UnderscoresToPascalCase("foo_bar")); Assert.Equal("FooBar", NameHelpers.UnderscoresToPascalCase("foo_bar"));
Assert.AreEqual("Foo0Bar", NameHelpers.UnderscoresToPascalCase("Foo0bar")); Assert.Equal("Foo0Bar", NameHelpers.UnderscoresToPascalCase("Foo0bar"));
Assert.AreEqual("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_+_Bar")); Assert.Equal("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_+_Bar"));
Assert.AreEqual("Bar", NameHelpers.UnderscoresToPascalCase("__+bar")); Assert.Equal("Bar", NameHelpers.UnderscoresToPascalCase("__+bar"));
Assert.AreEqual("Bar", NameHelpers.UnderscoresToPascalCase("bar_")); Assert.Equal("Bar", NameHelpers.UnderscoresToPascalCase("bar_"));
Assert.AreEqual("_0Bar", NameHelpers.UnderscoresToPascalCase("_0bar")); Assert.Equal("_0Bar", NameHelpers.UnderscoresToPascalCase("_0bar"));
Assert.AreEqual("_1Bar", NameHelpers.UnderscoresToPascalCase("_1_bar")); Assert.Equal("_1Bar", NameHelpers.UnderscoresToPascalCase("_1_bar"));
} }
[TestMethod] [Fact]
public void UnderscoresToCamelCase() public void UnderscoresToCamelCase()
{ {
Assert.AreEqual("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_bar")); Assert.Equal("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_bar"));
Assert.AreEqual("fooBar", NameHelpers.UnderscoresToCamelCase("foo_bar")); Assert.Equal("fooBar", NameHelpers.UnderscoresToCamelCase("foo_bar"));
Assert.AreEqual("foo0Bar", NameHelpers.UnderscoresToCamelCase("Foo0bar")); Assert.Equal("foo0Bar", NameHelpers.UnderscoresToCamelCase("Foo0bar"));
Assert.AreEqual("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_+_Bar")); Assert.Equal("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_+_Bar"));
Assert.AreEqual("bar", NameHelpers.UnderscoresToCamelCase("__+bar")); Assert.Equal("bar", NameHelpers.UnderscoresToCamelCase("__+bar"));
Assert.AreEqual("bar", NameHelpers.UnderscoresToCamelCase("bar_")); Assert.Equal("bar", NameHelpers.UnderscoresToCamelCase("bar_"));
Assert.AreEqual("_0Bar", NameHelpers.UnderscoresToCamelCase("_0bar")); Assert.Equal("_0Bar", NameHelpers.UnderscoresToCamelCase("_0bar"));
Assert.AreEqual("_1Bar", NameHelpers.UnderscoresToCamelCase("_1_bar")); Assert.Equal("_1Bar", NameHelpers.UnderscoresToCamelCase("_1_bar"));
} }
[TestMethod] [Fact]
public void StripSuffix() public void StripSuffix()
{ {
string text = "FooBar"; string text = "FooBar";
Assert.IsFalse(NameHelpers.StripSuffix(ref text, "Foo")); Assert.False(NameHelpers.StripSuffix(ref text, "Foo"));
Assert.AreEqual("FooBar", text); Assert.Equal("FooBar", text);
Assert.IsTrue(NameHelpers.StripSuffix(ref text, "Bar")); Assert.True(NameHelpers.StripSuffix(ref text, "Bar"));
Assert.AreEqual("Foo", text); Assert.Equal("Foo", text);
} }
} }
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <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> <PropertyGroup>
<EnvironmentFlavor>CLIENTPROFILE</EnvironmentFlavor>
<EnvironmentTemplate>NET35</EnvironmentTemplate>
<EnvironmentProjectType>TEST</EnvironmentProjectType>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion> <ProductVersion>9.0.30729</ProductVersion>
...@@ -13,12 +12,14 @@ ...@@ -13,12 +12,14 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Google.ProtocolBuffers</RootNamespace> <RootNamespace>Google.ProtocolBuffers</RootNamespace>
<AssemblyName>Google.ProtocolBuffers.Test</AssemblyName> <AssemblyName>Google.ProtocolBuffers.Test</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly> <SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
<OldToolsVersion>3.5</OldToolsVersion> <OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile> <TargetFrameworkProfile>
</TargetFrameworkProfile>
<NuGetPackageImportStamp>d37384c8</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoStdLib>true</NoStdLib> <NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
...@@ -44,32 +46,23 @@ ...@@ -44,32 +46,23 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoStdLib>true</NoStdLib> <NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> <Reference Include="xunit.abstractions">
<ItemGroup Condition=" '$(EnvironmentFlavor)' == 'CLIENTPROFILE' "> <HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Reference Include="nunit.framework">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NUnit\lib\nunit.framework.dll</HintPath>
</Reference> </Reference>
</ItemGroup> <Reference Include="xunit.assert">
<ItemGroup Condition=" '$(EnvironmentFlavor)' != 'CLIENTPROFILE' "> <HintPath>..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
<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> </Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="xunit.core">
<SpecificVersion>False</SpecificVersion> <HintPath>..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
<HintPath>..\..\lib\Microsoft.Silverlight.Testing\April2010\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\..\lib\NUnit-config\Microsoft.VisualStudio.TestTools.cs">
<Link>Microsoft.VisualStudio.TestTools.cs</Link>
</Compile>
<Compile Include="AbstractMessageTest.cs" /> <Compile Include="AbstractMessageTest.cs" />
<Compile Include="ByteStringTest.cs" /> <Compile Include="ByteStringTest.cs" />
<Compile Include="CodedInputStreamTest.cs" /> <Compile Include="CodedInputStreamTest.cs" />
...@@ -131,28 +124,16 @@ ...@@ -131,28 +124,16 @@
<Name>ProtocolBuffers</Name> <Name>ProtocolBuffers</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </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> <ItemGroup>
<EmbeddedResource Include="Compatibility\google_message1.dat" /> <EmbeddedResource Include="Compatibility\google_message1.dat" />
<EmbeddedResource Include="Compatibility\google_message2.dat" /> <EmbeddedResource Include="Compatibility\google_message2.dat" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
...@@ -161,10 +142,11 @@ ...@@ -161,10 +142,11 @@
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
<PropertyGroup Condition=" '$(EnvironmentFlavor)' == 'CLIENTPROFILE' "> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<StartAction>Program</StartAction> <PropertyGroup>
<StartProgram>$(ProjectDir)..\..\lib\NUnit\tools\nunit-console.exe</StartProgram> <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>
<StartArguments>/nologo /noshadow /labels /wait $(AssemblyName).dll</StartArguments> </PropertyGroup>
<StartWorkingDirectory>$(ProjectDir)$(OutputPath)</StartWorkingDirectory> <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'))" />
</PropertyGroup> <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> </Project>
\ No newline at end of file
using System; using UnitTest.Issues.TestProtos;
using System.Collections.Generic; using Xunit;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitTest.Issues.TestProtos;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class TestCornerCases public class TestCornerCases
{ {
[TestMethod] [Fact]
public void TestRoundTripNegativeEnums() public void TestRoundTripNegativeEnums()
{ {
NegativeEnumMessage msg = NegativeEnumMessage.CreateBuilder() NegativeEnumMessage msg = NegativeEnumMessage.CreateBuilder()
...@@ -23,16 +19,16 @@ namespace Google.ProtocolBuffers ...@@ -23,16 +19,16 @@ namespace Google.ProtocolBuffers
.AddPackedValues(NegativeEnum.FiveBelow) //10 .AddPackedValues(NegativeEnum.FiveBelow) //10
.Build(); .Build();
Assert.AreEqual(58, msg.SerializedSize); Assert.Equal(58, msg.SerializedSize);
byte[] bytes = new byte[58]; byte[] bytes = new byte[58];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes); CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
msg.WriteTo(output); msg.WriteTo(output);
Assert.AreEqual(0, output.SpaceLeft); Assert.Equal(0, output.SpaceLeft);
NegativeEnumMessage copy = NegativeEnumMessage.ParseFrom(bytes); NegativeEnumMessage copy = NegativeEnumMessage.ParseFrom(bytes);
Assert.AreEqual(msg, copy); Assert.Equal(msg, copy);
} }
} }
} }
using System; using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using Google.ProtocolBuffers.Serialization.Http; using Google.ProtocolBuffers.Serialization.Http;
using Xunit;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class TestReaderForUrlEncoded public class TestReaderForUrlEncoded
{ {
[TestMethod] [Fact]
public void Example_FromQueryString() 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); 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 ...@@ -21,14 +20,14 @@ namespace Google.ProtocolBuffers
builder.MergeFrom(input); builder.MergeFrom(input);
TestXmlMessage message = builder.Build(); TestXmlMessage message = builder.Build();
Assert.AreEqual(true, message.Valid); Assert.Equal(true, message.Valid);
Assert.AreEqual("two three four", message.Text); Assert.Equal("two three four", message.Text);
Assert.AreEqual(2, message.NumbersCount); Assert.Equal(2, message.NumbersCount);
Assert.AreEqual(1, message.NumbersList[0]); Assert.Equal(1, message.NumbersList[0]);
Assert.AreEqual(2, message.NumbersList[1]); Assert.Equal(2, message.NumbersList[1]);
} }
[TestMethod] [Fact]
public void Example_FromFormData() public void Example_FromFormData()
{ {
Stream rawPost = new MemoryStream(Encoding.UTF8.GetBytes("text=two+three%20four&valid=true&numbers=1&numbers=2"), false); 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 ...@@ -39,46 +38,46 @@ namespace Google.ProtocolBuffers
builder.MergeFrom(input); builder.MergeFrom(input);
TestXmlMessage message = builder.Build(); TestXmlMessage message = builder.Build();
Assert.AreEqual(true, message.Valid); Assert.Equal(true, message.Valid);
Assert.AreEqual("two three four", message.Text); Assert.Equal("two three four", message.Text);
Assert.AreEqual(2, message.NumbersCount); Assert.Equal(2, message.NumbersCount);
Assert.AreEqual(1, message.NumbersList[0]); Assert.Equal(1, message.NumbersList[0]);
Assert.AreEqual(2, message.NumbersList[1]); Assert.Equal(2, message.NumbersList[1]);
} }
[TestMethod] [Fact]
public void TestEmptyValues() public void TestEmptyValues()
{ {
ICodedInputStream input = FormUrlEncodedReader.CreateInstance("valid=true&text=&numbers=1"); ICodedInputStream input = FormUrlEncodedReader.CreateInstance("valid=true&text=&numbers=1");
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder(); TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
builder.MergeFrom(input); builder.MergeFrom(input);
Assert.IsTrue(builder.Valid); Assert.True(builder.Valid);
Assert.IsTrue(builder.HasText); Assert.True(builder.HasText);
Assert.AreEqual("", builder.Text); Assert.Equal("", builder.Text);
Assert.AreEqual(1, builder.NumbersCount); Assert.Equal(1, builder.NumbersCount);
Assert.AreEqual(1, builder.NumbersList[0]); Assert.Equal(1, builder.NumbersList[0]);
} }
[TestMethod] [Fact]
public void TestNoValue() public void TestNoValue()
{ {
ICodedInputStream input = FormUrlEncodedReader.CreateInstance("valid=true&text&numbers=1"); ICodedInputStream input = FormUrlEncodedReader.CreateInstance("valid=true&text&numbers=1");
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder(); TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
builder.MergeFrom(input); builder.MergeFrom(input);
Assert.IsTrue(builder.Valid); Assert.True(builder.Valid);
Assert.IsTrue(builder.HasText); Assert.True(builder.HasText);
Assert.AreEqual("", builder.Text); Assert.Equal("", builder.Text);
Assert.AreEqual(1, builder.NumbersCount); Assert.Equal(1, builder.NumbersCount);
Assert.AreEqual(1, builder.NumbersList[0]); Assert.Equal(1, builder.NumbersList[0]);
} }
[TestMethod, ExpectedException(typeof(NotSupportedException))] [Fact]
public void FormUrlEncodedReaderDoesNotSupportChildren() public void FormUrlEncodedReaderDoesNotSupportChildren()
{ {
ICodedInputStream input = FormUrlEncodedReader.CreateInstance("child=uh0"); ICodedInputStream input = FormUrlEncodedReader.CreateInstance("child=uh0");
TestXmlMessage.CreateBuilder().MergeFrom(input); Assert.Throws<NotSupportedException>(() => TestXmlMessage.CreateBuilder().MergeFrom(input));
} }
} }
} }
This diff is collapsed.
...@@ -38,17 +38,16 @@ using System.IO; ...@@ -38,17 +38,16 @@ using System.IO;
using System.Reflection; using System.Reflection;
using Google.ProtocolBuffers.Descriptors; using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
[TestClass]
public class WireFormatTest public class WireFormatTest
{ {
/// <summary> /// <summary>
/// Keeps the attributes on FieldType and the switch statement in WireFormat in sync. /// Keeps the attributes on FieldType and the switch statement in WireFormat in sync.
/// </summary> /// </summary>
[TestMethod] [Fact]
public void FieldTypeToWireTypeMapping() public void FieldTypeToWireTypeMapping()
{ {
foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public)) foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public))
...@@ -56,34 +55,34 @@ namespace Google.ProtocolBuffers ...@@ -56,34 +55,34 @@ namespace Google.ProtocolBuffers
FieldType fieldType = (FieldType) field.GetValue(null); FieldType fieldType = (FieldType) field.GetValue(null);
FieldMappingAttribute mapping = FieldMappingAttribute mapping =
(FieldMappingAttribute) field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0]; (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() public void Serialization()
{ {
TestAllTypes message = TestUtil.GetAllSet(); TestAllTypes message = TestUtil.GetAllSet();
ByteString rawBytes = message.ToByteString(); ByteString rawBytes = message.ToByteString();
Assert.AreEqual(rawBytes.Length, message.SerializedSize); Assert.Equal(rawBytes.Length, message.SerializedSize);
TestAllTypes message2 = TestAllTypes.ParseFrom(rawBytes); TestAllTypes message2 = TestAllTypes.ParseFrom(rawBytes);
TestUtil.AssertAllFieldsSet(message2); TestUtil.AssertAllFieldsSet(message2);
} }
[TestMethod] [Fact]
public void SerializationPacked() public void SerializationPacked()
{ {
TestPackedTypes message = TestUtil.GetPackedSet(); TestPackedTypes message = TestUtil.GetPackedSet();
ByteString rawBytes = message.ToByteString(); ByteString rawBytes = message.ToByteString();
Assert.AreEqual(rawBytes.Length, message.SerializedSize); Assert.Equal(rawBytes.Length, message.SerializedSize);
TestPackedTypes message2 = TestPackedTypes.ParseFrom(rawBytes); TestPackedTypes message2 = TestPackedTypes.ParseFrom(rawBytes);
TestUtil.AssertPackedFieldsSet(message2); TestUtil.AssertPackedFieldsSet(message2);
} }
[TestMethod] [Fact]
public void SerializeExtensions() public void SerializeExtensions()
{ {
// TestAllTypes and TestAllExtensions should have compatible wire formats, // TestAllTypes and TestAllExtensions should have compatible wire formats,
...@@ -91,14 +90,14 @@ namespace Google.ProtocolBuffers ...@@ -91,14 +90,14 @@ namespace Google.ProtocolBuffers
// it should work. // it should work.
TestAllExtensions message = TestUtil.GetAllExtensionsSet(); TestAllExtensions message = TestUtil.GetAllExtensionsSet();
ByteString rawBytes = message.ToByteString(); ByteString rawBytes = message.ToByteString();
Assert.AreEqual(rawBytes.Length, message.SerializedSize); Assert.Equal(rawBytes.Length, message.SerializedSize);
TestAllTypes message2 = TestAllTypes.ParseFrom(rawBytes); TestAllTypes message2 = TestAllTypes.ParseFrom(rawBytes);
TestUtil.AssertAllFieldsSet(message2); TestUtil.AssertAllFieldsSet(message2);
} }
[TestMethod] [Fact]
public void SerializePackedExtensions() public void SerializePackedExtensions()
{ {
// TestPackedTypes and TestPackedExtensions should have compatible wire // TestPackedTypes and TestPackedExtensions should have compatible wire
...@@ -109,10 +108,10 @@ namespace Google.ProtocolBuffers ...@@ -109,10 +108,10 @@ namespace Google.ProtocolBuffers
TestPackedTypes message2 = TestUtil.GetPackedSet(); TestPackedTypes message2 = TestUtil.GetPackedSet();
ByteString rawBytes2 = message2.ToByteString(); ByteString rawBytes2 = message2.ToByteString();
Assert.AreEqual(rawBytes, rawBytes2); Assert.Equal(rawBytes, rawBytes2);
} }
[TestMethod] [Fact]
public void SerializeDelimited() public void SerializeDelimited()
{ {
MemoryStream stream = new MemoryStream(); MemoryStream stream = new MemoryStream();
...@@ -124,13 +123,13 @@ namespace Google.ProtocolBuffers ...@@ -124,13 +123,13 @@ namespace Google.ProtocolBuffers
stream.Position = 0; stream.Position = 0;
TestUtil.AssertAllFieldsSet(TestAllTypes.ParseDelimitedFrom(stream)); TestUtil.AssertAllFieldsSet(TestAllTypes.ParseDelimitedFrom(stream));
Assert.AreEqual(12, stream.ReadByte()); Assert.Equal(12, stream.ReadByte());
TestUtil.AssertPackedFieldsSet(TestPackedTypes.ParseDelimitedFrom(stream)); TestUtil.AssertPackedFieldsSet(TestPackedTypes.ParseDelimitedFrom(stream));
Assert.AreEqual(34, stream.ReadByte()); Assert.Equal(34, stream.ReadByte());
Assert.AreEqual(-1, stream.ReadByte()); Assert.Equal(-1, stream.ReadByte());
} }
[TestMethod] [Fact]
public void ParseExtensions() public void ParseExtensions()
{ {
// TestAllTypes and TestAllExtensions should have compatible wire formats, // TestAllTypes and TestAllExtensions should have compatible wire formats,
...@@ -149,7 +148,7 @@ namespace Google.ProtocolBuffers ...@@ -149,7 +148,7 @@ namespace Google.ProtocolBuffers
TestUtil.AssertAllExtensionsSet(message2); TestUtil.AssertAllExtensionsSet(message2);
} }
[TestMethod] [Fact]
public void ParsePackedExtensions() public void ParsePackedExtensions()
{ {
// Ensure that packed extensions can be properly parsed. // Ensure that packed extensions can be properly parsed.
...@@ -162,10 +161,10 @@ namespace Google.ProtocolBuffers ...@@ -162,10 +161,10 @@ namespace Google.ProtocolBuffers
TestUtil.AssertPackedExtensionsSet(message2); TestUtil.AssertPackedExtensionsSet(message2);
} }
[TestMethod] [Fact]
public void ExtensionsSerializedSize() 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) private static void AssertFieldsInOrder(ByteString data)
...@@ -177,13 +176,13 @@ namespace Google.ProtocolBuffers ...@@ -177,13 +176,13 @@ namespace Google.ProtocolBuffers
string name; string name;
while (input.ReadTag(out tag, out name)) while (input.ReadTag(out tag, out name))
{ {
Assert.IsTrue(tag > previousTag); Assert.True(tag > previousTag);
previousTag = tag; previousTag = tag;
input.SkipField(); input.SkipField();
} }
} }
[TestMethod] [Fact]
public void InterleavedFieldsAndExtensions() public void InterleavedFieldsAndExtensions()
{ {
// Tests that fields are written in order even when extension ranges // Tests that fields are written in order even when extension ranges
...@@ -214,7 +213,7 @@ namespace Google.ProtocolBuffers ...@@ -214,7 +213,7 @@ namespace Google.ProtocolBuffers
private static readonly int TypeId1 = TestMessageSetExtension1.Descriptor.Extensions[0].FieldNumber; private static readonly int TypeId1 = TestMessageSetExtension1.Descriptor.Extensions[0].FieldNumber;
private static readonly int TypeId2 = TestMessageSetExtension2.Descriptor.Extensions[0].FieldNumber; private static readonly int TypeId2 = TestMessageSetExtension2.Descriptor.Extensions[0].FieldNumber;
[TestMethod] [Fact]
public void SerializeMessageSet() public void SerializeMessageSet()
{ {
// Set up a TestMessageSet with two known messages and an unknown one. // Set up a TestMessageSet with two known messages and an unknown one.
...@@ -240,23 +239,23 @@ namespace Google.ProtocolBuffers ...@@ -240,23 +239,23 @@ namespace Google.ProtocolBuffers
// Parse back using RawMessageSet and check the contents. // Parse back using RawMessageSet and check the contents.
RawMessageSet raw = RawMessageSet.ParseFrom(data); 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.Equal(3, raw.ItemCount);
Assert.AreEqual(TypeId1, raw.ItemList[0].TypeId); Assert.Equal(TypeId1, raw.ItemList[0].TypeId);
Assert.AreEqual(TypeId2, raw.ItemList[1].TypeId); Assert.Equal(TypeId2, raw.ItemList[1].TypeId);
Assert.AreEqual(UnknownTypeId, raw.ItemList[2].TypeId); Assert.Equal(UnknownTypeId, raw.ItemList[2].TypeId);
TestMessageSetExtension1 message1 = TestMessageSetExtension1.ParseFrom(raw.GetItem(0).Message.ToByteArray()); 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()); 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() public void ParseMessageSet()
{ {
ExtensionRegistry extensionRegistry = ExtensionRegistry.CreateInstance(); ExtensionRegistry extensionRegistry = ExtensionRegistry.CreateInstance();
...@@ -295,18 +294,18 @@ namespace Google.ProtocolBuffers ...@@ -295,18 +294,18 @@ namespace Google.ProtocolBuffers
TestMessageSet messageSet = TestMessageSet messageSet =
TestMessageSet.ParseFrom(data, extensionRegistry); TestMessageSet.ParseFrom(data, extensionRegistry);
Assert.AreEqual(123, messageSet.GetExtension(TestMessageSetExtension1.MessageSetExtension).I); Assert.Equal(123, messageSet.GetExtension(TestMessageSetExtension1.MessageSetExtension).I);
Assert.AreEqual("foo", messageSet.GetExtension(TestMessageSetExtension2.MessageSetExtension).Str); Assert.Equal("foo", messageSet.GetExtension(TestMessageSetExtension2.MessageSetExtension).Str);
// Check for unknown field with type LENGTH_DELIMITED, // Check for unknown field with type LENGTH_DELIMITED,
// number UNKNOWN_TYPE_ID, and contents "bar". // number UNKNOWN_TYPE_ID, and contents "bar".
UnknownFieldSet unknownFields = messageSet.UnknownFields; UnknownFieldSet unknownFields = messageSet.UnknownFields;
Assert.AreEqual(1, unknownFields.FieldDictionary.Count); Assert.Equal(1, unknownFields.FieldDictionary.Count);
Assert.IsTrue(unknownFields.HasField(UnknownTypeId)); Assert.True(unknownFields.HasField(UnknownTypeId));
UnknownField field = unknownFields[UnknownTypeId]; UnknownField field = unknownFields[UnknownTypeId];
Assert.AreEqual(1, field.LengthDelimitedList.Count); Assert.Equal(1, field.LengthDelimitedList.Count);
Assert.AreEqual("bar", field.LengthDelimitedList[0].ToStringUtf8()); Assert.Equal("bar", field.LengthDelimitedList[0].ToStringUtf8());
} }
} }
} }
\ No newline at end of file
<?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
This diff is collapsed.
<?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
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\ProtocolBuffers.Test\packages.config" />
<repository path="..\ProtocolBuffersLite.Test\packages.config" />
</repositories>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment