Skip to content

Instantly share code, notes, and snippets.

@ewilde
ewilde / WithConcreteSubject.cs
Created January 16, 2013 08:41
Machine.fakes class that enables you to program your tests against an interface, but have the SUT created as a concrete type with dependencies auto faked. #mspec
using System.Diagnostics.CodeAnalysis;
using global::Machine.Fakes;
using global::Machine.Specifications;
/// <summary>
/// Casts the subject as the supplied <typeparamref name="TInterface"/> but
/// creates it using a concrete type and fills in dependencies using the auto faking container.
/// </summary>
/// <typeparam name="TInterface">The type of the interface.</typeparam>
/// <typeparam name="TConcreteType">The type of the concrete type.</typeparam>
@ewilde
ewilde / FooContainer.cs
Created January 23, 2013 16:03
How to test #structuremap configuration using #mspec
[Subject(typeof (CommonRegistry))]
public class When_add_common_registry_to_a_container
{
Because of = () => ObjectFactory.Configure(x=>x.Scan(scanner=>
{
scanner.AssemblyContainingType<ISerializer>();
scanner.LookForRegistries();
}));
It should_register_a_default_i_serializer = () => ObjectFactory.GetAllInstances<ISerializer>().Count.ShouldBeGreaterThan(0);
/// <summary>
/// Resolves instances using the structure map object factory.
/// </summary>
public class StructureMapInstanceProvider : IInstanceProvider
{
/// <summary>
/// The service type
/// </summary>
private readonly Type serviceType;
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
/// <summary>
/// Wraps a service client so you can use "using" without worrying of getting
/// your business exception swallowed. Usage:
/// <example>
/// <code>
/// using(var serviceClient = new ServiceClientWrapper&lt;IServiceContract&gt;)
@ewilde
ewilde / Example.cs
Last active December 11, 2015 17:28
#mspec base class which creates a subject with DI instead of mocks, useful for integration test
public class When_calling_foo_service : WithIntegrationSubject<ServiceClientWrapper<IFooService>>
{
Establish context = () => With<RunningService>();
Because of = () => FooActionResponse = Subject.Channel.Action(new FooActionRequest());
It should_return_a_response = () => FooActionResponse.ShouldNotBeNull();
static FooActionResponse FooActionResponse;
}
@ewilde
ewilde / Example.cs
Created January 28, 2013 14:00
#structuremap instance factory pattern
public class Example
{
public IInstanceFactory InstanceFactory { get; set; }
public void GetInstanceWithArgument()
{
var foo = this.InstanceFactory<Employee, string>("ArgumentValue1")
}
}
@ewilde
ewilde / IOperationResult.cs
Created January 31, 2013 15:57
Create a operation timing class
/// <summary>
/// The result of a timing operation
/// </summary>
public interface IOperationResult : IDisposable, ISplitTimer
{
/// <summary>
/// Gets or sets the elapsed time this operation took to complete.
/// </summary>
TimeSpan Elapsed { get; set; }
public class TaskSchedulerPool
{
private readonly List<Lazy<TaskScheduler>> _taskSchedulers;
public TaskSchedulerPool(int maxSize)
{
_taskSchedulers = Enumerable.Range(1, maxSize)
.Select(
_ => new Lazy<TaskScheduler>(() => new ConcurrentExclusiveSchedulerPair().ExclusiveScheduler))
.ToList();
@ewilde
ewilde / vault.service
Last active December 10, 2021 16:56 — forked from yunano/vault.service
for development only /etc/systemd/system/vault.service
[Unit]
Description=vault server
Requires=network-online.target
After=network-online.target consul.service
[Service]
EnvironmentFile=-/etc/default/vault
Restart=on-failure
ExecStart=/usr/local/bin/vault server $OPTIONS -config=/etc/vault.d/vault.conf
ExecStartPost=/bin/bash -c "echo 'Waiting for vault to start' && sleep 5s && for key in $KEYS; do echo unsealing with key $key && /usr/local/bin/vault unseal $key; done"
@ewilde
ewilde / vault-install.sh
Last active September 27, 2020 17:56
Install hashicorp vault on ubuntu using systemd
#!/usr/bin/env bash
set -e
echo "Installing dependencies..."
sudo apt-get update -y
sudo apt-get install -y unzip
echo "Fetching vault..."
VAULT=0.6.5