Line data Source code
1 : using System;
2 : using System.Collections.Generic;
3 : using System.Diagnostics;
4 : using System.Linq;
5 : using cdmdotnet.Logging;
6 : using cdmdotnet.Logging.Configuration;
7 : using cdmdotnet.StateManagement.Threaded;
8 : using Cqrs.Azure.BlobStorage.Events;
9 : using Cqrs.Azure.ServiceBus.Tests.Unit;
10 : using Cqrs.Configuration;
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.BlobStorage.Test.Integration
20 : {
21 : /// <summary>
22 : /// A series of tests on the <see cref="BlobStorageEventStore{TAuthenticationToken}"/> class
23 : /// </summary>
24 : [TestClass]
25 : public class BlobStorageEventStoreTests
26 1 : {
27 : [TestMethod]
28 0 : public virtual void Save_ValidEvent_EventCanBeRetreived()
29 : {
30 : // Arrange
31 : var correlationIdHelper = new CorrelationIdHelper(new ThreadedContextItemCollectionFactory());
32 : correlationIdHelper.SetCorrelationId(Guid.NewGuid());
33 : var logger = new ConsoleLogger(new LoggerSettingsConfigurationSection(), correlationIdHelper);
34 : var eventStore = new BlobStorageEventStore<Guid>(new DefaultEventBuilder<Guid>(), new EventDeserialiser<Guid>(), logger, new BlobStorageEventStoreConnectionStringFactory(new ConfigurationManager(), logger));
35 :
36 : var event1 = new TestEvent
37 : {
38 : Rsn = Guid.NewGuid(),
39 : Id = Guid.NewGuid(),
40 : CorrelationId = correlationIdHelper.GetCorrelationId(),
41 : Frameworks = new List<string> { "Test 1" },
42 : TimeStamp = DateTimeOffset.UtcNow
43 : };
44 : var event2 = new TestEvent
45 : {
46 : Rsn = Guid.NewGuid(),
47 : Id = Guid.NewGuid(),
48 : CorrelationId = correlationIdHelper.GetCorrelationId(),
49 : Frameworks = new List<string> { "Test 2" },
50 : TimeStamp = DateTimeOffset.UtcNow
51 : };
52 :
53 : // Act
54 : eventStore.Save<TestEvent>(event1);
55 : eventStore.Save<TestEvent>(event2);
56 :
57 : // Assert
58 : var timer = new Stopwatch();
59 : IList<IEvent<Guid>> events = eventStore.Get<TestEvent>(event1.Id).ToList();
60 : timer.Stop();
61 : Console.WriteLine("Load one operation took {0}", timer.Elapsed);
62 : Assert.AreEqual(1, events.Count);
63 : Assert.AreEqual(event1.Id, events.Single().Id);
64 : Assert.AreEqual(event1.Frameworks.Single(), events.Single().Frameworks.Single());
65 :
66 : timer.Restart();
67 : events = eventStore.Get<TestEvent>(event2.Id).ToList();
68 : timer.Stop();
69 : Console.WriteLine("Load one operation took {0}", timer.Elapsed);
70 : Assert.AreEqual(1, events.Count);
71 : Assert.AreEqual(event2.Id, events.Single().Id);
72 : Assert.AreEqual(event2.Frameworks.Single(), events.Single().Frameworks.Single());
73 :
74 : timer.Restart();
75 : IList<EventData> correlatedEvents = eventStore.Get(event1.CorrelationId).ToList();
76 : timer.Stop();
77 : Console.WriteLine("Load several correlated operation took {0}", timer.Elapsed);
78 : Assert.AreEqual(2, correlatedEvents.Count);
79 : }
80 : }
81 : }
|