forked from LunaMultiplayer/LunaMultiplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageStoreTest.cs
More file actions
50 lines (38 loc) · 1.91 KB
/
MessageStoreTest.cs
File metadata and controls
50 lines (38 loc) · 1.91 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using LmpCommon.Message;
using LmpCommon.Message.Base;
using LmpCommon.Message.Data.Vessel;
using LmpCommon.Message.Server;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace LmpCommonTest
{
[TestClass]
public class MessageStoreTest
{
private static readonly ServerMessageFactory Factory = new ServerMessageFactory();
private static readonly Random Rnd = new Random();
[TestMethod]
public void TestMsgMessageStore()
{
var msg1 = Factory.CreateNew<VesselSrvMsg, VesselPositionMsgData>();
Assert.AreEqual(0, MessageStore.GetMessageCount(typeof(VesselSrvMsg)));
Assert.AreEqual(0, MessageStore.GetMessageDataCount(typeof(VesselPositionMsgData)));
var msg2 = Factory.CreateNew<VesselSrvMsg, VesselPositionMsgData>();
Assert.AreEqual(0, MessageStore.GetMessageCount(typeof(VesselSrvMsg)));
Assert.AreEqual(0, MessageStore.GetMessageDataCount(typeof(VesselPositionMsgData)));
//Set first message as "used"
msg1.Recycle();
Assert.AreEqual(1, MessageStore.GetMessageCount(typeof(VesselSrvMsg)));
Assert.AreEqual(1, MessageStore.GetMessageDataCount(typeof(VesselPositionMsgData)));
//If we retrieve a new message the first one should be reused
var msg3 = Factory.CreateNew<VesselSrvMsg, VesselPositionMsgData>();
msg2.Recycle();
msg3.Recycle();
Assert.AreEqual(2, MessageStore.GetMessageCount(typeof(VesselSrvMsg)));
Assert.AreEqual(2, MessageStore.GetMessageDataCount(typeof(VesselPositionMsgData)));
var msg4 = Factory.CreateNew<VesselSrvMsg, VesselPositionMsgData>();
Assert.AreEqual(1, MessageStore.GetMessageCount(typeof(VesselSrvMsg)));
Assert.AreEqual(1, MessageStore.GetMessageDataCount(typeof(VesselPositionMsgData)));
}
}
}