Skip to content

Instantly share code, notes, and snippets.

View cwe1ss's full-sized avatar

Christian Weiss cwe1ss

View GitHub Profile
@cwe1ss
cwe1ss / gist:970c65995280496a1864
Last active August 29, 2015 14:03
Custom ViewEngine for the "Feature Folder" project structure
public class FeatureFolderViewEngine : RazorViewEngine
{
public FeatureFolderViewEngine()
{
// {0} ActionName
// {1} ControllerName
// {2} AreaName
AreaViewLocationFormats = new[]
{
@cwe1ss
cwe1ss / ICookieContainer
Created August 9, 2014 13:15
ICookieContainer
public interface ICookieContainer
{
bool Exists(string key);
string GetValue(string key);
T GetValue<T>(string key);
void SetValue(string key, object value, DateTime expires);
}
public class CookieContainer : ICookieContainer
{
private readonly HttpRequestBase _request;
private readonly HttpResponseBase _response;
public CookieContainer(HttpRequestBase request, HttpResponseBase response)
{
// "Check" is a helper class, I've got from the "Kigg" project
Check.IsNotNull(request, "request");
Check.IsNotNull(response, "response");
public static class Mocks
{
public static Mock&lt;HttpRequestBase&gt; HttpRequest()
{
var httpRequest = new Mock&lt;HttpRequestBase&gt;();
httpRequest.Setup(x =&gt; x.Cookies).Returns(new HttpCookieCollection());
return httpRequest;
}
public static Mock&lt;HttpResponseBase&gt; HttpResponse()
public interface IAppCookies
{
string UserEmail { get; set; }
DateTime? LastVisit { get; set; }
}
public class AppCookies : IAppCookies
{
private readonly ICookieContainer _cookieContainer;
public class HomeController : Controller
{
private readonly IAppCookies _cookies;
public HomeController(IAppCookies cookies)
{
_cookies = cookies;
}
public ActionResult Index()
@cwe1ss
cwe1ss / ProjectsMissingInSolution.ps1
Created September 30, 2015 08:13
ProjectsMissingInSolution.ps1
$ErrorActionPreference = "Stop"
# Parameters
$baseFolder = (Get-Item (Get-Location)).Parent.FullName + "\"
$slnName = "All.sln"
$excludePatterns = @("Some\Exclusion")
# ################################################################
public class FeatureFolderViewLocationExpander : IViewLocationExpander
{
public void PopulateValues(ViewLocationExpanderContext context)
{
/* no-op */
}
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
// {0} - Action Name
[CmdletBinding(SupportsShouldProcess)]
param (
# Only one of these may be used.
[Parameter(ParameterSetName='Major')]
[switch]$Major,
[Parameter(ParameterSetName='Minor')]
[switch]$Minor,
[Parameter(ParameterSetName='Patch')]
[switch]$Patch,
[Parameter(ParameterSetName='Version')]
@cwe1ss
cwe1ss / Startup.cs
Last active November 25, 2021 10:57
Castle.Facilities.AspNetCoreIntegration
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// Configure regular ASP.NET Core services
services.AddMvc();
// ...
// Send configuration to Castle Windsor
Container.Populate(services);
Container.BeginScope();
return Container.Resolve<IServiceProvider>();