Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,74 +18,90 @@ public partial class RepositoriesApiTests
public async Task ShouldPostRepositoryAsync()
{
// given
Source randomSource = await PostRandomSourceAsync();
Repository randomRepository = await PostRandomRepository(sourceId: randomSource.Id);
Source randomSource = CreateRandomSource();
Source inputSource = randomSource;
Repository randomRepository = CreateRandomRepository(inputSource.Id);
Repository inputRepository = randomRepository;
Repository expectedRepository = inputRepository.DeepClone();

// when
await this.gitFyleCoreApiBroker.PostSourceAsync(inputSource);
inputRepository.SourceId = inputSource.Id;
expectedRepository.SourceId = inputSource.Id;
await this.gitFyleCoreApiBroker.PostRepositoryAsync(inputRepository);

Repository actualRepository =
await this.gitFyleCoreApiBroker.GetRepositoryByIdAsync(inputRepository.Id);

// then
actualRepository.Should().BeEquivalentTo(expectedRepository);
await this.gitFyleCoreApiBroker.DeleteRepositoryByIdAsync(actualRepository.Id);
await this.gitFyleCoreApiBroker.DeleteSourceByIdAsync(randomSource.Id);
await this.gitFyleCoreApiBroker.DeleteSourceByIdAsync(inputSource.Id);
}

[Fact]
public async Task ShouldGetRepositoryByIdAsync()
{
// given
Source randomSource = await PostRandomSourceAsync();
Repository randomRepository = await PostRandomRepository(sourceId: randomSource.Id);
Source randomSource = CreateRandomSource();
Source inputSource = randomSource;
Repository randomRepository = CreateRandomRepository(inputSource.Id);
Repository inputRepository = randomRepository;
Repository expectedRepository = inputRepository.DeepClone();

// when
await this.gitFyleCoreApiBroker.PostSourceAsync(inputSource);
randomRepository.SourceId = inputSource.Id;
expectedRepository.SourceId = inputSource.Id;
await this.gitFyleCoreApiBroker.PostRepositoryAsync(randomRepository);

Repository actualRepository =
await this.gitFyleCoreApiBroker.GetRepositoryByIdAsync(inputRepository.Id);
await this.gitFyleCoreApiBroker.GetRepositoryByIdAsync(randomRepository.Id);

// then
actualRepository.Should().BeEquivalentTo(expectedRepository);
await this.gitFyleCoreApiBroker.DeleteRepositoryByIdAsync(actualRepository.Id);
await this.gitFyleCoreApiBroker.DeleteSourceByIdAsync(randomSource.Id);
await this.gitFyleCoreApiBroker.DeleteSourceByIdAsync(inputSource.Id);
}

[Fact]
public async Task ShouldGetAllRepositoriesAsync()
{
// given
Source randomSource = await PostRandomSourceAsync();
Source randomSource = CreateRandomSource();

List<Repository> inputRepositories =
await PostRandomRepositoriesAsync(sourceId: randomSource.Id);
List<Repository> randomRepositories =
CreateRandomRepositories(randomSource.Id);

IEnumerable<Repository> expectedRepositories = inputRepositories;
List<Repository> expectedRepositories =
randomRepositories;

// when
IEnumerable<Repository> actualRepositories =
List<Repository> actualRepositories =
await this.gitFyleCoreApiBroker.GetAllRepositoriesAsync();

// then
foreach (Repository expectedRepository in expectedRepositories)
foreach (Repository expectedRepository in actualRepositories)
{
Repository actualRepository =
actualRepositories.Single(repository => repository.Id == expectedRepository.Id);
actualRepositories.Single(
product => product.Id == expectedRepository.Id);

actualRepository.Should().BeEquivalentTo(expectedRepository);
await this.gitFyleCoreApiBroker.DeleteRepositoryByIdAsync(actualRepository.Id);
}

await this.gitFyleCoreApiBroker.DeleteSourceByIdAsync(randomSource.Id);
await this.gitFyleCoreApiBroker
.DeleteRepositoryByIdAsync(actualRepository.Id);
}
}

