public void AddEventsForPatient3ToTestTable() { var eventsTestTable = TestFactory.GetClientForTable("EventsTestTable"); // Delete rows of patient Id 3 if already exists TableQuery <Event> rangeQuery = new TableQuery <Event>(); rangeQuery.Where(TableQuery.GenerateFilterConditionForInt("PatientId", QueryComparisons.Equal, 3)); var existingEvents = eventsTestTable.ExecuteQuerySegmentedAsync(rangeQuery, null).GetAwaiter().GetResult(); if (existingEvents.Any()) { TableBatchOperation batchDeleteOperation = new TableBatchOperation(); foreach (var item in existingEvents) { batchDeleteOperation.Delete(item); } eventsTestTable.ExecuteBatchAsync(batchDeleteOperation).GetAwaiter().GetResult(); } // Insert 2 events for patient Id = 3 var rowId = Guid.NewGuid(); var testEvent1 = new Event { RowKey = rowId.ToString(), PartitionKey = "BookingAppointmentEvent", EventId = rowId, PatientId = 3, DoctorId = 1, EventDate = DateTime.Now, EventCreationDate = DateTime.Now, EventType = "Booking Appointment", IsConflicted = false, IsConflictShown = false, }; rowId = Guid.NewGuid(); var testEvent2 = new Event { RowKey = rowId.ToString(), PartitionKey = "BookingAppointmentEvent", EventId = rowId, PatientId = 3, DoctorId = 1, EventDate = DateTime.Now, EventCreationDate = DateTime.Now.AddMinutes(-6), EventType = "Booking Appointment", IsConflicted = false, IsConflictShown = false }; TableBatchOperation batchInsertOperation = new TableBatchOperation(); batchInsertOperation.Insert(testEvent1); batchInsertOperation.Insert(testEvent2); eventsTestTable.ExecuteBatchAsync(batchInsertOperation).GetAwaiter().GetResult(); }
public async Task EventsRetreiverTests_WithDoctorIdFilter_ShouldGetEventForThisDoctor() { // Arrange var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List); var currentEventsTable = TestFactory.GetClientForTable("EventsTestTable"); AddEventsForDoctor1ToTestTable(); // Act var request = TestFactory.CreateHttpRequest("doctorId", "1"); var response = (OkObjectResult)await EventsRetreiver.Run(request, currentEventsTable, logger); // Assert var okResult = response as OkObjectResult; Assert.IsNotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); var returnedEvents = okResult.Value as List <Event>; Assert.IsNotNull(returnedEvents); Assert.IsInstanceOf(typeof(List <Event>), returnedEvents); Assert.AreEqual(returnedEvents.Any(), true); Assert.AreEqual(1, returnedEvents.Count); }
public void AppointmentsConflictsDetector_ShouldNotThrowException() { // Arrange var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List); var currentEventsTable = TestFactory.GetClientForTable("EventsTestTable"); var signalRMock = new Mock <IAsyncCollector <SignalRMessage> >(); // Act & Assert Assert.DoesNotThrow(() => AppointmentsConflictsDetector.Run(null, currentEventsTable, signalRMock.Object, logger).GetAwaiter().GetResult()); }
public void GenerateEvent_ShouldNotThrowException() { // Arrange var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List); var currentEventsTable = TestFactory.GetClientForTable("EventsTestTable"); var eventsQueueMock = new Mock <ICollector <Event> >(); var newEventsTableMock = new Mock <ICollector <Event> >(); // Act & Assert Assert.DoesNotThrow(() => EventsGenerator.Run(null, logger, eventsQueueMock.Object, currentEventsTable, newEventsTableMock.Object).GetAwaiter().GetResult()); }
public void AppointmentsConflictsDetector_NoConflictedEvents_ShouldNotAddMessageToSignalRService() { // Arrange var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List); var currentEventsTable = TestFactory.GetClientForTable("EventsTestTable"); var signalRMock = new Mock <IAsyncCollector <SignalRMessage> >(); // Act AppointmentsConflictsDetector.Run(null, currentEventsTable, signalRMock.Object, logger).GetAwaiter().GetResult(); // Assert signalRMock.Verify(m => m.AddAsync(It.IsAny <SignalRMessage>(), It.IsAny <CancellationToken>()), Times.Never()); }
public void GenerateEvent_ShouldCallAddToQueueOnlyOnce() { // Arrange var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List); var currentEventsTable = TestFactory.GetClientForTable("EventsTestTable"); var eventsQueueMock = new Mock <ICollector <Event> >(); var newEventsTableMock = new Mock <ICollector <Event> >(); // Act EventsGenerator.Run(null, logger, eventsQueueMock.Object, currentEventsTable, newEventsTableMock.Object).GetAwaiter().GetResult(); // Assert eventsQueueMock.Verify(m => m.Add(It.IsAny <Event>()), Times.Once()); }
public void AppointmentsConflictsDetector_ShoulLogMessageWhenStarted() { // Arrange var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List); var currentEventsTable = TestFactory.GetClientForTable("EventsTestTable"); var signalRMock = new Mock <IAsyncCollector <SignalRMessage> >(); // Act AppointmentsConflictsDetector.Run(null, currentEventsTable, signalRMock.Object, logger).GetAwaiter().GetResult(); // Assert var msg = logger.Logs[0]; Assert.AreEqual(true, msg.Contains("Appointments Conflicts Detector Timer trigger function executed at")); }
public void AddConflictedEventsToTestTable() { var eventsTestTable = TestFactory.GetClientForTable("EventsTestTable"); // Add non conficted event, then add a conflicted event to this one // The conflicted event is created with an old so that it s detected as a conflict as 5 minute should pass // before showing the event as conflicted var rowId = Guid.NewGuid(); var nonConflictedTestEvent = new Event { RowKey = rowId.ToString(), PartitionKey = "BookingAppointmentEvent", EventId = rowId, PatientId = 1, DoctorId = 1, EventDate = DateTime.Now, EventCreationDate = DateTime.Now, EventType = "Booking Appointment", IsConflicted = false, IsConflictShown = false, }; rowId = Guid.NewGuid(); var conflictedTestEvent = new Event { RowKey = rowId.ToString(), PartitionKey = "BookingAppointmentEvent", EventId = rowId, PatientId = 2, DoctorId = 1, EventDate = DateTime.Now, EventCreationDate = DateTime.Now.AddMinutes(-6), EventType = "Booking Appointment", IsConflicted = true, IsConflictShown = false, OriginalEventId = nonConflictedTestEvent.EventId }; TableBatchOperation batchOperation = new TableBatchOperation(); batchOperation.Insert(nonConflictedTestEvent); batchOperation.Insert(conflictedTestEvent); eventsTestTable.ExecuteBatchAsync(batchOperation).GetAwaiter().GetResult(); }