Browse Source

Add unit testing for document repository and application services.

pull/2826/head
maliming 7 years ago
parent
commit
41f918f2cf
  1. 55
      modules/docs/test/Volo.Docs.Admin.Application.Tests/Volo/Docs/DocumentAdminAppService_Tests.cs
  2. 25
      modules/docs/test/Volo.Docs.Domain.Tests/Volo/Docs/DocumentSourceFactory_Tests.cs
  3. 25
      modules/docs/test/Volo.Docs.Domain.Tests/Volo/Docs/DocumentStoreFactory_Tests.cs
  4. 14
      modules/docs/test/Volo.Docs.Domain.Tests/Volo/Docs/GithubDocumentSource_Tests.cs
  5. 6
      modules/docs/test/Volo.Docs.EntityFrameworkCore.Tests/Volo/Docs/EntityFrameworkCore/DocumentRepository_Tests.cs
  6. 9
      modules/docs/test/Volo.Docs.MongoDB.Tests/Volo/Docs/Document/DocumentRepository_Tests.cs
  7. 26
      modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestBase.cs
  8. 15
      modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestDataBuilder.cs
  9. 28
      modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocumentRepository_Tests.cs

55
modules/docs/test/Volo.Docs.Admin.Application.Tests/Volo/Docs/DocumentAdminAppService_Tests.cs

@ -0,0 +1,55 @@
using System.Threading.Tasks;
using Shouldly;
using Volo.Docs.Admin.Documents;
using Volo.Docs.Documents;
using Xunit;
namespace Volo.Docs
{
public class DocumentAdminAppService_Tests : DocsAdminApplicationTestBase
{
private readonly IDocumentAdminAppService _documentAdminAppService;
private readonly IDocumentRepository _documentRepository;
private readonly DocsTestData _testData;
public DocumentAdminAppService_Tests()
{
_documentAdminAppService = GetRequiredService<IDocumentAdminAppService>();
_documentRepository = GetRequiredService<IDocumentRepository>();
_testData = GetRequiredService<DocsTestData>();
}
[Fact]
public async Task PullAsync()
{
(await _documentRepository.FindAsync(_testData.PorjectId, "Part-I.md", "en", "1.0.0")).ShouldBeNull();
await _documentAdminAppService.PullAsync(new PullDocumentInput
{
ProjectId = _testData.PorjectId,
Name = "Part-I.md",
LanguageCode = "en",
Version = "1.0.0"
});
(await _documentRepository.FindAsync(_testData.PorjectId, "Part-I.md", "en", "1.0.0")).ShouldNotBeNull();
}
[Fact]
public async Task PullAllAsync()
{
(await _documentRepository.FindAsync(_testData.PorjectId, "Part-I.md", "en", "1.0.0")).ShouldBeNull();
(await _documentRepository.FindAsync(_testData.PorjectId, "Part-II.md", "en", "1.0.0")).ShouldBeNull();
await _documentAdminAppService.PullAllAsync(new PullAllDocumentInput
{
ProjectId = _testData.PorjectId,
LanguageCode = "en",
Version = "1.0.0"
});
(await _documentRepository.FindAsync(_testData.PorjectId, "Part-I.md", "en", "1.0.0")).ShouldNotBeNull();
(await _documentRepository.FindAsync(_testData.PorjectId, "Part-II.md", "en", "1.0.0")).ShouldNotBeNull();
}
}
}

25
modules/docs/test/Volo.Docs.Domain.Tests/Volo/Docs/DocumentSourceFactory_Tests.cs

@ -0,0 +1,25 @@
using Shouldly;
using Volo.Docs.Documents;
using Volo.Docs.FileSystem.Documents;
using Volo.Docs.GitHub.Documents;
using Xunit;
namespace Volo.Docs
{
public class DocumentSourceFactory_Tests : DocsDomainTestBase
{
private readonly IDocumentSourceFactory _documentSourceFactory;
public DocumentSourceFactory_Tests()
{
_documentSourceFactory = GetRequiredService<IDocumentSourceFactory>();
}
[Fact]
public void Create()
{
_documentSourceFactory.Create(GithubDocumentSource.Type).GetType().ShouldBe(typeof(GithubDocumentSource));
_documentSourceFactory.Create(FileSystemDocumentSource.Type).GetType().ShouldBe(typeof(FileSystemDocumentSource));
}
}
}

