Skip to content

Instantly share code, notes, and snippets.

View trailmax's full-sized avatar

Max Vasilyev trailmax

View GitHub Profile
@trailmax
trailmax / DomainEvents.cs
Created May 13, 2014 21:28
Ambient Context pattern for domain events with static call and mock replacement
public interface IDomainEventDispatcher
{
void Dispatch<TEvent>(TEvent eventToDispatch) where TEvent : IDomainEvent;
}
public static class DomainEvents
{
public static IDomainEventDispatcher Dispatcher { get; set; }
public static void Raise<TEvent>(TEvent eventToRaise) where TEvent : IDomainEvent
@trailmax
trailmax / gist:10988824
Created April 17, 2014 14:43
Kendo Sortable submit to server
$(document).ready(function () {
var sortableList = $('.sortable-list').kendoSortable({
hint: function(element){
return element.clone().addClass('sortable-list-hint');
},
cursor: "n-resize"
});
$('#sortable-submit').on('click', function (e) {
using System;
using System.Data.SqlClient;
using System.IO;
using System.IO.Compression;
using System.Data.Entity.Migrations.Infrastructure;
using System.Xml.Linq;
using MyApplication.Migrations;
using NUnit.Framework;
@trailmax
trailmax / IgnorableSerializerContractResolver.cs
Created March 4, 2014 23:18
Json.Net generic reusable "ignore property" resolver. Stole from here: http://stackoverflow.com/a/14510134/809357
/// <summary>
/// Special JsonConvert resolver that allows you to ignore properties. See http://stackoverflow.com/a/13588192/1037948
/// </summary>
public class IgnorableSerializerContractResolver : DefaultContractResolver {
protected readonly Dictionary<Type, HashSet<string>> Ignores;
public IgnorableSerializerContractResolver() {
this.Ignores = new Dictionary<Type, HashSet<string>>();
}
@trailmax
trailmax / EnforceHttpsHandlerTests.cs
Created February 22, 2014 23:08
Unit tests for EnforceHttpsHandler
using System.Net;
using System.Net.Http;
using System.Web;
using Moq;
using NUnit.Framework;
using MyApp.Tests.Stubs;
using MyApp.Web.Api.Infrastructure;
namespace MyApp.Tests.Web.Api.Infrastructure
@trailmax
trailmax / web.Release.config
Created February 22, 2014 22:33
Securing your cookies and STS header in web.config transformation
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<httpCookies httpOnlyCookies="true" requireSSL="true" lockItem="true" xdt:Transform="Replace" />
<authentication mode="Forms">
<forms loginUrl="~/Logon/LogOn" timeout="2880" requireSSL="true" xdt:Transform="Replace"/>
</authentication>
</system.web>
@trailmax
trailmax / RequreSecureConnectionFilter
Created February 22, 2014 21:50
RequreSecureConnectionFilter implementation and unit tests
using System;
using System.Web.Mvc;
public class RequreSecureConnectionFilter : RequireHttpsAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext == null)
{
@trailmax
trailmax / gist:9026408
Last active August 29, 2015 13:56
Verify that all appropriate controller actions have a sitemap/breadcrumb attribute. Rewritten in xUnit data Attribute.
// Issue with this approach is when there is nothing is wrong with the solution and no actions are in the bad, i.e. test should pass
// this test still fail with error saying "No data found".
public class ControllerActionsDataAttribute : DataAttribute
{
public override IEnumerable<object[]> GetData(MethodInfo methodUnderTest, Type[] parameterTypes)
{
var controllerTypes = SitemapControllersTests.GetControllerTypes();
var offendingActions = controllerTypes.Where(ct => !SitemapControllersTests.ExcludedControllers.Contains(ct))
.SelectMany(c => c.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
[Theory, AutoDomainData]
public void FrozenObjects_AreInjected_IntoSut([Frozen]ILocationAddressRepository repository,
CreateLocationAddressCommandHandler sut, CreateLocationAddressCommand command)
{
// Act
sut.Handle(command);
// Assert
repository.Received().Insert(Arg.Any<LocationAddress>());
repository.Received().Save();
public class CreateLocationAddressCommandHandlerTests
{
private IFixture fixture;
[SetUp]
public void SetUp()
{
fixture = new Fixture().Customize(new AutofixtureOnboardCustomization())
.Customize(new IgnoreVirtualMembersCustomisation());