Skip to content

Instantly share code, notes, and snippets.

Johan Vergeer johanvergeer

Block or report user

Report or block johanvergeer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View separate-component.js
// Create a component, which is global and can be used anywhere
// in the application
const Hello = Vue.component(
'Hello', // Name of the component
{ templdate: '<span>Hello</span>' } // Options object, which contains a template
)
new Vue({
template: '<div><Hello/> there</div>', // Hardcoded 'Hello' is replated with the component
el: '#app'
@johanvergeer
johanvergeer / Program.cs
Last active May 27, 2019
Check for 10 million Guids whether they are a UUID version 4. This Gist is used in my blog post https://johanvergeer.github.io/posts/net-guid-uuid-version
View Program.cs
/// <summary>
/// Simple script to check whether a C# Guid is really a UUID version 4.
/// </summary>
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"{"Current",-10}{"Errors found",-10}");
Console.WriteLine($"{"-------",-10}{"------------",-10}");
@johanvergeer
johanvergeer / Startup.ConfigureServices.cs
Last active May 21, 2019
An ASP.NET Core 2 Server test fixture for xUnit
View Startup.ConfigureServices.cs
public void ConfigureServices(IServiceCollection services)
{
var connectionString = Configuration.GetConnectionString("ApiTestsDbContext");
services.AddDbContext<PersonDbContext>(options =>
options.UseSqlServer(connectionString));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddScoped<IPersonRepository, PersonRepository>();
}
View PersonControllerSpec.Post_PersonWithoutName_PersonNotSaved.cs
[Fact]
public void Post_PersonWithoutName_PersonNotSaved()
{
// Create new person, without a name, which will not be accepted by the controller
var person = new Person();
// Create new controller with mock repository
var controller = new PersonController(this._repository.Object);
// Call controller to post person
View PersonControllerSpec.Post_Person_PersonSaved.cs
[Fact]
public void Post_Person_PersonSaved()
{
// Create person to post to controller
var person = new Person {Name = "Johan", Age = 37};
// Create new controller with mock repository
var controller = new PersonController(this._repository.Object);
// Call controller to post person
View PersonControllerSpec.Get_NoArgs_ReturnsAllPeople.cs
[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
Test method for PersonController returning an empty list of Person
View PersonControllerSpec.Get_NoArgs_ReturnsEmptyList.cs
[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
PersonControllerSpect with IPersonRepository mock
View PersonControllerSpec.cs
public class PersonControllerSpec
{
private readonly Mock<IPersonRepository> _repository;
public PersonControllerSpec()
{
this._repository = new Mock<IPersonRepository>();
}
}
View PersonController.cs
[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
Person Repository interface
View IPersonRepository.cs
public interface IPersonRepository
{
IReadOnlyCollection<Person> FindAll();
void Add(Person person);
}
You can’t perform that action at this time.