Commit 90c8932f authored by Jon Skeet's avatar Jon Skeet

Convert back to using NUnit, which is now loaded via NuGet.

This includes the NUnit test adapter which allows NUnit tests to be run under VS without any extra plugins.
Unfortunate the compatibility tests using the abstract test fixture class show up as "external" tests, and aren't well presented - but they do run.
parent c58b2c66
......@@ -39,13 +39,13 @@ using System.Collections.Generic;
using System.IO;
using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class AbstractMessageTest
{
[Fact]
[Test]
public void Clear()
{
AbstractMessageWrapper message =
......@@ -53,7 +53,7 @@ namespace Google.ProtocolBuffers
TestUtil.AssertClear((TestAllTypes) message.WrappedMessage);
}
[Fact]
[Test]
public void Copy()
{
AbstractMessageWrapper message =
......@@ -61,31 +61,31 @@ namespace Google.ProtocolBuffers
TestUtil.AssertAllFieldsSet((TestAllTypes) message.WrappedMessage);
}
[Fact]
[Test]
public void CreateAndBuild()
{
TestAllTypes.CreateBuilder()
.Build();
}
[Fact]
[Test]
public void SerializedSize()
{
TestAllTypes message = TestUtil.GetAllSet();
IMessage abstractMessage = new AbstractMessageWrapper(TestUtil.GetAllSet());
Assert.Equal(message.SerializedSize, abstractMessage.SerializedSize);
Assert.AreEqual(message.SerializedSize, abstractMessage.SerializedSize);
}
[Fact]
[Test]
public void Serialization()
{
IMessage abstractMessage = new AbstractMessageWrapper(TestUtil.GetAllSet());
TestUtil.AssertAllFieldsSet(TestAllTypes.ParseFrom(abstractMessage.ToByteString()));
Assert.Equal(TestUtil.GetAllSet().ToByteString(), abstractMessage.ToByteString());
Assert.AreEqual(TestUtil.GetAllSet().ToByteString(), abstractMessage.ToByteString());
}
[Fact]
[Test]
public void Parsing()
{
IBuilder builder = new AbstractMessageWrapper.Builder(TestAllTypes.CreateBuilder());
......@@ -94,15 +94,15 @@ namespace Google.ProtocolBuffers
TestUtil.AssertAllFieldsSet((TestAllTypes) message.WrappedMessage);
}
[Fact]
[Test]
public void PackedSerialization()
{
IMessage abstractMessage = new AbstractMessageWrapper(TestUtil.GetPackedSet());
TestUtil.AssertPackedFieldsSet(TestPackedTypes.ParseFrom(abstractMessage.ToByteString()));
Assert.Equal(TestUtil.GetPackedSet().ToByteString(), abstractMessage.ToByteString());
Assert.AreEqual(TestUtil.GetPackedSet().ToByteString(), abstractMessage.ToByteString());
}
[Fact]
[Test]
public void PackedParsing()
{
AbstractMessageWrapper.Builder builder = new AbstractMessageWrapper.Builder(TestPackedTypes.CreateBuilder());
......@@ -110,7 +110,7 @@ namespace Google.ProtocolBuffers
TestUtil.AssertPackedFieldsSet((TestPackedTypes)message.WrappedMessage);
}
[Fact]
[Test]
public void UnpackedParsingOfPackedInput()
{
byte[] bytes = TestUtil.GetPackedSet().ToByteArray();
......@@ -118,7 +118,7 @@ namespace Google.ProtocolBuffers
TestUtil.AssertUnpackedFieldsSet(message);
}
[Fact]
[Test]
public void PackedParsingOfUnpackedInput()
{
byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray();
......@@ -126,7 +126,7 @@ namespace Google.ProtocolBuffers
TestUtil.AssertPackedFieldsSet(message);
}
[Fact]
[Test]
public void UnpackedParsingOfPackedInputExtensions()
{
byte[] bytes = TestUtil.GetPackedSet().ToByteArray();
......@@ -137,7 +137,7 @@ namespace Google.ProtocolBuffers
TestUtil.AssertUnpackedExtensionsSet(message);
}
[Fact]
[Test]
public void PackedParsingOfUnpackedInputExtensions()
{
byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray();
......@@ -147,13 +147,13 @@ namespace Google.ProtocolBuffers
TestUtil.AssertPackedExtensionsSet(message);
}
[Fact]
[Test]
public void OptimizedForSize()
{
// We're mostly only Checking that this class was compiled successfully.
TestOptimizedForSize message = TestOptimizedForSize.CreateBuilder().SetI(1).Build();
message = TestOptimizedForSize.ParseFrom(message.ToByteString());
Assert.Equal(2, message.SerializedSize);
Assert.AreEqual(2, message.SerializedSize);
}
// -----------------------------------------------------------------
......@@ -164,40 +164,40 @@ namespace Google.ProtocolBuffers
private static readonly TestRequired TestRequiredInitialized =
TestRequired.CreateBuilder().SetA(1).SetB(2).SetC(3).Build();
[Fact]
[Test]
public void IsInitialized()
{
TestRequired.Builder builder = TestRequired.CreateBuilder();
AbstractMessageWrapper.Builder abstractBuilder = new AbstractMessageWrapper.Builder(builder);
Assert.False(abstractBuilder.IsInitialized);
Assert.IsFalse(abstractBuilder.IsInitialized);
builder.A = 1;
Assert.False(abstractBuilder.IsInitialized);
Assert.IsFalse(abstractBuilder.IsInitialized);
builder.B = 1;
Assert.False(abstractBuilder.IsInitialized);
Assert.IsFalse(abstractBuilder.IsInitialized);
builder.C = 1;
Assert.True(abstractBuilder.IsInitialized);
Assert.IsTrue(abstractBuilder.IsInitialized);
}
[Fact]
[Test]
public void ForeignIsInitialized()
{
TestRequiredForeign.Builder builder = TestRequiredForeign.CreateBuilder();
AbstractMessageWrapper.Builder abstractBuilder = new AbstractMessageWrapper.Builder(builder);
Assert.True(abstractBuilder.IsInitialized);
Assert.IsTrue(abstractBuilder.IsInitialized);
builder.SetOptionalMessage(TestRequiredUninitialized);
Assert.False(abstractBuilder.IsInitialized);
Assert.IsFalse(abstractBuilder.IsInitialized);
builder.SetOptionalMessage(TestRequiredInitialized);
Assert.True(abstractBuilder.IsInitialized);
Assert.IsTrue(abstractBuilder.IsInitialized);
builder.AddRepeatedMessage(TestRequiredUninitialized);
Assert.False(abstractBuilder.IsInitialized);
Assert.IsFalse(abstractBuilder.IsInitialized);
builder.SetRepeatedMessage(0, TestRequiredInitialized);
Assert.True(abstractBuilder.IsInitialized);
Assert.IsTrue(abstractBuilder.IsInitialized);
}
// -----------------------------------------------------------------
......@@ -226,7 +226,7 @@ namespace Google.ProtocolBuffers
"repeated_string: \"qux\"\n" +
"repeated_string: \"bar\"\n";
[Fact]
[Test]
public void MergeFrom()
{
AbstractMessageWrapper result = (AbstractMessageWrapper)
......@@ -234,13 +234,13 @@ namespace Google.ProtocolBuffers
.MergeFrom(MergeSource)
.Build();
Assert.Equal(MergeResultText, result.ToString());
Assert.AreEqual(MergeResultText, result.ToString());
}
// -----------------------------------------------------------------
// Tests for equals and hashCode
[Fact]
[Test]
public void EqualsAndHashCode()
{
TestAllTypes a = TestUtil.GetAllSet();
......@@ -296,7 +296,7 @@ namespace Google.ProtocolBuffers
private static void CheckEqualsIsConsistent(IMessage message)
{
// Object should be equal to itself.
Assert.Equal(message, message);
Assert.AreEqual(message, message);
// Object should be equal to a dynamic copy of itself.
DynamicMessage dynamic = DynamicMessage.CreateBuilder(message).Build();
......@@ -310,9 +310,9 @@ namespace Google.ProtocolBuffers
{
// Not using Assert.AreEqual as that checks for type equality, which isn't
// what we want bearing in mind the dynamic message checks.
Assert.True(message1.Equals(message2));
Assert.True(message2.Equals(message1));
Assert.Equal(message2.GetHashCode(), message1.GetHashCode());
Assert.IsTrue(message1.Equals(message2));
Assert.IsTrue(message2.Equals(message1));
Assert.AreEqual(message2.GetHashCode(), message1.GetHashCode());
}
/// <summary>
......@@ -326,10 +326,10 @@ namespace Google.ProtocolBuffers
private static void CheckNotEqual(IMessage m1, IMessage m2)
{
String equalsError = string.Format("{0} should not be equal to {1}", m1, m2);
Assert.False(m1.Equals(m2), equalsError);
Assert.False(m2.Equals(m1), equalsError);
Assert.IsFalse(m1.Equals(m2), equalsError);
Assert.IsFalse(m2.Equals(m1), equalsError);
Assert.False(m1.GetHashCode() == m2.GetHashCode(),
Assert.IsFalse(m1.GetHashCode() == m2.GetHashCode(),
string.Format("{0} should have a different hash code from {1}", m1, m2));
}
......
......@@ -36,112 +36,112 @@
using System;
using System.Text;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class ByteStringTest
{
[Fact]
[Test]
public void EmptyByteStringHasZeroSize()
{
Assert.Equal(0, ByteString.Empty.Length);
Assert.AreEqual(0, ByteString.Empty.Length);
}
[Fact]
[Test]
public void CopyFromStringWithExplicitEncoding()
{
ByteString bs = ByteString.CopyFrom("AB", Encoding.Unicode);
Assert.Equal(4, bs.Length);
Assert.Equal(65, bs[0]);
Assert.Equal(0, bs[1]);
Assert.Equal(66, bs[2]);
Assert.Equal(0, bs[3]);
Assert.AreEqual(4, bs.Length);
Assert.AreEqual(65, bs[0]);
Assert.AreEqual(0, bs[1]);
Assert.AreEqual(66, bs[2]);
Assert.AreEqual(0, bs[3]);
}
[Fact]
[Test]
public void IsEmptyWhenEmpty()
{
Assert.True(ByteString.CopyFromUtf8("").IsEmpty);
Assert.IsTrue(ByteString.CopyFromUtf8("").IsEmpty);
}
[Fact]
[Test]
public void IsEmptyWhenNotEmpty()
{
Assert.False(ByteString.CopyFromUtf8("X").IsEmpty);
Assert.IsFalse(ByteString.CopyFromUtf8("X").IsEmpty);
}
[Fact]
[Test]
public void CopyFromByteArrayCopiesContents()
{
byte[] data = new byte[1];
data[0] = 10;
ByteString bs = ByteString.CopyFrom(data);
Assert.Equal(10, bs[0]);
Assert.AreEqual(10, bs[0]);
data[0] = 5;
Assert.Equal(10, bs[0]);
Assert.AreEqual(10, bs[0]);
}
[Fact]
[Test]
public void ToByteArrayCopiesContents()
{
ByteString bs = ByteString.CopyFromUtf8("Hello");
byte[] data = bs.ToByteArray();
Assert.Equal((byte)'H', data[0]);
Assert.Equal((byte)'H', bs[0]);
Assert.AreEqual((byte)'H', data[0]);
Assert.AreEqual((byte)'H', bs[0]);
data[0] = 0;
Assert.Equal(0, data[0]);
Assert.Equal((byte)'H', bs[0]);
Assert.AreEqual(0, data[0]);
Assert.AreEqual((byte)'H', bs[0]);
}
[Fact]
[Test]
public void CopyFromUtf8UsesUtf8()
{
ByteString bs = ByteString.CopyFromUtf8("\u20ac");
Assert.Equal(3, bs.Length);
Assert.Equal(0xe2, bs[0]);
Assert.Equal(0x82, bs[1]);
Assert.Equal(0xac, bs[2]);
Assert.AreEqual(3, bs.Length);
Assert.AreEqual(0xe2, bs[0]);
Assert.AreEqual(0x82, bs[1]);
Assert.AreEqual(0xac, bs[2]);
}
[Fact]
[Test]
public void CopyFromPortion()
{
byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
ByteString bs = ByteString.CopyFrom(data, 2, 3);
Assert.Equal(3, bs.Length);
Assert.Equal(2, bs[0]);
Assert.Equal(3, bs[1]);
Assert.AreEqual(3, bs.Length);
Assert.AreEqual(2, bs[0]);
Assert.AreEqual(3, bs[1]);
}
[Fact]
[Test]
public void ToStringUtf8()
{
ByteString bs = ByteString.CopyFromUtf8("\u20ac");
Assert.Equal("\u20ac", bs.ToStringUtf8());
Assert.AreEqual("\u20ac", bs.ToStringUtf8());
}
[Fact]
[Test]
public void ToStringWithExplicitEncoding()
{
ByteString bs = ByteString.CopyFrom("\u20ac", Encoding.Unicode);
Assert.Equal("\u20ac", bs.ToString(Encoding.Unicode));
Assert.AreEqual("\u20ac", bs.ToString(Encoding.Unicode));
}
[Fact]
[Test]
public void FromBase64_WithText()
{
byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
string base64 = Convert.ToBase64String(data);
ByteString bs = ByteString.FromBase64(base64);
Assert.Equal(data, bs.ToByteArray());
Assert.AreEqual(data, bs.ToByteArray());
}
[Fact]
[Test]
public void FromBase64_Empty()
{
// Optimization which also fixes issue 61.
Assert.Same(ByteString.Empty, ByteString.FromBase64(""));
Assert.AreSame(ByteString.Empty, ByteString.FromBase64(""));
}
}
}
\ No newline at end of file
......@@ -36,13 +36,13 @@
using System;
using System.Collections.Generic;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers.Collections
{
public class PopsicleListTest
{
[Fact]
[Test]
public void MutatingOperationsOnFrozenList()
{
PopsicleList<string> list = new PopsicleList<string>();
......@@ -55,20 +55,20 @@ namespace Google.ProtocolBuffers.Collections
Assert.Throws<NotSupportedException>(() => list.Add(new[] { "", "" }));
}
[Fact]
[Test]
public void NonMutatingOperationsOnFrozenList()
{
PopsicleList<string> list = new PopsicleList<string>();
list.MakeReadOnly();
Assert.False(list.Contains(""));
Assert.Equal(0, list.Count);
Assert.IsFalse(list.Contains(""));
Assert.AreEqual(0, list.Count);
list.CopyTo(new string[5], 0);
list.GetEnumerator();
Assert.Equal(-1, list.IndexOf(""));
Assert.True(list.IsReadOnly);
Assert.AreEqual(-1, list.IndexOf(""));
Assert.IsTrue(list.IsReadOnly);
}
[Fact]
[Test]
public void MutatingOperationsOnFluidList()
{
PopsicleList<string> list = new PopsicleList<string>();
......@@ -80,26 +80,26 @@ namespace Google.ProtocolBuffers.Collections
list.RemoveAt(0);
}
[Fact]
[Test]
public void NonMutatingOperationsOnFluidList()
{
PopsicleList<string> list = new PopsicleList<string>();
Assert.False(list.Contains(""));
Assert.Equal(0, list.Count);
Assert.IsFalse(list.Contains(""));
Assert.AreEqual(0, list.Count);
list.CopyTo(new string[5], 0);
list.GetEnumerator();
Assert.Equal(-1, list.IndexOf(""));
Assert.False(list.IsReadOnly);
Assert.AreEqual(-1, list.IndexOf(""));
Assert.IsFalse(list.IsReadOnly);
}
[Fact]
[Test]
public void DoesNotAddNullEnumerable()
{
PopsicleList<string> list = new PopsicleList<string>();
Assert.Throws<ArgumentNullException>(() => list.Add((IEnumerable<string>) null));
}
[Fact]
[Test]
public void DoesNotAddRangeWithNull()
{
PopsicleList<string> list = new PopsicleList<string>();
......@@ -107,14 +107,14 @@ namespace Google.ProtocolBuffers.Collections
Assert.Throws<ArgumentNullException>(() => list.Add(new[] {"a", "b", null}));
}
[Fact]
[Test]
public void DoesNotAddNull()
{
PopsicleList<string> list = new PopsicleList<string>();
Assert.Throws<ArgumentNullException>(() => list.Add((string) null));
}
[Fact]
[Test]
public void DoesNotSetNull()
{
PopsicleList<string> list = new PopsicleList<string>();
......
using System;
using Google.ProtocolBuffers.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers.Compatibility
{
/// <summary>
/// This abstract base implements several tests to ensure that well-known messages can be written
/// and read to/from various formats without losing data. Implementations overload the two serailization
/// and read to/from various formats without losing data. Implementations override the two serialization
/// methods to provide the tests with the means to read and write for a given format.
/// </summary>
public abstract class CompatibilityTests
......@@ -22,10 +22,10 @@ namespace Google.ProtocolBuffers.Compatibility
protected virtual void AssertOutputEquals(object lhs, object rhs)
{
Assert.Equal<object>(lhs, rhs);
Assert.AreEqual(lhs, rhs);
}
[Fact]
[Test]
public virtual void RoundTripWithEmptyChildMessageSize()
{
SizeMessage1 msg = SizeMessage1.CreateBuilder()
......@@ -37,12 +37,12 @@ namespace Google.ProtocolBuffers.Compatibility
SizeMessage1 copy = DeserializeMessage<SizeMessage1, SizeMessage1.Builder>(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).BuildPartial();
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SizeMessage1, SizeMessage1.Builder>(copy));
Assert.Equal(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
Assert.AreEqual(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
}
[Fact]
[Test]
public virtual void RoundTripWithEmptyChildMessageSpeed()
{
SpeedMessage1 msg = SpeedMessage1.CreateBuilder()
......@@ -54,12 +54,12 @@ namespace Google.ProtocolBuffers.Compatibility
SpeedMessage1 copy = DeserializeMessage<SpeedMessage1, SpeedMessage1.Builder>(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).BuildPartial();
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(copy));
Assert.Equal(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
Assert.AreEqual(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
}
[Fact]
[Test]
public virtual void RoundTripMessage1OptimizeSize()
{
SizeMessage1 msg = SizeMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
......@@ -67,12 +67,12 @@ namespace Google.ProtocolBuffers.Compatibility
SizeMessage1 copy = DeserializeMessage<SizeMessage1, SizeMessage1.Builder>(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build();
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SizeMessage1, SizeMessage1.Builder>(copy));
Assert.Equal(Convert.ToBase64String(TestResources.google_message1), Convert.ToBase64String(copy.ToByteArray()));
Assert.AreEqual(Convert.ToBase64String(TestResources.google_message1), Convert.ToBase64String(copy.ToByteArray()));
}
[Fact]
[Test]
public virtual void RoundTripMessage2OptimizeSize()
{
SizeMessage2 msg = SizeMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
......@@ -80,12 +80,12 @@ namespace Google.ProtocolBuffers.Compatibility
SizeMessage2 copy = DeserializeMessage<SizeMessage2, SizeMessage2.Builder>(content, SizeMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build();
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SizeMessage2, SizeMessage2.Builder>(copy));
Assert.Equal(Convert.ToBase64String(TestResources.google_message2), Convert.ToBase64String(copy.ToByteArray()));
Assert.AreEqual(Convert.ToBase64String(TestResources.google_message2), Convert.ToBase64String(copy.ToByteArray()));
}
[Fact]
[Test]
public virtual void RoundTripMessage1OptimizeSpeed()
{
SpeedMessage1 msg = SpeedMessage1.CreateBuilder().MergeFrom(TestResources.google_message1).Build();
......@@ -93,12 +93,12 @@ namespace Google.ProtocolBuffers.Compatibility
SpeedMessage1 copy = DeserializeMessage<SpeedMessage1, SpeedMessage1.Builder>(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).Build();
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(copy));
Assert.Equal(Convert.ToBase64String(TestResources.google_message1), Convert.ToBase64String(copy.ToByteArray()));
Assert.AreEqual(Convert.ToBase64String(TestResources.google_message1), Convert.ToBase64String(copy.ToByteArray()));
}
[Fact]
[Test]
public virtual void RoundTripMessage2OptimizeSpeed()
{
SpeedMessage2 msg = SpeedMessage2.CreateBuilder().MergeFrom(TestResources.google_message2).Build();
......@@ -106,9 +106,9 @@ namespace Google.ProtocolBuffers.Compatibility
SpeedMessage2 copy = DeserializeMessage<SpeedMessage2, SpeedMessage2.Builder>(content, SpeedMessage2.CreateBuilder(), ExtensionRegistry.Empty).Build();
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SpeedMessage2, SpeedMessage2.Builder>(copy));
Assert.Equal(Convert.ToBase64String(TestResources.google_message2), Convert.ToBase64String(copy.ToByteArray()));
Assert.AreEqual(Convert.ToBase64String(TestResources.google_message2), Convert.ToBase64String(copy.ToByteArray()));
}
#region Test message builders
......@@ -185,7 +185,7 @@ namespace Google.ProtocolBuffers.Compatibility
#endregion
[Fact]
[Test]
public void TestRoundTripAllTypes()
{
TestAllTypes msg = AddAllTypes(new TestAllTypes.Builder()).Build();
......@@ -193,12 +193,12 @@ namespace Google.ProtocolBuffers.Compatibility
TestAllTypes copy = DeserializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy));
Assert.Equal(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
Assert.AreEqual(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
}
[Fact]
[Test]
public void TestRoundTripRepeatedTypes()
{
TestAllTypes msg = AddRepeatedTypes(new TestAllTypes.Builder(), 5).Build();
......@@ -206,12 +206,12 @@ namespace Google.ProtocolBuffers.Compatibility
TestAllTypes copy = DeserializeMessage<TestAllTypes, TestAllTypes.Builder>(content, TestAllTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<TestAllTypes, TestAllTypes.Builder>(copy));
Assert.Equal(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
Assert.AreEqual(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
}
[Fact]
[Test]
public void TestRoundTripPackedTypes()
{
TestPackedTypes msg = AddPackedTypes(new TestPackedTypes.Builder(), 5).Build();
......@@ -219,9 +219,9 @@ namespace Google.ProtocolBuffers.Compatibility
TestPackedTypes copy = DeserializeMessage<TestPackedTypes, TestPackedTypes.Builder>(content, TestPackedTypes.CreateBuilder(), ExtensionRegistry.Empty).Build();
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<TestPackedTypes, TestPackedTypes.Builder>(copy));
Assert.Equal(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
Assert.AreEqual(Convert.ToBase64String(msg.ToByteArray()), Convert.ToBase64String(copy.ToByteArray()));
}
}
}
using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.Serialization;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers.Compatibility
{
[TestFixture]
public class DictionaryCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
......@@ -25,7 +26,7 @@ namespace Google.ProtocolBuffers.Compatibility
IDictionary<string, object> left = (IDictionary<string, object>)lhs;
IDictionary<string, object> right = (IDictionary<string, object>)rhs;
Assert.Equal(
Assert.AreEqual(
String.Join(",", new List<string>(left.Keys).ToArray()),
String.Join(",", new List<string>(right.Keys).ToArray())
);
......
using System.IO;
using Google.ProtocolBuffers.Serialization;
using NUnit.Framework;
namespace Google.ProtocolBuffers.Compatibility
{
[TestFixture]
public class JsonCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
......@@ -20,6 +22,7 @@ namespace Google.ProtocolBuffers.Compatibility
}
}
[TestFixture]
public class JsonCompatibilityFormattedTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
......
using System.IO;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers.Compatibility
{
......@@ -16,7 +16,7 @@ namespace Google.ProtocolBuffers.Compatibility
byte[] bytes = new byte[resource.Length];
int amtRead = resource.Read(bytes, 0, bytes.Length);
Assert.Equal(bytes.Length, amtRead);
Assert.AreEqual(bytes.Length, amtRead);
return bytes;
}
}
......@@ -30,7 +30,7 @@ namespace Google.ProtocolBuffers.Compatibility
Assert.NotNull(resource);
byte[] bytes = new byte[resource.Length];
int amtRead = resource.Read(bytes, 0, bytes.Length);
Assert.Equal(bytes.Length, amtRead);
Assert.AreEqual(bytes.Length, amtRead);
return bytes;
}
}
......
using System.IO;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers.Compatibility
{
[TestFixture]
public class TextCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
......@@ -18,14 +19,14 @@ namespace Google.ProtocolBuffers.Compatibility
return builder;
}
//This test can take a very long time to run.
[Fact]
[Test]
public override void RoundTripMessage2OptimizeSize()
{
//base.RoundTripMessage2OptimizeSize();
}
//This test can take a very long time to run.
[Fact]
[Test]
public override void RoundTripMessage2OptimizeSpeed()
{
//base.RoundTripMessage2OptimizeSpeed();
......
using System.IO;
using System.Xml;
using Google.ProtocolBuffers.Serialization;
using NUnit.Framework;
namespace Google.ProtocolBuffers.Compatibility
{
[TestFixture]
public class XmlCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
......@@ -21,6 +23,7 @@ namespace Google.ProtocolBuffers.Compatibility
}
}
[TestFixture]
public class XmlCompatibilityFormattedTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
......
using System;
using System.Reflection;
using UnitTest.Issues.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
......@@ -10,10 +10,10 @@ namespace Google.ProtocolBuffers
private static void AssertIsDeprecated(MemberInfo member)
{
Assert.NotNull(member);
Assert.True(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
Assert.IsTrue(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
}
[Fact]
[Test]
public void TestDepreatedPrimitiveValue()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasPrimitiveValue"));
......@@ -24,7 +24,7 @@ namespace Google.ProtocolBuffers
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetPrimitiveValue"));
}
[Fact]
[Test]
public void TestDepreatedPrimitiveArray()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("PrimitiveArrayList"));
......@@ -39,7 +39,7 @@ namespace Google.ProtocolBuffers
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangePrimitiveArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveArray"));
}
[Fact]
[Test]
public void TestDepreatedMessageValue()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasMessageValue"));
......@@ -52,7 +52,7 @@ namespace Google.ProtocolBuffers
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageValue", new[] { typeof(DeprecatedChild) }));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageValue", new[] { typeof(DeprecatedChild.Builder) }));
}
[Fact]
[Test]
public void TestDepreatedMessageArray()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("MessageArrayList"));
......@@ -69,7 +69,7 @@ namespace Google.ProtocolBuffers
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangeMessageArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearMessageArray"));
}
[Fact]
[Test]
public void TestDepreatedEnumValue()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasEnumValue"));
......@@ -80,7 +80,7 @@ namespace Google.ProtocolBuffers
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearEnumValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetEnumValue"));
}
[Fact]
[Test]
public void TestDepreatedEnumArray()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("EnumArrayList"));
......
......@@ -37,7 +37,7 @@
using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
......@@ -54,7 +54,7 @@ namespace Google.ProtocolBuffers
packedReflectionTester = ReflectionTester.CreateTestPackedTypesInstance();
}
[Fact]
[Test]
public void DynamicMessageAccessors()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
......@@ -63,7 +63,7 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertAllFieldsSetViaReflection(message);
}
[Fact]
[Test]
public void DoubleBuildError()
{
DynamicMessage.Builder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
......@@ -71,14 +71,14 @@ namespace Google.ProtocolBuffers
Assert.Throws<InvalidOperationException>(() => builder.Build());
}
[Fact]
[Test]
public void DynamicMessageSettersRejectNull()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
reflectionTester.AssertReflectionSettersRejectNull(builder);
}
[Fact]
[Test]
public void DynamicMessageExtensionAccessors()
{
// We don't need to extensively test DynamicMessage's handling of
......@@ -90,14 +90,14 @@ namespace Google.ProtocolBuffers
extensionsReflectionTester.AssertAllFieldsSetViaReflection(message);
}
[Fact]
[Test]
public void DynamicMessageExtensionSettersRejectNull()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllExtensions.Descriptor);
extensionsReflectionTester.AssertReflectionSettersRejectNull(builder);
}
[Fact]
[Test]
public void DynamicMessageRepeatedSetters()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
......@@ -107,21 +107,21 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertRepeatedFieldsModifiedViaReflection(message);
}
[Fact]
[Test]
public void DynamicMessageRepeatedSettersRejectNull()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
reflectionTester.AssertReflectionRepeatedSettersRejectNull(builder);
}
[Fact]
[Test]
public void DynamicMessageDefaults()
{
reflectionTester.AssertClearViaReflection(DynamicMessage.GetDefaultInstance(TestAllTypes.Descriptor));
reflectionTester.AssertClearViaReflection(DynamicMessage.CreateBuilder(TestAllTypes.Descriptor).Build());
}
[Fact]
[Test]
public void DynamicMessageSerializedSize()
{
TestAllTypes message = TestUtil.GetAllSet();
......@@ -130,10 +130,10 @@ namespace Google.ProtocolBuffers
reflectionTester.SetAllFieldsViaReflection(dynamicBuilder);
IMessage dynamicMessage = dynamicBuilder.WeakBuild();
Assert.Equal(message.SerializedSize, dynamicMessage.SerializedSize);
Assert.AreEqual(message.SerializedSize, dynamicMessage.SerializedSize);
}
[Fact]
[Test]
public void DynamicMessageSerialization()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
......@@ -146,10 +146,10 @@ namespace Google.ProtocolBuffers
TestUtil.AssertAllFieldsSet(message2);
// In fact, the serialized forms should be exactly the same, byte-for-byte.
Assert.Equal(TestUtil.GetAllSet().ToByteString(), rawBytes);
Assert.AreEqual(TestUtil.GetAllSet().ToByteString(), rawBytes);
}
[Fact]
[Test]
public void DynamicMessageParsing()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
......@@ -162,7 +162,7 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertAllFieldsSetViaReflection(message2);
}
[Fact]
[Test]
public void DynamicMessagePackedSerialization()
{
IBuilder builder = DynamicMessage.CreateBuilder(TestPackedTypes.Descriptor);
......@@ -175,10 +175,10 @@ namespace Google.ProtocolBuffers
TestUtil.AssertPackedFieldsSet(message2);
// In fact, the serialized forms should be exactly the same, byte-for-byte.
Assert.Equal(TestUtil.GetPackedSet().ToByteString(), rawBytes);
Assert.AreEqual(TestUtil.GetPackedSet().ToByteString(), rawBytes);
}
[Fact]
[Test]
public void DynamicMessagePackedParsing()
{
TestPackedTypes.Builder builder = TestPackedTypes.CreateBuilder();
......@@ -191,7 +191,7 @@ namespace Google.ProtocolBuffers
packedReflectionTester.AssertPackedFieldsSetViaReflection(message2);
}
[Fact]
[Test]
public void DynamicMessageCopy()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
......@@ -202,7 +202,7 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertAllFieldsSetViaReflection(copy);
}
[Fact]
[Test]
public void ToBuilder()
{
DynamicMessage.Builder builder =
......@@ -220,8 +220,8 @@ namespace Google.ProtocolBuffers
reflectionTester.AssertAllFieldsSetViaReflection(derived);
IList<ulong> values = derived.UnknownFields.FieldDictionary[unknownFieldNum].VarintList;
Assert.Equal(1, values.Count);
Assert.Equal(unknownFieldVal, values[0]);
Assert.AreEqual(1, values.Count);
Assert.AreEqual(unknownFieldVal, values[0]);
}
}
}
\ No newline at end of file
......@@ -34,7 +34,7 @@
using System;
using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos.FieldPresence;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
......@@ -48,7 +48,7 @@ namespace Google.ProtocolBuffers
Assert.Null(proto3Type.GetProperty("Has" + name));
}
[Fact]
[Test]
public void TestHasMethod()
{
// Optional non-message fields don't have HasFoo method generated
......@@ -67,11 +67,11 @@ namespace Google.ProtocolBuffers
CheckHasMethodRemoved(proto2Type, proto3Type, "OptionalNestedEnum");
// message fields still have the HasFoo method generated
Assert.False(TestAllTypes.CreateBuilder().Build().HasOptionalNestedMessage);
Assert.False(TestAllTypes.CreateBuilder().HasOptionalNestedMessage);
Assert.IsFalse(TestAllTypes.CreateBuilder().Build().HasOptionalNestedMessage);
Assert.IsFalse(TestAllTypes.CreateBuilder().HasOptionalNestedMessage);
}
[Fact]
[Test]
public void TestFieldPresence()
{
// Optional non-message fields set to their default value are treated the same
......@@ -84,7 +84,7 @@ namespace Google.ProtocolBuffers
builder.SetOptionalBytes(ByteString.Empty);
builder.SetOptionalNestedEnum(TestAllTypes.Types.NestedEnum.FOO);
TestAllTypes message = builder.Build();
Assert.Equal(0, message.SerializedSize);
Assert.AreEqual(0, message.SerializedSize);
// Test merge
TestAllTypes.Builder a = TestAllTypes.CreateBuilder();
......@@ -94,19 +94,19 @@ namespace Google.ProtocolBuffers
a.SetOptionalNestedEnum(TestAllTypes.Types.NestedEnum.BAR);
a.MergeFrom(message);
TestAllTypes messageA = a.Build();
Assert.Equal(1, messageA.OptionalInt32);
Assert.Equal("x", messageA.OptionalString);
Assert.Equal(ByteString.CopyFromUtf8("y"), messageA.OptionalBytes);
Assert.Equal(TestAllTypes.Types.NestedEnum.BAR, messageA.OptionalNestedEnum);
Assert.AreEqual(1, messageA.OptionalInt32);
Assert.AreEqual("x", messageA.OptionalString);
Assert.AreEqual(ByteString.CopyFromUtf8("y"), messageA.OptionalBytes);
Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR, messageA.OptionalNestedEnum);
// equals/hashCode should produce the same results
TestAllTypes empty = TestAllTypes.CreateBuilder().Build();
Assert.True(empty.Equals(message));
Assert.True(message.Equals(empty));
Assert.Equal(empty.GetHashCode(), message.GetHashCode());
Assert.IsTrue(empty.Equals(message));
Assert.IsTrue(message.Equals(empty));
Assert.AreEqual(empty.GetHashCode(), message.GetHashCode());
}
[Fact]
[Test]
public void TestFieldPresenceReflection()
{
MessageDescriptor descriptor = TestAllTypes.Descriptor;
......@@ -116,10 +116,10 @@ namespace Google.ProtocolBuffers
FieldDescriptor optionalNestedEnumField = descriptor.FindFieldByName("optional_nested_enum");
TestAllTypes message = TestAllTypes.CreateBuilder().Build();
Assert.False(message.HasField(optionalInt32Field));
Assert.False(message.HasField(optionalStringField));
Assert.False(message.HasField(optionalBytesField));
Assert.False(message.HasField(optionalNestedEnumField));
Assert.IsFalse(message.HasField(optionalInt32Field));
Assert.IsFalse(message.HasField(optionalStringField));
Assert.IsFalse(message.HasField(optionalBytesField));
Assert.IsFalse(message.HasField(optionalNestedEnumField));
// Set to default value is seen as not present
message = TestAllTypes.CreateBuilder()
......@@ -128,11 +128,11 @@ namespace Google.ProtocolBuffers
.SetOptionalBytes(ByteString.Empty)
.SetOptionalNestedEnum(TestAllTypes.Types.NestedEnum.FOO)
.Build();
Assert.False(message.HasField(optionalInt32Field));
Assert.False(message.HasField(optionalStringField));
Assert.False(message.HasField(optionalBytesField));
Assert.False(message.HasField(optionalNestedEnumField));
Assert.Equal(0, message.AllFields.Count);
Assert.IsFalse(message.HasField(optionalInt32Field));
Assert.IsFalse(message.HasField(optionalStringField));
Assert.IsFalse(message.HasField(optionalBytesField));
Assert.IsFalse(message.HasField(optionalNestedEnumField));
Assert.AreEqual(0, message.AllFields.Count);
// Set t0 non-defalut value is seen as present
message = TestAllTypes.CreateBuilder()
......@@ -141,28 +141,28 @@ namespace Google.ProtocolBuffers
.SetOptionalBytes(ByteString.CopyFromUtf8("y"))
.SetOptionalNestedEnum(TestAllTypes.Types.NestedEnum.BAR)
.Build();
Assert.True(message.HasField(optionalInt32Field));
Assert.True(message.HasField(optionalStringField));
Assert.True(message.HasField(optionalBytesField));
Assert.True(message.HasField(optionalNestedEnumField));
Assert.Equal(4, message.AllFields.Count);
Assert.IsTrue(message.HasField(optionalInt32Field));
Assert.IsTrue(message.HasField(optionalStringField));
Assert.IsTrue(message.HasField(optionalBytesField));
Assert.IsTrue(message.HasField(optionalNestedEnumField));
Assert.AreEqual(4, message.AllFields.Count);
}
[Fact]
[Test]
public void TestMessageField()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
Assert.False(builder.HasOptionalNestedMessage);
Assert.False(builder.Build().HasOptionalNestedMessage);
Assert.IsFalse(builder.HasOptionalNestedMessage);
Assert.IsFalse(builder.Build().HasOptionalNestedMessage);
// Unlike non-message fields, if we set default value to message field, the field
// shoule be seem as present.
builder.SetOptionalNestedMessage(TestAllTypes.Types.NestedMessage.DefaultInstance);
Assert.True(builder.HasOptionalNestedMessage);
Assert.True(builder.Build().HasOptionalNestedMessage);
Assert.IsTrue(builder.HasOptionalNestedMessage);
Assert.IsTrue(builder.Build().HasOptionalNestedMessage);
}
[Fact]
[Test]
public void TestSerializeAndParse()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
......@@ -172,12 +172,12 @@ namespace Google.ProtocolBuffers
ByteString data = builder.Build().ToByteString();
TestAllTypes message = TestAllTypes.ParseFrom(data);
Assert.Equal(1234, message.OptionalInt32);
Assert.Equal("hello", message.OptionalString);
Assert.Equal(ByteString.Empty, message.OptionalBytes);
Assert.Equal(TestAllTypes.Types.NestedEnum.FOO, message.OptionalNestedEnum);
Assert.True(message.HasOptionalNestedMessage);
Assert.Equal(0, message.OptionalNestedMessage.Value);
Assert.AreEqual(1234, message.OptionalInt32);
Assert.AreEqual("hello", message.OptionalString);
Assert.AreEqual(ByteString.Empty, message.OptionalBytes);
Assert.AreEqual(TestAllTypes.Types.NestedEnum.FOO, message.OptionalNestedEnum);
Assert.IsTrue(message.HasOptionalNestedMessage);
Assert.AreEqual(0, message.OptionalNestedMessage.Value);
}
}
}
using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
......@@ -17,7 +17,7 @@ namespace Google.ProtocolBuffers
}
public IEnumerator<T> GetEnumerator()
{
Assert.False(_enumerated);
Assert.IsFalse(_enumerated);
_enumerated = true;
yield return _item;
}
......@@ -27,49 +27,49 @@ namespace Google.ProtocolBuffers
}
}
[Fact]
[Test]
public void DoesNotEnumerateTwiceForMessageList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedForeignMessage(new OneTimeEnumerator<ForeignMessage>(ForeignMessage.DefaultInstance));
}
[Fact]
[Test]
public void DoesNotEnumerateTwiceForPrimitiveList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedInt32(new OneTimeEnumerator<int>(1));
}
[Fact]
[Test]
public void DoesNotEnumerateTwiceForStringList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedString(new OneTimeEnumerator<string>("test"));
}
[Fact]
[Test]
public void DoesNotEnumerateTwiceForEnumList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedForeignEnum(new OneTimeEnumerator<ForeignEnum>(ForeignEnum.FOREIGN_BAR));
}
[Fact]
[Test]
public void DoesNotAddNullToMessageListByAddRange()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
Assert.Throws<ArgumentNullException>(() => b.AddRangeRepeatedForeignMessage(new ForeignMessage[] { null }));
}
[Fact]
[Test]
public void DoesNotAddNullToMessageListByAdd()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
Assert.Throws<ArgumentNullException>(() => b.AddRepeatedForeignMessage((ForeignMessage)null));
}
[Fact]
[Test]
public void DoesNotAddNullToMessageListBySet()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
......@@ -77,21 +77,21 @@ namespace Google.ProtocolBuffers
Assert.Throws<ArgumentNullException>(() => b.SetRepeatedForeignMessage(0, (ForeignMessage)null));
}
[Fact]
[Test]
public void DoesNotAddNullToStringListByAddRange()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
Assert.Throws<ArgumentNullException>(() => b.AddRangeRepeatedString(new String[] { null }));
}
[Fact]
[Test]
public void DoesNotAddNullToStringListByAdd()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
Assert.Throws<ArgumentNullException>(() => b.AddRepeatedString(null));
}
[Fact]
[Test]
public void DoesNotAddNullToStringListBySet()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
......
......@@ -37,7 +37,7 @@
using Google.ProtocolBuffers.Descriptors;
using UnitTest.Issues.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
......@@ -48,13 +48,13 @@ namespace Google.ProtocolBuffers
public class IssuesTest
{
// Issue 45
[Fact]
[Test]
public void FieldCalledItem()
{
ItemField message = new ItemField.Builder { Item = 3 }.Build();
FieldDescriptor field = ItemField.Descriptor.FindFieldByName("item");
Assert.NotNull(field);
Assert.Equal(3, (int)message[field]);
Assert.AreEqual(3, (int)message[field]);
}
}
}
......@@ -37,27 +37,27 @@
using System.Collections.Generic;
using System.IO;
using Google.ProtocolBuffers.TestProtos;
using Xunit;
using NUnit.Framework;
using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage;
namespace Google.ProtocolBuffers
{
public class MessageStreamIteratorTest
{
[Fact]
[Test]
public void ThreeMessagesInMemory()
{
MemoryStream stream = new MemoryStream(MessageStreamWriterTest.ThreeMessageData);
IEnumerable<NestedMessage> iterator = MessageStreamIterator<NestedMessage>.FromStreamProvider(() => stream);
List<NestedMessage> messages = new List<NestedMessage>(iterator);
Assert.Equal(3, messages.Count);
Assert.Equal(5, messages[0].Bb);
Assert.Equal(1500, messages[1].Bb);
Assert.False(messages[2].HasBb);
Assert.AreEqual(3, messages.Count);
Assert.AreEqual(5, messages[0].Bb);
Assert.AreEqual(1500, messages[1].Bb);
Assert.IsFalse(messages[2].HasBb);
}
[Fact]
[Test]
public void ManyMessagesShouldNotTriggerSizeAlert()
{
int messageSize = TestUtil.GetAllSet().SerializedSize;
......@@ -83,7 +83,7 @@ namespace Google.ProtocolBuffers
count++;
TestUtil.AssertAllFieldsSet(message);
}
Assert.Equal(correctCount, count);
Assert.AreEqual(correctCount, count);
}
}
}
......
......@@ -35,7 +35,7 @@
#endregion
using System.IO;
using Xunit;
using NUnit.Framework;
using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage;
namespace Google.ProtocolBuffers
......@@ -54,7 +54,7 @@ namespace Google.ProtocolBuffers
(1 << 3) | 2, 0, // Field 1, no data (third message)
};
[Fact]
[Test]
public void ThreeMessages()
{
NestedMessage message1 = new NestedMessage.Builder {Bb = 5}.Build();
......
......@@ -36,47 +36,47 @@
using System;
using Google.ProtocolBuffers.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class MessageUtilTest
{
[Fact]
[Test]
public void NullTypeName()
{
Assert.Throws<ArgumentNullException>(() => MessageUtil.GetDefaultMessage((string) null));
}
[Fact]
[Test]
public void InvalidTypeName()
{
Assert.Throws<ArgumentException>(() => MessageUtil.GetDefaultMessage("invalidtypename"));
}
[Fact]
[Test]
public void ValidTypeName()
{
Assert.Same(TestAllTypes.DefaultInstance,
Assert.AreSame(TestAllTypes.DefaultInstance,
MessageUtil.GetDefaultMessage(typeof(TestAllTypes).AssemblyQualifiedName));
}
[Fact]
[Test]
public void NullType()
{
Assert.Throws<ArgumentNullException>(() => MessageUtil.GetDefaultMessage((Type)null));
}
[Fact]
[Test]
public void NonMessageType()
{
Assert.Throws<ArgumentException>(() => MessageUtil.GetDefaultMessage(typeof(string)));
}
[Fact]
[Test]
public void ValidType()
{
Assert.Same(TestAllTypes.DefaultInstance, MessageUtil.GetDefaultMessage(typeof(TestAllTypes)));
Assert.AreSame(TestAllTypes.DefaultInstance, MessageUtil.GetDefaultMessage(typeof(TestAllTypes)));
}
}
}
\ No newline at end of file
......@@ -34,48 +34,48 @@
#endregion
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class NameHelpersTest
{
[Fact]
[Test]
public void UnderscoresToPascalCase()
{
Assert.Equal("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_bar"));
Assert.Equal("FooBar", NameHelpers.UnderscoresToPascalCase("foo_bar"));
Assert.Equal("Foo0Bar", NameHelpers.UnderscoresToPascalCase("Foo0bar"));
Assert.Equal("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_+_Bar"));
Assert.AreEqual("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_bar"));
Assert.AreEqual("FooBar", NameHelpers.UnderscoresToPascalCase("foo_bar"));
Assert.AreEqual("Foo0Bar", NameHelpers.UnderscoresToPascalCase("Foo0bar"));
Assert.AreEqual("FooBar", NameHelpers.UnderscoresToPascalCase("Foo_+_Bar"));
Assert.Equal("Bar", NameHelpers.UnderscoresToPascalCase("__+bar"));
Assert.Equal("Bar", NameHelpers.UnderscoresToPascalCase("bar_"));
Assert.Equal("_0Bar", NameHelpers.UnderscoresToPascalCase("_0bar"));
Assert.Equal("_1Bar", NameHelpers.UnderscoresToPascalCase("_1_bar"));
Assert.AreEqual("Bar", NameHelpers.UnderscoresToPascalCase("__+bar"));
Assert.AreEqual("Bar", NameHelpers.UnderscoresToPascalCase("bar_"));
Assert.AreEqual("_0Bar", NameHelpers.UnderscoresToPascalCase("_0bar"));
Assert.AreEqual("_1Bar", NameHelpers.UnderscoresToPascalCase("_1_bar"));
}
[Fact]
[Test]
public void UnderscoresToCamelCase()
{
Assert.Equal("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_bar"));
Assert.Equal("fooBar", NameHelpers.UnderscoresToCamelCase("foo_bar"));
Assert.Equal("foo0Bar", NameHelpers.UnderscoresToCamelCase("Foo0bar"));
Assert.Equal("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_+_Bar"));
Assert.AreEqual("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_bar"));
Assert.AreEqual("fooBar", NameHelpers.UnderscoresToCamelCase("foo_bar"));
Assert.AreEqual("foo0Bar", NameHelpers.UnderscoresToCamelCase("Foo0bar"));
Assert.AreEqual("fooBar", NameHelpers.UnderscoresToCamelCase("Foo_+_Bar"));
Assert.Equal("bar", NameHelpers.UnderscoresToCamelCase("__+bar"));
Assert.Equal("bar", NameHelpers.UnderscoresToCamelCase("bar_"));
Assert.Equal("_0Bar", NameHelpers.UnderscoresToCamelCase("_0bar"));
Assert.Equal("_1Bar", NameHelpers.UnderscoresToCamelCase("_1_bar"));
Assert.AreEqual("bar", NameHelpers.UnderscoresToCamelCase("__+bar"));
Assert.AreEqual("bar", NameHelpers.UnderscoresToCamelCase("bar_"));
Assert.AreEqual("_0Bar", NameHelpers.UnderscoresToCamelCase("_0bar"));
Assert.AreEqual("_1Bar", NameHelpers.UnderscoresToCamelCase("_1_bar"));
}
[Fact]
[Test]
public void StripSuffix()
{
string text = "FooBar";
Assert.False(NameHelpers.StripSuffix(ref text, "Foo"));
Assert.Equal("FooBar", text);
Assert.True(NameHelpers.StripSuffix(ref text, "Bar"));
Assert.Equal("Foo", text);
Assert.IsFalse(NameHelpers.StripSuffix(ref text, "Foo"));
Assert.AreEqual("FooBar", text);
Assert.IsTrue(NameHelpers.StripSuffix(ref text, "Bar"));
Assert.AreEqual("Foo", text);
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
......@@ -19,7 +17,8 @@
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<NuGetPackageImportStamp>d37384c8</NuGetPackageImportStamp>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
......@@ -50,17 +49,28 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert">
<HintPath>..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core">
<HintPath>..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AbstractMessageTest.cs" />
......@@ -144,11 +154,4 @@
<Target Name="AfterBuild">
</Target>
-->
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
</Project>
\ No newline at end of file
......@@ -2,14 +2,14 @@
using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.TestProtos;
using UnitTest.Issues.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class ReusableBuilderTest
{
//Issue 28: Circular message dependencies result in null defaults for DefaultInstance
[Fact]
[Test]
public void EnsureStaticCicularReference()
{
MyMessageAReferenceB ab = MyMessageAReferenceB.DefaultInstance;
......@@ -20,24 +20,24 @@ namespace Google.ProtocolBuffers
Assert.NotNull(ba.Value);
}
[Fact]
[Test]
public void TestModifyDefaultInstance()
{
//verify that the default instance has correctly been marked as read-only
Assert.Equal(typeof(PopsicleList<bool>), TestAllTypes.DefaultInstance.RepeatedBoolList.GetType());
Assert.AreEqual(typeof(PopsicleList<bool>), TestAllTypes.DefaultInstance.RepeatedBoolList.GetType());
PopsicleList<bool> list = (PopsicleList<bool>)TestAllTypes.DefaultInstance.RepeatedBoolList;
Assert.True(list.IsReadOnly);
Assert.IsTrue(list.IsReadOnly);
}
[Fact]
[Test]
public void TestUnmodifiedDefaultInstance()
{
//Simply calling ToBuilder().Build() no longer creates a copy of the message
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Fact]
[Test]
public void BuildMultipleWithoutChange()
{
//Calling Build() or BuildPartial() does not require a copy of the message
......@@ -46,31 +46,31 @@ namespace Google.ProtocolBuffers
TestAllTypes first = builder.BuildPartial();
//Still the same instance?
Assert.True(ReferenceEquals(first, builder.Build()));
Assert.IsTrue(ReferenceEquals(first, builder.Build()));
//Still the same instance?
Assert.True(ReferenceEquals(first, builder.BuildPartial().ToBuilder().Build()));
Assert.IsTrue(ReferenceEquals(first, builder.BuildPartial().ToBuilder().Build()));
}
[Fact]
[Test]
public void MergeFromDefaultInstance()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.MergeFrom(TestAllTypes.DefaultInstance);
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Fact]
[Test]
public void BuildNewBuilderIsDefaultInstance()
{
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, new TestAllTypes.Builder().Build()));
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, TestAllTypes.CreateBuilder().Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, new TestAllTypes.Builder().Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, TestAllTypes.CreateBuilder().Build()));
//last test, if you clear a builder it reverts to default instance
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance,
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance,
TestAllTypes.CreateBuilder().SetOptionalBool(true).Build().ToBuilder().Clear().Build()));
}
[Fact]
[Test]
public void BuildModifyAndRebuild()
{
TestAllTypes.Builder b1 = new TestAllTypes.Builder();
......@@ -86,80 +86,80 @@ namespace Google.ProtocolBuffers
TestAllTypes m2 = b1.Build();
Assert.Equal("{\"optional_foreign_message\":{},\"repeated_int32\":[2],\"default_int32\":1}", Extensions.ToJson(m1));
Assert.Equal("{\"optional_foreign_message\":{\"c\":7},\"repeated_int32\":[2,6],\"default_int32\":5}", Extensions.ToJson(m2));
Assert.AreEqual("{\"optional_foreign_message\":{},\"repeated_int32\":[2],\"default_int32\":1}", Extensions.ToJson(m1));
Assert.AreEqual("{\"optional_foreign_message\":{\"c\":7},\"repeated_int32\":[2,6],\"default_int32\":5}", Extensions.ToJson(m2));
}
[Fact]
[Test]
public void CloneOnChangePrimitive()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.SetDefaultBool(true);
Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Fact]
[Test]
public void CloneOnAddRepeatedBool()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.AddRepeatedBool(true);
Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Fact]
[Test]
public void CloneOnGetRepeatedBoolList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedBoolList);
Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Fact]
[Test]
public void CloneOnChangeMessage()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.SetOptionalForeignMessage(new ForeignMessage.Builder());
Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Fact]
[Test]
public void CloneOnClearMessage()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.ClearOptionalForeignMessage();
Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Fact]
[Test]
public void CloneOnGetRepeatedForeignMessageList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedForeignMessageList);
Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Fact]
[Test]
public void CloneOnChangeEnumValue()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.SetOptionalForeignEnum(ForeignEnum.FOREIGN_BAR);
Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Fact]
[Test]
public void CloneOnGetRepeatedForeignEnumList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.True(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedForeignEnumList);
Assert.False(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
}
......
using UnitTest.Issues.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class TestCornerCases
{
[Fact]
[Test]
public void TestRoundTripNegativeEnums()
{
NegativeEnumMessage msg = NegativeEnumMessage.CreateBuilder()
......@@ -19,16 +19,16 @@ namespace Google.ProtocolBuffers
.AddPackedValues(NegativeEnum.FiveBelow) //10
.Build();
Assert.Equal(58, msg.SerializedSize);
Assert.AreEqual(58, msg.SerializedSize);
byte[] bytes = new byte[58];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
msg.WriteTo(output);
Assert.Equal(0, output.SpaceLeft);
Assert.AreEqual(0, output.SpaceLeft);
NegativeEnumMessage copy = NegativeEnumMessage.ParseFrom(bytes);
Assert.Equal(msg, copy);
Assert.AreEqual(msg, copy);
}
}
}
......@@ -3,13 +3,13 @@ using System.IO;
using System.Text;
using Google.ProtocolBuffers.TestProtos;
using Google.ProtocolBuffers.Serialization.Http;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class TestReaderForUrlEncoded
{
[Fact]
[Test]
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);
......@@ -20,14 +20,14 @@ namespace Google.ProtocolBuffers
builder.MergeFrom(input);
TestXmlMessage message = builder.Build();
Assert.Equal(true, message.Valid);
Assert.Equal("two three four", message.Text);
Assert.Equal(2, message.NumbersCount);
Assert.Equal(1, message.NumbersList[0]);
Assert.Equal(2, message.NumbersList[1]);
Assert.AreEqual(true, message.Valid);
Assert.AreEqual("two three four", message.Text);
Assert.AreEqual(2, message.NumbersCount);
Assert.AreEqual(1, message.NumbersList[0]);
Assert.AreEqual(2, message.NumbersList[1]);
}
[Fact]
[Test]
public void Example_FromFormData()
{
Stream rawPost = new MemoryStream(Encoding.UTF8.GetBytes("text=two+three%20four&valid=true&numbers=1&numbers=2"), false);
......@@ -38,42 +38,42 @@ namespace Google.ProtocolBuffers
builder.MergeFrom(input);
TestXmlMessage message = builder.Build();
Assert.Equal(true, message.Valid);
Assert.Equal("two three four", message.Text);
Assert.Equal(2, message.NumbersCount);
Assert.Equal(1, message.NumbersList[0]);
Assert.Equal(2, message.NumbersList[1]);
Assert.AreEqual(true, message.Valid);
Assert.AreEqual("two three four", message.Text);
Assert.AreEqual(2, message.NumbersCount);
Assert.AreEqual(1, message.NumbersList[0]);
Assert.AreEqual(2, message.NumbersList[1]);
}
[Fact]
[Test]
public void TestEmptyValues()
{
ICodedInputStream input = FormUrlEncodedReader.CreateInstance("valid=true&text=&numbers=1");
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
builder.MergeFrom(input);
Assert.True(builder.Valid);
Assert.True(builder.HasText);
Assert.Equal("", builder.Text);
Assert.Equal(1, builder.NumbersCount);
Assert.Equal(1, builder.NumbersList[0]);
Assert.IsTrue(builder.Valid);
Assert.IsTrue(builder.HasText);
Assert.AreEqual("", builder.Text);
Assert.AreEqual(1, builder.NumbersCount);
Assert.AreEqual(1, builder.NumbersList[0]);
}
[Fact]
[Test]
public void TestNoValue()
{
ICodedInputStream input = FormUrlEncodedReader.CreateInstance("valid=true&text&numbers=1");
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder();
builder.MergeFrom(input);
Assert.True(builder.Valid);
Assert.True(builder.HasText);
Assert.Equal("", builder.Text);
Assert.Equal(1, builder.NumbersCount);
Assert.Equal(1, builder.NumbersList[0]);
Assert.IsTrue(builder.Valid);
Assert.IsTrue(builder.HasText);
Assert.AreEqual("", builder.Text);
Assert.AreEqual(1, builder.NumbersCount);
Assert.AreEqual(1, builder.NumbersList[0]);
}
[Fact]
[Test]
public void FormUrlEncodedReaderDoesNotSupportChildren()
{
ICodedInputStream input = FormUrlEncodedReader.CreateInstance("child=uh0");
......
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" />
<package id="NUnit" version="2.6.4" targetFramework="net45" userInstalled="true" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net45" userInstalled="true" />
</packages>
\ No newline at end of file
......@@ -37,13 +37,13 @@
using System;
using System.IO;
using Google.ProtocolBuffers.TestProtos;
using Xunit;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class AbstractMessageLiteTest
{
[Fact]
[Test]
public void TestMessageLiteToByteString()
{
TestRequiredLite msg = TestRequiredLite.CreateBuilder()
......@@ -52,14 +52,14 @@ namespace Google.ProtocolBuffers
.Build();
ByteString b = msg.ToByteString();
Assert.Equal(4, b.Length);
Assert.Equal(TestRequiredLite.DFieldNumber << 3, b[0]);
Assert.Equal(42, b[1]);
Assert.Equal(TestRequiredLite.EnFieldNumber << 3, b[2]);
Assert.Equal((int) ExtraEnum.EXLITE_BAZ, b[3]);
Assert.AreEqual(4, b.Length);
Assert.AreEqual(TestRequiredLite.DFieldNumber << 3, b[0]);
Assert.AreEqual(42, b[1]);
Assert.AreEqual(TestRequiredLite.EnFieldNumber << 3, b[2]);
Assert.AreEqual((int) ExtraEnum.EXLITE_BAZ, b[3]);
}
[Fact]
[Test]
public void TestMessageLiteToByteArray()
{
TestRequiredLite msg = TestRequiredLite.CreateBuilder()
......@@ -69,10 +69,10 @@ namespace Google.ProtocolBuffers
ByteString b = msg.ToByteString();
ByteString copy = ByteString.CopyFrom(msg.ToByteArray());
Assert.Equal(b, copy);
Assert.AreEqual(b, copy);
}
[Fact]
[Test]
public void TestMessageLiteWriteTo()
{
TestRequiredLite msg = TestRequiredLite.CreateBuilder()
......@@ -82,10 +82,10 @@ namespace Google.ProtocolBuffers
MemoryStream ms = new MemoryStream();
msg.WriteTo(ms);
Assert.Equal(msg.ToByteArray(), ms.ToArray());
Assert.AreEqual(msg.ToByteArray(), ms.ToArray());
}
[Fact]
[Test]
public void TestMessageLiteWriteDelimitedTo()
{
TestRequiredLite msg = TestRequiredLite.CreateBuilder()
......@@ -97,21 +97,21 @@ namespace Google.ProtocolBuffers
msg.WriteDelimitedTo(ms);
byte[] buffer = ms.ToArray();
Assert.Equal(5, buffer.Length);
Assert.Equal(4, buffer[0]);
Assert.AreEqual(5, buffer.Length);
Assert.AreEqual(4, buffer[0]);
byte[] msgBytes = new byte[4];
Array.Copy(buffer, 1, msgBytes, 0, 4);
Assert.Equal(msg.ToByteArray(), msgBytes);
Assert.AreEqual(msg.ToByteArray(), msgBytes);
}
[Fact]
[Test]
public void TestIMessageLiteWeakCreateBuilderForType()
{
IMessageLite msg = TestRequiredLite.DefaultInstance;
Assert.Equal(typeof(TestRequiredLite.Builder), msg.WeakCreateBuilderForType().GetType());
Assert.AreEqual(typeof(TestRequiredLite.Builder), msg.WeakCreateBuilderForType().GetType());
}
[Fact]
[Test]
public void TestMessageLiteWeakToBuilder()
{
IMessageLite msg = TestRequiredLite.CreateBuilder()
......@@ -120,14 +120,14 @@ namespace Google.ProtocolBuffers
.Build();
IMessageLite copy = msg.WeakToBuilder().WeakBuild();
Assert.Equal(msg.ToByteArray(), copy.ToByteArray());
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
}
[Fact]
[Test]
public void TestMessageLiteWeakDefaultInstanceForType()
{
IMessageLite msg = TestRequiredLite.DefaultInstance;
Assert.True(Object.ReferenceEquals(TestRequiredLite.DefaultInstance, msg.WeakDefaultInstanceForType));
Assert.IsTrue(Object.ReferenceEquals(TestRequiredLite.DefaultInstance, msg.WeakDefaultInstanceForType));
}
}
}
\ 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" />
<package id="NUnit" version="2.6.4" targetFramework="net45" userInstalled="true" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net45" userInstalled="true" />
</packages>
\ 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