Skip to content

Instantly share code, notes, and snippets.

@johanvergeer
johanvergeer / PersonControllerSpec.Get_NoArgs_ReturnsAllPeople.cs
Last active May 19, 2019 14:41
Expect three Person objects to return
[Fact]
public void Get_NoArgs_ReturnsAllPeople()
{
var people = new List<Person>
{
new Person {Name = "Johan", Age = 37},
new Person {Name = "Angela", Age = 34},
new Person {Name = "Robert", Age = 36}
};
@johanvergeer
johanvergeer / PersonControllerSpec.Get_NoArgs_ReturnsEmptyList.cs
Last active May 19, 2019 14:32
Test method for PersonController returning an empty list of Person
[Fact]
public void Get_NoArgs_ReturnsEmptyList()
{
// Setup repository to return an empty list
this._repository.Setup(r => r.FindAll())
.Returns(new List<Person>());
// Pass the mock repository to the controllers constructor
var controller = new PersonController(this._repository.Object);
@johanvergeer
johanvergeer / PersonControllerSpec.cs
Created May 19, 2019 14:24
PersonControllerSpect with IPersonRepository mock
public class PersonControllerSpec
{
private readonly Mock<IPersonRepository> _repository;
public PersonControllerSpec()
{
this._repository = new Mock<IPersonRepository>();
}
}
@johanvergeer
johanvergeer / PersonController.cs
Created May 19, 2019 14:09
Person API Controller
[Route("api/[controller]")]
[ApiController]
public class PersonController : Controller
{
private readonly IPersonRepository _repository;
public PersonController(IPersonRepository _repository)
{
this._repository = _repository;
}
@johanvergeer
johanvergeer / IPersonRepository.cs
Last active May 19, 2019 14:08
Person Repository interface
public interface IPersonRepository
{
IReadOnlyCollection<Person> FindAll();
void Add(Person person);
}
@johanvergeer
johanvergeer / PersonModel.cs
Last active May 19, 2019 13:56
Simple Person model
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public bool IsValid => !string.IsNullOrWhiteSpace(this.Name);
}
@johanvergeer
johanvergeer / .editorconfig
Last active April 23, 2019 06:43
My default EditorConfig for C# projects
# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Workspace\Uniforms codebase based on best match to current usage at 12-4-2019
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
[*.cs]
#Core editorconfig formatting - indentation
#use soft tabs (spaces) for indentation
indent_style = space
indent_size = 4
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
" Kotlin Vim Plugin # https://github.com/udalov/kotlin-vim
Plugin 'udalov/kotlin-vim'
" Syntax checking # https://github.com/vim-syntastic/syntastic
@johanvergeer
johanvergeer / _macbook-setup.md
Last active October 13, 2018 09:08
My Macbook setup
@johanvergeer
johanvergeer / download-docker-compose.sh
Last active September 28, 2018 08:38
Docker Jenkins
cd /usr/local/bin
wget https://github.com/docker/compose/releases/download/1.13.0/docker-compose-Linux-x86_64
mv docker-compose* docker-compose
chmod +x docker-compose