Exemplo n.º 1
0
 public async Task ApiKeyListContainsKeysInRepo()
 {
     var controller = new ApiKeyController();
     var response = await controller.List(new Request(HttpMethod.Get, "/apikeys", new Dictionary<string, string>(), CreateRepo().Object, null));
     var viewResponse = (ViewResponse)response;
     Assert.AreEqual("ApiKeyList", viewResponse.ViewName);
     Assert.AreEqual("api_secret_1", viewResponse.Model.ApiKeys[0].Secret);
 }
Exemplo n.º 2
0
 public async Task ApiKeyListAddsKeysToRepo()
 {
     var controller = new ApiKeyController();
     var repo = CreateRepo();
     var postData = @"{ id: 1001, secret: ""a secret"" }";
     var postDataStream = new MemoryStream(Encoding.UTF8.GetBytes(postData));
     var response = await controller.Add(new Request(HttpMethod.Post, "/apikeys", new Dictionary<string, string>(), repo.Object, postDataStream));
     repo.Verify(x => x.AddApiKey(It.Is<ApiKey>(k => k.Id == 1001 && k.Secret == "a secret")));
     Assert.AreEqual("/apikeys", ((SeeOtherResponse)response).Location);
 }
Exemplo n.º 3
0
        public static Action<IAppBuilder> Configuration(Func<IRepository> createRepository)
        {
            return app => {
                app.UseErrorPage();
                app.Use(new Func<AppFunc, AppFunc>(next => (async env =>
                {
                    try
                    {
                        await next.Invoke(env);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                })));
                app.Use(new Func<AppFunc, AppFunc>(next => (async env =>
                {
                    using (var repository = createRepository())
                    {
                        env["evefifo.Repository"] = repository;
                        await next.Invoke(env);
                    }
                })));

                var characterController = new CharacterController();
                var apiKeyController = new ApiKeyController();
                app.UseStaticFiles();
                app.UseRoutes(
                    new Route("/", characterController.List),
                    new Route("/characters/{id}", characterController.Show),
                    new Route("/apikeys", apiKeyController.List),
                    new Route("/apikeys", apiKeyController.Add, HttpMethod.Post)
                );
            };
        }