Ejemplo n.º 1
0
        public void Ensure_That_If_We_Add_Two_Revisions_Where_Both_Revisions_Change_The_Same_Word_In_The_Previous_Revisions_The_Document_Throws_A_Conflict_Exception()
        {
            var document = new Document("I went to the store to get mom some milk");
            var revisionStrings = new[]
                {
                    "I went to the store to get mom some cheese",
                    "I went to the store to get mom some orange juice"
                };
            var revisions = revisionStrings.Select(s => new BasicRevision(document.CurrentRevision,
                                                                          Patches.Make(
                                                                              "I went to the store to get mom some milk",
                                                                              s))).ToList();
            foreach (var revision in revisions)
                document.Edit(revision);

            Assert.Throws<ConflictException>(() => document.CurrentRevision.GenerateEditedContent());
        }
        public void Ensure_That_When_We_Save_And_Then_Reload_a_Document_That_The_NextRevision_Applied_Property_On_Its_Revisios_Is_Populated()
        {
            Document document;
            using (var session = DocumentStore.OpenSession())
            {
                document = new Document("Test");
                var revision = new BasicRevision(document.CurrentRevision, Patches.Make(document.Contents, "Test2"));
                document.Edit(revision);
                session.Store(document);

                session.SaveChanges();
            }

            using (var session = DocumentStore.OpenSession())
            {
                var loadedDoc = session.Load<Document>(document.Id);
                Assert.That(loadedDoc.CurrentRevision.PreviousRevisionAppliedTo.NextRevisionApplied, Is.EqualTo(loadedDoc.CurrentRevision));
            }
        }
        public void Given_That_We_Have_Executed_The_SubscribeToDocumentUpdatesCommand_Ensure_That_When_The_Document_Is_Edited_The_Connection_Associated_With_The_Request_Has_Its_Send_Method_Called()
        {
            var document = new Document("Test");
            Session.Store(document);
            var connection = Substitute.For<IConnection>();

            var request = new SubscriptionRequest
                {
                    Id = document.Id,
                    Connection = connection
                };

            var command = new SubscribeToDocumentUpdatesCommand(request);
            ExecuteCommand(command);

            document.Edit(new BasicRevision(document.CurrentRevision, Patches.Make(document.Contents, "Test2")));

            connection.Received().Send(Arg.Any<ConnectionMessage>());
        }
Ejemplo n.º 4
0
        public void Ensure_That_If_We_Add_Four_Revisions_With_The_Same_Previous_Revision_The_Document_Handles_The_Merge()
        {
            var document = new Document("I went to the store to get mom some milk");
            var revisionStrings = new[]
                {
                    "I went to the store to get mom some milk and crackers",
                    "I ran to the store to get mom some milk",
                    "I went to the corner store to get mom some milk",
                    "I went to the store to get mom and dad some milk"
                };
            var revisions = revisionStrings.Select(s => new BasicRevision(document.CurrentRevision,
                                                                          Patches.Make(
                                                                              "I went to the store to get mom some milk",
                                                                              s))).ToList();
            foreach (var revision in revisions)
                document.Edit(revision);

            Assert.That(document.CurrentRevision.GenerateEditedContent(),
                        Is.EqualTo("I ran to the corner store to get mom and dad some milk and crackers"));
        }
Ejemplo n.º 5
0
        public void Ensure_That_If_We_Add_Two_Revisions_With_The_Same_Previous_Revision_The_Document_Handles_The_Merge()
        {
            var document = new Document("I went to the store to get mom some milk");

            var revisionOne = new BasicRevision(document.CurrentRevision,
                                                Patches.Make("I went to the store to get mom some milk",
                                                             "I went to the store to get mom some milk and crackers"));
            var revisionTwo = new BasicRevision(document.CurrentRevision,
                                                Patches.Make("I went to the store to get mom some milk",
                                                             "I ran to the store to get mom some milk"));

            document.Edit(revisionTwo);
            document.Edit(revisionOne);

            Assert.That(document.CurrentRevision.GenerateEditedContent(),
                        Is.EqualTo("I ran to the store to get mom some milk and crackers"));
        }
