//protected FakeS3Client s3Mock; public FileServiceTests(DbUnitTestSearchFixture fixture) { this.fixture = fixture; this.mapper = fixture.GetService <IMapper>(); //This client throws exceptions for everything //s3Mock = new FakeS3Client(); s3provider = new S3Provider(); //As is, it will returned NotImplemented for IAmazonS3 searcher = fixture.GetGenericSearcher(); writer = fixture.GetWriter(); config = new FileServiceConfig() { HighQualityResize = false }; service = new FileService(fixture.GetService <ILogger <FileService> >(), fixture.dbFactory, config, s3provider, new ImageManipulator_Direct(fixture.GetService <ILogger <ImageManipulator_Direct> >())); //Always want a fresh database! fixture.ResetDatabase(); //Every test gets their own directory config.MainLocation = Guid.NewGuid().ToString() + "_main"; config.ThumbnailLocation = Guid.NewGuid().ToString() + "_thumbnails"; config.TempLocation = Guid.NewGuid().ToString() + "_temp(quant)"; }
//The tests here are rather complicated; we can probably simplify them in the future, but for now, //I just need a system that REALLY tests if this whole thing works, and that is most reliable if //I just use the (known to work) dbwriter to set up the database in a way we expect. public EventQueueTest(DbUnitTestSearchFixture fixture) { this.fixture = fixture; this.searcher = fixture.GetGenericSearcher(); this.mapper = fixture.GetService <IMapper>(); this.permission = fixture.GetService <IPermissionService>(); this.shortcuts = fixture.GetService <ShortcutsService>(); this.config = new LiveEventQueueConfig() { //Ensure nothing ever expires DataCacheExpire = System.TimeSpan.MaxValue }; this.trackerConfig = new CacheCheckpointTrackerConfig() { CacheCleanFrequency = int.MaxValue }; //Note: WE HAVE TO create a new tracker every time! We don't want old data clogging this up!! this.tracker = new CacheCheckpointTracker <LiveEvent>(fixture.GetService <ILogger <CacheCheckpointTracker <LiveEvent> > >(), trackerConfig); this.queue = new LiveEventQueue(fixture.GetService <ILogger <LiveEventQueue> >(), this.config, this.tracker, fixture.dbFactory, this.permission, this.mapper); writer = new DbWriter(fixture.GetService <ILogger <DbWriter> >(), this.searcher, fixture.GetConnection(), fixture.GetService <IViewTypeInfoService>(), this.mapper, fixture.GetService <History.IHistoryConverter>(), this.permission, this.queue, new DbWriterConfig(), new RandomGenerator(), fixture.GetService <IUserService>()); //Reset it for every test fixture.ResetDatabase(); }
/// <summary> /// Get a single module by name with only the fields required for system blah blah blah /// </summary> /// <param name="search"></param> /// <param name="name"></param> /// <param name="userId"></param> /// <returns></returns> public static async Task <ContentView?> GetModuleForSystemByNameAsync(this IGenericSearch search, string name, long userId = -1) { var request = new SearchRequest() { type = "content", fields = "~votes,permissions,keywords,values", query = "name = @name and contentType = @type and !notdeleted()" }; var values = new Dictionary <string, object> { { "name", name }, { "type", InternalContentType.module } }; List <ContentView> modules = new List <ContentView>(); if (userId < 0) { modules = await search.SearchSingleTypeUnrestricted <ContentView>(request, values); } else { modules = await search.SearchSingleType <ContentView>(userId, request, values); } return(modules.FirstOrDefault(x => x.name == name && x.contentType == InternalContentType.module)); }
public LiveExtensionsTest(DbUnitTestSearchFixture fixture) { this.fixture = fixture; userStatuses = GetService <IUserStatusTracker>(); //DON'T use the fixture! want NEW service every time! searcher = fixture.GetGenericSearcher(); fixture.ResetDatabase(); }
public ShortcutsServiceTests(DbUnitTestSearchFixture fixture) { this.fixture = fixture; this.writer = fixture.GetWriter(); this.search = fixture.GetGenericSearcher(); this.mapper = fixture.GetService <IMapper>(); this.service = new ShortcutsService(fixture.GetService <ILogger <ShortcutsService> >(), fixture.dbFactory, mapper); }
public SpecializedSearchTests(DbUnitTestSearchFixture fixture) { this.fixture = fixture; this.mapper = fixture.GetService <IMapper>(); searcher = fixture.GetGenericSearcher(); //GetService<IGenericSearch>(); writer = fixture.GetWriter(); //Always want a fresh database! fixture.ResetDatabase(); }
/// <summary> /// Get all statuses the given user is allowed to retrieve. /// </summary> /// <param name="uid"></param> /// <returns></returns> public static async Task <UserlistResult> GetUserStatusesAsync(this IUserStatusTracker userStatuses, IGenericSearch searcher, long uid, string contentFields = "*", string userFields = "*", params long[] contentIds) { //Always allow 0 in there FYI var allStatuses = await userStatuses.GetUserStatusesAsync(contentIds); var allIds = allStatuses.Keys.ToList(); //Search content AS THE USER so they only get the content they're allowed to get. Hopefully //there will never be an instance where there are over a thousand contents currently being watched var allSearch = await searcher.Search(new SearchRequests() { requests = new List <SearchRequest>() { new SearchRequest() { type = "content", fields = contentFields, query = "id in @ids" }, new SearchRequest() { type = "user", fields = userFields, query = "id in @content.createUserId or id in @userIds" } }, values = new Dictionary <string, object>() { { "ids", allIds }, { "userIds", allStatuses.SelectMany(x => x.Value.Keys) } } }, uid); //Remove the statuses they can't see, meaning anything that's NOT in the allSearch set foreach (var id in allIds.Where(x => x != 0).Except(allSearch.objects["content"].Select(x => (long)x["id"]))) { allStatuses.Remove(id); } //Don't leak information: remove users that aren't referenced var allUsers = allStatuses.SelectMany(x => x.Value.Keys).Union(allSearch.objects["content"].Select(x => (long)x["createUserId"])); allSearch.objects["user"] = allSearch.objects["user"].Where(x => allUsers.Contains((long)x["id"])); return(new UserlistResult() { statuses = allStatuses, objects = allSearch.objects }); }
public CombinedUserTests(DbUnitTestSearchFixture fixture) { this.fixture = fixture; this.mapper = fixture.GetService <IMapper>(); searcher = fixture.GetGenericSearcher(); writer = fixture.GetWriter(); service = fixture.GetService <IUserService>(); //Always want a fresh database! fixture.ResetDatabase(); }
public static async Task <List <T> > SearchSingleType <T>(this IGenericSearch search, long uid, SearchRequest request, Dictionary <string, object>?values = null) { //Now go get some random-ass module message var searchResult = await search.Search(new SearchRequests() { values = values ?? new Dictionary <string, object>(), requests = new List <SearchRequest> { request } }, uid); return(search.ToStronglyTyped <T>(searchResult.objects.First().Value)); }
public ModuleServiceTests(DbUnitTestSearchFixture fixture) { this.fixture = fixture; this.writer = fixture.GetWriter(); this.searcher = fixture.GetGenericSearcher(); config = new ModuleServiceConfig() { ModuleDataConnectionString = "Data Source=moduledata;Mode=Memory;Cache=Shared" }; service = new ModuleService(config, fixture.GetService <ILogger <ModuleService> >(), fixture.dbFactory); masterconnection = new SqliteConnection(config.ModuleDataConnectionString); masterconnection.Open(); fixture.ResetDatabase(); }
public UserServiceTests(DbUnitTestBase fixture) { config = new UserServiceConfig { MinPasswordLength = 4, MaxPasswordLength = 8, MinUsernameLength = 4, MaxUsernameLength = 8, UsernameRegex = "^[a-zA-Z0-9]+$" }; searcher = fixture.GetGenericSearcher(); this.fixture = fixture; this.service = new UserService(fixture.GetService <ILogger <UserService> >(), fixture.GetService <IHashService>(), fixture.GetService <IAuthTokenService <long> >(), config, fixture.dbFactory, fixture.GetService <IViewTypeInfoService>()); //, fixture.GetService<IDbWriter>()); //Always want a fresh database! fixture.ResetDatabase(); }
/// <summary> /// Query for module by name, update the loaded module, and return the loaded module /// </summary> /// <param name="service"></param> /// <param name="search"></param> /// <param name="name"></param> /// <param name="userId"></param> /// <returns></returns> public static async Task <LoadedModule> RefreshModuleAsync(this IModuleService service, IGenericSearch search, string name, long userId = -1) { var ourModule = await GetModuleForSystemByNameAsync(search, name, userId); if (ourModule == null) { throw new NotFoundException($"Couldn't find module {name}!"); } return(RefreshModule(service, ourModule)); }
/// <summary> /// Pages the <paramref name="query"/> results using a cached request object to obtain the paging parameters. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="search"></param> /// <returns></returns> public static IQueryable <T> Paginate <T>(this IQueryable <T> query, IGenericSearch search) { return(search.Paginate(query)); }
/// <summary> /// Pages the <paramref name="query"/> results using the provided request object to obtain the paging parameters. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="search"></param> /// <param name="request"></param> /// <returns></returns> public static IQueryable <T> Paginate <T>(this IQueryable <T> query, IGenericSearch search, object request) { return(search.Paginate(query, request)); }
/// <summary> /// Sorts the <paramref name="query"/> results using a cached request object to obtain the sort parameters. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="search"></param> /// <returns></returns> public static IQueryable <T> Sort <T>(this IQueryable <T> query, IGenericSearch search) { return(search.Sort(query)); }
/// <summary> /// Sorts the <paramref name="query"/> results using the provided request object to obtain the sort parameters. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="search"></param> /// <param name="request"></param> /// <returns></returns> public static IQueryable <T> Sort <T>(this IQueryable <T> query, IGenericSearch search, object request) { return(search.Sort(query, request)); }
public Handler(NorthwindDbContext context, IMapper mapper, IGenericSearch search) { this.context = context; this.mapper = mapper; this.search = search; }