public void MergeFileDeletionChange(IObjectRepositoryLoader loader, ObjectRepository sut, Page page, Signature signature, string message, Func <RepositoryDescription, IComputeTreeChanges> computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            var repositoryDescription = RepositoryFixture.GetRepositoryDescription();

            sut.SaveInNewRepository(signature, message, repositoryDescription); // A

            // Act
            sut.Branch("newBranch");
            var updateName = page.With(p => p.Fields.Delete(page.Fields[1]));

            sut.Commit(updateName.Repository, signature, message); // B
            sut.Checkout("master");
            var updateDescription = page.With(p => p.Description == "modified description");
            var commitC           = sut.Commit(updateDescription.Repository, signature, message); // C
            var loaded            = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());
            var mergeCommit       = loaded.Merge("newBranch").Apply(signature);                   // D

            // Assert
            var changes = computeTreeChangesFactory(RepositoryFixture.GetRepositoryDescription())
                          .Compare(commitC, mergeCommit);

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Deleted));
            Assert.That(changes[0].Old.Id, Is.EqualTo(page.Fields[1].Id));
        }
        public void MergeSamePropertyConflict(IObjectRepositoryLoader loader, ObjectRepository sut, Page page, Signature signature, string message, Func <RepositoryDescription, IComputeTreeChanges> computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            var repositoryDescription = RepositoryFixture.GetRepositoryDescription();

            sut.SaveInNewRepository(signature, message, repositoryDescription); // A

            // Act
            sut.Branch("newBranch");
            var updateName = page.With(p => p.Name == "modified name");

            sut.Commit(updateName.Repository, signature, message); // B
            sut.Checkout("master");
            var updateNameOther = page.With(p => p.Name == "yet again modified name");
            var commitC         = sut.Commit(updateNameOther.Repository, signature, message); // C
            var loaded          = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());
            var merge           = loaded.Merge("newBranch");
            var chunk           = merge.ModifiedChunks.Single();

            chunk.Resolve(JToken.FromObject("merged name"));
            var mergeCommit = merge.Apply(signature); // D

            // Assert
            var changes = computeTreeChangesFactory(RepositoryFixture.GetRepositoryDescription())
                          .Compare(commitC, mergeCommit);

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(changes[0].Old.Name, Is.EqualTo("yet again modified name"));
            Assert.That(changes[0].New.Name, Is.EqualTo("merged name"));
        }
Exemplo n.º 3
0
        public void CommitPageNameUpdate(ObjectRepository sut, Page page, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Act
            sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var modifiedPage = page.With(p => p.Name == "modified");
            var commit       = sut.Commit(modifiedPage.Repository, signature, message);

            // Assert
            Assert.That(commit, Is.Not.Null);
        }
Exemplo n.º 4
0
        public void LoadLinkField(IObjectRepositoryLoader loader, ObjectRepository sut, LinkField linkField, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Act
            sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var loaded          = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var loadedLinkField = (LinkField)loaded.GetFromGitPath(linkField.GetFolderPath());

            // Assert
            Assert.That(loadedLinkField.PageLink.Link.Id, Is.EqualTo(linkField.PageLink.Link.Id));
        }
Exemplo n.º 5
0
        public void PreCommitCancelsCommitIfRequested(GitHooks sut, ObjectRepository instance, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            sut.CommitStarted += (_, args) => args.Cancel = true;

            // Act
            var commit = instance.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));

            // Assert
            Assert.That(commit, Is.Null);
        }
Exemplo n.º 6
0
        public void CreateAndLoadRepository(IObjectRepositoryLoader loader, ObjectRepository sut, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Act
            sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var loaded = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription(inMemoryBackend));

            // Assert
            PAssert.IsTrue(AreFunctionnally.Equivalent <ObjectRepository>(() => sut == loaded));
            foreach (var apps in sut.Applications.OrderBy(v => v.Id).Zip(loaded.Applications.OrderBy(v => v.Id), (a, b) => new { source = a, desctination = b }))
            {
                PAssert.IsTrue(AreFunctionnally.Equivalent <Application>(() => apps.source == apps.desctination));
            }
        }
