aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2015-04-30 14:51:42 +0100
committerJon Skeet <skeet@pobox.com>2015-04-30 14:51:42 +0100
commit0884b77975146be5d0557b254fbeab940cda641a (patch)
treeeee4106598d0faf92b566f7e03930f25df38a56c /csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs
parent151018e888927f4e89e325af013613cc1b08196c (diff)
parentc56475088d2d36d29a2640f35b9a8621796c051c (diff)
downloadprotobuf-0884b77975146be5d0557b254fbeab940cda641a.tar.gz
protobuf-0884b77975146be5d0557b254fbeab940cda641a.tar.bz2
protobuf-0884b77975146be5d0557b254fbeab940cda641a.zip
Merge pull request #324 from jskeet/csharp
Change to using xUnit for all unit tests, and fetch that via NuGet.
Diffstat (limited to 'csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs')
-rw-r--r--csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs85
1 files changed, 31 insertions, 54 deletions
diff --git a/csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs b/csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs
index 1dcb1c21..692bfd11 100644
--- a/csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs
+++ b/csharp/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
-using System.Text;
using Google.ProtocolBuffers.TestProtos;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Xunit;
namespace Google.ProtocolBuffers
{
- [TestClass]
public class GeneratedBuilderTest
{
class OneTimeEnumerator<T> : IEnumerable<T>
@@ -19,107 +17,86 @@ namespace Google.ProtocolBuffers
}
public IEnumerator<T> GetEnumerator()
{
- Assert.IsFalse(_enumerated, "The collection {0} has already been enumerated", GetType());
+ Assert.False(_enumerated);
_enumerated = true;
yield return _item;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- { return GetEnumerator(); }
+ {
+ return GetEnumerator();
+ }
}
- [TestMethod]
+ [Fact]
public void DoesNotEnumerateTwiceForMessageList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- b.AddRangeRepeatedForeignMessage(
- new OneTimeEnumerator<ForeignMessage>(
- ForeignMessage.DefaultInstance));
+ b.AddRangeRepeatedForeignMessage(new OneTimeEnumerator<ForeignMessage>(ForeignMessage.DefaultInstance));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotEnumerateTwiceForPrimitiveList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedInt32(new OneTimeEnumerator<int>(1));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotEnumerateTwiceForStringList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedString(new OneTimeEnumerator<string>("test"));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotEnumerateTwiceForEnumList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedForeignEnum(new OneTimeEnumerator<ForeignEnum>(ForeignEnum.FOREIGN_BAR));
}
-
- private delegate void TestMethod();
-
- private static void AssertThrows<T>(TestMethod method) where T : Exception
- {
- try
- {
- method();
- }
- catch (Exception error)
- {
- if (error is T)
- return;
- throw;
- }
- Assert.Fail("Expected exception of type " + typeof(T));
- }
-
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToMessageListByAddRange()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- AssertThrows<ArgumentNullException>(
- () => b.AddRangeRepeatedForeignMessage(new ForeignMessage[] { null })
- );
+ Assert.Throws<ArgumentNullException>(() => b.AddRangeRepeatedForeignMessage(new ForeignMessage[] { null }));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToMessageListByAdd()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- AssertThrows<ArgumentNullException>(
- () => b.AddRepeatedForeignMessage((ForeignMessage)null)
- );
+ Assert.Throws<ArgumentNullException>(() => b.AddRepeatedForeignMessage((ForeignMessage)null));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToMessageListBySet()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRepeatedForeignMessage(ForeignMessage.DefaultInstance);
- AssertThrows<ArgumentNullException>(
- () => b.SetRepeatedForeignMessage(0, (ForeignMessage)null)
- );
+ Assert.Throws<ArgumentNullException>(() => b.SetRepeatedForeignMessage(0, (ForeignMessage)null));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToStringListByAddRange()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- AssertThrows<ArgumentNullException>(
- () => b.AddRangeRepeatedString(new String[] { null })
- );
+ Assert.Throws<ArgumentNullException>(() => b.AddRangeRepeatedString(new String[] { null }));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToStringListByAdd()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
- AssertThrows<ArgumentNullException>(
- () => b.AddRepeatedString(null)
- );
+ Assert.Throws<ArgumentNullException>(() => b.AddRepeatedString(null));
}
- [TestMethod]
+
+ [Fact]
public void DoesNotAddNullToStringListBySet()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRepeatedString("one");
- AssertThrows<ArgumentNullException>(
- () => b.SetRepeatedString(0, null)
- );
+ Assert.Throws<ArgumentNullException>(() => b.SetRepeatedString(0, null));
}
}
}