25
modules/docs/test/Volo.Docs.Domain.Tests/Volo/Docs/DocumentStoreFactory_Tests.cs

@ -1,25 +0,0 @@
using Shouldly;
using Volo.Docs.Documents;
using Volo.Docs.FileSystem.Documents;
using Volo.Docs.GitHub.Documents;
using Xunit;
namespace Volo.Docs
{
public class DocumentStoreFactory_Tests : DocsDomainTestBase
{
private readonly IDocumentSourceFactory _documentStoreFactory;
public DocumentStoreFactory_Tests()
{
_documentStoreFactory = GetRequiredService<IDocumentSourceFactory>();
}
[Fact]
public void Create()
{
_documentStoreFactory.Create(GithubDocumentSource.Type).GetType().ShouldBe(typeof(GithubDocumentSource));
_documentStoreFactory.Create(FileSystemDocumentSource.Type).GetType().ShouldBe(typeof(FileSystemDocumentSource));
}
}
}

14
modules/docs/test/Volo.Docs.Domain.Tests/Volo/Docs/GithubDocumentStore_Tests.cs → modules/docs/test/Volo.Docs.Domain.Tests/Volo/Docs/GithubDocumentSource_Tests.cs

@ -7,15 +7,15 @@ using Xunit;
namespace Volo.Docs
{
public class GithubDocumentStore_Tests : DocsDomainTestBase
public class GithubDocumentSource_Tests : DocsDomainTestBase
{
private readonly IDocumentSourceFactory _documentStoreFactory;
private readonly IDocumentSourceFactory _documentSourceFactory;
private readonly IProjectRepository _projectRepository;
private readonly DocsTestData _testData;
public GithubDocumentStore_Tests()
public GithubDocumentSource_Tests()
{
_documentStoreFactory = GetRequiredService<IDocumentSourceFactory>();
_documentSourceFactory = GetRequiredService<IDocumentSourceFactory>();
_projectRepository = GetRequiredService<IProjectRepository>();
_testData = GetRequiredService<DocsTestData>();
}
@ -23,7 +23,7 @@ namespace Volo.Docs
[Fact]
public async Task GetDocumentAsync()
{
var source = _documentStoreFactory.Create(GithubDocumentSource.Type);
var source = _documentSourceFactory.Create(GithubDocumentSource.Type);
var project = await _projectRepository.FindAsync(_testData.PorjectId);
project.ShouldNotBeNull();
@ -40,7 +40,7 @@ namespace Volo.Docs
[Fact]
public async Task GetVersionsAsync()
{
var source = _documentStoreFactory.Create(GithubDocumentSource.Type);
var source = _documentSourceFactory.Create(GithubDocumentSource.Type);
var project = await _projectRepository.FindAsync(_testData.PorjectId);
project.ShouldNotBeNull();
@ -55,7 +55,7 @@ namespace Volo.Docs
[Fact]
public async Task GetResource()
{
var source = _documentStoreFactory.Create(GithubDocumentSource.Type);
var source = _documentSourceFactory.Create(GithubDocumentSource.Type);
var project = await _projectRepository.FindAsync(_testData.PorjectId);
project.ShouldNotBeNull();

6
modules/docs/test/Volo.Docs.EntityFrameworkCore.Tests/Volo/Docs/EntityFrameworkCore/DocumentRepository_Tests.cs

@ -0,0 +1,6 @@
namespace Volo.Docs.EntityFrameworkCore
{
public class DocumentRepository_Tests : DocumentRepository_Tests<DocsEntityFrameworkCoreTestModule>
{
}
}

9
modules/docs/test/Volo.Docs.MongoDB.Tests/Volo/Docs/Document/DocumentRepository_Tests.cs

@ -0,0 +1,9 @@
using Volo.Docs.MongoDB;
namespace Volo.Docs.Document
{
public class DocumentRepository_Tests : DocumentRepository_Tests<DocsMongoDBTestModule>
{
}
}

26
modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestBase.cs

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
@ -23,6 +23,11 @@ namespace Volo.Docs
var repositoryManager = Substitute.For<IGithubRepositoryManager>();
repositoryManager.GetFileRawStringContentAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
.Returns("stringContent");
repositoryManager.GetFileRawStringContentAsync(
Arg.Is<string>(x => x.Contains("docs-nav.json", StringComparison.InvariantCultureIgnoreCase)),
Arg.Any<string>(), Arg.Any<string>())
.Returns("{\"items\":[{\"text\":\"Part-I.md\",\"path\":\"Part-I.md\"},{\"text\":\"Part-II\",\"path\":\"Part-II.md\"}]}");
repositoryManager.GetFileRawByteArrayContentAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
.Returns(new byte[] { 0x01, 0x02, 0x03 });
repositoryManager.GetReleasesAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
@ -47,6 +52,25 @@ namespace Volo.Docs
"https://api.github.com/repos/abpframework/abp/zipball/0.15.0",
null)
});
repositoryManager.GetFileCommitsAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<string>())
.Returns(new List<GitHubCommit>
{
new GitHubCommit("", "", "", "", "", null, null,
new Author("hikalkan ", 2, "", "https://avatars1.githubusercontent.com/u/1?v=4", "",
"https://github.com/hikalkan", "", "", "", "", "", "", "", "", "", "", false), "",
new Commit("", "", "", "", "", null, null, "", new Committer("", "", DateTimeOffset.Now),
null, null, new []{ new GitReference("", "", "", "", "", null, null) }, 1, null),
null, "", null, new []{ new GitReference("", "", "", "", "", null, null) }, null),
new GitHubCommit("", "", "", "", "", null, null,
new Author("ebicoglu ", 2, "", "https://avatars1.githubusercontent.com/u/2?v=4", "",
"https://github.com/ebicoglu", "", "", "", "", "", "", "", "", "", "", false), "",
new Commit("", "", "", "", "", null, null, "", new Committer("", "", DateTimeOffset.Now),
null, null, new []{ new GitReference("", "", "", "", "", null, null) }, 1, null),
null, "", null, new []{ new GitReference("", "", "", "", "", null, null) }, null)
});
services.AddSingleton(repositoryManager);
}
}

