Skip to content

Commit

Permalink
Removed NullRelease, Using only GitHubRelease and HistoryRelease now.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcduiker committed Jun 19, 2020
1 parent 3060f9b commit 75f6d88
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void GivenHistoryReleaseIsNullRelease_WhenIsNewAndShouldBeStoredIsCalled_
const string repoName = "repo";
var repoConfig = RepositoryConfigurationBuilder.BuildOne(repoName);
var releasesFromGitHub = RepositoryReleaseBuilder.BuildListContainingOneWithReleaseId<GitHubRepositoryRelease>(repoName, 1);
var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<HistoryNullRelease>(repoName);
var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<HistoryRepositoryRelease>(repoName);
var releaseMatchFunction = ReleaseFunctionBuilder.BuildForMatchingRepositoryName();

// Act
Expand Down Expand Up @@ -58,8 +58,8 @@ public void GivenHistoryReleaseIsNullReleaseAndGitHubReleaseIsNullRelease_WhenIs
// Arrange
const string repoName = "repo";
var repoConfig = RepositoryConfigurationBuilder.BuildOne(repoName);
var releasesFromGitHub = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<GitHubNullRelease>(repoName);
var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<HistoryNullRelease>(repoName);
var releasesFromGitHub = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<GitHubRepositoryRelease>(repoName);
var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<HistoryRepositoryRelease>(repoName);
var releaseMatchFunction = ReleaseFunctionBuilder.BuildForMatchingRepositoryName();

// Act
Expand Down Expand Up @@ -106,7 +106,7 @@ public void GivenHistoryReleaseIsNullReleaseAndGitHubReleaseIsWithinTimeWindow_W
var gitHubReleaseDate = DateTimeOffset.UtcNow.Subtract(daysTimespan);
var repoConfig = RepositoryConfigurationBuilder.BuildOne(repoName);
var releasesFromGitHub = RepositoryReleaseBuilder.BuildListContainingOneWithReleaseIdAndDate<GitHubRepositoryRelease>(repoName, releaseIdGithub, gitHubReleaseDate);
var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<HistoryNullRelease>(repoName);
var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<HistoryRepositoryRelease>(repoName);
var releaseMatchFunction = ReleaseFunctionBuilder.BuildForMatchingRepositoryName();

// Act
Expand All @@ -127,11 +127,11 @@ public void GivenHistoryReleaseIsNullReleaseAndGitHubReleaseIsOutsideTimeWindow_
// Arrange
const string repoName = "repo";
const int releaseIdGithub = 1;
var daysTimespan = new TimeSpan(5, 0, 0, 0);
var daysTimespan = new TimeSpan(8, 0, 0, 0);
var gitHubReleaseDate = DateTimeOffset.UtcNow.Subtract(daysTimespan);
var repoConfig = RepositoryConfigurationBuilder.BuildOne(repoName);
var releasesFromGitHub = RepositoryReleaseBuilder.BuildListContainingOneWithReleaseIdAndDate<GitHubRepositoryRelease>(repoName, releaseIdGithub, gitHubReleaseDate);
var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<HistoryNullRelease>(repoName);
var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease<HistoryRepositoryRelease>(repoName);
var releaseMatchFunction = ReleaseFunctionBuilder.BuildForMatchingRepositoryName();

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,34 @@ public static Mock<IDurableOrchestrationContext> BuildWithoutHistoryAndWithGitHu
// Setup GetLatestReleaseFromGitHub
var gitHubRepositoryReleaseRepo1 = RepositoryReleaseBuilder.BuildOne<GitHubRepositoryRelease>(repository1Name);
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<GitHubRepositoryRelease>(
nameof(GetLatestReleaseFromGitHubActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
.ReturnsAsync(gitHubRepositoryReleaseRepo1);

var gitHubRepositoryReleaseRepo2 = RepositoryReleaseBuilder.BuildOne<GitHubRepositoryRelease>(repository2Name);
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<GitHubRepositoryRelease>(
nameof(GetLatestReleaseFromGitHubActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository2Name))))
.ReturnsAsync(gitHubRepositoryReleaseRepo2);

// Setup GetLatestReleaseFromHistory
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<HistoryRepositoryRelease>(
nameof(GetLatestReleaseFromHistoryActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<HistoryNullRelease>(repository1Name));
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<HistoryRepositoryRelease>(repository1Name));

mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<HistoryRepositoryRelease>(
nameof(GetLatestReleaseFromHistoryActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository2Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<HistoryNullRelease>(repository2Name));
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<HistoryRepositoryRelease>(repository2Name));

