-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for toggle update event (#153)
* Added support for toggle update event * Updated README for TogglesUpdatedEvent * Remove redundant parens per code analysis * Static code analysis wants 2 spaces, so I added two spaces for all event items in the list
- Loading branch information
1 parent
8158ccf
commit 76427ee
Showing
6 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Unleash.Internal | ||
{ | ||
public class TogglesUpdatedEvent | ||
{ | ||
public DateTime UpdatedOn { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using FakeItEasy; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Unleash.Communication; | ||
using Unleash.Internal; | ||
using Unleash.Scheduling; | ||
using Unleash.Serialization; | ||
using Unleash.Tests.Mock; | ||
|
||
namespace Unleash.Tests.Internal | ||
{ | ||
public class TogglesUpdatedEvent_Tests | ||
{ | ||
[Test] | ||
public void TogglesUpdated_Event_Gets_Called_For_HasChanged_True() | ||
{ | ||
// Arrange | ||
TogglesUpdatedEvent callbackEvent = null; | ||
var callbackConfig = new EventCallbackConfig | ||
{ | ||
TogglesUpdatedEvent = evt => { callbackEvent = evt; } | ||
}; | ||
|
||
var fakeApiClient = A.Fake<IUnleashApiClient>(); | ||
A.CallTo(() => fakeApiClient.FetchToggles(A<string>._, A<CancellationToken>._)) | ||
.Returns(Task.FromResult(new FetchTogglesResult { HasChanged = true, ToggleCollection = new ToggleCollection(), Etag = "one" })); | ||
|
||
var collection = new ThreadSafeToggleCollection(); | ||
var serializer = new DynamicNewtonsoftJsonSerializer(); | ||
serializer.TryLoad(); | ||
|
||
var filesystem = new MockFileSystem(); | ||
var tokenSource = new CancellationTokenSource(); | ||
var task = new FetchFeatureTogglesTask(fakeApiClient, collection, serializer, filesystem, callbackConfig, "togglefile.txt", "etagfile.txt"); | ||
|
||
// Act | ||
Task.WaitAll(task.ExecuteAsync(tokenSource.Token)); | ||
|
||
// Assert | ||
callbackEvent.Should().NotBeNull(); | ||
} | ||
|
||
[Test] | ||
public void TogglesUpdated_Event_Does_Not_Get_Called_For_HasChanged_False() | ||
{ | ||
// Arrange | ||
TogglesUpdatedEvent callbackEvent = null; | ||
var callbackConfig = new EventCallbackConfig | ||
{ | ||
TogglesUpdatedEvent = evt => { callbackEvent = evt; } | ||
}; | ||
|
||
var fakeApiClient = A.Fake<IUnleashApiClient>(); | ||
A.CallTo(() => fakeApiClient.FetchToggles(A<string>._, A<CancellationToken>._)) | ||
.Returns(Task.FromResult(new FetchTogglesResult { HasChanged = false, ToggleCollection = new ToggleCollection(), Etag = "one" })); | ||
|
||
var collection = new ThreadSafeToggleCollection(); | ||
var serializer = new DynamicNewtonsoftJsonSerializer(); | ||
serializer.TryLoad(); | ||
|
||
var filesystem = new MockFileSystem(); | ||
var tokenSource = new CancellationTokenSource(); | ||
var task = new FetchFeatureTogglesTask(fakeApiClient, collection, serializer, filesystem, callbackConfig, "togglefile.txt", "etagfile.txt"); | ||
|
||
// Act | ||
Task.WaitAll(task.ExecuteAsync(tokenSource.Token)); | ||
|
||
// Assert | ||
callbackEvent.Should().BeNull(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters