Skip to content

Instantly share code, notes, and snippets.

💭
developing...

Aykut Asil aykuttasil

💭
developing...
Block or report user

Report or block aykuttasil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View HomeController.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using aspnetcore_filter.Models;
using aspnetcore_filter.Filters;
namespace aspnetcore_filter.Controllers
View ResultFilterSample.cs
using System;
using Microsoft.AspNetCore.Mvc.Filters;
namespace aspnetcore_filter.Filters
{
public class ResultFilterSampleAttribute : ResultFilterAttribute
{
override public void OnResultExecuting(ResultExecutingContext context)
{
context.HttpContext.Response.Headers.Add("Author", "Aykut Asil");
@aykuttasil
aykuttasil / Startup.cs
Created Apr 29, 2019
Global Scope Filters
View Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
View run_middleware.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
View startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
View robolectric.java
ActivityController controller = Robolectric.buildActivity(MyAwesomeActivity.class).create().start();
Activity activity = controller.get();
// assert that something hasn't happened
activityController.resume();
// assert it happened!
View okhttp_builder.kt
val okHttpClient = OkHttpClient.Builder()
.connectTimeout(2, TimeUnit.SECONDS) // For testing purposes
.readTimeout(2, TimeUnit.SECONDS) // For testing purposes
.writeTimeout(2, TimeUnit.SECONDS)
.build()
View build.gradle
android {
// ...
testOptions {
unitTests.returnDefaultValues = true
}
}
View dispatcher.java
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().equals("/v1/login/auth/")){
return new MockResponse().setResponseCode(200);
} else if (request.getPath().equals("v1/check/version/")){
return new MockResponse().setResponseCode(200).setBody("version=9");
} else if (request.getPath().equals("/v1/profile/info")) {
View mockwebserver.kt
val mockServer = MockWebServer()
mockServer.start()
val mockedResponse = MockResponse()
mockedResponse.setResponseCode(200)
mockedResponse.setBody("{}") // sample JSON
mockServer.enqueue(mockedReponse)
You can’t perform that action at this time.