Skip to content

Instantly share code, notes, and snippets.

@rkttu
Last active July 12, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkttu/4fc2a9fa8fdba51dbdb13deec8658a78 to your computer and use it in GitHub Desktop.
Save rkttu/4fc2a9fa8fdba51dbdb13deec8658a78 to your computer and use it in GitHub Desktop.
MSpec, EF Core 2.0 In-Memory Provider Sample
using TheCompany.Something.Api.Repositories;
using TheCompany.Something.Data;
using TheCompany.Something.Data.Models;
using Machine.Fakes;
using Machine.Specifications;
using Microsoft.EntityFrameworkCore;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace TheCompany.Something.Test
{
[Subject("Data Access")]
public class WhenUsingAppRepository : WithSubject<ApplicationRepository>
{
static Application result;
Establish context = () =>
{
Configure(x => x.For<SomethingDataContext>().Use(() =>
{
var options = new DbContextOptionsBuilder();
options.UseInMemoryDatabase(nameof(SomethingDataContext));
var context = new SomethingDataContext(options.Options);
context.ApplicationAccessKeys.Add(new ApplicationAccessKey()
{
Application = new Application() { UniqueId = Guid.Empty },
MasterKey = "secret_key",
Enabled = true
});
context.SaveChanges();
return context;
}));
};
Because of = () => result = Subject.GetApplicationBySecretKey(Guid.Empty, "secret_key", CancellationToken.None).Result;
It should_not_be_null = () => result.ShouldNotBeNull();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment