コード例 #1
0
        public void NoValidationErrorIfVersionIsLowerOrEqual(IObjectRepositoryContainer <ObjectRepository> container, ObjectRepository repository, ObjectRepository dependency, Signature signature, string message)
        {
            // Arrange
            container.AddRepository(dependency, signature, message);
            var newDependency = new RepositoryDependency(dependency, new System.Version(dependency.Version.Major - 1, 0));

            repository = repository.With(repository, r => r.Dependencies, repository.Dependencies.Add(newDependency));
            container.AddRepository(repository, signature, message);

            // Act
            var result = container.Validate();

            // Assert
            Assert.That(result.IsValid, Is.True);
        }
コード例 #2
0
        public void ThrowIfWrongDependencyVersion(IObjectRepositoryContainer <ObjectRepository> container, ObjectRepository repository, ObjectRepository dependency, Signature signature, string message)
        {
            // Arrange
            container.AddRepository(dependency, signature, message);
            var wrongDependency = new RepositoryDependency(dependency, new System.Version(dependency.Version.Major + 1, 0));

            repository = repository.With(repository, r => r.Dependencies, repository.Dependencies.Add(wrongDependency));
            container.AddRepository(repository, signature, message);

            // Act
            var result = container.Validate();

            // Assert
            Assert.That(result.ToString(), Does.Contain("should be of version"));
        }
コード例 #3
0
        public void PullRequiringMerge(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, IObjectRepositoryContainerFactory containerFactory, Signature signature, string message)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var tempPath        = RepositoryFixture.GetAvailableFolderPath();
            var clientContainer = containerFactory.Create <ObjectRepository>(tempPath);

            clientContainer.Clone(container.Repositories.Single().RepositoryDescription.Path);

            // Arrange - Update source repository
            var change = sut.With(sut.Applications[0].Pages[0], p => p.Description, "foo");

            sut = container.Commit(change.Repository, signature, message);

            // Arrange - Update client repository
            var clientChange = sut.With(sut.Applications[0].Pages[0], p => p.Name, "bar");

            clientContainer.Commit(clientChange.Repository, signature, message);

            // Act
            var pullResult = clientContainer.Pull(clientContainer.Repositories.Single().Id);

            pullResult.Apply(signature);

            // Assert
            Assert.That(pullResult.RequiresMergeCommit, Is.True);
            Assert.That(clientContainer.Repositories.Single().Applications[0].Pages[0].Description, Is.EqualTo("foo"));
        }
コード例 #4
0
        public void PreMergeGetsFiredWhenPulling(GitHooks sut, ObjectRepository repository, IObjectRepositoryContainer <ObjectRepository> origin, IObjectRepositoryContainerFactory containerFactory, Signature signature, string message)
        {
            // Arrange - Create origin and local repositories
            repository = origin.AddRepository(repository, signature, message);
            var tempPath        = RepositoryFixture.GetAvailableFolderPath();
            var clientContainer = containerFactory.Create <ObjectRepository>(tempPath);

            clientContainer.Clone(origin.Repositories.Single().RepositoryDescription.Path);

            // Arrange - Commit change on origin
            var change = repository.With(repository.Applications[0].Pages[0], p => p.Description, "foo");

            origin.Commit(change.Repository, signature, message);

            // Arrange - suscribe to hook
            MergeStartedEventArgs lastEvent = null;

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

            // Act - Pull commit from origin
            var pullResult = clientContainer.Pull(clientContainer.Repositories.Single().Id);
            var result     = pullResult.Apply(signature);

            // Assert
            Assert.That(lastEvent, Is.Not.Null);
            Assert.That(result, Is.Not.Null);
        }