// Setup SaveLatestRelease
mockContext
Expand All @@ -72,6 +72,8 @@ public static Mock<IDurableOrchestrationContext> BuildWithoutHistoryAndWithGitHu
It.Is<RepositoryRelease>(r => r.RepositoryName.Equals(repository1Name))))
.ReturnsAsync(gitHubRepositoryReleaseRepo1);

mockContext.Setup(c => c.SetCustomStatus(It.IsAny<LatestReleases>()));

mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
nameof(SaveLatestReleaseActivity),
Expand Down Expand Up @@ -118,7 +120,7 @@ public static Mock<IDurableOrchestrationContext> BuildWithoutHistoryAndGitHubRet
// Setup GetLatestReleaseFromGitHub
var gitHubReleaseRepo1 = RepositoryReleaseBuilder.BuildOne<GitHubRepositoryRelease>(repository1Name);
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<GitHubRepositoryRelease>(
nameof(GetLatestReleaseFromGitHubActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
Expand All @@ -127,26 +129,28 @@ public static Mock<IDurableOrchestrationContext> BuildWithoutHistoryAndGitHubRet

// Returns NullRelease because no release info is retrieved from GitHub
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<GitHubRepositoryRelease>(
nameof(GetLatestReleaseFromGitHubActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository2Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<GitHubNullRelease>(repository2Name));
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<GitHubRepositoryRelease>(repository2Name));

// Setup GetLatestReleaseFromHistory
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<HistoryRepositoryRelease>(
nameof(GetLatestReleaseFromHistoryActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<HistoryNullRelease>(repository1Name));
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<HistoryRepositoryRelease>(repository1Name));

mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<HistoryRepositoryRelease>(
nameof(GetLatestReleaseFromHistoryActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository2Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<HistoryNullRelease>(repository2Name));
.ReturnsAsync(RepositoryReleaseBuilder.BuildNullRelease<HistoryRepositoryRelease>(repository2Name));

mockContext.Setup(c => c.SetCustomStatus(It.IsAny<LatestReleases>()));

// Setup SaveLatestRelease
mockContext
Expand Down Expand Up @@ -189,34 +193,36 @@ public static Mock<IDurableOrchestrationContext> BuildWithHistoryAndWithGitHubWi

// Setup GetLatestReleaseFromGitHub
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<GitHubRepositoryRelease>(
nameof(GetLatestReleaseFromGitHubActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildOneWithReleaseId<GitHubRepositoryRelease>(repository1Name, releaseIdRepo1));

mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<GitHubRepositoryRelease>(
nameof(GetLatestReleaseFromGitHubActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository2Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildOneWithReleaseId<GitHubRepositoryRelease>(repository2Name, releaseIdRepo2));

// Setup GetLatestReleaseFromHistory
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<HistoryRepositoryRelease>(
nameof(GetLatestReleaseFromHistoryActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildOneWithReleaseId<HistoryRepositoryRelease>(repository1Name, releaseIdRepo1));

mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<HistoryRepositoryRelease>(
nameof(GetLatestReleaseFromHistoryActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository2Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildOneWithReleaseId<HistoryRepositoryRelease>(repository2Name, releaseIdRepo2));

mockContext.Setup(c => c.SetCustomStatus(It.IsAny<LatestReleases>()));

return mockContext;
}

Expand Down Expand Up @@ -244,7 +250,7 @@ public static Mock<IDurableOrchestrationContext> BuildWithHistoryAndWithGitHubWi

// Setup GetLatestReleaseFromGitHub
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<GitHubRepositoryRelease>(
nameof(GetLatestReleaseFromGitHubActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
Expand All @@ -254,27 +260,29 @@ public static Mock<IDurableOrchestrationContext> BuildWithHistoryAndWithGitHubWi
repository2Name,
releaseIdGithubRepo2);
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<GitHubRepositoryRelease>(
nameof(GetLatestReleaseFromGitHubActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository2Name))))
.ReturnsAsync(gitHubRepositoryReleaseRepo2);

// Setup GetLatestReleaseFromHistory
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<HistoryRepositoryRelease>(
nameof(GetLatestReleaseFromHistoryActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildOneWithReleaseId<HistoryRepositoryRelease>(repository1Name, releaseIdHistoryRepo1));

mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<HistoryRepositoryRelease>(
nameof(GetLatestReleaseFromHistoryActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository2Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildOneWithReleaseId<HistoryRepositoryRelease>(repository2Name, releaseIdHistoryRepo2));

mockContext.Setup(c => c.SetCustomStatus(It.IsAny<LatestReleases>()));

// Setup SaveLatestRelease
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
Expand Down Expand Up @@ -315,21 +323,22 @@ public static Mock<IDurableOrchestrationContext> BuildWithHistoryAndWithGitHubWi

// Setup GetLatestReleaseFromGitHub
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<GitHubRepositoryRelease>(
nameof(GetLatestReleaseFromGitHubActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildOneWithReleaseId<GitHubRepositoryRelease>(repository1Name, releaseIdGithubRepo1));

// Setup GetLatestReleaseFromHistory
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
.Setup(c => c.CallActivityWithRetryAsync<HistoryRepositoryRelease>(
nameof(GetLatestReleaseFromHistoryActivity),
It.IsAny<RetryOptions>(),
It.Is<RepositoryConfiguration>(r => r.RepositoryName.Equals(repository1Name))))
.ReturnsAsync(RepositoryReleaseBuilder.BuildOneWithReleaseId<HistoryRepositoryRelease>(repository1Name, releaseIdHistoryRepo1));


mockContext.Setup(c => c.SetCustomStatus(It.IsAny<LatestReleases>()));

// Setup SaveLatestRelease, throws
mockContext
.Setup(c => c.CallActivityWithRetryAsync<RepositoryRelease>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ public static T BuildOneWithShortRepoAndReleaseNameOnAspecificDate<T>()
}

public static T BuildNullRelease<T>(string repositoryName)
where T : NullRelease
where T : RepositoryRelease
{
var release =_fixture.Build<T>()
.With(r => r.RepositoryName, repositoryName)
.Without(r => r.PartitionKey)
.Create();

return release;
Expand All @@ -92,7 +93,7 @@ public static IReadOnlyList<RepositoryRelease> BuildListContainingOneWithRelease
}

public static IReadOnlyList<RepositoryRelease> BuildListContainingOneNullRelease<T>(string repositoryName)
where T : NullRelease
where T : RepositoryRelease
{
return new List<RepositoryRelease>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class SaveLatestReleaseActivity
{
[FunctionName(nameof(SaveLatestReleaseActivity))]
[return: Table(Configuration.Releases.TableName, Connection = Configuration.ConnectionName)]
public RepositoryRelease Run(
[ActivityTrigger] RepositoryRelease repoRelease,
public GitHubRepositoryRelease Run(
[ActivityTrigger] GitHubRepositoryRelease repoRelease,
ILogger logger)
{
logger.LogInformation($"Started {nameof(SaveLatestReleaseActivity)} for " +
Expand Down
4 changes: 3 additions & 1 deletion src/AzureFunctionsUpdates/Builders/LatestObjectsBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AzureFunctionsUpdates.Models.RepositoryReleases;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,8 +11,9 @@ public static TLatest Build<TConfiguration, TRelease, TLatest>(
TConfiguration configuration,
IEnumerable<TRelease> newObjects,
IEnumerable<TRelease> historicalObjects,
Func<TConfiguration, TRelease, bool> matchObject)
Func<TConfiguration, TRelease, bool> matchObject)
where TLatest : new()

{
var latestNew = newObjects.First(obj => matchObject(configuration, obj));
var latestHistorical = historicalObjects.First(obj => matchObject(configuration, obj));
Expand Down
4 changes: 2 additions & 2 deletions src/AzureFunctionsUpdates/Clients/TimerBasedStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace AzureFunctionsUpdates.Clients
public class TimerBasedStarter
{
[FunctionName(nameof(TimerBasedStarter))]
public async Task Run([TimerTrigger("0 0 */1 * * *")]TimerInfo timer,
public async Task Run([TimerTrigger("0 0 */2 * * *")]TimerInfo timer,
[DurableClient] IDurableOrchestrationClient client,
ILogger logger)
{
await client.StartNewAsync(nameof(ReleaseUpdateOrchestration), null);
await client.StartNewAsync(nameof(PublicationUpdateOrchestration), null);
// await client.StartNewAsync(nameof(PublicationUpdateOrchestration), null);
}
}
}
12 changes: 6 additions & 6 deletions src/AzureFunctionsUpdates/Models/Publications/NullPublication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class NullPublication : Publication
public NullPublication(string publicationSourceName) :
base (
publicationSourceName: publicationSourceName,
id: default(string),
publicationDate: default(DateTimeOffset),
title: default(string),
description: default(string),
url: default(string),
hashTags: default(string)
id: default,
publicationDate: default,
title: default,
description: default,
url: default,
hashTags: default
)
{}
}
Expand Down
Loading

0 comments on commit 75f6d88

Please sign in to comment.