public BasicServiceTest(ITestOutputHelper _output) { output = _output; mockCfg = new Mock <IOptions <AppConfig> >(); var ds = Path.DirectorySeparatorChar; var ac = new AppConfig(); ac.CurrentPath = Environment.CurrentDirectory + "/../../../../../../src/App.WebHost"; ac.AppDbPath = Path.GetDirectoryName(ac.CurrentPath) + ds + "App.DB" + ds; ac.CoreDbPath = Path.GetDirectoryName(Path.GetDirectoryName(ac.CurrentPath)) + ds + "Astum.Core" + ds + "src" + ds + "App.Core.DB" + ds; mockCfg.Setup(x => x.Value).Returns(ac); var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); Configuration = builder.Build(); var connection = Configuration.GetConnectionString("DefaultConnection"); var contextOption = new DbContextOptionsBuilder <ApplicationDbContext>().UseNpgsql(connection).Options; _context = new ApplicationDbContext(contextOption); var conditionsHelper = new PostgresQueryConditionsBuilder(); var helper = new SqlRepositoryHelper(conditionsHelper); IMemoryCache memoryCache = new MemoryCache(new MemoryCacheOptions()); IQueryableCacheService cacheService = new QueryableCacheService(memoryCache); var repo = new CommonRepository(_context, helper, cacheService); IObjectMapper mapper = new ObjectMapper(); DataService = new CommonDataService(repo, mapper); }
public void LoadSqlFromResource_ResourcePathDoesNotExist_Returns_Null(string filename) { var sut = new SqlRepositoryHelper(new MemoryCache(new MemoryCacheOptions()), EmptyLogFactory.Instance); var sql = sut.LoadSqlFromResource(filename); Assert.Null(sql); }
static BaseServiceGlobalFixture() { mockCfg = new Mock <IOptions <AppConfig> >(); var ds = Path.DirectorySeparatorChar; var ac = new AppConfig(); ac.CurrentPath = Environment.CurrentDirectory + "/../../../../../../src/App.WebHost"; ac.AppDbPath = Path.GetDirectoryName(ac.CurrentPath) + ds + "App.DB" + ds; ac.CoreDbPath = Path.GetDirectoryName(Path.GetDirectoryName(ac.CurrentPath)) + ds + "Astum.Core" + ds + "src" + ds + "App.Core.DB" + ds; mockCfg.Setup(x => x.Value).Returns(ac); var mockUserIdentInfo = new Mock <UserInfo>(); mockUserIdentInfo.Setup(x => x.Id).Returns("xUnit"); mockUserIdentInfo.Setup(x => x.LoginData).Returns(new Dictionary <string, string> { { "UserLogin", "xUnit" } }); var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); Configuration = builder.Build(); var connection = Configuration.GetConnectionString("DefaultConnection"); var contextOption = new DbContextOptionsBuilder <CoreDbContext>().UseNpgsql(connection).Options; _context = new CoreDbContext(contextOption) { UserInfo = mockUserIdentInfo.Object }; _context.Database.EnsureCreated(); var conditionsHelper = new PostgresQueryConditionsBuilder(); var helper = new SqlRepositoryHelper(conditionsHelper); _OrgDepartmentService = new BaseService <OrgDepartmentListDTO, OrgDepartmentDetailDTO, Department>( new DTOService <OrgDepartmentListDTO>(new DTORepository <OrgDepartmentListDTO>(_context, helper)), new DTOService <OrgDepartmentDetailDTO>(new DTORepository <OrgDepartmentDetailDTO>(_context, helper)), new EntityRepository <Department>(_context) ); _OrgDepartmentService.GetEntity().Where(x => x.Name.Contains("BaseService")).ToList().ForEach(x => _OrgDepartmentService.Remove(x)); }
public void LoadSqlFromResource_InvalidParameters_RaisesException(string filename) { var sut = new SqlRepositoryHelper(new MemoryCache(new MemoryCacheOptions()), EmptyLogFactory.Instance); Assert.Throws <ArgumentNullException>(() => sut.LoadSqlFromResource(filename)); }