コード例 #5
0
        public void MergeFileDeletionChange(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            var a = container.AddRepository(sut, signature, message); // A

            // Act
            a = container.Checkout(a.Id, "newBranch", createNewBranch: true);
            var page       = a.Applications[0].Pages[0];
            var updateName = a.With(c => c.Remove(page, p => p.Fields, page.Fields[1]));

            container.Commit(updateName, signature, message); // B
            a = container.Checkout(a.Id, "master");
            var updateDescription = a.With(a.Applications[0].Pages[0], p => p.Description, "modified description");
            var commitC           = container.Commit(updateDescription.Repository, signature, message); // C
            var mergeCommit       = container.Merge(sut.Id, "newBranch").Apply(signature);              // D

            // Assert
            var changes = computeTreeChangesFactory(container, container[sut.Id].RepositoryDescription)
                          .Compare(commitC.CommitId, mergeCommit)
                          .SkipIndexChanges();

            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));
        }
コード例 #6
0
        public void MergeFileAdditionChange(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, IServiceProvider serviceProvider, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            sut = container.AddRepository(sut, signature, message); // A

            // Act
            sut = container.Checkout(sut.Id, "newBranch", createNewBranch: true);
            var updateName = sut.With(c => c.Add(sut.Applications[0].Pages[0], p => p.Fields, new Field(serviceProvider, UniqueId.CreateNew(), "new field", FieldContent.Default)));

            container.Commit(updateName.Repository, signature, message); // B
            var a = container.Checkout(sut.Id, "master");
            var updateDescription = a.With(a.Applications[0].Pages[0], p => p.Description, "modified description");
            var commitC           = container.Commit(updateDescription.Repository, signature, message); // C
            var mergeCommit       = container.Merge(sut.Id, "newBranch").Apply(signature);              // D

            // Assert
            var changes = computeTreeChangesFactory(container, container[sut.Id].RepositoryDescription)
                          .Compare(commitC.CommitId, mergeCommit)
                          .SkipIndexChanges();

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Added));
            Assert.That(changes[0].New.Name, Is.EqualTo("new field"));
        }
コード例 #7
0
        public void MergeTwoDifferentPropertiesChanged(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            sut = container.AddRepository(sut, signature, message); // A

            // Act
            sut = container.Checkout(sut.Id, "newBranch", createNewBranch: true);
            var updateName = sut.With(sut.Applications[0].Pages[0], p => p.Name, "modified name");

            container.Commit(updateName.Repository, signature, message); // B
            var a = container.Checkout(sut.Id, "master");
            var updateDescription = a.With(a.Applications[0].Pages[0], p => p.Description, "modified description");
            var commitC           = container.Commit(updateDescription.Repository, signature, message); // C
            var mergeCommit       = container.Merge(sut.Id, "newBranch").Apply(signature);              // D

            // Assert
            var changes = computeTreeChangesFactory(container, container[sut.Id].RepositoryDescription)
                          .Compare(commitC.CommitId, mergeCommit)
                          .SkipIndexChanges();

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(changes[0].Old.Name, Is.EqualTo(sut.Applications[0].Pages[0].Name));
            Assert.That(changes[0].New.Name, Is.EqualTo(updateName.Name));
        }
コード例 #8
0
        public void ObjectDeletionIsAlsoDeletingBlobs(BlobRepository repository, IObjectRepositoryContainer <BlobRepository> container, Signature signature, string message)
        {
            // Arrange
            var a = container.AddRepository(repository, signature, message);

            // Act
            var b = container.Commit(
                repository.With(c => c.Remove(repository, r => r.Cars, repository.Cars[0])),
                signature,
                message);

            // Assert
            b.Execute(r =>
            {
                var changes = r.Diff.Compare <TreeChanges>(
                    r.Lookup <Commit>(a.CommitId).Tree,
                    r.Lookup <Commit>(b.CommitId).Tree);
                Assert.That(
                    changes.Deleted.Select(c => c.Path),
                    Is.EquivalentTo(new[]
                {
                    $"Cars/{a.Cars[0].Id}/blob{FileSystemStorage.BlobExtension}",
                    $"Cars/{a.Cars[0].Id}/{FileSystemStorage.DataFile}"
                }));
            });
        }
