Skip to content

Instantly share code, notes, and snippets.

View lkaczanowski's full-sized avatar

Łukasz Kaczanowski lkaczanowski

View GitHub Profile
@lkaczanowski
lkaczanowski / HtmlActionResult
Created August 6, 2014 12:25
Implementation of ASP.NET Web.Api IHttpActionResult that returns html rendered by Razor
public class HtmlActionResult<T> : IHttpActionResult
{
private readonly string _viewTemplate;
private readonly T _model;
public HtmlActionResult(string viewTemplateFullPath, T model)
{
_viewTemplate = File.ReadAllText(viewTemplateFullPath);
_model = model;
}
@lkaczanowski
lkaczanowski / MvcModelBinderTestHelper.cs
Last active August 29, 2015 14:14
MVC ModelBinder test helper
public static class MvcModelBinderTestHelper
{
public static ModelBindingContext FakeModelBindingContext<T>(NameValueCollection formCollection) where T : class
{
var valueProvider = new NameValueCollectionValueProvider(formCollection, null);
var metadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(T));
var bindingContext = new ModelBindingContext
{
@lkaczanowski
lkaczanowski / NugetHelpers.ps1
Last active August 29, 2015 14:22
Nuget Powershell Helpers
Register-TabExpansion 'Get-SolutionPackages' @{
'PackageName' = { Get-Package | Sort-Object -Property Id -Unique | foreach { $_.Id } }
}
Register-TabExpansion 'Refresh-Package' @{
'PackageName' = { Get-Package | Sort-Object -Property Id -Unique | foreach { $_.Id } }
}
function Refresh-Package($PackageName) {
@lkaczanowski
lkaczanowski / SequenceGenerator.cs
Last active November 3, 2019 11:35
Method to generate infinite iterations of elements with IEnumerable and IAsyncEnumerable
public static class SequenceGenerator
{
public static IEnumerable<T> Generate<T>(T initialValue, Func<T, T> generator)
where T : struct
{
var value = initialValue;
while (true)
{
yield return value;
value = generator(value);
@lkaczanowski
lkaczanowski / MockHttpMessageHandlerHelper.cs
Created December 16, 2015 14:57
HttpMessageHandler mock helper
internal static class MockHttpMessageHandlerHelper
{
public static void SetupSendAsync(this Mock<HttpMessageHandler> handler, Func<HttpResponseMessage> sendAsyncResultFunc)
{
handler.Protected()
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
.Returns(Task<HttpResponseMessage>.Factory.StartNew(sendAsyncResultFunc));
}
public static void VerifySendAsync(this Mock<HttpMessageHandler> handler, Times times)
@lkaczanowski
lkaczanowski / RestSharpExtensions.cs
Created December 18, 2015 11:44
RestSharp extensions
using System;
using System.Net;
using System.Text;
using RestSharp;
namespace RestSharpExtensions
{
public static class RestSharpExtensions
{
@lkaczanowski
lkaczanowski / RestSharpExtensions.cs
Last active November 4, 2022 23:08
RestSharp extensions for error handling
using System;
using System.Net;
using System.Text;
using RestSharp;
namespace RestSharpExtensions
{
internal static class RestSharpExtensions
{
@lkaczanowski
lkaczanowski / FluentValidationExtensions.cs
Last active January 8, 2016 11:15
Fluent Validation helper methods to get errors for specific property
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Resources;
using System.Web.Mvc;
using FluentValidation.Results;
namespace Helpers
{
@lkaczanowski
lkaczanowski / AutoFixtureExtensions.cs
Last active February 17, 2016 08:10
Extensions for AutoFixture
namespace AutoFixtureExtensions
{
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoMoq;
using Ploeh.AutoFixture.Kernel;
public class SpecificArgumentsConstructorQuery : IMethodQuery
{
private readonly Type[] _types;
@lkaczanowski
lkaczanowski / ResharperTestingWithAutofixtureAndNUnit.DotSettings
Created February 22, 2016 15:20
Resharper teample for testing class with Autofixture and NUnit
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Shortcut/@EntryValue">test</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Description/@EntryValue">Creates NUnit test</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Text/@EntryValue">[Test]&#xD;
public void $MethodName$()&#xD;
{&#xD;
// assign&#xD;
$END$&#xD;
&#xD;