public async Task <UserRequest> GetUserRequest(int id) { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { return(await context.UserRequests.FirstOrDefaultAsync(ur => ur.Id == id)); } }
public async Task <Page <Post> > GetPosts(int index, int pageSize, string tag = null) { var result = new Page <Post>() { CurrentPage = index, PageSize = pageSize }; using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { var query = context.Posts.AsQueryable(); if (!string.IsNullOrWhiteSpace(tag)) { query = query.Where(p => p.Tags.Any(t => t.TagName == tag)); } result.TotalPages = await query.CountAsync(); query = query .Include(p => p.Tags) .Include(p => p.Comments) .OrderByDescending(p => p.CreatedDate) .Skip(index * pageSize).Take(pageSize); result.Records = await query.ToListAsync(); } return(result); }
public async Task <List <string> > GetAllTagNames() { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { return(await context.Tags.Select(t => t.TagName).Distinct().ToListAsync()); } }
public async Task <List <UserRequest> > GetUserRequests() { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { return(await context.UserRequests.ToListAsync()); } }
public void CanStartMessageBroker() { var queueFactory = Substitute.For<IQueueFactory>(); var messageBrokerConfig = new MessageBrokerConfig { RemoteQueueName = "MyRemoteQueueName", ServiceName = "TestBroker" }; var entityConnectionConfig = new EntityConnectionConfig(new DatabaseConnectionConfig("(localdb)\\MSSQLLocalDB", "ABJA_Ripples")); var logger = NullLogger.Instance; var repositoryContextFactory = new RepositoryContextFactory(logger, entityConnectionConfig); var queueHandlerFactory = new QueueHandlerFactory(logger, queueFactory); var processInformation = new ProcessInformation(); using (var messageBroker = new MessageBroker(logger, messageBrokerConfig, repositoryContextFactory, queueHandlerFactory, queueFactory, processInformation)) { var cancellationToken = new CancellationToken(); messageBroker.Start(cancellationToken); messageBroker.Handler(new MessageBusServiceHandshakeMessage { ServiceName = "MyServiceName", ServerName = "MyTestServer", ReplyQueue = "MyQueue", SendDateTime = DateTimeOffset.Now, SubscribeHandlers = new List<SubscribeHandler> { new SubscribeHandler { Name = "MySubscriber", QueueName = "MyQueue", Durable = true, MessageType = "string", Topic = "MyTopic" } } }); } }
public async Task <User> GetUser(string userName) { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { return(await context.Users.FirstOrDefaultAsync(u => u.Login == userName)); } }
/// <inheritdoc /> public async Task <ICollection <OrderDto> > GetAsync(Query query, Expression <Func <OrderDto, bool> > predicate = null) { using (var context = RepositoryContextFactory.CreateDbContext()) { var dbQuery = GetQueryableOrders(context, query.NeedProducts); if (predicate != null) { dbQuery = dbQuery.Where(predicate); } var pagination = query?.Pagination ?? new Pagination(); if (pagination.Offset != null) { dbQuery = dbQuery.Skip(pagination.Offset.Value); } if (pagination.Count != null) { dbQuery = dbQuery.Take(pagination.Count.Value); } var result = await dbQuery.ToListAsync(); return(result); } }
public async Task <Post> GetPost(int postId) { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { return(await context.Posts.Include(p => p.Tags).Include(p => p.Comments).FirstOrDefaultAsync(p => p.PostId == postId)); } }
public async Task AddComment(Comment comment) { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { context.Comments.Add(comment); await context.SaveChangesAsync(); } }
/// <inheritdoc /> public async Task <OrderDto> GetAsync(long id) { using (var context = RepositoryContextFactory.CreateDbContext()) { var result = await GetQueryableOrders(context, true).SingleOrDefaultAsync(e => e.Id == id); return(result); } }
public async Task AddPost(Post post) { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { context.Posts.Add(post); await context.SaveChangesAsync(); } }
public async Task AddUserRequest(UserRequest userRequest) { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { context.UserRequests.Add(userRequest); await context.SaveChangesAsync(); } }
public SearchController(RepositoryContextFactory contextFactory, ServicesRepository servicesRepository, UsersRepository usersRepository) { this.contextFactory = contextFactory; this.servicesRepository = servicesRepository; this.usersRepository = usersRepository; }
public void GetBookTesT_1() { var conString = "Server=DESKTOP-RF07Q5U;Database=AspCoreBookApp;Trusted_Connection=True;MultipleActiveResultSets=true"; IRepositoryContextFactory repositoryContextFactory = new RepositoryContextFactory(); IBookRepository publisherRepository = new BookRepository(conString, repositoryContextFactory); var result = publisherRepository.GetBooks(0, 10, "Author.Name", "Author1").Result.Records; var result1 = result.ToList(); }
public async Task GetPublisherTesT_1() { var conString = "Server=DESKTOP-RF07Q5U;Database=AspCoreBookApp;Trusted_Connection=True;MultipleActiveResultSets=true"; IRepositoryContextFactory repositoryContextFactory = new RepositoryContextFactory(); IPublisherRepository publisherRepository = new PublisherRepository(conString, repositoryContextFactory); var authorList = await publisherRepository.GetPublishers(0, 10); var ext = authorList.Records.ToList(); }
public RepositoryContext CreateDbContext(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); var config = builder.Build(); var connectionString = config.GetConnectionString("DefaultConnection"); var repositoryFactory = new RepositoryContextFactory(); return(repositoryFactory.CreateDbContext(connectionString)); }
public async Task AddNewAuthorTest_1() { string conString = "Server=DESKTOP-RF07Q5U;Database=AspCoreBookApp;Trusted_Connection=True;MultipleActiveResultSets=true"; IRepositoryContextFactory repositoryContextFactory = new RepositoryContextFactory(); IAuthorRepository authorRepository = new AuthorRepository(conString, repositoryContextFactory); await authorRepository.AddAuthor(new Author { Id = 0, Name = "Author4" }); var authorList = await authorRepository.GetAuthors(0, 10); var ext = authorList.Records.ToList(); }
public async Task DeleteComment(int commentId) { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { var coomment = new Comment() { CommentId = commentId }; context.Comments.Remove(coomment); await context.SaveChangesAsync(); } }
public async Task DeletePost(int postId) { using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString)) { var post = new Post() { PostId = postId }; context.Posts.Remove(post); await context.SaveChangesAsync(); } }
/// <summary> /// Внедрение зависимостей приложения /// </summary> /// <param name="services">описание сервисов</param> /// <param name="configuration">настройки</param> public static void InjectDependencies(IServiceCollection services, IConfiguration configuration) { var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new MappingProfile()); }); var mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); services.AddSingleton(opt => RepositoryContextFactory.Create(configuration)); services.AddScoped <IOrdersRepository, OrdersRepository>(); services.AddScoped <IOrdersManager, OrdersManager>(); }
public RepositoryContext CreateDbContext(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); var config = builder.Build(); //вытаскиваем строку подключения из конфига var connectionString = config.GetConnectionString("DefaultConnection"); var repositoryFactory = new RepositoryContextFactory(); //создаем и возвращаем DBContext return(repositoryFactory.CreateDbContext(connectionString)); }
public FeatureToggleIntegrationTests() { var logger = NullLogger.Instance; var entityConnectionConfig = new EntityConnectionConfig(new DatabaseConnectionConfig(@"(localdb)\MSSQLLocalDB", "Grumpy.FeatureToggle.Database_Model")); var repositoryContextFactory = new RepositoryContextFactory(logger, entityConnectionConfig); var messageBusBuilder = new MessageBusBuilder(); var messageBus = messageBusBuilder.Build(); _cut = new Core.FeatureToggle(logger, messageBus, repositoryContextFactory); messageBus.Start(new CancellationToken()); }
public void OnLongRunningStoredProcedure_EventIsNotRaisedIfStoredProcedureRunsForAShortTime() { string actualStoredProcedureName = null; int actualExecutionTimeSeconds = -1; RepositoryContextFactory repositoryContextFactory = RepositoryContextFactory.Instance; repositoryContextFactory.OnLongRunningStoredProcedure += (s, e) => { actualStoredProcedureName = e.StoredProcedureName; actualExecutionTimeSeconds = e.ExecutionTimeSeconds; }; Assert.Null(actualStoredProcedureName); Assert.AreEqual(-1, actualExecutionTimeSeconds); }
public async Task AddNewBookToAuthorTest_1() { var conString = "Server=DESKTOP-RF07Q5U;Database=AspCoreBookApp;Trusted_Connection=True;MultipleActiveResultSets=true"; IRepositoryContextFactory repositoryContextFactory = new RepositoryContextFactory(); IAuthorRepository authorRepository = new AuthorRepository(conString, repositoryContextFactory); IBookRepository bookRepository = new BookRepository(conString, repositoryContextFactory); var txt = await bookRepository.AddBookToAuthor(new BooksToAuthors { BookId = 5, AuthorId = 3 }); var authorList = await bookRepository.GetBooks(0, 10); var ext = authorList.Records.ToList(); }
public void OnLongRunningStoredProcedure_EventIsRaisedIfStoredProcedureRunsForALongTime() { const string expectedStoredProcedureName = "LongRunningStoredProcedure"; int expectedExecutionTimeSeconds = /*Settings.Default.LongRunningStoredProcedureTimeSeconds*/ 5 + 1; string actualStoredProcedureName = null; int actualExecutionTimeSeconds = -1; RepositoryContextFactory repositoryContextFactory = RepositoryContextFactory.Instance; repositoryContextFactory.OnLongRunningStoredProcedure += (s, e) => { actualStoredProcedureName = e.StoredProcedureName; actualExecutionTimeSeconds = e.ExecutionTimeSeconds; }; Assert.NotNull(actualStoredProcedureName); Assert.AreEqual(expectedStoredProcedureName, actualStoredProcedureName); Assert.AreNotEqual(-1, actualExecutionTimeSeconds); Assert.True(actualExecutionTimeSeconds >= expectedExecutionTimeSeconds); }
protected override void Process(CancellationToken cancellationToken) { Logger = new ConsoleLogger(ServiceName, (message, level) => level >= _logLevel, false); var appSettings = ConfigurationManager.AppSettings; Enum.TryParse(appSettings["LogLevel"], true, out _logLevel); var entityConnectionConfig = new EntityConnectionConfig(new DatabaseConnectionConfig(appSettings["DatabaseServer"], appSettings["DatabaseName"])); var repositoryContextFactory = new RepositoryContextFactory(Logger, entityConnectionConfig); var messageBusBuilder = new MessageBusBuilder(); messageBusBuilder.WithLogger(Logger); messageBusBuilder.WithServiceName(ServiceName); _messageBus = messageBusBuilder.Build(); _featureToggle = new Core.FeatureToggle(Logger, _messageBus, repositoryContextFactory); _messageBus.Start(cancellationToken); }
public async Task AddNewBookTest_1() { var conString = "Server=DESKTOP-RF07Q5U;Database=AspCoreBookApp;Trusted_Connection=True;MultipleActiveResultSets=true"; IRepositoryContextFactory repositoryContextFactory = new RepositoryContextFactory(); IBookRepository bookRepository = new BookRepository(conString, repositoryContextFactory); await bookRepository.AddBook(new Book { Id = 0, Name = "Book4", Description = "Test", PublishedAt = DateTime.Now, Price = 1, Publisher = new Publisher { Id = 1 }, }); var authorList = await bookRepository.GetBooks(0, 10); var ext = authorList.Records.ToList(); }
protected SearchIndexerBase(RepositoryContextFactory contextFactory) { this.contextFactory = contextFactory; }
protected ServiceSearchIndexer(RepositoryContextFactory contextFactory) : base(contextFactory) { }
public UserGeolocationsIndexer(RepositoryContextFactory contextFactory) : base(contextFactory) { }