コード例 #9
0
        public void MergeSamePropertyConflict(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            var a = container.AddRepository(sut, signature, message); // A

            // Act
            a = container.Checkout(sut.Id, "newBranch", createNewBranch: true);
            var updateName = a.With(a.Applications[0].Pages[0], p => p.Name, "modified name");

            container.Commit(updateName.Repository, signature, message); // B
            a = container.Checkout(sut.Id, "master");
            var updateNameOther = a.With(a.Applications[0].Pages[0], p => p.Name, "yet again modified name");
            var commitC         = container.Commit(updateNameOther.Repository, signature, message); // C
            var merge           = container.Merge(sut.Id, "newBranch");
            var chunk           = merge.ModifiedProperties.Single();

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

            // Assert
            var changes = computeTreeChangesFactory(container, container[sut.Id].RepositoryDescription)
                          .Compare(commitC.CommitId, mergeCommit)
                          .SkipIndexChanges();

            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"));
        }
コード例 #10
0
        public void Search(IObjectRepositorySearch search, ObjectRepository repository, Field field, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            // Arrange
            container.AddRepository(repository, signature, message);

            // Act
            var found = search.Grep(container, field.Id.ToString()).ToList();

            // Assert
            Assert.That(found, Is.Not.Empty);
        }
コード例 #11
0
        public void PreCommitCancelsCommitIfRequested(GitHooks sut, ObjectRepository instance, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            // Arrange
            sut.CommitStarted += (_, args) => args.Cancel = true;

            // Act
            var update = container.AddRepository(instance, signature, message);

            // Assert
            Assert.That(update, Is.Null);
        }
コード例 #12
0
        public void CommitPageNameUpdate(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            // Act
            sut = container.AddRepository(sut, signature, message);
            var modifiedPage  = sut.With(sut.Applications[0].Pages[0], p => p.Name, "modified");
            var updated       = container.Commit(modifiedPage.Repository, signature, message);
            var retrievedPage = updated.Flatten().OfType <Page>().FirstOrDefault(p => p.Name == "modified");

            // Assert
            Assert.That(retrievedPage.Name, Is.EqualTo("modified"));
        }
コード例 #13
0
        public void BlobSerializedAsNestedFile(BlobRepository sut, IObjectRepositoryContainer <BlobRepository> container, Signature signature, string message)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);

            // Assert
            sut.Execute(r =>
            {
                var blob = (Blob)r.Head[$"blob{FileSystemStorage.BlobExtension}"].Target;
                Assert.AreEqual(sut.Blob.Value, blob.GetContentText());
            });
        }
コード例 #14
0
        public void ResolveLinkReferers(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var linkField = sut.Flatten().OfType <Field>().First(
                f => f.Content.MatchOrDefault(matchLink: l => true));
            var target = linkField.Content.MatchOrDefault(matchLink: c => c.Target).Link;

            // Act
            var referrers = sut.GetReferrers(target);

            // Assert
            Assert.That(referrers, Does.Contain(linkField));
        }
コード例 #15
0
        static void CreateConflictingChange(BlobRepository sut, IObjectRepositoryContainer <BlobRepository> container, Signature signature, string message)
        {
            // master:    A---B
            //             \    (B & C change same value)
            // newBranch:   C   ->   A---B---C
            var a          = container.AddRepository(sut, signature, message); // A
            var updateName = a.With(a, r => r.Blob, new StringBlob("x\nb\nc"));

            container.Commit(updateName.Repository, signature, message); // B
            container.Checkout(a.Id, "newBranch", createNewBranch: true, "HEAD~1");
            var updates = a.With(a, r => r.Blob, new StringBlob("z\nb\nd"));

            container.Commit(updates, signature, message);
        }
コード例 #16
0
        public void ThrowIfMissingDependency(IObjectRepositoryContainer <ObjectRepository> container, ObjectRepository repository, Signature signature, string message)
        {
            // Arrange
            var wrongDependency = new RepositoryDependency(UniqueId.CreateNew(), "foo", new System.Version(1, 0));

            repository = repository.With(repository, r => r.Dependencies, repository.Dependencies.Add(wrongDependency));
            container.AddRepository(repository, signature, message);

            // Act
            var result = container.Validate();

            // Assert
            Assert.That(result.ToString(), Does.Contain("could not be found"));
        }
