public void Append()
        {
            const string eventStoreFolderPath = "ESAppendTest";

            if (Directory.Exists(eventStoreFolderPath))
            {
                Directory.Delete(eventStoreFolderPath, true);
            }
            var sut = new FilesystemEventStore(eventStoreFolderPath);

            sut.OnAppended += _ => { };

            var e = new Event {
                ContextId = "ctx1",
                Name      = "eventname",
                Payload   = "payload1\npayload2"
            };
            var seqnum = sut.Append(e);

            var eventText = File.ReadAllLines(Path.Combine(eventStoreFolderPath, e.ContextId, seqnum + ".txt"));

            Assert.AreEqual(4, eventText.Length);
            Assert.AreEqual("eventname", eventText[0]);
            Assert.IsTrue(eventText[1].IndexOf("2017") >= 0);
            Assert.AreEqual("payload1", eventText[2]);
            Assert.AreEqual("payload2", eventText[3]);
        }
        public void Append_several()
        {
            const string eventStoreFolderPath = "ESAppendTest";

            if (Directory.Exists(eventStoreFolderPath))
            {
                Directory.Delete(eventStoreFolderPath, true);
            }
            var sut = new FilesystemEventStore(eventStoreFolderPath);

            Event[] result = null;
            sut.OnAppended += events => result = events.ToArray();

            var e1 = new Event {
                ContextId = "ctx1",
                Name      = "eventname",
                Payload   = "payload1\npayload2"
            };
            var e2 = new Event {
                ContextId = "ctx1",
                Name      = "eventname2",
                Payload   = "payload"
            };
            var seqnum = sut.Append(new[] { e1, e2 });

            var contextFolderPath = Path.Combine(eventStoreFolderPath, e1.ContextId);
            var filenames         = Directory.GetFiles(contextFolderPath, "*.txt");

            Assert.AreEqual(2, filenames.Length);

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual("eventname2", result[1].Name);
        }
        public void Replay_all_contexts()
        {
            const string eventStoreFolderPath = "ESReplayTest";

            if (Directory.Exists(eventStoreFolderPath))
            {
                Directory.Delete(eventStoreFolderPath, true);
            }

            var sut = new FilesystemEventStore(eventStoreFolderPath);

            sut.OnAppended += _ => { };
            var e1 = new Event
            {
                ContextId = "ctx2",
                Name      = "en",
                Payload   = "pl1\npl1.1"
            };
            var e2 = new Event
            {
                ContextId = "ctx1",
                Name      = "en2",
                Payload   = "pl2"
            };

            sut.Append(new[] { e1, e2 });

            var result = sut.Replay().ToArray();

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual(-1, result[0].SequenceNumber.CompareTo(result[1].SequenceNumber));
            Assert.AreEqual("ctx2", result[0].ContextId);
            Assert.AreEqual("ctx1", result[1].ContextId);
        }
        public void Usage_scenario()
        {
            const string eventStoreFolderPath = "SprintRepoTest";

            if (Directory.Exists(eventStoreFolderPath))
            {
                Directory.Delete(eventStoreFolderPath, true);
            }
            var es = new FilesystemEventStore(eventStoreFolderPath);

            es.OnAppended += events => {
                foreach (var e in events)
                {
                    Console.WriteLine(e.Name);
                }
            };

            var sut = new SprintRepository(es);

            // Sprint anlegen
            var sprint   = sut.Create(new[] { "a", "b", "c" });
            var sprintId = sprint.Id;

            // Sprint laden
            sprint = sut.Load(sprintId);
            Assert.AreEqual(new[] { "a", "b", "c" }, sprint.UserStories);

            // Voting abgeben
            sprint.Register(new Voting("v1", new[] { 0, 1, 2 }));
            sut.Store(sprint);

            // Sprint laden und Voting überprüfen
            sprint = sut.Load(sprintId);
            Assert.AreEqual(1, sprint.Votings.Length);
            Assert.AreEqual(new[] { 0, 1, 2 }, sprint.Votings[0].UserStoryIndexes);

            // weiteres Voting abgeben und bisheriges überschreiben
            sprint.Register(new Voting("v2", new[] { 2, 1, 0 }));
            sprint.Register(new Voting("v1", new[] { 1, 2, 0 }));
            sut.Store(sprint);

            // Votings überprüfen
            sprint = sut.Load(sprintId);
            Assert.AreEqual(2, sprint.Votings.Length);
            Assert.AreEqual("v1", sprint.Votings[0].VoterId);
            Assert.AreEqual(new[] { 1, 2, 0 }, sprint.Votings[0].UserStoryIndexes);
            Assert.AreEqual("v2", sprint.Votings[1].VoterId);
            Assert.AreEqual(new[] { 2, 1, 0 }, sprint.Votings[1].UserStoryIndexes);

            // Sprint löschen
            sut.Delete(sprintId);
            Assert.Throws <InvalidOperationException>(() => sut.Load(sprintId));
        }
        public void Create()
        {
            const string eventStoreFolderPath = "ESCreationTest";

            if (Directory.Exists(eventStoreFolderPath))
            {
                Directory.Delete(eventStoreFolderPath, true);
            }

            var sut = new FilesystemEventStore(eventStoreFolderPath);

            Assert.IsTrue(Directory.Exists(eventStoreFolderPath));

            var sut2 = new FilesystemEventStore(eventStoreFolderPath);

            Assert.IsTrue(Directory.Exists(eventStoreFolderPath));
        }
        public void Append_fires_events()
        {
            const string eventStoreFolderPath = "ESAppendTest";

            if (Directory.Exists(eventStoreFolderPath))
            {
                Directory.Delete(eventStoreFolderPath, true);
            }
            var   sut    = new FilesystemEventStore(eventStoreFolderPath);
            Event result = null;

            sut.OnAppended += events => result = events.First();

            var e = new Event {
                ContextId = "ctx1",
                Name      = "eventname",
                Payload   = "payload1\npayload2"
            };
            var seqnum = sut.Append(e);

            Assert.AreEqual(seqnum, result.SequenceNumber);
            Assert.AreEqual("ctx1", result.ContextId);
            Assert.AreEqual("eventname", result.Name);
        }
