Esempio n. 1
0
 public async Task <UserRequest> GetUserRequest(int id)
 {
     using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString))
     {
         return(await context.UserRequests.FirstOrDefaultAsync(ur => ur.Id == id));
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public async Task <List <string> > GetAllTagNames()
 {
     using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString))
     {
         return(await context.Tags.Select(t => t.TagName).Distinct().ToListAsync());
     }
 }
Esempio n. 4
0
 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" } }
                });
            }
        }
Esempio n. 6
0
 public async Task <User> GetUser(string userName)
 {
     using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString))
     {
         return(await context.Users.FirstOrDefaultAsync(u => u.Login == userName));
     }
 }
Esempio n. 7
0
        /// <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);
            }
        }
Esempio n. 8
0
 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));
     }
 }
Esempio n. 9
0
 public async Task AddComment(Comment comment)
 {
     using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString))
     {
         context.Comments.Add(comment);
         await context.SaveChangesAsync();
     }
 }
Esempio n. 10
0
        /// <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);
            }
        }
Esempio n. 11
0
 public async Task AddPost(Post post)
 {
     using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString))
     {
         context.Posts.Add(post);
         await context.SaveChangesAsync();
     }
 }
Esempio n. 12
0
 public async Task AddUserRequest(UserRequest userRequest)
 {
     using (var context = RepositoryContextFactory.CreateDbContext(ConnectionString))
     {
         context.UserRequests.Add(userRequest);
         await context.SaveChangesAsync();
     }
 }
Esempio n. 13
0
 public SearchController(RepositoryContextFactory contextFactory,
                         ServicesRepository servicesRepository,
                         UsersRepository usersRepository)
 {
     this.contextFactory     = contextFactory;
     this.servicesRepository = servicesRepository;
     this.usersRepository    = usersRepository;
 }
Esempio n. 14
0
        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();
        }
Esempio n. 15
0
        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();
        }
Esempio n. 16
0
        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));
        }
Esempio n. 17
0
        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();
        }
Esempio n. 18
0
 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();
     }
 }
Esempio n. 19
0
 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();
     }
 }
Esempio n. 20
0
        /// <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());
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        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();
        }
Esempio n. 25
0
        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);
        }
Esempio n. 27
0
        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();
        }
Esempio n. 28
0
 protected SearchIndexerBase(RepositoryContextFactory contextFactory)
 {
     this.contextFactory = contextFactory;
 }
Esempio n. 29
0
 protected ServiceSearchIndexer(RepositoryContextFactory contextFactory) : base(contextFactory)
 {
 }
Esempio n. 30
0
 public UserGeolocationsIndexer(RepositoryContextFactory contextFactory) : base(contextFactory)
 {
 }