Exemplo n.º 7
0
        public void PostCommitWhenPropertyChangeGetsFired(GitHooks sut, ObjectRepository instance, Page page, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            CommitCompletedEventArgs lastEvent = null;

            sut.CommitCompleted += (_, args) => lastEvent = args;

            // Act
            instance.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var modifiedPage = page.With(p => p.Name == "modified");
            var commit       = instance.Commit(modifiedPage.Repository, signature, message);

            // Assert
            Assert.That(lastEvent, Is.Not.Null);
            Assert.That(lastEvent.CommitId, Is.EqualTo(commit));
        }
Exemplo n.º 8
0
        public void ResolveDiffsPageNameUpdate(ObjectRepository sut, Page page, Signature signature, string message, Func <RepositoryDescription, IComputeTreeChanges> computeTreeChangesFactory, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            var originalCommit = sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var modifiedPage   = page.With(p => p.Name == "modified");
            var commit         = sut.Commit(modifiedPage.Repository, signature, message);

            // Act
            var changes = computeTreeChangesFactory(RepositoryFixture.GetRepositoryDescription(inMemoryBackend))
                          .Compare(originalCommit, commit);

            // Assert
            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(changes[0].Old.Name, Is.EqualTo(page.Name));
            Assert.That(changes[0].New.Name, Is.EqualTo(modifiedPage.Name));
        }
Exemplo n.º 9
0
        public void CreateLargeRepository(IFixture fixture, Signature signature, string message)
        {
            // Arrange
            var targetDir = RepositoryFixture.GetRepositoryPath("Benchmark");

            DirectoryUtils.Delete(targetDir);
            fixture.Customize(new MetadataCustomization(2, 200, 30));

            // Act
            var sut = fixture.Create <ObjectRepository>();

            sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(targetDir));

            // Assert
            // No assertion, the goal of this test is to create a repository to update Assets\Benchmark.zip
            Console.WriteLine($"Repository created at '{targetDir}'.");
        }
Exemplo n.º 10
0
        public void ResolveDiffsFieldAddition(IServiceProvider serviceProvider, ObjectRepository sut, Page page, Signature signature, string message, Func <RepositoryDescription, IComputeTreeChanges> computeTreeChangesFactory, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            var originalCommit = sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var field          = new Field(serviceProvider, Guid.NewGuid(), "foo");
            var modifiedPage   = page.With(p => p.Fields.Add(field));
            var commit         = sut.Commit(modifiedPage.Repository, signature, message);

            // Act
            var changes = computeTreeChangesFactory(RepositoryFixture.GetRepositoryDescription(inMemoryBackend))
                          .Compare(originalCommit, commit);

            // Assert
            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Added));
            Assert.That(changes[0].Old, Is.Null);
            Assert.That(changes[0].New.Name, Is.EqualTo(field.Name));
        }
        public void MergeTwoDifferentPropertiesWithMigrationChanged(IFixture fixture, IObjectRepositoryLoader loader, ObjectRepository sut, Page page, Signature signature, string message)
        {
            // master:    A-----D-----E---F
            //             \         /   /
            //              \   ,---'   /
            //               \ /   x   /
            // newBranch:     B---C---' (B contains a non-idempotent migration)

            // Arrange
            var repositoryDescription = RepositoryFixture.GetRepositoryDescription();

            sut.SaveInNewRepository(signature, message, repositoryDescription); // A

            // B, C
            sut.Branch("newBranch");
            var updatedInstance = sut.With(i => i.Migrations.Add(fixture.Create <Migration>()));

            sut.Commit(updatedInstance.Repository, signature, message); // B
            var loaded     = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());
            var updateName = loaded.Applications[1].Pages[1].With(p => p.Name == "modified name");

            loaded.Commit(updateName.Repository, signature, message); // C

            // D
            sut.Checkout("master");
            var updateDescription = page.With(p => p.Description == "modified description");

            sut.Commit(updateDescription.Repository, signature, message); // D
            loaded = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());

            // E
            var mergeStep1 = loaded.Merge("newBranch");

            Assert.That(mergeStep1.IsPartialMerge, Is.True);
            mergeStep1.Apply(signature); // E

            // F
            loaded = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());
            var mergeStep2 = loaded.Merge("newBranch");

            Assert.That(mergeStep2.IsPartialMerge, Is.False);
            mergeStep2.Apply(signature); // F
        }
