コード例 #1
0
 public UpdateSystemUserCommandHandler(IIntegrationEventPublisherServiceService eventcontext, IMapper mapper)
 {
     _systemUserRepository = new SystemUserRepository(new TaxatHand_StgContext());
     _eventcontext         = eventcontext;
     _mapper  = mapper;
     _context = new CosmosDBContext();
 }
コード例 #2
0
 public UpdateResourceGroupCommandHandler(IIntegrationEventPublisherServiceService eventcontext, IMapper mapper)
 {
     _ResourceGroupRepository = new ResourceGroupRepository(new TaxatHand_StgContext());
     _eventcontext            = eventcontext;
     _mapper  = mapper;
     _context = new CosmosDBContext();
 }
コード例 #3
0
        public async Task AddAsync_Creates_IfTrue_AndNotFound(string partitionKeyPath, int collectionThroughput)
        {
            // Arrange
            var             mockService = new Mock <ICosmosDBService>(MockBehavior.Strict);
            CosmosDBContext context     = CosmosDBTestUtility.CreateContext(mockService.Object, partitionKeyPath: partitionKeyPath,
                                                                            throughput: collectionThroughput, createIfNotExists: true);
            var collector = new CosmosDBAsyncCollector <Item>(context);

            mockService
            .SetupSequence(m => m.UpsertDocumentAsync(It.IsAny <Uri>(), It.IsAny <object>()))
            .Throws(CosmosDBTestUtility.CreateDocumentClientException(HttpStatusCode.NotFound))
            .Returns(Task.FromResult(new Document()));

            CosmosDBTestUtility.SetupDatabaseMock(mockService);
            CosmosDBTestUtility.SetupCollectionMock(mockService, partitionKeyPath, collectionThroughput);

            // Act
            await collector.AddAsync(new Item { Text = "hello!" });

            // Assert
            mockService.VerifyAll();

            // Verify that we upsert again after creation.
            mockService.Verify(m => m.UpsertDocumentAsync(It.IsAny <Uri>(), It.IsAny <object>()), Times.Exactly(2));
        }
コード例 #4
0
 public ManipulateTaxGroupCommandHandler(IIntegrationEventPublisherServiceService Eventcontext, ILogger <ManipulateTaxGroupCommandHandler> logger)
 {
     _tagGroupRepository = new TagGroupsRepository(new TaxatHand_StgContext());
     _Eventcontext       = Eventcontext;
     _logger             = logger;
     _context            = new CosmosDBContext();
 }
コード例 #5
0
 public UpdateCountryGroupsCommandHandler(IIntegrationEventPublisherServiceService Eventcontext, ILogger <UpdateCountryGroupsCommandHandler> logger, IIntegrationEventBlobService Eventblobcontext)
 {
     _CountryGroupsRepository = new CountryGroupsRepository(new TaxatHand_StgContext());
     _Eventcontext            = Eventcontext;
     _Eventblobcontext        = Eventblobcontext;
     _logger  = logger;
     _context = new CosmosDBContext();
 }
コード例 #6
0
 public ManipulateCountriesCommandHandler(IIntegrationEventPublisherServiceService Eventcontext, ILogger <ManipulateCountriesCommandHandler> logger, ICacheService <Countries, Countries> cacheService)
 {
     _CountryRepository = new CountryRepository(new TaxatHand_StgContext());
     _Eventcontext      = Eventcontext;
     _logger            = logger;
     _context           = new CosmosDBContext();
     _cacheService      = cacheService ?? throw new ArgumentNullException(nameof(cacheService));
 }
コード例 #7
0
        //  private readonly ILogger _logger;

        public UpdateArticleCommandHandler(IIntegrationEventPublisherServiceService Eventcontext)
        {
            _ArticleRepository = new ArticleRepository(new TaxatHand_StgContext());
            // _context = new ArticleRepository();
            _Eventcontext = Eventcontext;
            _context      = new CosmosDBContext();
            //    _logger = logger;
        }
コード例 #8
0
        public EvaluationResult CosmosDB(DeviceWebAPIParameters parms)
        {
            parms.Fix(Config);
            var context = new CosmosDBContext(parms);
            var result  = context.TestDocuments("iot", "events");

            return(result);
        }
コード例 #9
0
        public static async Task <CosmosDbClaimDocumentService> GetCosmosDbClaimDocumentService()
        {
            var cosmosDbAccount       = CosmosDBConfigurationTestHelper.CosmosDbAccount;
            var cosmosDbKey           = CosmosDBConfigurationTestHelper.CosmosDbKey;
            var cosmosDbDatabaseName  = CosmosDBConfigurationTestHelper.CosmosDbDatabaseName;
            var cosmosDbContainerName = CosmosDBConfigurationTestHelper.CosmosDbContainerName;
            var service = await CosmosDBContext.InitializeCosmosClientInstanceAsync(cosmosDbAccount, cosmosDbKey, cosmosDbDatabaseName, cosmosDbContainerName);

            return(service);
        }
コード例 #10
0
        public static async Task <CosmosDbClaimDocumentService> GetCosmosDbClaimDocumentService()
        {
            var configurationRoot     = GetConfiguration();
            var cosmosDbAccount       = configurationRoot["CosmosDbAccount"];
            var cosmosDbKey           = configurationRoot["CosmosDbKey"];
            var cosmosDbDatabaseName  = configurationRoot["CosmosDbDatabaseName"];
            var cosmosDbContainerName = configurationRoot["CosmosDbContainerName"];
            var service = await CosmosDBContext.InitializeCosmosClientInstanceAsync(cosmosDbAccount, cosmosDbKey, cosmosDbDatabaseName, cosmosDbContainerName);

            return(service);
        }
コード例 #11
0
        public async Task CreateIfNotExist_Succeeds()
        {
            // Arrange
            var             mockService = new Mock <ICosmosDBService>(MockBehavior.Strict);
            CosmosDBContext context     = CosmosDBTestUtility.CreateContext(mockService.Object);

            CosmosDBTestUtility.SetupDatabaseMock(mockService);
            CosmosDBTestUtility.SetupCollectionMock(mockService);

            // Act
            await CosmosDBUtility.CreateDatabaseAndCollectionIfNotExistAsync(context);

            // Assert
            mockService.VerifyAll();
        }
コード例 #12
0
        private static CosmosDBItemValueBinder <T> CreateBinder <T>(out Mock <ICosmosDBService> mockService, string partitionKey = null)
            where T : class
        {
            mockService = new Mock <ICosmosDBService>(MockBehavior.Strict);

            CosmosDBAttribute attribute = new CosmosDBAttribute(DatabaseName, CollectionName)
            {
                Id           = Id,
                PartitionKey = partitionKey
            };

            var context = new CosmosDBContext
            {
                ResolvedAttribute = attribute,
                Service           = mockService.Object
            };

            return(new CosmosDBItemValueBinder <T>(context));
        }
コード例 #13
0
        public async Task CreateIfNotExist_Rethrows()
        {
            // Arrange
            var             mockService = new Mock <ICosmosDBService>(MockBehavior.Strict);
            CosmosDBContext context     = CosmosDBTestUtility.CreateContext(mockService.Object);

            CosmosDBTestUtility.SetupDatabaseMock(mockService);

            // overwrite the default setup with one that throws
            mockService
            .Setup(m => m.CreateDatabaseIfNotExistsAsync(It.Is <Database>(d => d.Id == CosmosDBTestUtility.DatabaseName)))
            .ThrowsAsync(CosmosDBTestUtility.CreateDocumentClientException(HttpStatusCode.BadRequest));

            // Act
            await Assert.ThrowsAsync <DocumentClientException>(
                () => CosmosDBUtility.CreateDatabaseAndCollectionIfNotExistAsync(context));

            // Assert
            mockService.VerifyAll();
        }
コード例 #14
0
        public async Task SetAsync_Updates_IfPropertyChanges()
        {
            // Arrange
            var mockService = new Mock <ICosmosDBService>(MockBehavior.Strict);

            Item original = new Item
            {
                Id   = "abc123",
                Text = "hello"
            };

            Item updated = new Item
            {
                Id   = "abc123",
                Text = "goodbye"
            };

            mockService
            .Setup(m => m.ReplaceDocumentAsync(_expectedUri, updated))
            .ReturnsAsync(new Document());

            CosmosDBAttribute attribute = new CosmosDBAttribute(DatabaseName, CollectionName)
            {
                Id = Id
            };

            var context = new CosmosDBContext
            {
                Service           = mockService.Object,
                ResolvedAttribute = attribute
            };

            JObject clonedOrig = CosmosDBItemValueBinder <object> .CloneItem(original);

            // Act
            await CosmosDBItemValueBinder <Item> .SetValueInternalAsync(clonedOrig, updated, context);

            // Assert
            mockService.VerifyAll();
        }
コード例 #15
0
        public async Task SetAsync_Poco_SkipsUpdate_IfSame()
        {
            // Arrange
            var mockService = new Mock <ICosmosDBService>(MockBehavior.Strict);

            Item original = new Item
            {
                Id   = "abc123",
                Text = "hello"
            };

            Item updated = new Item
            {
                Id   = "abc123",
                Text = "hello"
            };

            CosmosDBAttribute attribute = new CosmosDBAttribute(DatabaseName, CollectionName)
            {
                Id = Id
            };

            var context = new CosmosDBContext
            {
                Service           = mockService.Object,
                ResolvedAttribute = attribute
            };

            JObject clonedOrig = CosmosDBItemValueBinder <object> .CloneItem(original);

            // Act
            await CosmosDBItemValueBinder <Item> .SetValueInternalAsync(clonedOrig, updated, context);

            // Assert

            // nothing on the client should be called
            mockService.VerifyAll();
        }
コード例 #16
0
        public async Task SetAsync_Poco_Throws_IfIdChanges()
        {
            // Arrange
            var mockService = new Mock <ICosmosDBService>(MockBehavior.Strict);

            Item original = new Item
            {
                Id = "abc123",
            };

            Item updated = new Item
            {
                Id = "def456",
            };

            CosmosDBAttribute attribute = new CosmosDBAttribute(DatabaseName, CollectionName)
            {
                Id = Id
            };

            var context = new CosmosDBContext
            {
                Service           = mockService.Object,
                ResolvedAttribute = attribute
            };

            var originalJson = JObject.FromObject(original);

            // Act
            var ex = await Assert.ThrowsAsync <InvalidOperationException>(
                () => CosmosDBItemValueBinder <Item> .SetValueInternalAsync(originalJson, updated, context));

            // Assert
            Assert.Equal("Cannot update the 'Id' property.", ex.Message);
            mockService.Verify();
        }
コード例 #17
0
 public DeleteSiteDisclaimerCommandHandler(IIntegrationEventPublisherServiceService eventcontext)
 {
     _eventcontext             = eventcontext;
     _siteDisclaimerRepository = new SiteDisclaimerRepository(new TaxatHand_StgContext());
     _context = new CosmosDBContext();
 }
コード例 #18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info {
                    Title = "Insurance Claim Handler API", Version = "v1"
                });
            });

            var builder          = new ConfigurationBuilder();
            var keyVaultEndpoint = AzurekeyVaultConfigurationHelper.Url;

            if (!string.IsNullOrEmpty(keyVaultEndpoint))
            {
                var azureServiceTokenProvider = new AzureServiceTokenProvider();
                var keyVaultClient            = new KeyVaultClient(
                    new KeyVaultClient.AuthenticationCallback(
                        azureServiceTokenProvider.KeyVaultTokenCallback));
                builder.AddAzureKeyVault(
                    keyVaultEndpoint, keyVaultClient, new DefaultKeyVaultSecretManager());
            }
            var configurationRoot = builder.Build();

            services.AddLogging(logging =>
            {
                logging.AddConfiguration(Configuration.GetSection("Logging"));
                logging.AddConsole();
            }).Configure <LoggerFilterOptions>(options => options.MinLevel =
                                                   LogLevel.Information);

            var cosmosDBConfiguration = CosmosDBConfigurationHelper.LoadCosmosDBConfiguration(configurationRoot);

            services.AddSingleton <ICosmosDbClaimDocumentService>(CosmosDBContext.InitializeCosmosClientInstanceAsync(cosmosDBConfiguration.CosmosDbAccount, cosmosDBConfiguration.CosmosDbKey, cosmosDBConfiguration.CosmosDbDatabaseName, cosmosDBConfiguration.CosmosDbContainerName).GetAwaiter().GetResult());

            services.AddSingleton <IConfiguration>(configurationRoot);

            services.AddTransient <IPublishEvent, PublishEvent>();

            services.AddMediatR(typeof(AddClaimCommandHandler));

            services.AddMediatR(typeof(Startup));

            services.AddHealthChecks();

            services.AddCors(o => o.AddPolicy("ClaimApiAccessPolicy", b =>
            {
                b.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));


            services.AddMvc(options =>
            {
                options.EnableEndpointRouting = false;
                options.Filters.Add(typeof(ValidationFilter));
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddFluentValidation(configuration =>
            {
                configuration.RunDefaultMvcValidationAfterFluentValidationExecutes = false;
                configuration.RegisterValidatorsFromAssemblyContaining <AddClaimCommandValidator>();
            });
        }
コード例 #19
0
 public CosmosUnitOfWork(CosmosDBContext context)
 {
     dbContext          = context;
     PropertyRepository = new PropertyRepository(dbContext);
 }
コード例 #20
0
        public IAsyncCollector <T> Convert(CosmosDBAttribute attribute)
        {
            CosmosDBContext context = _configProvider.CreateContext(attribute);

            return(new CosmosDBAsyncCollector <T>(context));
        }
コード例 #21
0
 public MyService(CosmosDBContext cosmosDBContext)
 {
     _cosmosDbContext = cosmosDBContext;
 }