public static FestivalsContext Create() { var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = ":memory:" }; var connection = new SqliteConnection(connectionStringBuilder.ToString()); var options = new DbContextOptionsBuilder <FestivalsContext>() .UseSqlite(connection) .Options; var dateTimeMock = new Mock <IDateTimeService>(); dateTimeMock.Setup(m => m.Now) .Returns(DateTime.Now); var userInfoServiceMock = new Mock <IUserInfoService>(); userInfoServiceMock.Setup(m => m.UserId) .Returns("00000000-0000-0000-0000-000000000000"); var context = new FestivalsContext( options, dateTimeMock.Object, userInfoServiceMock.Object); context.Database.OpenConnection(); context.Database.EnsureCreated(); return(context); }
public FestivalsRepository( FestivalsContext festivalsContext, IPropertyMappingService propertyMappingService) { _festivalsContext = festivalsContext ?? throw new ArgumentNullException(nameof(festivalsContext)); this._propertyMappingService = propertyMappingService; }
public FestivalsContextTestBase() { var options = new DbContextOptionsBuilder <FestivalsContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; DateTimeMock = new Mock <IDateTimeService>(); DateTimeMock.Setup(m => m.Now).Returns(new DateTime(3001, 1, 1)); var userInfoServiceMock = new Mock <IUserInfoService>(); userInfoServiceMock.Setup(m => m.UserId) .Returns("00000000-0000-0000-0000-000000000000"); ContextBase = new FestivalsContext(options, new DateTimeService(), userInfoServiceMock.Object); }
public static void Destroy(FestivalsContext context) { context.Database.EnsureDeleted(); context.Dispose(); }