Last active
July 12, 2017 06:31
-
-
Save rkttu/4fc2a9fa8fdba51dbdb13deec8658a78 to your computer and use it in GitHub Desktop.
MSpec, EF Core 2.0 In-Memory Provider Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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