コード例 #17
0
        public void ResolveLinkReferersUsingIndex(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var linkField = sut.Flatten().OfType <Field>().First(
                f => f.Content.MatchOrDefault(matchLink: l => true));
            var target = linkField.Content.MatchOrDefault(matchLink: c => c.Target).Link;

            // Act
            var index     = sut.Indexes.Single(i => i is LinkFieldReferrerIndex);
            var referrers = index[target.Path.FullPath];

            // Assert
            Assert.That(referrers, Does.Contain(linkField));
        }
コード例 #18
0
ファイル: PushTests.cs プロジェクト: frblondin/GitObjectDb
        static (string, ObjectRepository) PushNewRemoteImpl(ObjectRepository repository, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            var tempPath = RepositoryFixture.GetAvailableFolderPath();

            Repository.Init(tempPath, isBare: true);
            repository = container.AddRepository(repository, signature, message);
            repository.Execute(r => r.Network.Remotes.Add("origin", tempPath));

            var change = repository.With(repository.Applications[0].Pages[0], p => p.Description, "foo");

            repository = container.Commit(change.Repository, signature, message);

            container.Push(repository.Id, "origin");
            return(tempPath, repository);
        }
コード例 #19
0
        public void CreateAndLoadRepository(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, IObjectRepositoryContainerFactory containerFactory, Signature signature, string message)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);

            // Act
            var newContainer = containerFactory.Create <ObjectRepository>(container.Path);
            var loaded       = newContainer.Repositories.Single();

            // 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));
            }
        }
コード例 #20
0
        public void PostCommitWhenPropertyChangeGetsFired(GitHooks sut, ObjectRepository repository, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            // Arrange
            CommitCompletedEventArgs lastEvent = null;

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

            // Act
            repository = container.AddRepository(repository, signature, message);
            var modifiedPage = repository.With(repository.Applications[0].Pages[0], p => p.Name, "modified");
            var commit       = container.Commit(modifiedPage.Repository, signature, message);

            // Assert
            Assert.That(lastEvent, Is.Not.Null);
            Assert.That(lastEvent.CommitId, Is.EqualTo(commit.CommitId));
        }
コード例 #21
0
        public void IndexUpdateWhenPropertyIsBeingChanged(IServiceProvider serviceProvider, ObjectRepository repository, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, string name)
        {
            // Arrange
            repository = repository.With(c => c
                                         .Add(repository, r => r.Indexes, new Index(serviceProvider, UniqueId.CreateNew(), name, nameof(IModelObject.Name))));
            repository = container.AddRepository(repository, signature, message);
            ComputeKeysCalls.Clear();

            // Act
            var modified = repository.With(repository.Applications[0].Pages[1], p => p.Description, "modified description");

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

            // Assert
            Assert.That(ComputeKeysCalls, Has.Count.EqualTo(2)); // Two calls to ComputeKeys for before/after
        }
コード例 #22
0
        public void IndexUpdateWhenBlobIsBeingChanged(IServiceProvider serviceProvider, BlobRepository repository, IObjectRepositoryContainer <BlobRepository> container, Signature signature, string message, string name)
        {
            // Arrange
            repository = repository.With(c => c
                                         .Add(repository, r => r.Indexes, new Index(serviceProvider, UniqueId.CreateNew(), name, nameof(Car.Blob))));
            repository = container.AddRepository(repository, signature, message);
            IndexTests.ComputeKeysCalls.Clear();

            // Act
            var modified = repository.With(repository, r => r.Blob, new StringBlob("modified blob"));

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

            // Assert
            Assert.That(IndexTests.ComputeKeysCalls, Has.Count.EqualTo(2)); // Two calls to ComputeKeys for before/after
        }
コード例 #23
0
        public void MigrationScaffolderDetectsRequiredChanges(ObjectRepository repository, IObjectRepositoryContainer <ObjectRepository> container, IFixture fixture, IServiceProvider serviceProvider, Signature signature, string message)
        {
            // Arrange
            repository = container.AddRepository(repository, signature, message);
            var updated = repository.With(c => c.Add(repository, r => r.Migrations, fixture.Create <DummyMigration>()));
            var commit  = container.Commit(updated, signature, message);

            // Act
            var migrationScaffolder = new MigrationScaffolder(container, repository.RepositoryDescription,
                                                              serviceProvider.GetRequiredService <IRepositoryProvider>(), serviceProvider.GetRequiredService <ObjectRepositorySerializerFactory>());
            var migrators = migrationScaffolder.Scaffold(repository.CommitId, commit.CommitId, MigrationMode.Upgrade);

            // Assert
            Assert.That(migrators, Has.Count.EqualTo(1));
            Assert.That(migrators[0].CommitId, Is.EqualTo(commit.CommitId));
            Assert.That(migrators[0].Mode, Is.EqualTo(MigrationMode.Upgrade));
            Assert.That(migrators[0].Migrations, Has.Count.EqualTo(1));
        }
コード例 #24
0
        static IObjectRepositoryCherryPick CreateConflictingCherryPick(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            // master:    A---B
            //             \    (B & C change same property)
            // newBranch:   C   ->   A---C---B
            var a = container.AddRepository(sut, signature, message);                                   // A
            var b = container.Commit(
                a.With(a.Applications[0].Pages[0], p => p.Name, "foo").Repository, signature, message); // B

            a = container.Checkout(a.Id, "newBranch", createNewBranch: true, "HEAD~1");
            container.Commit(
                a.With(c => c
                       .Update(a.Applications[0].Pages[0], p => p.Name, "bar")
                       .Update(a.Applications[0].Pages[0], p => p.Description, "bar")
                       .Update(a.Applications[0].Pages[0].Fields[0], f => f.Name, "bar")),
                signature, message);
            return(container.CherryPick(sut.Id, b.CommitId));
        }
コード例 #25
0
        public void ResolveDiffsPageNameUpdate(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var modifiedPage = sut.With(sut.Applications[0].Pages[0], p => p.Name, "modified");
            var commit       = container.Commit(modifiedPage.Repository, signature, message);

            // Act
            var changes = computeTreeChangesFactory(container, sut.RepositoryDescription)
                          .Compare(sut.CommitId, commit.CommitId)
                          .SkipIndexChanges();

            // 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(sut.Applications[0].Pages[0].Name));
            Assert.That(changes[0].New.Name, Is.EqualTo(modifiedPage.Name));
        }
コード例 #26
0
        public void IndexUpdateWhenObjectIsBeingAdded(IServiceProvider serviceProvider, ObjectRepository repository, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, string name)
        {
            // Arrange
            repository = repository.With(c => c
                                         .Add(repository, r => r.Indexes, new Index(serviceProvider, UniqueId.CreateNew(), name, nameof(IModelObject.Name))));
            repository = container.AddRepository(repository, signature, message);
            ComputeKeysCalls.Clear();
            var page = new Page(serviceProvider, UniqueId.CreateNew(), "name", "description", new LazyChildren <Field>(ImmutableList.Create(
                                                                                                                           new Field(serviceProvider, UniqueId.CreateNew(), "name", FieldContent.Default))));

            // Act
            var modified = repository.With(c => c.Add(repository.Applications[0], app => app.Pages, page));

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

            // Assert
            Assert.That(ComputeKeysCalls, Has.Count.EqualTo(2));
        }
コード例 #27
0
        public void IndexUpdateWhenObjectIsBeingRemoved(IServiceProvider serviceProvider, ObjectRepository repository, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, string name)
        {
            // Arrange
            repository = repository.With(c => c
                                         .Add(repository, r => r.Indexes, new Index(serviceProvider, UniqueId.CreateNew(), name, nameof(IModelObject.Name))));
            repository = container.AddRepository(repository, signature, message);
            ComputeKeysCalls.Clear();

            // Act
            var modified = repository.With(c => c.Remove(repository.Applications[0], app => app.Pages, repository.Applications[0].Pages[0]));

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

            // Assert
            var nestedCount = repository.Applications[0].Pages[0].Flatten().Count();

            Assert.That(ComputeKeysCalls, Has.Count.EqualTo(nestedCount));
        }
