public static async Task <HttpResponseMessage> SendJsonAsync( this HttpClient client, HttpMethod method, string requestUri, object obj = null) { string json; if (obj == null) { json = "{}"; } else { json = JsonConvert.SerializeObject(obj, JsonSerializerSettingsExtensions.CreateWithDefaults()); } StringContent content = new StringContent( json, Encoding.UTF8, "application/json"); HttpRequestMessage request = new HttpRequestMessage(method, requestUri) { Content = content }; return(await client.SendAsync(request)); }
SagaRepository() { Client = new CosmosClient(Configuration.EndpointUri, Configuration.Key, new CosmosClientOptions { Serializer = new CosmosJsonDotNetSerializer(JsonSerializerSettingsExtensions.GetSagaRenameSettings <TSaga>()) }); }
public async Task <TSaga> GetSaga <TSaga>(Guid correlationId, bool useJsonSerializerSettings) where TSaga : class, IVersionedSaga { try { RequestOptions options = null; JsonSerializerSettings serializerSettings = null; if (useJsonSerializerSettings) { options = new RequestOptions(); serializerSettings = JsonSerializerSettingsExtensions.GetSagaRenameSettings <TSaga>(); options.JsonSerializerSettings = serializerSettings; } ResourceResponse <Document> document = await Client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseName, CollectionName, correlationId.ToString()), options); return(JsonConvert.DeserializeObject <TSaga>(document.Resource.ToString(), serializerSettings)); } catch (DocumentClientException e) when(e.StatusCode == HttpStatusCode.NotFound) { return(null); } }
public When_using_DocumentDbConcurrencyOptimistic() { _databaseName = "choirSagas"; _collectionName = "sagas"; _documentClient = new DocumentClient(new Uri(EmulatorConstants.EndpointUri), EmulatorConstants.Key); _jsonSerializerSettings = JsonSerializerSettingsExtensions.GetSagaRenameSettings <ChoirState>(); _repository = new Lazy <ISagaRepository <ChoirState> >(() => new DocumentDbSagaRepository <ChoirState>(_documentClient, _databaseName, _jsonSerializerSettings)); }
public When_using_Cosmos() { _databaseName = "shoppingChoreSagas"; _collectionName = "sagas"; _cosmosClient = new CosmosClient(Configuration.EndpointUri, Configuration.Key, new CosmosClientOptions { Serializer = new CosmosJsonDotNetSerializer(JsonSerializerSettingsExtensions.GetSagaRenameSettings <ShoppingChore>()) }); _repository = new Lazy <ISagaRepository <ShoppingChore> >(() => CosmosSagaRepository <ShoppingChore> .Create(_cosmosClient, _databaseName, _collectionName)); }
public When_using_CosmosConcurrencyOptimistic() { _databaseName = "choirSagas"; _collectionName = "sagas"; _cosmosClient = new CosmosClient(Configuration.EndpointUri, Configuration.Key, new CosmosClientOptions { Serializer = new CosmosJsonDotNetSerializer(JsonSerializerSettingsExtensions.GetSagaRenameSettings <ChoirStateOptimistic>()) }); _repository = new Lazy <ISagaRepository <ChoirStateOptimistic> >(() => CosmosSagaRepository <ChoirStateOptimistic> .Create(_cosmosClient, _databaseName, _collectionName)); }
public When_matching_to_an_instance() { _databaseName = "masstransitunittests"; _collectionName = "sagas"; _cosmosClient = new CosmosClient(Configuration.EndpointUri, Configuration.Key, new CosmosClientOptions { Serializer = new CosmosJsonDotNetSerializer(JsonSerializerSettingsExtensions.GetSagaRenameSettings <MissingInstance>()) }); _repository = new Lazy <ISagaRepository <MissingInstance> >(() => CosmosSagaRepository <MissingInstance> .Create(_cosmosClient, _databaseName, _collectionName)); }
public async Task <Document> InsertSaga <TSaga>(TSaga saga, bool useJsonSerializerSettings) where TSaga : class, IVersionedSaga { RequestOptions options = null; if (useJsonSerializerSettings) { options = new RequestOptions { JsonSerializerSettings = JsonSerializerSettingsExtensions.GetSagaRenameSettings <TSaga>() } } ; return(await Client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName), saga, options, true)); }
public When_using_DocumentDB() { _databaseName = "shoppingChoreSagas"; _collectionName = "sagas"; _documentClient = new DocumentClient(new Uri(EmulatorConstants.EndpointUri), EmulatorConstants.Key); _repository = new Lazy <ISagaRepository <ShoppingChore> >(() => new DocumentDbSagaRepository <ShoppingChore>(_documentClient, _databaseName, JsonSerializerSettingsExtensions.GetSagaRenameSettings <ShoppingChore>())); }
public When_using_DocumentDbConcurrencyNoRetry() { _databaseName = "choirSagas"; _collectionName = "sagas"; _documentClient = new DocumentClient(EmulatorConstants.EndpointUri, EmulatorConstants.Key); _repository = new Lazy <ISagaRepository <ChoirStateOptimistic> >(() => new DocumentDbSagaRepository <ChoirStateOptimistic>(_documentClient, _databaseName, JsonSerializerSettingsExtensions.GetSagaRenameSettings <ChoirStateOptimistic>())); TestTimeout = TimeSpan.FromMinutes(3); }
public async Task Query_Other_Property_Passes_With_Json_Resolver_Rename() { // Arrange var correlationId = Guid.NewGuid(); _ids.Add(correlationId); var username = Guid.NewGuid().ToString(); // wouldn't actually be a guid, but used this for uniqueness SagaRepository.Instance.InsertSaga(new SimpleSaga { CorrelationId = correlationId, Username = username }, true).GetAwaiter().GetResult(); ISagaQuery <SimpleSaga> query = new SagaQuery <SimpleSaga>(x => x.Username == username); // Act var repository = new DocumentDbSagaRepository <SimpleSaga>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, JsonSerializerSettingsExtensions.GetSagaRenameSettings <SimpleSaga>()); var result = repository.Find(query).GetAwaiter().GetResult(); // Assert Assert.That(result.Single(), Is.EqualTo(correlationId)); // So it does find it }
public async Task Query_Fails_With_Json_Resolver_Rename() { // Arrange var correlationId = Guid.NewGuid(); _ids.Add(correlationId); SagaRepository.Instance.InsertSaga(new SimpleSaga { CorrelationId = correlationId }, true).GetAwaiter().GetResult(); ISagaQuery <SimpleSaga> query = new SagaQuery <SimpleSaga>(x => x.CorrelationId == correlationId); // Act var repository = new DocumentDbSagaRepository <SimpleSaga>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, JsonSerializerSettingsExtensions.GetSagaRenameSettings <SimpleSaga>()); var result = repository.Find(query).GetAwaiter().GetResult(); // Assert Assert.That(result.Any(), Is.False); }