Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
pr-ix: correct tests & extensions w/ new major versions
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnmoreels committed Mar 18, 2024
1 parent d041607 commit f76edd2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,18 @@ public async Task EventGridSubscriptionValidation_WithCorrectRequestValidationDa
{
// Arrange
var validationCode = Guid.NewGuid().ToString();
var eventGridEvent = new EventGridEvent(
subject: "Sample.Subect",
data: JObject.Parse($"{{ \"validationCode\": \"{validationCode}\" }}"),
eventType: "Microsoft.EventGrid.SubscriptionValidationEvent",
dataVersion: "1.0")
{
Id = Guid.NewGuid().ToString(),
EventTime = DateTimeOffset.UtcNow
};
string json = JsonConvert.SerializeObject(eventGridEvent);
string json = $@"[
{{
""id"": ""2d1781af-3a4c-4d7c-bd0c-e34b19da4e66"",
""topic"": ""/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"",
""subject"": ""Sample.Subject"",
""data"": {{
""validationCode"": ""{validationCode}""
}}, ""dataVersion"": """",
""eventType"": ""Microsoft.EventGrid.SubscriptionValidationEvent"",
""eventTime"": ""2017-08-06T22:09:30.740323Z""
}}
]";

await using (var server = await TestApiServer.StartNewAsync(_logger))
{
Expand Down
36 changes: 28 additions & 8 deletions src/Arcus.EventGrid.Tests.Unit/Testing/EventConsumerHostTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Arcus.EventGrid.Testing.Infrastructure.Hosts;
using Arcus.EventGrid.Tests.Core.Events.Data;
using Arcus.EventGrid.Tests.Unit.Testing.Fixture;
Expand All @@ -15,7 +16,7 @@ namespace Arcus.EventGrid.Tests.Unit.Testing
public class EventConsumerHostTests
{
private readonly ILogger _logger;
private static readonly Faker BogusGenerator = new Faker();
private static readonly Faker Bogus = new Faker();

/// <summary>
/// Initializes a new instance of the <see cref="EventConsumerHostTests" /> class.
Expand All @@ -25,6 +26,25 @@ public EventConsumerHostTests(ITestOutputHelper outputWriter)
_logger = new XunitTestLogger(outputWriter);
}

[Fact]
public void GetReceivedEventByEventId_WithAvailableEvents_Succeeds()
{
// Arrange
IEnumerable<CloudEvent> cloudEvents = Bogus.Make(Bogus.Random.Int(1, 10), () => GenerateCloudEvent());
CloudEvent expected = Bogus.PickRandom(cloudEvents);

var host = new InMemoryEventConsumerHost(_logger);
host.ReceiveEvents(cloudEvents);

// Act
string receivedEvent = host.GetReceivedEvent(expected.Id);

// Assert
CloudEvent actual = CloudEvent.Parse(BinaryData.FromString(receivedEvent));
Assert.NotNull(actual);
Assert.Equal(expected.Id, actual.Id);
}

[Fact]
public void GetReceivedEventByEventIdWithRetryCount_WithAvailableEvent_Succeeds()
{
Expand Down Expand Up @@ -201,9 +221,9 @@ public void GetReceivedEventByEventGridEventFilter_WithoutAvailableEvent_Fails()
private static CloudEvent GenerateCloudEvent(string eventId = null)
{
return new CloudEvent(
source: BogusGenerator.Lorem.Word(),
type: BogusGenerator.Lorem.Word(),
jsonSerializableData: new CarEventData(BogusGenerator.Vehicle.Vin()))
source: Bogus.Lorem.Word(),
type: Bogus.Lorem.Word(),
jsonSerializableData: new CarEventData(Bogus.Vehicle.Vin()))
{
Id = eventId ?? Guid.NewGuid().ToString(),
Time = DateTimeOffset.UtcNow
Expand All @@ -213,10 +233,10 @@ private static CloudEvent GenerateCloudEvent(string eventId = null)
private static EventGridEvent GenerateEventGridEvent(string eventId = null)
{
return new EventGridEvent(
subject: BogusGenerator.Lorem.Word(),
eventType: BogusGenerator.Lorem.Word(),
dataVersion: BogusGenerator.System.Version().ToString(),
data: new CarEventData(BogusGenerator.Vehicle.Vin()))
subject: Bogus.Lorem.Word(),
eventType: Bogus.Lorem.Word(),
dataVersion: Bogus.System.Version().ToString(),
data: new CarEventData(Bogus.Vehicle.Vin()))
{
Id = eventId ?? Guid.NewGuid().ToString(),
EventTime = DateTimeOffset.UtcNow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public void ReceiveEvent(EventGridEvent eventGridEvent)
EventsReceived(rawReceivedEvents);
}

public void ReceiveEvents(IEnumerable<CloudEvent> cloudEvents)
{
EventsReceived(JsonSerializer.Serialize(cloudEvents));
}

public void ReceiveEvents(IEnumerable<EventGridEvent> eventGridEvents)
{
EventsReceived(JsonSerializer.Serialize(eventGridEvents));
}

public void ReceiveEvent(string raw)
{
EventsReceived(raw);
Expand Down

0 comments on commit f76edd2

Please sign in to comment.