public async Task UpdateAsyncByIAndPartShouldSucceed() { var searchResults = await _mockRepo.SearchAsync(x => x .Query(q => !q .Term(t => t .Field(f => f.Id) .Value(_mockDocumentWithId.Id) ) ) ); var item1 = await _mockRepo.GetAsync(_mockDocumentWithId.Id); var item2 = searchResults.First(); var utcNow = DateTime.UtcNow; var updateResult1 = await _mockRepo.UpdateAsync(item1.Id, new { UpdateDate = utcNow, IsActive = false }); var updateResult2 = await _mockRepo.UpdateAsync(item2.Id, new { UpdateDate = utcNow, IsActive = false }); var updatedItem1 = await _mockRepo.GetAsync(item1.Id); var updatedItem2 = await _mockRepo.GetAsync(item2.Id); Assert.True(updateResult1); Assert.NotNull(updatedItem1); Assert.Equal(utcNow, updatedItem1.UpdateDate); Assert.False(updatedItem1.IsActive); Assert.True(updateResult2); Assert.NotNull(updatedItem2); Assert.Equal(utcNow, updatedItem2.UpdateDate); Assert.False(updatedItem2.IsActive); }
public void StartServer(CancellationToken cancellationToken) { this._logger.LogDebug(LoggingEvents.Debug, "Started Data Replication Server"); Console.WriteLine(" *** Started App Data Replication Server ***"); // This is the event handler for emailNotification queue. Make sure this does not throw exception // Kafka message handling block would not be responsible to handle any exceptions Func <KMessage <AppEventArgs <Customer> >, Task> appEventHandler = async(message) => { this._logger.LogTrace(LoggingEvents.Trace, $"Response: Partition:{message.Partition}, Offset:{message.Offset} :: {message.Message}"); AppEventArgs <Customer> evt = message.Message; try { Customer customer = evt.afterChange; switch (evt.appEventType) { case AppEventType.Insert: _logger.LogTrace(LoggingEvents.Trace, String.Format("Adding new Customer:{0}", customer.name)); await _custrepo.AddAsync(customer); await this._searchrepo.AddAsync(customer); break; case AppEventType.Delete: var cust = await _custrepo.GetByEntityIdAsync(customer.entityid); if (cust == null) { _logger.LogTrace(LoggingEvents.Trace, $"Trying to delete Customer {customer.name} with EmtityID: {customer.entityid} that does not exist"); } else { await _custrepo.DeleteAsync(customer.entityid); } if (this._searchrepo.Exists(customer.id)) { await this._searchrepo.DeleteAsync(customer.id); } break; case AppEventType.Update: _logger.LogTrace(LoggingEvents.Trace, $"Processing request to update customer:{customer.entityid}"); await _custrepo.UpdateAsync(customer); await _searchrepo.UpdateAsync(customer); break; default: _logger.LogTrace(LoggingEvents.Trace, $"No action required for event:{evt.id} of type:{evt.appEventType}"); break; } this._logger.LogDebug(LoggingEvents.Trace, $"Processed Customer CRUD event {evt.id}"); } catch (Exception ex) { var msg = $"Event:{evt.id} - Error:{ex.Message}"; this._logger.LogError(LoggingEvents.Error, ex, msg); // We will send out a notification for every update var notifyEvt = new EmailEventArgs { subject = "Data Replication Error", textMsg = $"Error replicating customer information. {msg}", htmlMsg = $"<p> Error replicating customer information. </p><p> <b>Message Details: </b> {msg} <p>", notifyTo = new List <string>() { "*****@*****.**" }, notifyCC = new List <string>(), notifyBCC = new List <string>() }; await this._notificationProducer.ProduceAsync(this._notificationMsgQueueTopic, notifyEvt); } }; this._appEventMsgConsumer.Consume(cancellationToken, appEventHandler, null, null); this._appEventMsgConsumer.Dispose(); Console.WriteLine(" *** Stopped App Data Replication Server ***"); this._logger.LogDebug(LoggingEvents.Debug, "Stopped App Data Replication Server"); }