Beispiel #7
0
        public void UseCase()
        {
            const string EVENTSTORE_FOLDER = "UseCaseEventStore";

            if (Directory.Exists(EVENTSTORE_FOLDER))
            {
                Directory.Delete(EVENTSTORE_FOLDER, true);
            }

            var we  = new Weighting();
            var es  = new FilesystemEventStore(EVENTSTORE_FOLDER);
            var sut = new RequestHandler(we, es);

            // create first sprint
            var sprintId = sut.Create_Sprint(new[] { "a", "b", "c" });

            // ab, ac, bc
            var cp = sut.ComparisonPairs(sprintId);

            Assert.AreEqual(sprintId, cp.SprintId);
            Assert.AreEqual("a", cp.Pairs[0].A);
            Assert.AreEqual("b", cp.Pairs[0].B);
            Assert.AreEqual("a", cp.Pairs[1].A);
            Assert.AreEqual("c", cp.Pairs[1].B);

            var voting = new VotingDto {
                VoterId = "v1", Weightings = new[] {
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[0].Id, Selection = Selection.B
                    },
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[1].Id, Selection = Selection.B
                    },
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[2].Id, Selection = Selection.B
                    }
                }
            };

            sut.Submit_voting(sprintId, voting,
                              () => { Console.WriteLine("voting sprint 1 submitted"); },
                              null);

            var total = sut.Get_total_weighting_for_sprint(sprintId);

            Assert.AreEqual(sprintId, total.SprintId);
            Assert.AreEqual(new[] { "c", "b", "a" }, total.Stories);
            Assert.AreEqual(1, total.NumberOfVotings);


            // create second sprint
            var sprintId2 = sut.Create_Sprint(new[] { "x", "y", "z" });

            cp = sut.ComparisonPairs(sprintId2);
            Assert.AreEqual(sprintId2, cp.SprintId);
            Assert.AreEqual("x", cp.Pairs[0].A);
            Assert.AreEqual("y", cp.Pairs[0].B);
            voting = new VotingDto {
                VoterId    = "vI",
                Weightings = new[] {
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[0].Id, Selection = Selection.A
                    },
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[1].Id, Selection = Selection.A
                    },
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[2].Id, Selection = Selection.A
                    }
                }
            };
            sut.Submit_voting(sprintId2, voting,
                              () => { Console.WriteLine("voting sprint 2 submitted"); },
                              null);
            total = sut.Get_total_weighting_for_sprint(sprintId2);
            Assert.AreEqual(sprintId2, total.SprintId);
            Assert.AreEqual(new[] { "x", "y", "z" }, total.Stories);
            Assert.AreEqual(1, total.NumberOfVotings);


            // both sprints coexist
            cp = sut.ComparisonPairs(sprintId);
            Assert.AreEqual(sprintId, cp.SprintId);
            cp = sut.ComparisonPairs(sprintId2);
            Assert.AreEqual(sprintId2, cp.SprintId);


            // delete only second sprint
            sut.Delete_Sprint(sprintId2);
            Assert.Throws <InvalidOperationException>(() => sut.Get_total_weighting_for_sprint(sprintId2));

            cp = sut.ComparisonPairs(sprintId);
            Assert.AreEqual(sprintId, cp.SprintId);
        }