Skip to content

Commit

Permalink
Merge pull request #657 from frankebersoll/aspnet-core
Browse files Browse the repository at this point in the history
Fixed issues with ASP.NET metadata providers
  • Loading branch information
rasmus authored Jun 25, 2019
2 parents c031fef + 9ecf71d commit f3f4e06
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 275 deletions.
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
### New in 0.74 (not released yet)

* Breaking: Renamed `AspNetCoreEventFlowOptions.AddMetadataProviders()`
to `AddDefaultMetadataProviders()` and made `AddUserClaimsMetadata` opt-in
in order to prevent policy issues.
* Fix: Allow explicit implementations of `IEmit<>` in aggregate roots
* Fix: Using `.AddAspNetCore()` with defaults now doesn't throw a DI
exception.

### New in 0.73.3933 (released 2019-06-11)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,49 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Net.Http;
using System.Threading.Tasks;
using EventFlow.AspNetCore.Extensions;
using EventFlow.AspNetCore.Middlewares;
using EventFlow.Configuration;
using EventFlow.DependencyInjection.Extensions;
using EventFlow.Extensions;
using EventFlow.TestHelpers;
using EventFlow.TestHelpers.Aggregates.Queries;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using EventFlow.TestHelpers.Aggregates.Commands;
using FluentAssertions;
using NUnit.Framework;

namespace EventFlow.AspNetCore.Tests.IntegrationTests.Site
{
public class Startup
[Category(Categories.Integration)]
public class DefaultConfigurationTests : SiteTestsBase
{
public void ConfigureServices(IServiceCollection services)
[Test]
public async Task Ping()
{
services.AddMvc();
// Act
await GetAsync("thingy/ping?id=thingy-d15b1562-11f2-4645-8b1a-f8b946b566d3").ConfigureAwait(false);
await GetAsync("thingy/ping?id=thingy-d15b1562-11f2-4645-8b1a-f8b946b566d3").ConfigureAwait(false);
}

[Test]
public async Task PublishCommand()
{
// Arrange
ThingyPingCommand pingCommand = A<ThingyPingCommand>();

services.AddLogging(logging => logging
.AddConsole()
.SetMinimumLevel(LogLevel.Debug));
// Act
await PostAsync("commands/ThingyPing/1", pingCommand).ConfigureAwait(false);
}

[Test]
public void PublishCommand_WithNull_ThrowsException()
{
// Arrange + Act
Action action = () => Task.WaitAll(PostAsync("commands/ThingyPing/1", null));

services
.AddEventFlow(o => o
.AddDefaults(EventFlowTestHelpers.Assembly)
.RegisterServices(sr => sr.Register<IScopedContext, ScopedContext>(Lifetime.Scoped))
.ConfigureJson(j => j
.AddSingleValueObjects())
.AddAspNetCore(c => c
.RunBootstrapperOnHostStartup()
.UseMvcJsonOptions()
.UseModelBinding()
.AddUserClaimsMetadata()
.UseLogging()
));
action.Should().Throw<HttpRequestException>("because of command is null.");
}

public void Configure(IApplicationBuilder app)
protected override void ConfigureAspNetCore(AspNetCoreEventFlowOptions options)
{
app.UseMiddleware<TestAuthenticationMiddleware>();
app.UseMiddleware<CommandPublishMiddleware>();
app.UseMvcWithDefaultRoute();
options.UseDefaults();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// The MIT License (MIT)
//
// Copyright (c) 2015-2019 Rasmus Mikkelsen
// Copyright (c) 2015-2019 eBay Software Foundation
// https://github.com/eventflow/EventFlow
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using EventFlow.Aggregates;
using EventFlow.AspNetCore.Extensions;
using EventFlow.TestHelpers;
using EventFlow.TestHelpers.Aggregates;
using FluentAssertions;
using NUnit.Framework;

namespace EventFlow.AspNetCore.Tests.IntegrationTests.Site
{
[Category(Categories.Integration)]
public class ModelBindingTests : SiteTestsBase
{
[Test]
public async Task PingWithModelBinding()
{
// Act
await GetAsync("thingy/pingWithModelBinding?id=thingy-d15b1562-11f2-4645-8b1a-f8b946b566d3")
.ConfigureAwait(false);
await GetAsync("thingy/pingWithModelBinding?id=thingy-d15b1562-11f2-4645-8b1a-f8b946b566d3")
.ConfigureAwait(false);
}

[Test]
public async Task ValidSingleValue()
{
// Act
var result = await GetAsync("thingy/singlevalue/123").ConfigureAwait(false);
result.Should().Be("123");
}

[Test]
public void InvalidSingleValue()
{
// Arrange + Act
Func<Task> call = async () => await GetAsync("thingy/singlevalue/asdf").ConfigureAwait(false);

call.Should().Throw<HttpRequestException>();
}

[Test]
public async Task EventsContainMetadata()
{
ThingyId id = ThingyId.New;
// Arrange + Act
await GetAsync($"thingy/ping?id={id}").ConfigureAwait(false);

// Assert
var events = await EventStore.LoadEventsAsync<ThingyAggregate, ThingyId>(id, CancellationToken.None);
IMetadata metadata = events.Single().Metadata;

metadata.Should().Contain(new[]
{
new KeyValuePair<string, string>("user_claim[sid]", "test-sid"),
new KeyValuePair<string, string>("user_claim[role]", "test-role-1;test-role-2")
}
);

metadata.Should().NotContain(
new KeyValuePair<string, string>("user_claim[name]", "test-name"));
}

protected override void ConfigureAspNetCore(AspNetCoreEventFlowOptions options)
{
options
.RunBootstrapperOnHostStartup()
.UseMvcJsonOptions()
.UseModelBinding()
.AddUserClaimsMetadata()
.UseLogging();
}
}
}
184 changes: 0 additions & 184 deletions Source/EventFlow.AspNetCore.Tests/IntegrationTests/Site/SiteTests.cs

This file was deleted.

Loading

0 comments on commit f3f4e06

Please sign in to comment.