[Fact]
public async Task ShouldPutRepositoryAsync()
{
// given
Source randomSource = await PostRandomSourceAsync();
Repository modifiedRepository = await ModifyRandomRepository(sourceId: randomSource.Id);

Repository modifiedRepository =
await ModifyRandomRepository(sourceId: randomSource.Id);

// when
await this.gitFyleCoreApiBroker.PutRepositoryAsync(modifiedRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ private async Task<List<Repository>> PostRandomRepositoriesAsync(Guid sourceId)
return repositories;
}

private static IQueryable<Repository> CreateRandomRepositories(Guid sourceId)
private static List<Repository> CreateRandomRepositories(Guid sourceId)
{
return CreateRepositoryFiller(sourceId)
.Create(GetRandomNumber())
.AsQueryable();
.ToList();
}

private async ValueTask<Repository> ModifyRandomRepository(Guid sourceId)
Expand All @@ -49,9 +49,15 @@ private async ValueTask<Repository> ModifyRandomRepository(Guid sourceId)
return randomRepository;
}

private static DateTimeOffset GetRandomDateTimeOffset() =>
new DateTimeRange(earliestDate: new DateTime()).GetValue();

private static int GetRandomNumber() =>
new IntRange(min: 2, max: 10).GetValue();

private static string GetRandomString() =>
new MnemonicString(wordCount: GetRandomNumber()).GetValue();

private async ValueTask<Repository> PostRandomRepository(Guid sourceId)
{
Repository randomRepository = CreateRandomRepository(sourceId);
Expand All @@ -65,11 +71,12 @@ private static Repository CreateRandomRepository(Guid sourceId) =>

private static Filler<Repository> CreateRepositoryFiller(Guid sourceId)
{
DateTimeOffset now = DateTimeOffset.UtcNow;
string someUser = Guid.NewGuid().ToString();
var filler = new Filler<Repository>();

filler.Setup()
.OnType<DateTimeOffset>().Use(DateTimeOffset.UtcNow)
.OnType<DateTimeOffset>().Use(now)
.OnProperty(repository => repository.SourceId).Use(sourceId)
.OnProperty(repository => repository.CreatedBy).Use(someUser)
.OnProperty(repository => repository.UpdatedBy).Use(someUser)
Expand All @@ -81,22 +88,23 @@ private static Filler<Repository> CreateRepositoryFiller(Guid sourceId)

private async ValueTask<Source> PostRandomSourceAsync()
{
Source randomSource = CreateRandomSource(DateTimeOffset.UtcNow);
Source randomSource = CreateRandomSource();
await this.gitFyleCoreApiBroker.PostSourceAsync(randomSource);

return randomSource;
}

private static Source CreateRandomSource(DateTimeOffset dateTimeOffset) =>
CreateSourceFiller(dateTimeOffset).Create();
private static Source CreateRandomSource() =>
CreateSourceFiller().Create();

private static Filler<Source> CreateSourceFiller(DateTimeOffset dateTimeOffset)
private static Filler<Source> CreateSourceFiller()
{
DateTimeOffset now = DateTimeOffset.UtcNow;
string someUser = Guid.NewGuid().ToString();
var filler = new Filler<Source>();

filler.Setup()
.OnType<DateTimeOffset>().Use(dateTimeOffset)
.OnType<DateTimeOffset>().Use(now)
.OnProperty(source => source.Url).Use(new RandomUrl().GetValue())
.OnProperty(source => source.CreatedBy).Use(someUser)
.OnProperty(source => source.UpdatedBy).Use(someUser)
Expand All @@ -106,4 +114,4 @@ private static Filler<Source> CreateSourceFiller(DateTimeOffset dateTimeOffset)
return filler;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public async ValueTask<Repository> PostRepositoryAsync(Repository repository) =>
public async ValueTask<Repository> GetRepositoryByIdAsync(Guid repositoryId) =>
await this.apiFactoryClient.GetContentAsync<Repository>($"{RepositoryRelativeUrl}/{repositoryId}");

public async ValueTask<IEnumerable<Repository>> GetAllRepositoriesAsync() =>
await this.apiFactoryClient.GetContentAsync<IEnumerable<Repository>>(RepositoryRelativeUrl);
public async ValueTask<List<Repository>> GetAllRepositoriesAsync() =>
await this.apiFactoryClient.GetContentAsync<List<Repository>>(RepositoryRelativeUrl);

public async ValueTask<Repository> PutRepositoryAsync(Repository repository) =>
await this.apiFactoryClient.PutContentAsync(RepositoryRelativeUrl, repository);
Expand Down