diff options
Diffstat (limited to 'csharp/src/ProtocolBuffers.Test/RepeatedFieldTest.cs')
-rw-r--r-- | csharp/src/ProtocolBuffers.Test/RepeatedFieldTest.cs | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/csharp/src/ProtocolBuffers.Test/RepeatedFieldTest.cs b/csharp/src/ProtocolBuffers.Test/RepeatedFieldTest.cs index cbe79294..c01cd8ff 100644 --- a/csharp/src/ProtocolBuffers.Test/RepeatedFieldTest.cs +++ b/csharp/src/ProtocolBuffers.Test/RepeatedFieldTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Google.Protobuf.Collections; +using Google.Protobuf.TestProtos; using NUnit.Framework; namespace Google.Protobuf @@ -11,8 +12,8 @@ namespace Google.Protobuf public void NullValuesRejected() { var list = new RepeatedField<string>(); - Assert.Throws<ArgumentNullException>(() => list.Add((string) null)); - Assert.Throws<ArgumentNullException>(() => list.Add((IEnumerable<string>) null)); + Assert.Throws<ArgumentNullException>(() => list.Add((string)null)); + Assert.Throws<ArgumentNullException>(() => list.Add((IEnumerable<string>)null)); Assert.Throws<ArgumentNullException>(() => list.Add((RepeatedField<string>)null)); Assert.Throws<ArgumentNullException>(() => list.Contains(null)); Assert.Throws<ArgumentNullException>(() => list.IndexOf(null)); @@ -47,5 +48,47 @@ namespace Google.Protobuf Assert.AreEqual("foo", list[1]); Assert.AreEqual("bar", list[2]); } + + [Test] + public void Freeze_FreezesElements() + { + var list = new RepeatedField<TestAllTypes> { new TestAllTypes() }; + Assert.IsFalse(list[0].IsFrozen); + list.Freeze(); + Assert.IsTrue(list[0].IsFrozen); + } + + [Test] + public void Freeze_PreventsMutations() + { + var list = new RepeatedField<int> { 0 }; + list.Freeze(); + Assert.Throws<InvalidOperationException>(() => list.Add(1)); + Assert.Throws<InvalidOperationException>(() => list[0] = 1); + Assert.Throws<InvalidOperationException>(() => list.Clear()); + Assert.Throws<InvalidOperationException>(() => list.RemoveAt(0)); + Assert.Throws<InvalidOperationException>(() => list.Remove(0)); + Assert.Throws<InvalidOperationException>(() => list.Insert(0, 0)); + } + + [Test] + public void Freeze_ReportsFrozen() + { + var list = new RepeatedField<int> { 0 }; + Assert.IsFalse(list.IsFrozen); + Assert.IsFalse(list.IsReadOnly); + list.Freeze(); + Assert.IsTrue(list.IsFrozen); + Assert.IsTrue(list.IsReadOnly); + } + + [Test] + public void Clone_ReturnsMutable() + { + var list = new RepeatedField<int> { 0 }; + list.Freeze(); + var clone = list.Clone(); + clone[0] = 1; + } } } |