-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace KafkaFlow | ||
Check warning on line 1 in src/KafkaFlow.Abstractions/IEvent.cs GitHub Actions / build
Check warning on line 1 in src/KafkaFlow.Abstractions/IEvent.cs GitHub Actions / build
Check warning on line 1 in src/KafkaFlow.Abstractions/IEvent.cs GitHub Actions / build
Check warning on line 1 in src/KafkaFlow.Abstractions/IEvent.cs GitHub Actions / build
|
||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
public interface IEvent | ||
{ | ||
void Subscribe(Func<Task> handle); | ||
} | ||
|
||
public interface IEvent<TArg> | ||
{ | ||
void Subscribe(Func<TArg, Task> handle); | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"profiles": { | ||
"KafkaFlow.Admin.Dashboard": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53859;http://localhost:53860" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
namespace KafkaFlow.UnitTests | ||
{ | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
[TestClass] | ||
public class EventTests | ||
{ | ||
[TestMethod] | ||
public async Task FireAsync_EventSubscribed_CallDelegateWithSuccess() | ||
{ | ||
// Arrange | ||
var numberOfCalls = 0; | ||
var log = new Mock<ILogHandler>(); | ||
|
||
var event1 = new Event(log.Object); | ||
|
||
event1.Subscribe(() => | ||
{ | ||
numberOfCalls++; | ||
return Task.CompletedTask; | ||
}); | ||
|
||
// Act | ||
await event1.FireAsync(); | ||
|
||
// Assert | ||
Assert.AreEqual(1, numberOfCalls); | ||
} | ||
|
||
[TestMethod] | ||
public async Task FireAsync_EventWithMultipleObservers_CallAllDelegatesWithSuccess() | ||
{ | ||
// Arrange | ||
var numberOfCalls = 0; | ||
var log = new Mock<ILogHandler>(); | ||
|
||
var event1 = new Event(log.Object); | ||
|
||
event1.Subscribe(() => | ||
{ | ||
numberOfCalls++; | ||
return Task.CompletedTask; | ||
}); | ||
|
||
event1.Subscribe(() => | ||
{ | ||
numberOfCalls++; | ||
return Task.CompletedTask; | ||
}); | ||
|
||
// Act | ||
await event1.FireAsync(); | ||
|
||
// Assert | ||
Assert.AreEqual(2, numberOfCalls); | ||
} | ||
|
||
[TestMethod] | ||
public async Task FireAsync_EventWithMultipleObserversAndErrors_CallAllDelegatesAndContinueWithoutErrors() | ||
{ | ||
// Arrange | ||
var numberOfCalls = 0; | ||
var log = new Mock<ILogHandler>(); | ||
|
||
var event1 = new Event(log.Object); | ||
|
||
event1.Subscribe(() => | ||
{ | ||
throw new System.Exception(); | ||
}); | ||
|
||
event1.Subscribe(() => | ||
{ | ||
numberOfCalls++; | ||
return Task.CompletedTask; | ||
}); | ||
|
||
// Act | ||
await event1.FireAsync(); | ||
|
||
// Assert | ||
Assert.AreEqual(1, numberOfCalls); | ||
} | ||
} | ||
} |