コード例 #28
0
        public void ResolveDiffsBlobUpdate(BlobRepository sut, IObjectRepositoryContainer <BlobRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var modified = sut.With(sut, r => r.Blob, new StringBlob("z\nb\nz"));
            var commit   = container.Commit(modified.Repository, signature, message);

            // Act
            var changes = computeTreeChangesFactory(container, sut.RepositoryDescription)
                          .Compare(sut.CommitId, commit.CommitId)
                          .SkipIndexChanges();

            // Assert
            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(((BlobRepository)changes[0].Old).Blob, Is.EqualTo(sut.Blob));
            Assert.That(((BlobRepository)changes[0].New).Blob, Is.EqualTo(modified.Blob));
        }
コード例 #29
0
        public void LoadLinkField(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, IObjectRepositoryContainerFactory containerFactory, Signature signature, string message)
        {
            // Arrange
            container.AddRepository(sut, signature, message);
            var linkField = sut.Flatten().OfType <Field>().First(
                f => f.Content.MatchOrDefault(matchLink: l => true));

            // Act
            var newContainer    = containerFactory.Create <ObjectRepository>(container.Path);
            var loaded          = newContainer.Repositories.Single();
            var loadedLinkField = (Field)loaded.GetFromGitPath(linkField.GetFolderPath());

            // Assert
            var target    = linkField.Content.MatchOrDefault(matchLink: c => c.Target).Link;
            var newTarget = loadedLinkField.Content.MatchOrDefault(matchLink: c => c.Target).Link;

            Assert.That(newTarget.Id, Is.EqualTo(target.Id));
        }
コード例 #30
0
        public void CherryPickChildAddition(IServiceProvider serviceProvider, ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            // master:    A---B---C
            //             \
            // newBranch:   D   ->   A---D---C

            // Arrange
            var a = container.AddRepository(sut, signature, message); // A

            // Act
            var b = container.Commit(
                a.With(a.Applications[0], app => app.Name, "unpicked modified name").Repository,
                signature, message); // B
            var page = new Page(serviceProvider, UniqueId.CreateNew(), "name", "description", new LazyChildren <Field>());
            var c    = container.Commit(
                b.With(comp => comp.Add(b.Applications[0], app => app.Pages, page)).Repository,
                signature, message); // C

            a = container.Checkout(a.Id, "newBranch", createNewBranch: true, "HEAD~2");
            var d = container.Commit(
                a.With(a.Applications[0], app => app.Name, "modified name").Repository,
                signature, message); // D
            var cherryPick = container.CherryPick(sut.Id, c.CommitId);
            var repository = container.Repositories.Single();

            // Assert
            Assert.That(cherryPick.Status, Is.EqualTo(CherryPickStatus.CherryPicked));
            var(commits, tip) = repository.Execute(r =>
            {
                var commitFilter = new CommitFilter
                {
                    IncludeReachableFrom = r.Head.Tip,
                    SortBy = CommitSortStrategies.Reverse | CommitSortStrategies.Topological,
                };
                return(r.Commits.QueryBy(commitFilter).Select(commit => commit.Id).ToList(), r.Head.Tip.Id);
            });
            Assert.That(commits, Has.Count.EqualTo(3));
            Assert.That(commits[0], Is.EqualTo(a.CommitId));
            Assert.That(commits[1], Is.EqualTo(d.CommitId));
            Assert.That(commits[2], Is.EqualTo(tip));
            Assert.That(repository.CommitId, Is.EqualTo(tip));
            Assert.That(repository.Applications[0].Name, Is.EqualTo("modified name"));
            Assert.That(repository.Applications[0].Pages, Has.Count.EqualTo(a.Applications[0].Pages.Count + 1));
        }