Exemplo n.º 12
0
        public void MigrationScaffolderDetectsRequiredChanges(IFixture fixture, IServiceProvider serviceProvider, ObjectRepository sut, Signature signature, string message)
        {
            // Arrange
            var repositoryDescription = RepositoryFixture.GetRepositoryDescription();

            sut.SaveInNewRepository(signature, message, repositoryDescription);
            var updated = sut.With(i => i.Migrations.Add(fixture.Create <Migration>()));
            var commit  = sut.Commit(updated, signature, message);

            // Act
            var migrationScaffolder = new MigrationScaffolder(serviceProvider, repositoryDescription);
            var migrators           = migrationScaffolder.Scaffold(sut.CommitId, commit, MigrationMode.Upgrade);

            // Assert
            Assert.That(migrators, Has.Count.EqualTo(1));
            Assert.That(migrators[0].CommitId, Is.EqualTo(commit));
            Assert.That(migrators[0].Mode, Is.EqualTo(MigrationMode.Upgrade));
            Assert.That(migrators[0].Migrations, Has.Count.EqualTo(1));
        }
Exemplo n.º 13
0
        public void PreCommitWhenPropertyChangeGetsFired(GitHooks sut, ObjectRepository instance, Page page, LinkField field, Page newLinkedPage, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            CommitStartedEventArgs lastEvent = null;

            sut.CommitStarted += (_, args) => lastEvent = args;

            // Act
            instance.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var composer = new PredicateComposer()
                           .And(field, f => f.Name == "modified field name" && f.PageLink == new LazyLink <Page>(newLinkedPage))
                           .And(page, p => p.Name == "modified page name");
            var modified = field.With(composer);

            instance.Commit(modified.Repository, signature, message);

            // Assert
            Assert.That(lastEvent, Is.Not.Null);
            Assert.That(lastEvent.Changes, Has.Count.EqualTo(2));
        }
Exemplo n.º 14
0
        public void ResolveDiffsPageDeletion(ObjectRepository sut, Application application, Signature signature, string message, Func <RepositoryDescription, IComputeTreeChanges> computeTreeChangesFactory, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            var originalCommit      = sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var page                = application.Pages[1];
            var modifiedApplication = application.With(p => p.Pages.Delete(page));
            var commit              = sut.Commit(modifiedApplication.Repository, signature, message);

            // Act
            var changes = computeTreeChangesFactory(RepositoryFixture.GetRepositoryDescription(inMemoryBackend))
                          .Compare(originalCommit, commit);

            // Assert
            Assert.That(changes.Modified, Is.Empty);
            Assert.That(changes.Added, Is.Empty);
            Assert.That(changes, Has.Count.EqualTo(MetadataCustomization.DefaultFieldPerPageCount + 1));
            var pageDeletion = changes.Deleted.FirstOrDefault(o => o.Old is Page);

            Assert.That(pageDeletion, Is.Not.Null);
            Assert.That(pageDeletion.New, Is.Null);
            Assert.That(pageDeletion.Old.Name, Is.EqualTo(page.Name));
        }
        public void MergeSamePropertyDetectsConflicts(IObjectRepositoryLoader loader, ObjectRepository sut, Page page, Signature signature, string message)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            var repositoryDescription = RepositoryFixture.GetRepositoryDescription();

            sut.SaveInNewRepository(signature, message, repositoryDescription); // A

            // Act
            sut.Branch("newBranch");
            var updateName = page.With(p => p.Name == "modified name");

            sut.Commit(updateName.Repository, signature, message); // B
            sut.Checkout("master");
            var updateNameOther = page.With(p => p.Name == "yet again modified name");

            sut.Commit(updateNameOther.Repository, signature, message); // C
            var loaded = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());

            Assert.Throws <RemainingConflictsException>(() => loaded.Merge("newBranch").Apply(signature));
        }
Exemplo n.º 16
0
        public void CloneRepository(IObjectRepositoryLoader loader)
        {
            // Act
            var loaded = loader.Clone <ObjectRepository>(RepositoryFixture.SmallRepositoryPath, RepositoryFixture.GetRepositoryDescription());

            // Assert
            Assert.That(loaded.Applications, Has.Count.EqualTo(2));
        }