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")); }
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 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 }
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); }
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)); }
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)); }
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)); }
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 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)); }
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)); }
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)); }