Created
November 5, 2012 11:07
-
-
Save JamesTryand/4016669 to your computer and use it in GitHub Desktop.
Quick Eventstore Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using Some.Infrastructure.Domain; | |
| //using grensesnitt.Framework; | |
| //using NUnit.Framework; | |
| using Simple.Testing.ClientFramework; | |
| namespace Some.Infrastructure.Tests | |
| { | |
| public class SomeEvent : Event | |
| { | |
| public string Name { get; set; } | |
| public int Age { get; set; } | |
| public string Gibbon { get; set; } | |
| } | |
| public class OtherEvent : Event | |
| { | |
| public string Name { get; set; } | |
| public int Height { get; set; } | |
| public string Monkey { get; set; } | |
| } | |
| public class MSSqlEventStoreSpecification | |
| { | |
| public Specification Round_trip_returns_events() | |
| { | |
| Guid root = Guid.NewGuid(); | |
| return new QuerySpecification<TestEnvironmentFor<MSSqlEventStore, IEnumerable<Event>>, IEnumerable<Event>>() | |
| { | |
| On = () => | |
| new TestEnvironmentFor<MSSqlEventStore, IEnumerable<Event>>( | |
| () => new MSSqlEventStore( | |
| new InMemoryBus(), | |
| "Data Source=.;Initial Catalog=EventStore;Integrated Security=True;Pooling=False")), | |
| When = we => | |
| we.First(store => | |
| store.SaveEvents(root, new Event[] { | |
| new SomeEvent { | |
| Name = "Bob", | |
| Age = 41, | |
| Gibbon = "hohoho", | |
| Version = 1, | |
| }, | |
| new OtherEvent { | |
| Name = "Yoho", | |
| Monkey = "Gaffle", | |
| Height = 51, | |
| Version = 2, | |
| }, | |
| }.AsEnumerable(), | |
| 1)) | |
| .AndFinally(store => | |
| store.GetEventsForAggregate(root)), | |
| Expect = { | |
| results => results != null, | |
| results => results.Count() == 2, | |
| results => results.First().GetType().ToString().Contains("SomeEvent"), | |
| results => results.Last().GetType().ToString().Contains("OtherEvent"), | |
| }, | |
| }; | |
| } | |
| } | |
| /// <summary> | |
| /// This class provides a fluent container to perform multiple operations upon a class and be | |
| /// able to return the appropriate type from it. | |
| /// This is useful when testing a sequence of operations. This is done when testing infrastructure | |
| /// components. (as opposed to domain behaviour which is populated by a stream of events) | |
| /// </summary> | |
| /// <typeparam name="TContext"></typeparam> | |
| /// <typeparam name="TResult"></typeparam> | |
| public class TestEnvironmentFor<TContext,TResult> | |
| { | |
| TContext Container; | |
| public TestEnvironmentFor(Func<TContext> Constructor) | |
| { | |
| Container = Constructor(); | |
| } | |
| public TestEnvironmentFor<TContext, TResult> First(Action<TContext> task) | |
| { | |
| task(Container); | |
| return this; | |
| } | |
| public TestEnvironmentFor<TContext, TResult> AndThen(Action<TContext> task) | |
| { | |
| task(Container); | |
| return this; | |
| } | |
| public TResult AndFinally(Func<TContext, TResult> final) | |
| { | |
| return final(Container); | |
| } | |
| // public override string ToString() | |
| // { | |
| // return "Running a test against " + typeof(TContext).Name + " that returns " + typeof(TResult); | |
| // } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment