コード例 #1
0
        public static void SetStoredProcedureHandler <T>(this ICosmosDbRepository <T> self, string id, Func <object[], RequestOptions, Task <object> > func)
        {
            if (self is null)
            {
                throw new ArgumentNullException(nameof(self));
            }

            if (!(self is CosmosDbRepositorySubstitute <T> substitute))
            {
                throw new ArgumentException($"self is not a CosmosDbRepositorySubstituteBase<{typeof(T).Name}>", nameof(self));
            }

            substitute.SetStoredProcedureHandler(id, func);
        }
コード例 #2
0
        public static void ClearGenerateExceptionOnCount <T>(this ICosmosDbRepository <T> self)
        {
            if (self is null)
            {
                throw new ArgumentNullException(nameof(self));
            }

            if (!(self is CosmosDbRepositorySubstitute <T> substitute))
            {
                throw new ArgumentException($"self is not a CosmosDbRepositorySubstituteBase<{typeof(T).Name}>", nameof(self));
            }

            substitute.ClearGenerateExceptionOnCount();
        }
        public static void GenerateExceptionOnAddWhen <T>(this ICosmosDbRepository <T> self,
                                                          Predicate <T> predicate,
                                                          HttpStatusCode statusCode,
                                                          string message = default)
        {
            if (self is null)
            {
                throw new ArgumentNullException(nameof(self));
            }
            if (predicate is null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            if (!(self is CosmosDbRepositorySubstitute <T> substitute))
            {
                throw new ArgumentException($"self is not a CosmosDbRepositorySubstituteBase<{typeof(T).Name}>", nameof(self));
            }

            substitute.GenerateExceptionOnAddWhen(predicate, statusCode, message);
        }
コード例 #4
0
        public TestingContext(IServiceProvider services, Action <ICosmosDbBuilder> builderCallback, Action <ICosmosDbRepositoryBuilder <T> > repoBuilderCallback)
        {
            DbConfig   = services.GetRequiredService <IOptions <CosmosDbConfig> >().Value;
            TestConfig = services.GetRequiredService <IOptions <TestConfig> >().Value.Clone();
            EnvConfig  = services.GetRequiredService <IOptions <EnvironmentConfig> >().Value;

            if (EnvConfig.RandomizeCollectionName)
            {
                TestConfig.CollectionName = $"{TestConfig.CollectionName}{Guid.NewGuid()}";
            }

            DbClient = new DocumentClient(new Uri(DbConfig.DbEndPoint), DbConfig.DbKey);
            var builder = new CosmosDbBuilder()
                          .WithId(DbConfig.DbName)
                          .WithDefaultThroughput(400)
                          .AddCollection <T>(TestConfig.CollectionName, repoBuilderCallback);

            builderCallback?.Invoke(builder);

            CosmosDb = builder.Build(DbClient);

            Repo = CosmosDb.Repository <T>();
        }
コード例 #5
0
 public static Task <IList <U> > SelectManyAsync <T, U, V>(this ICosmosDbRepository <T> repo, V partitionKey, Expression <Func <T, IEnumerable <U> > > selector, Func <IQueryable <T>, IQueryable <T> > whereClauses = null, Func <IQueryable <U>, IQueryable <U> > selectClauses = null, FeedOptions feedOptions = null)
 {
     feedOptions = SetPartitionKey(partitionKey, feedOptions);
     return(repo.SelectManyAsync(selector, whereClauses, selectClauses, feedOptions));
 }
コード例 #6
0
 public static Task <T> UpsertAsync <T, U>(this ICosmosDbRepository <T> repo, U partitionKey, T entity, RequestOptions requestOptions = null)
 {
     requestOptions = SetPartitionKey(partitionKey, requestOptions);
     return(repo.ReplaceAsync(entity, requestOptions));
 }
コード例 #7
0
 public static Task <CosmosDbRepositoryPagedResults <T> > FindAsync <T, U>(this ICosmosDbRepository <T> repo, U partitionKey, int pageSize, string continuationToken, Expression <Func <T, bool> > predicate = null, Func <IQueryable <T>, IQueryable <T> > clauses = null, FeedOptions feedOptions = null)
 {
     feedOptions = SetPartitionKey(partitionKey, feedOptions);
     return(repo.FindAsync(pageSize, continuationToken, predicate, clauses, feedOptions));
 }
コード例 #8
0
 public Queue(ICosmosDb cosmosDb)
 {
     _queueRepository = cosmosDb.Repository <QueueDocument>();
 }
コード例 #9
0
 public TokenContainer(ICosmosDbRepository storgeRepository)
 {
     _container = storgeRepository.GetContainer(nameof(ContainerName.AccoTokens));
 }
コード例 #10
0
 public static Task <T> GetAsync <T, U>(this ICosmosDbRepository <T> repo, U partitionKey, DocumentId itemId, RequestOptions requestOptions = null)
 {
     requestOptions = SetPartitionKey(partitionKey, requestOptions);
     return(repo.GetAsync(itemId, requestOptions));
 }
コード例 #11
0
 public AuthorizeService(IConfiguration config, ICosmosDbRepository <Admin> repository)
 {
     _config     = config;
     _repository = repository;
 }
コード例 #12
0
 public FoodTruckController(ICosmosDbRepository <FoodTruck> repo, ILogger <FoodTruckController> logger)
 {
     _repo   = repo ?? throw new ArgumentNullException(nameof(repo));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
コード例 #13
0
 public OfficesController(ICosmosDbRepository <Office> repository)
 {
     _repository = repository;
 }
コード例 #14
0
 public TestingSubstituteContext(Func <T, object> partionkeySelector, bool?partitioned)
 {
     Repo = new CosmosDbRepositorySubstitute <T>(partionkeySelector, partitioned);
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FoodTruckProvider"/> class.
 /// </summary>
 /// <param name="csvRepository">The CSV repository.</param>
 /// <param name="cosmosDbRepository">The cosmos database repository.</param>
 public FoodTruckProvider(ICsvRepository csvRepository,
                          ICosmosDbRepository cosmosDbRepository)
 {
     _csvRepository      = csvRepository;
     _cosmosDbRepository = cosmosDbRepository;
 }
コード例 #16
0
 public HfeaFormValidationService(ICosmosDbRepository <HfeaForm> hfeaRepository)
 {
     _hfeaRepository = hfeaRepository;
 }
コード例 #17
0
 public PrintersController(ICosmosDbRepository <Printer> repository)
 {
     _repository = repository;
 }
コード例 #18
0
 public DesksController(ICosmosDbRepository <Desk> repository)
 {
     _repository = repository;
 }
コード例 #19
0
 public static Task <CosmosDbRepositoryPagedResults <U> > SelectManyAsync <T, U, V>(this ICosmosDbRepository <T> repo, V partitionKey, int pageSize, string continuationToken, Expression <Func <T, IEnumerable <U> > > selector, Func <IQueryable <T>, IQueryable <T> > whereClauses = null, Func <IQueryable <U>, IQueryable <U> > selectClauses = null, FeedOptions feedOptions = null)
 {
     feedOptions = SetPartitionKey(partitionKey, feedOptions);
     return(repo.SelectManyAsync(pageSize, continuationToken, selector, whereClauses, selectClauses, feedOptions));
 }
コード例 #20
0
 public static Task <bool> DeleteDocumentAsync <T, U>(this ICosmosDbRepository <T> repo, U partitionKey, T entity, RequestOptions requestOptions = null)
 {
     requestOptions = SetPartitionKey(partitionKey, requestOptions);
     return(repo.DeleteDocumentAsync(entity, requestOptions));
 }
コード例 #21
0
 public static Task <T> FindFirstOrDefaultAsync <T, U>(this ICosmosDbRepository <T> repo, U partitionKey, Expression <Func <T, bool> > predicate = null, Func <IQueryable <T>, IQueryable <T> > clauses = null, FeedOptions feedOptions = null)
 {
     feedOptions = SetPartitionKey(partitionKey, feedOptions);
     return(repo.FindFirstOrDefaultAsync(predicate, clauses, feedOptions));
 }
コード例 #22
0
 public StoreProcedureImpl(IDocumentClient client, ICosmosDbRepository repository, string id)
 {
     Client        = client;
     StoredProcUri = new AsyncLazy <Uri>(() => GetStoredProcUri(repository, id));
 }
コード例 #23
0
 public Stores(ICosmosDb cosmosDb)
 {
     _storeRepository = cosmosDb.Repository <StoreDocument>();
 }
コード例 #24
0
 public TestingSubstituteContext()
 {
     Repo = new CosmosDbRepositorySubstitute <T>();
 }
コード例 #25
0
 public GuestsController(ICosmosDbRepository <Guest> repository)
 {
     _repository = repository;
 }
コード例 #26
0
 public static Task <int> CrossPartitionCountAsync <T>(this ICosmosDbRepository <T> repo, Expression <Func <T, bool> > predicate = null, Func <IQueryable <T>, IQueryable <T> > clauses = null, FeedOptions feedOptions = null)
 {
     feedOptions = SetCrossPartition(feedOptions);
     return(repo.CountAsync(predicate, clauses, feedOptions));
 }
コード例 #27
0
 public static Task <IList <U> > CrossPartitionSelectAsync <T, U, V>(this ICosmosDbRepository <T> repo, Expression <Func <V, U> > selector, Func <IQueryable <T>, IQueryable <V> > whereClauses = null, Func <IQueryable <U>, IQueryable <U> > selectClauses = null, FeedOptions feedOptions = null)
 {
     feedOptions = SetCrossPartition(feedOptions);
     return(repo.SelectAsync(selector, whereClauses, selectClauses, feedOptions));
 }
コード例 #28
0
 public RoomsController(ICosmosDbRepository <Room> repository)
 {
     _repository = repository;
 }
コード例 #29
0
 private async Task <Uri> GetStoredProcUri(ICosmosDbRepository repository, string id)
 {
     return(new Uri($"{await repository.AltLink}/sprocs/{Uri.EscapeUriString(id)}", UriKind.Relative));
 }
コード例 #30
0
 public static Task <CosmosDbRepositoryPagedResults <U> > CrossPartitionSelectAsync <T, U, V>(this ICosmosDbRepository <T> repo, int pageSize, string continuationToken, Expression <Func <V, U> > selector, Func <IQueryable <T>, IQueryable <V> > whereClauses, Func <IQueryable <U>, IQueryable <U> > selectClauses = null, FeedOptions feedOptions = null)
 {
     feedOptions = SetCrossPartition(feedOptions);
     return(repo.SelectAsync(pageSize, continuationToken, selector, whereClauses, selectClauses, feedOptions));
 }