public async Task Handle(ShoppingItemUpdated @event) { var updateResponse = await _elasticClient.UpdateAsync <ShoppingItemEs>(@event.Id.ToString(), u => u .Doc(new ShoppingItemEs { Name = @event.Name, Price = @event.Price }) .Refresh(Refresh.WaitFor)); }
public async Task <bool> Match(ShoppingItemUpdated shoppingItemUpdated) { //TODO: write query to check for registered percolators var searchResponse = await _elasticClient.SearchAsync <ShoppingItemEs>(s => s .Query(q => q.Percolate(p => p .Field(f => f.Query) .Document(new ShoppingItemEs { Name = shoppingItemUpdated.Name, Price = shoppingItemUpdated.Price })))); return(searchResponse.Documents.Any()); }
public async Task UpdatingTeslaItemTo110ShouldNotRiseAlert() { //register alert var registered = await new PricesAlert(_elasticClient).Register(100, "tesla"); var @event = new ShoppingItemUpdated { Id = 1, Name = "tesla", Price = 110 }; await new UpdateShoppingItemInElasticSearchHandler(_elasticClient).Handle(@event); var updatedDocument = await _elasticClient.GetAsync <ShoppingItemEs>(@event.Id.ToString()); updatedDocument.Source.Price.ShouldBe(110); var alertsFound = await new CheckAlertsHandler(_elasticClient).Handle(@event); alertsFound.ShouldBe(false); }
public Task <bool> Handle(ShoppingItemUpdated @event) { return(new PricesAlert(_elasticClient).Match(@event)); }