Skip to content

Instantly share code, notes, and snippets.

View trailmax's full-sized avatar

Max Vasilyev trailmax

View GitHub Profile
@trailmax
trailmax / LogOutFilterAttribute.cs
Created October 1, 2014 23:01
Logging out attribute
public class LogOutFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var authenticationManager = filterContext.HttpContext.GetOwinContext().Authentication;
authenticationManager.SignOut();
base.OnActionExecuting(filterContext);
}
@trailmax
trailmax / NEventStoreRepositoryTests.cs
Last active August 29, 2015 14:10
Bugreport for NEventStore.EventStoreRepository
using System;
using CommonDomain.Core;
using CommonDomain.Persistence.EventStore;
using FluentAssertions;
using NEventStore;
using Xunit;
public class NEventStoreRepositoryTests
{
@trailmax
trailmax / Preferences.Sublime-settings.json
Created December 30, 2014 02:30
My configuration for SublimeText
{
"color_scheme": "Packages/Color Scheme - Default/Sunburst.tmTheme",
"dictionary": "Packages/Language - English/en_GB.dic",
"font_face": "Source Code Pro Light",
"font_size": 11,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages":
[
"Vintage"
@trailmax
trailmax / ApplicationDbContext.cs
Created January 15, 2015 16:45
ApplicationDbContext trying out some overriding stuff
using System.Data.Entity;
using System.Threading.Tasks;
using IoCIdentity.Models;
using Microsoft.AspNet.Identity.EntityFramework;
namespace IoCIdentity.Identity
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, IApplicationDbContext
{
@trailmax
trailmax / Controller.cs
Created January 17, 2015 22:12
IoC debugging
public async Task<ActionResult> DoSeed()
{
return await InitializeIdentityForEF(db)
}
private async Task InitializeIdentityForEF(ApplicationDbContext db)
{
var userManager = HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>();
var roleManager = HttpContext.Current.GetOwinContext().Get<ApplicationRoleManager>();
[TestCase("Projects Topside", "Projects Systems")]
[TestCase("Topside", "Systems")]
public void ProjectsTopsides_vs_ProjectsSystems(string one, string another)
{
// Act
var fuzzyMatchValue = one.FuzzyMatch(another);
var diceCoefficient = one.DiceCoefficient(another);
var levenshteinDistance = one.LevenshteinDistance(another);
var lcs = one.LongestCommonSubsequence(another);
public partial class Startup
{
private static string clientId = CloudConfigurationManager.GetSetting("ida:ClientId");
private static string appKey = CloudConfigurationManager.GetSetting("ida:ClientSecret");
private static string aadInstance = CloudConfigurationManager.GetSetting("ida:AADInstance");
private static string tenantId = CloudConfigurationManager.GetSetting("ida:TenantId");
private static string postLogoutRedirectUri = CloudConfigurationManager.GetSetting("ida:PostLogoutRedirectUri");
public static readonly string Authority = aadInstance + tenantId;
@trailmax
trailmax / gist:c84c2a9d9cf0769ff14b
Created January 18, 2016 12:01
Automocking with MOQ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Instrumentation;
using Autofac;
using Autofac.Builder;
using Autofac.Core;
using Autofac.Features.ResolveAnything;
using Moq;
using MyProject.Domain.Services.Configuration;
#addin "nuget:?package=Cake.SqlServer"
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
Task("Testing-Database")
.Does(() =>
{
LocalDbCreateInstance("v12.0", LocalDbVersion.V12);
@trailmax
trailmax / AspNetPrincipalProxy
Created June 16, 2017 21:52
AspNetPrincipalProxy
// Defers the use of runtime data after object graph construction
// see: https://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=99
public sealed class AspNetPrincipalProxy : IPrincipal
{
public IIdentity Identity => User.Identity;
public bool IsInRole(string role) => User.IsInRole(role);
private IPrincipal User => HttpContext.Current.User;
}