forked from acken/AutoTest.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageTestBase.cs
More file actions
36 lines (33 loc) · 1.19 KB
/
Copy pathMessageTestBase.cs
File metadata and controls
36 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
namespace AutoTest.Test.Core.Messaging
{
public abstract class MessageTestBase<T>
{
protected abstract T CreateMessage();
public abstract void Should_be_immutable();
protected void should_be_immutable_test()
{
var messageType = CreateMessage().GetType();
var infos = messageType.GetProperties().Where(p => p.CanWrite);
var writableProperites = infos.Count();
if (writableProperites > 0)
{
Assert.IsTrue(false,
String.Format("Message of type {1} has writable property {0}. Not immutable",
infos.First().Name, messageType.Name));
}
var fields = messageType.GetFields();
foreach (var info in fields)
{
if (info.Attributes != FieldAttributes.InitOnly)
{
Assert.IsTrue(false,
String.Format("{0} was not readonly in message of type {1}", info.Name, messageType.Name));
}
}
}
}
}