Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using Cqrs.Commands;
11 : using Cqrs.Events;
12 : using NUnit.Framework;
13 : using TestClass = NUnit.Framework.TestFixtureAttribute;
14 : using TestMethod = NUnit.Framework.TestAttribute;
15 : using TestInitialize = NUnit.Framework.SetUpAttribute;
16 : using TestCleanup = NUnit.Framework.TearDownAttribute;
17 : using TestContext = System.Object;
18 :
19 : namespace Cqrs.Azure.ServiceBus.Tests.Unit
20 : {
21 : /// <summary>
22 : /// A series of tests on the <see cref="MessageSerialiser{TAuthenticationToken}"/> class
23 : /// </summary>
24 : [TestClass]
25 : public class MessageSerialiserTests
26 1 : {
27 : private const string GoodEventData = "{\"$id\":\"1\",\"$type\":\"Cqrs.Azure.ServiceBus.Tests.Unit.TestEvent, Cqrs.Azure.ServiceBus.Tests.Unit\",\"Id\":\"a3008122-b365-45ef-86ec-865df098b886\"}";
28 :
29 : private const string GoodCommandData = "{\"$id\":\"1\",\"$type\":\"Cqrs.Azure.ServiceBus.Tests.Unit.TestCommand, Cqrs.Azure.ServiceBus.Tests.Unit\",\"Id\":\"17c0585b-3b24-4865-9afc-5fa97e36606a\"}";
30 :
31 : /// <summary>
32 : /// Tests the <see cref="MessageSerialiser{TAuthenticationToken}.SerialiseEvent{TEvent}"/> method
33 : /// Passing a valid test <see cref="IEvent{TAuthenticationToken}"/>
34 : /// Expecting the serialised data is as expected.
35 : /// </summary>
36 : [TestMethod]
37 1 : public void SerialiseEvent_TestEvent_ExpectedSerialisedData()
38 : {
39 : // Arrange
40 : var eventSerialiser = new MessageSerialiser<Guid>();
41 :
42 : // Act
43 : string data = eventSerialiser.SerialiseEvent(new TestEvent { Id = new Guid("a3008122-b365-45ef-86ec-865df098b886") });
44 :
45 : // Assert
46 : Assert.AreEqual(GoodEventData, data);
47 : }
48 :
49 : /// <summary>
50 : /// Tests the <see cref="MessageSerialiser{TAuthenticationToken}.DeserialiseEvent"/> method
51 : /// Passing a valid test string of JSON
52 : /// Expecting the data deserialised to the expected <see cref="Type"/>.
53 : /// </summary>
54 : [TestMethod]
55 1 : public void DeserialiseEvent_TestEventData_ExpectedEvent()
56 : {
57 : // Arrange
58 : var eventSerialiser = new MessageSerialiser<Guid>();
59 :
60 : // Act
61 : IEvent<Guid> @event = eventSerialiser.DeserialiseEvent(GoodEventData);
62 :
63 : // Assert
64 : Assert.AreEqual("Cqrs.Azure.ServiceBus.Tests.Unit.TestEvent", @event.GetType().FullName);
65 : }
66 :
67 : /// <summary>
68 : /// Tests the <see cref="MessageSerialiser{TAuthenticationToken}.SerialiseCommand{TEvent}"/> method
69 : /// Passing a valid test <see cref="ICommand{TAuthenticationToken}"/>
70 : /// Expecting the serialised data is as expected.
71 : /// </summary>
72 : [TestMethod]
73 1 : public void SerialiseCommand_TestCommand_ExpectedSerialisedData()
74 : {
75 : // Arrange
76 : var command = new MessageSerialiser<Guid>();
77 :
78 : // Act
79 : string data = command.SerialiseCommand(new TestCommand { Id = new Guid("17c0585b-3b24-4865-9afc-5fa97e36606a") });
80 :
81 : // Assert
82 : Assert.AreEqual(GoodCommandData, data);
83 : }
84 :
85 : /// <summary>
86 : /// Tests the <see cref="MessageSerialiser{TAuthenticationToken}.DeserialiseCommand"/> method
87 : /// Passing a valid test string of JSON
88 : /// Expecting the data deserialised to the expected <see cref="Type"/>.
89 : /// </summary>
90 : [TestMethod]
91 1 : public void DeserialiseCommand_TestCommandData_ExpectedCommand()
92 : {
93 : // Arrange
94 : var commandSerialiser = new MessageSerialiser<Guid>();
95 :
96 : // Act
97 : ICommand<Guid> command = commandSerialiser.DeserialiseCommand(GoodCommandData);
98 :
99 : // Assert
100 : Assert.AreEqual("Cqrs.Azure.ServiceBus.Tests.Unit.TestCommand", command.GetType().FullName);
101 : }
102 : }
103 : }
|