Exemplo n.º 1
0
        public async Task Get_Categories_Should_Return_All_Categories()
        {
            // Assign
            var category = new Category
            {
                Id    = 1,
                Title = "title",
            };

            DbContextFake.SeedDb <IntranetApiContext>(c => c.Add(category));

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var categoryController = ControllerFake.GetController <CategoriesController>(context);

                // Act
                var result = await categoryController.Index();

                var responses = result.GetModelAs <IEnumerable <Category> >();
                var response  = responses.First();

                // Assert
                Assert.IsType <ViewResult>(result);
                Assert.Equal(ActionResultExtensions.CountModelItems(result), 1);
                Assert.Equal(response.Title, "title");
            }
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseRouting();

            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "areas",
                    pattern: "{area}/{controller=Home}/{action=Index}/{id?}"
                    );

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

            ActionResultExtensions.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>(),
                                             app.ApplicationServices.GetRequiredService <ITempDataDictionaryFactory>());
        }