Ejemplo n.º 6
0
        public void Given_We_Have_A_Document_With_A_Merging_Revision_As_The_Parent_Of_The_Current_Revision_Ensure_That_When_The_Document_Is_Edited_With_A_Revision_Targeting_One_Of_The_Merged_Revisions_The_New_Revision_Is_Merged_In()
        {
            var document = new Document("I went to the store to get some milk");
            var revisionsToMerge = new[]
                {
                    "I ran to the store to get some milk",
                    "I went to the store to get some milk and crackers"
                }.Select(s => new BasicRevision(document.CurrentRevision, Patches.Make(document.Contents, s))).ToList();

            foreach (var basicRevision in revisionsToMerge)
                document.Edit(basicRevision);

            var postMergeRevision = new BasicRevision(document.CurrentRevision,
                                                      Patches.Make(document.Contents,
                                                                   "I ran to the store to get mom some milk and crackers"));
            document.Edit(postMergeRevision);

            var lateRevisionsParent = revisionsToMerge.First();
            var lateRevision = new BasicRevision(lateRevisionsParent,
                                                 Patches.Make(lateRevisionsParent.GenerateEditedContent(),
                                                              "I ran to the corner store to get some milk"));

            document.Edit(lateRevision);

            Assert.That(document.Contents, Is.EqualTo("I ran to the corner store to get mom some milk and crackers"));
        }
Ejemplo n.º 7
0
        public void Given_We_Have_Added_A_Subscriber_To_A_Document_Ensure_That_When_The_Document_Merges_Two_Revisions_The_Subscriber_Is_Notified_With_The_Merging_Revision()
        {
            var document = new Document("I went to the store");
            var subscriber = new Subscriber(Guid.NewGuid().ToString());
            document.AddSubscriber(subscriber);

            var revision1 = new BasicRevision(document.CurrentRevision, Patches.Make(document.Contents, "I went to the store to get some milk"));
            var revision2 = new BasicRevision(document.CurrentRevision, Patches.Make(document.Contents, "I went to the corner store"));
            IList<Patch> notifiedPatch = null;
            subscriber.SubscriberNotifiedOfUpdate +=
                (o, e) => notifiedPatch = e.patches;
            document.Edit(revision1);
            document.Edit(revision2);
            var patch = document.CurrentRevision.BuildPatch();

            Assert.That(notifiedPatch.Select(p=> p.ToString()), Is.EquivalentTo(patch.Select(p=> p.ToString())));
        }
Ejemplo n.º 8
0
        public void Given_We_Have_Added_A_Subscriber_To_A_Document_Ensure_That_When_A_Document_Is_Edited_The_Subscriber_Is_Notified()
        {
            var document = new Document("Test");
            var subscriber = new Subscriber(Guid.NewGuid().ToString());
            document.AddSubscriber(subscriber);

            var revision = new BasicRevision(document.CurrentRevision, Patches.Make(document.Contents, "Test 2"));
            var eventFired = false;
            subscriber.SubscriberNotifiedOfUpdate += (o, e) => eventFired = true;
            document.Edit(revision);

            Assert.That(eventFired);
        }
Ejemplo n.º 9
0
        public void Given_A_Revision_Guid_For_A_Revision_That_Was_Part_Of_A_Merge_Ensure_We_Can_Load_That_Revision()
        {
            var document = new Document("Test");
            var sharedParentRevision = document.CurrentRevision;
            document.Edit(new BasicRevision(sharedParentRevision, Patches.Make(document.Contents, "Test2")));
            var revisionIdToLoad = document.CurrentRevision.Id;
            document.Edit(new BasicRevision(sharedParentRevision, Patches.Make(document.Contents, "Test3")));

            var revision = document.LoadRevision(revisionIdToLoad);

            Assert.That(revision.GenerateEditedContent(), Is.EqualTo("Test2"));
        }
Ejemplo n.º 10
0
        public void Given_A_Revision_Guid_Ensure_We_Can_Load_A_Specific_Revision()
        {
            var document = new Document("Test");
            document.Edit(new BasicRevision(document.CurrentRevision, Patches.Make(document.Contents, "Test2")));
            var revisionIdToLoad = document.CurrentRevision.Id;
            document.Edit(new BasicRevision(document.CurrentRevision, Patches.Make(document.Contents, "Test3")));

            var revision = document.LoadRevision(revisionIdToLoad);

            Assert.That(revision.GenerateEditedContent(), Is.EqualTo("Test2"));
        }
Ejemplo n.º 11
0
        public void Ensure_We_Can_Add_A_Revision_To_A_Document_And_Then_Retrive_The_New_Document_Contents()
        {
            var document = new Document();
            var patch = Patches.Make("", "This is a test");
            var revision = new BasicRevision(document.CurrentRevision, patch);

            document.Edit(revision);
            Assert.That(document.CurrentRevision.GenerateEditedContent(), Is.EqualTo("This is a test"));
        }