Skip to content

Commit

Permalink
Migrated Dapr.AspNetCore.IntegrationTest
Browse files Browse the repository at this point in the history
Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
  • Loading branch information
WhitWaldo committed Jan 18, 2025
1 parent 7183f7f commit c35a299
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 45 deletions.
6 changes: 3 additions & 3 deletions test/Dapr.AspNetCore.IntegrationTest/AuthenticationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using System.Text;
using System.Threading.Tasks;
using Dapr.AspNetCore.IntegrationTest.App;
using FluentAssertions;
using Shouldly;
using Newtonsoft.Json;
using Xunit;

Expand All @@ -43,7 +43,7 @@ public async Task ValidToken_ShouldBeAuthenticatedAndAuthorized()
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
var responseUserInfo = JsonConvert.DeserializeObject<UserInfo>(responseContent);
responseUserInfo.Name.Should().Be(userInfo.Name);
responseUserInfo.Name.ShouldBe(userInfo.Name);
}
}

Expand All @@ -64,7 +64,7 @@ public async Task InvalidToken_ShouldBeUnauthorized()
request.Headers.Add("Dapr-Api-Token", "asdfgh");
var response = await httpClient.SendAsync(request);

response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
response.StatusCode.ShouldBe(HttpStatusCode.Unauthorized);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Dapr.AspNetCore.IntegrationTest
using System.Text.Json;
using System.Threading.Tasks;
using Dapr.AspNetCore.IntegrationTest.App;
using FluentAssertions;
using Shouldly;
using Xunit;

public class CloudEventsIntegrationTest
Expand Down Expand Up @@ -48,6 +48,7 @@ public async Task CanSendEmptyStructuredCloudEvent()
}
}


[Fact]
public async Task CanSendStructuredCloudEvent()
{
Expand All @@ -74,7 +75,7 @@ public async Task CanSendStructuredCloudEvent()
response.EnsureSuccessStatusCode();

var userInfo = await JsonSerializer.DeserializeAsync<UserInfo>(await response.Content.ReadAsStreamAsync(), this.options);
userInfo.Name.Should().Be("jimmy");
userInfo.Name.ShouldBe("jimmy");
}
}

Expand Down Expand Up @@ -105,7 +106,7 @@ public async Task CanSendStructuredCloudEvent_WithContentType()
response.EnsureSuccessStatusCode();

var userInfo = await JsonSerializer.DeserializeAsync<UserInfo>(await response.Content.ReadAsStreamAsync(), this.options);
userInfo.Name.Should().Be("jimmy");
userInfo.Name.ShouldBe("jimmy");
}
}

Expand Down Expand Up @@ -133,7 +134,7 @@ public async Task CanSendStructuredCloudEvent_WithNonJsonContentType()
response.EnsureSuccessStatusCode();

var user = await response.Content.ReadAsStringAsync();
user.Should().Be("jimmy \"the cool guy\" smith");
user.ShouldBe("jimmy \"the cool guy\" smith");
}
}

Expand Down Expand Up @@ -163,7 +164,7 @@ public async Task CanSendBinaryCloudEvent_WithContentType()
response.EnsureSuccessStatusCode();

var userInfo = await JsonSerializer.DeserializeAsync<UserInfo>(await response.Content.ReadAsStreamAsync(), this.options);
userInfo.Name.Should().Be("jimmy");
userInfo.Name.ShouldBe("jimmy");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Dapr.AspNetCore.IntegrationTest
using System.Net.Http;
using System.Threading.Tasks;
using Dapr.AspNetCore.IntegrationTest.App;
using FluentAssertions;
using Shouldly;
using Newtonsoft.Json;
using Xunit;

Expand All @@ -37,7 +37,7 @@ public async Task ModelBinder_CanBindFromState()
response.EnsureSuccessStatusCode();

var widget = await daprClient.GetStateAsync<Widget>("testStore", "test");
widget.Count.Should().Be(18);
widget.Count.ShouldBe(18);
}
}

Expand All @@ -56,8 +56,8 @@ public async Task ModelBinder_GetFromStateEntryWithKeyPresentInStateStore_Return
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
var responseWidget = JsonConvert.DeserializeObject<Widget>(responseContent);
responseWidget.Size.Should().Be(widget.Size);
responseWidget.Count.Should().Be(widget.Count);
responseWidget.Size.ShouldBe(widget.Size);
responseWidget.Count.ShouldBe(widget.Count);
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task ModelBinder_CanBindFromState_WithStateEntry()
response.EnsureSuccessStatusCode();

var widget = await daprClient.GetStateAsync<Widget>("testStore", "test");
widget.Count.Should().Be(18);
widget.Count.ShouldBe(18);
}
}

Expand All @@ -111,7 +111,7 @@ public async Task ModelBinder_CanBindFromState_WithStateEntryAndCustomKey()
response.EnsureSuccessStatusCode();

var widget = await daprClient.GetStateAsync<Widget>("testStore", "test");
widget.Count.Should().Be(18);
widget.Count.ShouldBe(18);
}
}

Expand All @@ -130,8 +130,8 @@ public async Task ModelBinder_GetFromStateEntryWithStateEntry_WithKeyPresentInSt
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
var responseWidget = JsonConvert.DeserializeObject<Widget>(responseContent);
responseWidget.Size.Should().Be(widget.Size);
responseWidget.Count.Should().Be(widget.Count);
responseWidget.Size.ShouldBe(widget.Size);
responseWidget.Count.ShouldBe(widget.Count);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Shouldly"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<!-- <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />-->
<PackageReference Include="xunit" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Dapr.AspNetCore.IntegrationTest
using System.Net.Http;
using System.Threading.Tasks;
using Dapr.AspNetCore.IntegrationTest.App;
using FluentAssertions;
using Shouldly;
using Xunit;

