/// <summary> /// Create a database containing a static know set of testing data /// </summary> public static Mock <RepositoryService> CreateStandard() { // Create mock for ILogger. var loggerMock = new Mock <ILogger <AudioConversion.Program> >(); // Create mock for IDatabase. Include some testing data. NOTE: Use a unique database name or tests will share and fail. var options = new DbContextOptionsBuilder <SQLDatabaseContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning)).Options; SQLDatabaseContext context = new SQLDatabaseContext(options); // Create the seed data. context.Database.EnsureCreated(); context.AudioConversion.Add(new Call() { Id = 1, CallerName = "Vo", CallerPhone = "0393916603", DestinationName = "Anne", DestinationPhone = "0398673456", DirectionType = 0, DurationSeconds = 56 }); context.AudioConversion.Add(new Call() { Id = 1, CallerName = "Jo", CallerPhone = "0393916603", DestinationName = "Vo", DestinationPhone = "0398673456", DirectionType = 0, DurationSeconds = 56 }); context.AudioConversion.Add(new Call() { Id = 1, CallerName = "Paul", CallerPhone = "0393916603", DestinationName = "Vo", DestinationPhone = "040378956", DirectionType = 0, DurationSeconds = 56 }); context.SaveChanges(); var hostEnvironment = new Mock <IHostEnvironment>(); hostEnvironment.SetupGet(x => x.EnvironmentName).Returns("Development"); // context needs to be wrapped in an IServiceScopeTestory. Can't just put context straight into the constructor. return(new Mock <RepositoryService>(loggerMock.Object, new MockServiceScopeFactory(context), hostEnvironment.Object)); }
/// <summary> /// Create a database containing no data /// </summary> public static Mock <RepositoryService> CreateEmpty() { // Create mock for ILogger. var loggerMock = new Mock <ILogger <AudioConversion.Program> >(); // Create mock for IDatabase. Include some testing data. NOTE: Use a unique database name or tests will share and fail. var options = new DbContextOptionsBuilder <SQLDatabaseContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning)).Options; SQLDatabaseContext context = new SQLDatabaseContext(options); // Create the seed data. context.Database.EnsureCreated(); // Return the mocked object. return(new Mock <RepositoryService>(loggerMock.Object, context)); }
/// <summary> /// Gets the database manager to execute T-SQL statements against it /// </summary> /// <returns></returns> protected void SetContainer(DatabaseServers dBServer = DatabaseServers.DB_DEMO) { var configurationName = this.Configuration["ENVIRONMENT"]; var keyName = $"{configurationName}:{dBServer.ToString()}"; var connection = this.Configuration[keyName]; var commandTimeout = this.Configuration["FRAMEWORK.COMMAND.TIMEOUT"].ToInt(); var connectionTimeout = this.Configuration["FRAMEWORK.CONNECTION.TIMEOUT"].ToInt(); var traceEnabled = this.Configuration["FRAMEWORK.TRACE.ENABLED"].ToBool(); var traceFilePath = this.Configuration["FRAMEWORK.TRACE.PATH"]; if (!traceEnabled) { traceFilePath = string.Empty; } connection = Cryptography.DecryptUsingTripleDES(connection); var databaseContext = new SQLDatabaseContext(connection, commandTimeout, connectionTimeout); var databaseRepository = new SQLDatabaseRepository(false, traceFilePath); container = new ContainerDI(databaseContext, databaseRepository); }
public ProductService(SQLDatabaseContext context) { _context = context; }
public AuthenticateService(SQLDatabaseContext context) { _context = context; }
public MockServiceScope(SQLDatabaseContext Database) { ServiceProvider = new MockServiceProvider(Database); }
public MockServiceScopeFactory(SQLDatabaseContext Database) { _database = Database; }
public MockServiceProvider(SQLDatabaseContext Database) { _database = Database; }