-1?(p||v()):1)}if(!!J){J=parseFloat(J)*(J.indexOf(y)>-1?(p||v()):1)}if(!K.hasquery||(!A||!L)&&(A||H>=C)&&(L||H<=J)){if(!D[K.media]){D[K.media]=[]}D[K.media].push(k[K.rules])}}for(var E in q){if(q[E]&&q[E].parentNode===f){f.removeChild(q[E])}}for(var E in D){var M=w.createElement("style"),F=D[E].join("\n");M.type="text/css";M.media=E;f.insertBefore(M,G.nextSibling);if(M.styleSheet){M.styleSheet.cssText=F}else{M.appendChild(w.createTextNode(F))}q.push(M)}},n=function(x,z){var y=c();if(!y){return}y.open("GET",x,true);y.onreadystatechange=function(){if(y.readyState!=4||y.status!=200&&y.status!=304){return}z(y.responseText)};if(y.readyState==4){return}y.send(null)},c=(function(){var x=false;try{x=new XMLHttpRequest()}catch(y){x=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return x}})();a();respond.update=a;function t(){j(true)}if(e.addEventListener){e.addEventListener("resize",t,false)}else{if(e.attachEvent){e.attachEvent("onresize",t)}}})(this);
--------------------------------------------------------------------------------
/EbookManager.Web/Startup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Owin;
2 | using Owin;
3 |
4 | [assembly: OwinStartupAttribute(typeof(EbookManager.Web.Startup))]
5 | namespace EbookManager.Web
6 | {
7 | public partial class Startup
8 | {
9 | public void Configuration(IAppBuilder app)
10 | {
11 | //Configuration du middleware de logs OWIN
12 | ConfigureLogMiddleware(app);
13 |
14 | //Configuration de l'authentification Web via OWIN
15 | ConfigureWebAuth(app);
16 |
17 | //Configuration de l'authentification OAuth2 via OWIN
18 | ConfigureOAuth2(app);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Account/ExternalLoginConfirmation.cshtml:
--------------------------------------------------------------------------------
1 | @model EbookManager.Web.Models.ExternalLoginConfirmationViewModel
2 | @{
3 | ViewBag.Title = "S'enregistrer";
4 | }
5 | @ViewBag.Title.
6 | Associez votre compte @ViewBag.LoginProvider.
7 |
8 | @using (Html.BeginForm("ExternalLoginConfirmation", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
9 | {
10 | @Html.AntiForgeryToken()
11 |
12 |
13 | @Html.ValidationSummary(true)
14 |
15 | Vous vous êtes authentifié à l'aide de @ViewBag.LoginProvider.
16 | Pour terminer votre inscription, merci d'entrer votre nom d'utilisateur ci-dessous.
17 |
18 |
25 |
30 | }
31 |
32 | @section Scripts {
33 | @Scripts.Render("~/bundles/jqueryval")
34 | }
35 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Account/ExternalLoginFailure.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewBag.Title = "Echec d'authentification";
3 | }
4 |
5 | @ViewBag.Title.
6 | Le service ne vous a pas correctement authentifié.
7 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Account/Login.cshtml:
--------------------------------------------------------------------------------
1 | @model EbookManager.Web.Models.LoginViewModel
2 |
3 | @{
4 | ViewBag.Title = "Connexion";
5 | }
6 |
7 | @ViewBag.Title.
8 |
56 | @section Scripts {
57 | @Scripts.Render("~/bundles/jqueryval")
58 | }
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Account/Manage.cshtml:
--------------------------------------------------------------------------------
1 | @using EbookManager.Web.Models;
2 | @using Microsoft.AspNet.Identity;
3 | @{
4 | ViewBag.Title = "Gérer mon compte";
5 | }
6 |
7 | @ViewBag.Title.
8 |
9 | @ViewBag.StatusMessage
10 |
11 |
12 | @if (ViewBag.HasLocalPassword)
13 | {
14 | @Html.Partial("_ChangePasswordPartial")
15 | }
16 | else
17 | {
18 | @Html.Partial("_SetPasswordPartial")
19 | }
20 |
21 |
22 | @Html.Action("RemoveAccountList")
23 | @Html.Partial("_ExternalLoginsListPartial", new { Action = "LinkLogin", ReturnUrl = ViewBag.ReturnUrl })
24 |
25 |
26 |
27 | @section Scripts {
28 | @Scripts.Render("~/bundles/jqueryval")
29 | }
30 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Account/Register.cshtml:
--------------------------------------------------------------------------------
1 | @model EbookManager.Web.Models.RegisterViewModel
2 | @{
3 | ViewBag.Title = "S'enregistrer";
4 | }
5 |
6 | @ViewBag.Title.
7 |
8 | @using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
9 | {
10 | @Html.AntiForgeryToken()
11 | Créer une nouveau compte.
12 |
13 | @Html.ValidationSummary()
14 |
20 |
26 |
32 |
37 | }
38 |
39 | @section Scripts {
40 | @Scripts.Render("~/bundles/jqueryval")
41 | }
42 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Account/_ChangePasswordPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNet.Identity
2 | @model EbookManager.Web.Models.ManageUserViewModel
3 |
4 | Vous êtes connecté en tant que @User.Identity.GetUserName().
5 |
6 | @using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
7 | {
8 | @Html.AntiForgeryToken()
9 | Changement de mot de passe
10 |
11 | @Html.ValidationSummary()
12 |
18 |
24 |
30 |
31 |
36 | }
37 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Account/_ExternalLoginsListPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.Owin.Security
2 |
3 | Utilisez un service externe pour vous authentifier.
4 |
5 | @{
6 | var loginProviders = Context.GetOwinContext().Authentication.GetExternalAuthenticationTypes();
7 | if (loginProviders.Count() == 0)
8 | {
9 |
10 |
Aucun service configuré.
11 |
12 | }
13 | else
14 | {
15 | string action = Model.Action;
16 | string returnUrl = Model.ReturnUrl;
17 | using (Html.BeginForm(action, "Account", new { ReturnUrl = returnUrl }))
18 | {
19 | @Html.AntiForgeryToken()
20 |
21 |
22 | @foreach (AuthenticationDescription p in loginProviders)
23 | {
24 |
25 | }
26 |
27 |
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Account/_RemoveAccountPartial.cshtml:
--------------------------------------------------------------------------------
1 | @model ICollection
2 |
3 | @if (Model.Count > 0)
4 | {
5 | Comptes associés
6 |
34 | }
35 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Account/_SetPasswordPartial.cshtml:
--------------------------------------------------------------------------------
1 | @model EbookManager.Web.Models.ManageUserViewModel
2 |
3 |
4 | @using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
5 | {
6 | @Html.AntiForgeryToken()
7 |
8 |
9 | @Html.ValidationSummary()
10 |
16 |
22 |
27 | }
28 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Catalog/Details.cshtml:
--------------------------------------------------------------------------------
1 | @model EbookManager.CommonViewModels.EbookViewModel
2 | @{
3 | ViewBag.Title = Model.Title;
4 | }
5 |
6 | @Model.Title
7 |
8 |
9 |
10 |
11 |

12 |
13 |
14 |
15 | Résumé
16 |
17 |
18 | @Html.DisplayFor(m => m.Summary)
19 |
20 |
21 |
22 |
23 |
24 | Cet ebook est composé de @Model.PartsCount partie(s).
25 |
26 |
27 |
28 |
29 |
30 | @if (ViewBag.UserOwnsBook)
31 | {
32 |
33 |
34 | Vous possédez déjà cet eBook dans @Html.ActionLink("votre catalogue", "Index", "MySpace").
35 |
36 |
37 | }
38 | else
39 | {
40 |
41 |
42 | @using (Html.BeginForm("Buy", "Catalog", FormMethod.Post))
43 | {
44 | @Html.HiddenFor(m => m.Id)
45 |
46 | }
47 |
48 |
49 | }
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Catalog/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model EbookManager.Web.Models.CatalogViewModel
2 |
3 | @{
4 | ViewBag.Title = "Parcourir le catalogue";
5 | }
6 |
7 | @ViewBag.Title
8 |
9 |
10 | @if (!Model.Ebooks.Any())
11 | {
12 |
13 |
Ooops
14 |
Notre catalogue semble vide...
15 |
16 | }
17 | else
18 | {
19 |
20 | @foreach (var ebook in Model.Ebooks)
21 | {
22 | @Html.DisplayFor(m => ebook)
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/EbookManager.Web/Views/DemoAuthenticated/Index.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewBag.Title = "Index";
4 | }
5 |
6 | Index
7 |
8 |
9 |
Demo Webview
10 |
You are correcly authenticated as @User.Identity.Name
11 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewBag.Title = "Accueil";
3 | }
4 |
5 |
6 |
Ebook Manager
7 |
Application de démonstration utilisée pour la session "ASP.NET MVC 5 et Web API 2, Techdays 2014".
8 |
9 |
10 |
11 |
12 |
Catalogue
13 |
14 | Parcourez notre catalogue de livre, achetez et commencez à lire en quelques instants...
15 |
16 |
@Html.ActionLink("Accéder", "Index", "Catalog", null, new{ @class = "btn btn-primary"})
17 |
18 |
19 |
Mes eBooks
20 |
Retrouvez votre collection d'eBooks déjà acheté sur Ebook Manager.
21 |
@Html.ActionLink("Accéder", "Index", "MySpace", null, new { @class = "btn btn-primary" })
22 |
23 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/MySpace/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model EbookManager.Web.Models.CatalogViewModel
2 |
3 | @{
4 | ViewBag.Title = "Votre catalogue d'eBooks";
5 | }
6 |
7 | @ViewBag.Title
8 |
9 |
10 | @if (!Model.Ebooks.Any())
11 | {
12 |
13 |
Ooops
14 |
Votre catalogue est vide... Rendez-vous sur @Html.ActionLink("cette page", "Index", "Catalog") pour découvrir notre collection !
15 |
16 | }
17 | else
18 | {
19 |
20 | @foreach (var ebook in Model.Ebooks)
21 | {
22 | @Html.DisplayFor(m => ebook)
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Shared/DisplayTemplates/EbookViewModel.cshtml:
--------------------------------------------------------------------------------
1 | @model EbookManager.CommonViewModels.EbookViewModel
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
@Model.Title
11 |
@Model.Summary
12 |
13 |
14 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 | @model System.Web.Mvc.HandleErrorInfo
2 |
3 | @{
4 | ViewBag.Title = "Error";
5 | }
6 |
7 | Error.
8 | An error occurred while processing your request.
9 |
10 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Shared/_Layout.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | @ViewBag.Title - Techdays 2014
7 | @Styles.Render("~/Content/css")
8 | @Scripts.Render("~/bundles/modernizr")
9 |
10 |
11 |
12 |
13 |
14 |
22 |
23 | @if (User.Identity.IsAuthenticated)
24 | {
25 |
26 | - @Html.ActionLink("Accueil", "Index", "Home")
27 | - @Html.ActionLink("Catalogue", "Index", "Catalog")
28 | - @Html.ActionLink("Mes eBooks", "Index", "MySpace")
29 |
30 | }
31 | @Html.Partial("_LoginPartial")
32 |
33 |
34 |
35 |
36 | @RenderBody()
37 |
38 |
41 |
42 |
43 | @Scripts.Render("~/bundles/jquery")
44 | @Scripts.Render("~/bundles/jqueryval")
45 | @Scripts.Render("~/bundles/bootstrap")
46 | @RenderSection("scripts", required: false)
47 |
48 |
49 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Shared/_LoginPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNet.Identity
2 | @if (Request.IsAuthenticated)
3 | {
4 | using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
5 | {
6 | @Html.AntiForgeryToken()
7 |
8 |
9 | -
10 | @Html.ActionLink("Bonjour " + User.Identity.GetUserName() + "!", "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" })
11 |
12 | - Se déconnecter
13 |
14 | }
15 | }
16 | else
17 | {
18 |
19 | - @Html.ActionLink("S'enregistrer", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })
20 | - @Html.ActionLink("Connexion", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/EbookManager.Web/Views/_ViewStart.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | Layout = "~/Views/Shared/_Layout.cshtml";
3 | }
4 |
--------------------------------------------------------------------------------
/EbookManager.Web/Web.Debug.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/EbookManager.Web/Web.Release.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/EbookManager.Web/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/EbookManager.Web/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simonferquel/techdays-paris-2014-mvc-webapi/2676a01fa3fc0ebfa52e98fa93ae4b03aac3b50d/EbookManager.Web/favicon.ico
--------------------------------------------------------------------------------
/EbookManager.Web/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simonferquel/techdays-paris-2014-mvc-webapi/2676a01fa3fc0ebfa52e98fa93ae4b03aac3b50d/EbookManager.Web/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/EbookManager.Web/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simonferquel/techdays-paris-2014-mvc-webapi/2676a01fa3fc0ebfa52e98fa93ae4b03aac3b50d/EbookManager.Web/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/EbookManager.Web/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simonferquel/techdays-paris-2014-mvc-webapi/2676a01fa3fc0ebfa52e98fa93ae4b03aac3b50d/EbookManager.Web/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/EbookManager.Web/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | techdays-paris-2014-mvc-webapi
2 | ==============================
3 |
4 | Code source associé à la session http://www.microsoft.com/france/mstechdays/programmes/2014/fiche-session.aspx?ID=5f7102fa-7fc1-4aed-b916-00a9303415c3
5 |
--------------------------------------------------------------------------------
/UnitTests/AssemblyResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Web.Http.Dispatcher;
8 |
9 | namespace UnitTests
10 | {
11 | class TestWebApiResolver : DefaultAssembliesResolver
12 | {
13 | public override ICollection GetAssemblies()
14 | {
15 | return new List { typeof(EbookManager.Web.Api.UserController).Assembly };
16 |
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/UnitTests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("UnitTests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("UnitTests")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("4ca04fe7-22cd-4c03-b65c-de1271730a30")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/UnitTests/TestAuthenticationMiddleware.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Owin;
2 | using Microsoft.Owin.Security;
3 | using Microsoft.Owin.Security.Infrastructure;
4 | using Owin;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Security.Claims;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace UnitTests
13 | {
14 | public class TestAuthenticationOptions : AuthenticationOptions
15 | {
16 | ClaimsIdentity _identity;
17 | public ClaimsIdentity Identity { get { return _identity; } }
18 |
19 | public TestAuthenticationOptions(ClaimsIdentity identity)
20 | : base(identity.AuthenticationType)
21 | {
22 | _identity = identity;
23 | base.AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active;
24 | }
25 |
26 | }
27 |
28 | public static class TestAuthenticationMiddlewareExtensions
29 | {
30 | public static IAppBuilder UseTestAuthentication(this IAppBuilder app, ClaimsIdentity identity)
31 | {
32 | return app.Use(new TestAuthenticationOptions(identity));
33 | }
34 | }
35 | public class TestAuthenticationMiddleware : AuthenticationMiddleware
36 | {
37 | public TestAuthenticationMiddleware(OwinMiddleware next, TestAuthenticationOptions options)
38 | : base(next, options)
39 | {
40 |
41 | }
42 | protected override AuthenticationHandler CreateHandler()
43 | {
44 | return new TestAuthenticationHandler();
45 | }
46 | }
47 |
48 | public class TestAuthenticationHandler : AuthenticationHandler
49 | {
50 | protected override async Task AuthenticateCoreAsync()
51 | {
52 | return new AuthenticationTicket(Options.Identity, new AuthenticationProperties());
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/UnitTests/WebApiTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using EbookManager.Web.Owin;
3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
4 | using System.Threading.Tasks;
5 | using Microsoft.Owin.Testing;
6 | using Owin;
7 | using System.Security.Claims;
8 | using System.Web.Http;
9 | using System.Net.Http;
10 | using System.Web.Http.Dispatcher;
11 | using System.Collections.Generic;
12 | using System.Reflection;
13 |
14 | namespace UnitTests
15 | {
16 | [TestClass]
17 | public class WebApiTests
18 | {
19 | static ClaimsIdentity _testIdentity;
20 | class OwinTestConf
21 | {
22 | public void Configuration(IAppBuilder app)
23 | {
24 | app.Use(typeof (LogMiddleware));
25 | app.UseTestAuthentication(_testIdentity);
26 | HttpConfiguration config = new HttpConfiguration();
27 | config.Services.Replace(typeof(IAssembliesResolver), new TestWebApiResolver());
28 | config.MapHttpAttributeRoutes();
29 | app.UseWebApi(config);
30 | }
31 | }
32 |
33 |
34 |
35 | class WhoAmiResult
36 | {
37 | public string UserName { get; set; }
38 | public string NameIdentifier { get; set; }
39 | }
40 |
41 | [TestMethod]
42 | public async Task Test_WhoAmi()
43 | {
44 | _testIdentity = new ClaimsIdentity("testidentity");
45 | _testIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "test name identifier"));
46 | _testIdentity.AddClaim(new Claim(ClaimTypes.Name, "test user"));
47 | using (var server = TestServer.Create())
48 | {
49 | using (var client = new HttpClient(server.Handler))
50 | {
51 | var response = await client.GetAsync("http://testserver/api/user/whoami");
52 | var result = await response.Content.ReadAsAsync();
53 | Assert.AreEqual("test user", result.UserName);
54 | Assert.AreEqual("test name identifier", result.NameIdentifier);
55 | }
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/UnitTests/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/UnitTests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------