Skip to content

Commit

Permalink
Merge pull request #33 from JasperFx/auth
Browse files Browse the repository at this point in the history
Updates to support sites that use Authentication
  • Loading branch information
joemcbride committed Feb 3, 2017
2 parents 94135c6 + 8239aff commit baad396
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 64 deletions.
3 changes: 0 additions & 3 deletions src/Alba.Testing/Acceptance/specs_against_aspnet_core_app.cs
@@ -1,8 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using WebApp;
using WebApp.Controllers;
Expand Down
3 changes: 2 additions & 1 deletion src/Alba.Testing/BasicScenarioSupport.cs
Expand Up @@ -30,6 +30,7 @@ public class BasicScenarioSupport : ISystemUnderTest
public BasicScenarioSupport()
{
var registry = new Registry();
registry.ForSingletonOf<IHttpContextAccessor>().Use<HttpContextAccessor>();
registry.Populate(new ServiceDescriptor[0]);

Container = new Container(registry);
Expand All @@ -40,7 +41,7 @@ public HttpContext CreateContext()
return new StubHttpContext(Features, Services);
}

public IFeatureCollection Features { get; } = null;
public IFeatureCollection Features { get; } = new FeatureCollection();
public IServiceProvider Services => new StructureMapServiceProvider(Container);
public RequestDelegate Invoker => Invoke;

Expand Down
4 changes: 1 addition & 3 deletions src/Alba.Testing/FormDataExtensionsTests.cs
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using Alba.Stubs;
using Baseline;
using Shouldly;
Expand All @@ -21,7 +19,7 @@ public void round_trip_writing_and_parsing()
["c"] = "really?"
};

var context = new StubHttpContext(null, null);
var context = StubHttpContext.Empty();

context.WriteFormData(form1);

Expand Down
2 changes: 1 addition & 1 deletion src/Alba/Scenario.cs
Expand Up @@ -223,7 +223,7 @@ SendExpression IUrlExpression.FormData(Dictionary<string, string> input)
public SendExpression Text(string text)
{
Body.TextIs(text);
Context.Request.ContentType = "text/plain";
Context.Request.ContentType = MimeType.Text.Value;

return new SendExpression(Context);
}
Expand Down
19 changes: 11 additions & 8 deletions src/Alba/Stubs/StubAuthenticationManager.cs
@@ -1,48 +1,51 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Authentication;
using Microsoft.AspNetCore.Http.Authentication.Internal;
using Microsoft.AspNetCore.Http.Features.Authentication;

namespace Alba
{
public class StubAuthenticationManager : AuthenticationManager
{
private readonly DefaultAuthenticationManager _default;

public StubAuthenticationManager(HttpContext context)
{
HttpContext = context;
_default = new DefaultAuthenticationManager(context);
}

public override IEnumerable<AuthenticationDescription> GetAuthenticationSchemes()
{
throw new NotImplementedException();
return _default.GetAuthenticationSchemes();
}

public override Task<AuthenticateInfo> GetAuthenticateInfoAsync(string authenticationScheme)
{
throw new NotImplementedException();
return _default.GetAuthenticateInfoAsync(authenticationScheme);
}

public override Task AuthenticateAsync(AuthenticateContext context)
{
throw new NotImplementedException();
return _default.AuthenticateAsync(context);
}

public override Task ChallengeAsync(string authenticationScheme, AuthenticationProperties properties, ChallengeBehavior behavior)
{
throw new NotImplementedException();
return _default.ChallengeAsync(authenticationScheme, properties, behavior);
}

public override Task SignInAsync(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties)
{
throw new NotImplementedException();
return _default.SignInAsync(authenticationScheme, principal, properties);
}

public override Task SignOutAsync(string authenticationScheme, AuthenticationProperties properties)
{
throw new NotImplementedException();
return _default.SignOutAsync(authenticationScheme, properties);
}

public override HttpContext HttpContext { get; }
Expand Down
1 change: 1 addition & 0 deletions src/Alba/SystemUnderTest.cs
Expand Up @@ -56,6 +56,7 @@ public static string FindParallelFolder(string folderName)
{
_.AddSingleton<IHostingEnvironment>(environment);
_.AddSingleton<IServer>(new TestServer());
_.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
});

builder.UseStartup<T>();
Expand Down
5 changes: 5 additions & 0 deletions src/Alba/SystemUnderTestExtensions.cs
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace Alba
Expand All @@ -13,6 +14,10 @@ public static async Task<IScenarioResult> Scenario(this ISystemUnderTest system,
using (var scope = system.Services.GetService<IServiceScopeFactory>().CreateScope())
{
var scenario = new Scenario(system, scope);

var contextAccessor = scope.ServiceProvider.GetService<IHttpContextAccessor>();
contextAccessor.HttpContext = scenario.Context;

configure(scenario);

scenario.Rewind();
Expand Down

0 comments on commit baad396

Please sign in to comment.