Пример #1
0
        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);
        }
Пример #2
0
        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));
        }