35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import "reflect-metadata"
|
|
import { container } from "tsyringe"
|
|
|
|
import * as fs from 'fs'
|
|
import * as path from 'path'
|
|
|
|
import { InterfaceName as ConfigurationName, IConfiguration } from '../src/interfaces/IConfiguration'
|
|
import { InterfaceName as TestServiceName, TestService } from '../src/services/testService'
|
|
|
|
class Program {
|
|
constructor() {
|
|
this.RegisterServices()
|
|
}
|
|
|
|
private RegisterServices = () => {
|
|
const nodeEnv: string | undefined = process.env.NODE_ENV
|
|
const rawConfig: Buffer = fs.readFileSync(path.join(__dirname, `appsettings${nodeEnv === 'PROD' ? '.production': ''}.json`))
|
|
const configuration: IConfiguration = JSON.parse(rawConfig.toString())
|
|
|
|
container.register(ConfigurationName, { useValue: configuration })
|
|
container.register(TestServiceName, { useClass: TestService })
|
|
}
|
|
|
|
public Main = () => {
|
|
const testService = container.resolve(TestService)
|
|
|
|
test('adds 1 + 2 to equal 3', () => {
|
|
expect(testService.Sum(1, 2)).toBe(3)
|
|
})
|
|
}
|
|
}
|
|
|
|
const program = new Program
|
|
program.Main()
|