public void DownloadCommitWithAddedBinaryItem() { var push = CreatePushRequest("b6f447775f71a092854a2555eea084bd6d19958e"); var fakeDownloadRequest = new Fakes.StubIDownloadRequest() { DownloadChangesInCommitAsyncStringGuidCancellationToken = (commitId, repositoryId, token) => { var changes = new ItemChange[] { new ItemChange(ItemChangeType.Add, new Item("/favicon.ico")) }; return Task.FromResult(changes.AsEnumerable()); }, DownloadItemAndContentInCommitAsyncItemChangeStringGuidCancellationToken = (itemChange, commitId, repositoryId, token) => { itemChange.Item.ContentMetadata = CreateBinaryContentMetadataTestData(); itemChange.NewContent = CreateBinaryContentTestData(); return Task.FromResult(0); } }; var repo = new SourceRepository(fakeDownloadRequest); repo.DownloadChangesAsync(push, "/", CancellationToken.None).Wait(); var change = push.Commits.Single().Changes.Single(); Assert.AreEqual(ItemChangeType.Add, change.ChangeType); Assert.AreEqual("/favicon.ico", change.Item.Path); Assert.IsTrue(change.Item.ContentMetadata.IsBinary); Assert.AreEqual("image/x-icon", change.Item.ContentMetadata.ContentType); Assert.IsNotNull(change.NewContent); Assert.AreEqual(ItemContentType.Base64Encoded, change.NewContent.ContentType); Assert.AreEqual(12, change.NewContent.Content.Length); }
public void DownloadCommitWithAddedTextItem() { var push = CreatePushRequest("5597f65ce55386a771e4bf6fa190b5a26c0f5ce5"); var fakeDownloadRequest = new Fakes.StubIDownloadRequest() { DownloadChangesInCommitAsyncStringGuidCancellationToken = (commitId, repositoryId, token) => { var changes = new ItemChange[] { new ItemChange(ItemChangeType.Add, new Item("/index.html")) }; return Task.FromResult(changes.AsEnumerable()); }, DownloadItemAndContentInCommitAsyncItemChangeStringGuidCancellationToken = (itemChange, commitId, repositoryId, token) => { itemChange.Item.ContentMetadata = CreateTextContentMetadataTestData(); itemChange.NewContent = CreateTextContentTestData(); return Task.FromResult(0); } }; var repo = new SourceRepository(fakeDownloadRequest); repo.DownloadChangesAsync(push, "/", CancellationToken.None).Wait(); var change = push.Commits.Single().Changes.Single(); Assert.AreEqual(ItemChangeType.Add, change.ChangeType); Assert.AreEqual("/index.html", change.Item.Path); Assert.IsNotNull(change.Item.ContentMetadata); Assert.IsFalse(change.Item.ContentMetadata.IsBinary); Assert.AreEqual("text/html", change.Item.ContentMetadata.ContentType); Assert.IsNotNull(change.NewContent); Assert.AreEqual(ItemContentType.RawText, change.NewContent.ContentType); Assert.AreEqual("Testing", change.NewContent.Content); }
public void DownloadCommitWithRenamedTextItem() { var push = CreatePushRequest("de3e7a550c40fe75085d11e81d5770bc5b0dd33c"); var fakeDownloadRequest = new Fakes.StubIDownloadRequest() { DownloadChangesInCommitAsyncStringGuidCancellationToken = (commitId, repositoryId, token) => { var changes = new ItemChange[] { new ItemChange(ItemChangeType.Rename, new Item("/index.html")), new ItemChange(ItemChangeType.Delete | ItemChangeType.SourceRename, new Item("/index2.html")) }; return Task.FromResult(changes.AsEnumerable()); }, DownloadItemAndContentInCommitAsyncItemChangeStringGuidCancellationToken = (itemChange, commitId, repositoryId, token) => { if (itemChange.Item.Path == "/index.html") { itemChange.Item.ContentMetadata = CreateTextContentMetadataTestData(); itemChange.NewContent = CreateTextContentTestData(); } return Task.FromResult(0); } }; var repo = new SourceRepository(fakeDownloadRequest); repo.DownloadChangesAsync(push, "/", CancellationToken.None).Wait(); var index2Item = push.Commits.Single().Changes.Single(c => c.Item.Path == "/index2.html"); Assert.AreEqual(ItemChangeType.Delete | ItemChangeType.SourceRename, index2Item.ChangeType); var indexItem = push.Commits.Single().Changes.Single(c => c.Item.Path == "/index.html"); Assert.AreEqual(ItemChangeType.Rename, indexItem.ChangeType); Assert.IsNotNull(indexItem.Item.ContentMetadata); Assert.IsFalse(indexItem.Item.ContentMetadata.IsBinary); Assert.AreEqual("text/html", indexItem.Item.ContentMetadata.ContentType); Assert.IsNotNull(indexItem.NewContent); Assert.AreEqual(ItemContentType.RawText, indexItem.NewContent.ContentType); Assert.AreEqual("Testing", indexItem.NewContent.Content); }
public void DownloadNoChangesInRoot() { var push = CreatePushRequest("1b1859c414e800d24036b9ee547d1530431ae055"); var fakeDownloadRequest = new Fakes.StubIDownloadRequest() { DownloadChangesInCommitAsyncStringGuidCancellationToken = (commit, repositoryId, token) => { var changes = new ItemChange[] { new ItemChange(ItemChangeType.Edit, new Item("/index.html")), new ItemChange(ItemChangeType.Add, new Item("/index2.html")) }; return Task.FromResult(changes.AsEnumerable()); } }; var repo = new SourceRepository(fakeDownloadRequest); repo.DownloadChangesAsync(push, "/fake/", CancellationToken.None).Wait(); Assert.AreEqual(0, push.Commits.Single().Changes.Count()); }
public void DownloadCommitWithChanges() { var commitIdRequest = "1b1859c414e800d24036b9ee547d1530431ae055"; var pushRequest = CreatePushRequest(commitIdRequest); var fakeChanges = new ItemChange[] { new ItemChange(ItemChangeType.None, new Item("/index.html")) }; var fakeDownloadRequest = new Fakes.StubIDownloadRequest() { DownloadChangesInCommitAsyncStringGuidCancellationToken = (commitId, repositoryId, token) => { Assert.AreEqual(commitIdRequest, commitId); return Task.FromResult(fakeChanges.AsEnumerable()); } }; var repo = new SourceRepository(fakeDownloadRequest); repo.DownloadChangesAsync(pushRequest, "/", CancellationToken.None).Wait(); Assert.IsTrue(fakeChanges.SequenceEqual(pushRequest.Commits.Single().Changes)); }