15
modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestDataBuilder.cs

@ -1,6 +1,8 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Docs.Documents;
using Volo.Docs.GitHub.Documents;
using Volo.Docs.Projects;
@ -10,13 +12,16 @@ namespace Volo.Docs
{
private readonly DocsTestData _testData;
private readonly IProjectRepository _projectRepository;
private readonly IDocumentRepository _documentRepository;
public DocsTestDataBuilder(
DocsTestData testData,
IProjectRepository projectRepository)
IProjectRepository projectRepository,
IDocumentRepository documentRepository)
{
_testData = testData;
_projectRepository = projectRepository;
_documentRepository = documentRepository;
}
public async Task BuildAsync()
@ -38,6 +43,12 @@ namespace Volo.Docs
.SetProperty("GitHubUserAgent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
await _projectRepository.InsertAsync(project);
await _documentRepository.InsertAsync(new Document(Guid.NewGuid(), project.Id, "CLI.md", "2.0.0", "en", "CLI.md",
"this is abp cli", "md", "https://github.com/abpframework/abp/blob/2.0.0/docs/en/CLI.md",
"https://github.com/abpframework/abp/tree/2.0.0/docs/",
"https://raw.githubusercontent.com/abpframework/abp/2.0.0/docs/en/", "", DateTime.Now, 1,
DateTime.Now));
}
}
}

28
modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocumentRepository_Tests.cs

@ -0,0 +1,28 @@
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Modularity;
using Volo.Docs.Documents;
using Xunit;
namespace Volo.Docs
{
public abstract class DocumentRepository_Tests<TStartupModule> : DocsTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
protected readonly IDocumentRepository DocumentRepository;
protected readonly DocsTestData DocsTestData;
protected DocumentRepository_Tests()
{
DocumentRepository = GetRequiredService<IDocumentRepository>();
DocsTestData = GetRequiredService<DocsTestData>();
}
[Fact]
public async Task FindAsync()
{
var document = await DocumentRepository.FindAsync(DocsTestData.PorjectId, "CLI.md", "en", "2.0.0");
document.ShouldNotBeNull();
}
}
}
Loading…
Cancel
Save