public class RoutingIntegrationTest
Expand All @@ -36,7 +36,7 @@ public async Task StateClient_CanBindFromState()
response.EnsureSuccessStatusCode();

var widget = await daprClient.GetStateAsync<Widget>("testStore", "test");
widget.Count.Should().Be(18);
widget.Count.ShouldBe(18);
}
}
}
Expand Down
52 changes: 26 additions & 26 deletions test/Dapr.AspNetCore.IntegrationTest/SubscribeEndpointTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Dapr.AspNetCore.IntegrationTest
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using FluentAssertions;
using Shouldly;
using Xunit;

public class SubscribeEndpointTest
Expand All @@ -39,8 +39,8 @@ public async Task SubscribeEndpoint_ReportsTopics()
{
var json = await JsonSerializer.DeserializeAsync<JsonElement>(stream);

json.ValueKind.Should().Be(JsonValueKind.Array);
json.GetArrayLength().Should().Be(18);
json.ValueKind.ShouldBe(JsonValueKind.Array);
json.GetArrayLength().ShouldBe(18);

var subscriptions = new List<(string PubsubName, string Topic, string Route, string rawPayload,
string match, string metadata, string DeadLetterTopic, string bulkSubscribeMetadata)>();
Expand Down Expand Up @@ -109,34 +109,34 @@ public async Task SubscribeEndpoint_ReportsTopics()
}
}

subscriptions.Should().Contain(("testpubsub", "A", "topic-a", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("testpubsub", "A.1", "topic-a", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "B", "B", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("custom-pubsub", "custom-C", "C", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "register-user", "register-user", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "register-user-plaintext", "register-user-plaintext", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "D", "D", "true", string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "E", "E", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "E", "E-Critical", string.Empty, "event.type == \"critical\"", string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "E", "E-Important", string.Empty, "event.type == \"important\"", string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "F", "multiTopicAttr", string.Empty, string.Empty, string.Empty, string.Empty,
subscriptions.ShouldContain(("testpubsub", "A", "topic-a", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("testpubsub", "A.1", "topic-a", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "B", "B", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("custom-pubsub", "custom-C", "C", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "register-user", "register-user", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "register-user-plaintext", "register-user-plaintext", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "D", "D", "true", string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "E", "E", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "E", "E-Critical", string.Empty, "event.type == \"critical\"", string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "E", "E-Important", string.Empty, "event.type == \"important\"", string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "F", "multiTopicAttr", string.Empty, string.Empty, string.Empty, string.Empty,
"{\"enabled\":true,\"maxMessagesCount\":100,\"maxAwaitDurationMs\":1000}"));
subscriptions.Should().Contain(("pubsub", "F.1", "multiTopicAttr", "true", string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "G", "G", string.Empty, string.Empty, string.Empty, "deadLetterTopicName",
subscriptions.ShouldContain(("pubsub", "F.1", "multiTopicAttr", "true", string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "G", "G", string.Empty, string.Empty, string.Empty, "deadLetterTopicName",
"{\"enabled\":true,\"maxMessagesCount\":300,\"maxAwaitDurationMs\":1000}"));
subscriptions.Should().Contain(("pubsub", "splitTopicBuilder", "splitTopics", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "splitTopicAttr", "splitTopics", "true", string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "metadata", "multiMetadataTopicAttr", string.Empty, string.Empty, "n1=v1;n2=v2,v3", string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "metadata.1", "multiMetadataTopicAttr", "true", string.Empty, "n1=v1", string.Empty,
subscriptions.ShouldContain(("pubsub", "splitTopicBuilder", "splitTopics", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "splitTopicAttr", "splitTopics", "true", string.Empty, string.Empty, string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "metadata", "multiMetadataTopicAttr", string.Empty, string.Empty, "n1=v1;n2=v2,v3", string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "metadata.1", "multiMetadataTopicAttr", "true", string.Empty, "n1=v1", string.Empty,
"{\"enabled\":true,\"maxMessagesCount\":500,\"maxAwaitDurationMs\":2000}"));
subscriptions.Should().Contain(("pubsub", "splitMetadataTopicBuilder", "splitMetadataTopics", string.Empty, string.Empty, "n1=v1;n2=v1", string.Empty, String.Empty));
subscriptions.Should().Contain(("pubsub", "metadataseparatorbyemptytring", "topicmetadataseparatorattrbyemptytring", string.Empty, string.Empty, "n1=v1,", string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "splitMetadataTopicBuilder", "splitMetadataTopics", string.Empty, string.Empty, "n1=v1;n2=v1", string.Empty, String.Empty));
subscriptions.ShouldContain(("pubsub", "metadataseparatorbyemptytring", "topicmetadataseparatorattrbyemptytring", string.Empty, string.Empty, "n1=v1,", string.Empty, String.Empty));
// Test priority route sorting
var eTopic = subscriptions.FindAll(e => e.Topic == "E");
eTopic.Count.Should().Be(3);
eTopic[0].Route.Should().Be("E-Critical");
eTopic[1].Route.Should().Be("E-Important");
eTopic[2].Route.Should().Be("E");
eTopic.Count.ShouldBe(3);
eTopic[0].Route.ShouldBe("E-Critical");
eTopic[1].Route.ShouldBe("E-Important");
eTopic[2].Route.ShouldBe("E");
}
}
}
Expand Down

0 comments on commit c35a299

Please sign in to comment.