public void PublishEventsToCertainQueueTestFourTimes() { var repoMock = new Mock <IRepository>(MockBehavior.Strict); var ev = new SerializedEvent() { ID = 1337, TimeReceived = DateTime.Now, Body = "test body", EventType = typeof(TestEvent).FullName, RoutingKey = "#" }; repoMock.Setup(repo => repo.FindBy(It.IsAny <Expression <Func <SerializedEvent, bool> > >())).Returns(() => new List <SerializedEvent>() { ev, ev, ev, ev }); var queueName = "TestQueue2"; using (var sender = new EventPublisher(_busOptions)) using (var receiver = new TestDispatcher(_direct, queueName)) using (var publisher = new AuditPublisher(_direct)) using (var dispatcher = new AuditDispatcher(repoMock.Object, publisher, _busOptions)) { var saec = new SendAllEventCommand(); saec.returnQueueName = queueName; saec.StartTime = DateTime.MinValue; saec.EndTime = DateTime.MaxValue; sender.Publish(saec); Thread.Sleep(1000); Assert.AreEqual(4, receiver.ReceivedTestEventCount); } }
private static void TestAuditFailure(int numberOfMessagesToCreate) { while (numberOfMessagesToCreate > 0) { QueueMessage msg = new QueueMessage(); DataAudit da = new DataAudit(); da.Contract = "inhealth001"; da.EntityID = "531f2dcc072ef727c4d29e22"; da.EntityType = "testentitytype"; da.UserId = "531f2dcc072ef727c4d29yyy"; da.TimeStamp = DateTime.Now; string xmlBody = AuditDispatcher.ToXML(da); string messageQueue = @".\private$\failure"; QueueMessage newMessage = new QueueMessage(ASEMessageType.Process, messageQueue); newMessage.Body = xmlBody; MessageQueueHelper.SendMessage(@messageQueue, newMessage, "TestFailureType"); --numberOfMessagesToCreate; } }
private static void DataAuditAsynch(string userId, string collectionName, string entityId, string entityKeyField, DataAuditType auditType, string contractNumber) { //throw new SystemException("test error in new thread starts"); DataAudit data = GetDataAuditLog(userId, collectionName, entityId, entityKeyField, auditType, contractNumber); AuditDispatcher.WriteAudit(data, string.Format("{0}_{1}", data.Type, data.EntityType)); }
private static void AuditAsynch(IAppDomainRequest request, string sqlUserID, List <string> patientids, string browser, string userIPAddress, string returnTypeName) { //throw new SystemException("test error in new thread starts"); string callingMethod = FindMethodType(returnTypeName); int auditTypeId = GetAuditTypeID(callingMethod); AuditData data = GetAuditLog(auditTypeId, request, sqlUserID, patientids, browser, userIPAddress, callingMethod); AuditDispatcher.WriteAudit(data); }
public static void Main(string[] args) { string connectionString = @"server=db;userid=admin;password=1234;database=auditlog;"; DbContextOptions options = new DbContextOptionsBuilder().UseMySQL(connectionString).Options; AuditLogDbContext context = new AuditLogDbContext(options); BusOptions busOptions = new BusOptions(hostname: "rabbitmq", port: 5672, username: "******", password: "******", exchangeName: "Lapiwe.GMS"); using (IRepository repo = new AuditLogRepository(context)) using (var all = new AllEventDispatcher(repo, busOptions)) using (var publisher = new AuditPublisher(busOptions)) using (var dispatcher = new AuditDispatcher(repo, publisher, busOptions)) { Console.Read(); } }
public void AuditDispatcher_isRoutingkeyMatch_IncorrectMatchWithHashWildcardThreeLevelsWithTrailingText() { // Arrange using (var target = new AuditDispatcher(null, null, options)) { var commandKey = "Test.#.event"; var eventKey = "Test.test.test"; // Act var result = target.isRoutingKeyMatch(commandKey, eventKey); // Assert Assert.IsFalse(result); } }
public void AuditDispatcher_isRoutingkeyMatch_CorrectMatchWithHashWildcardFourLevelsWithLeadingAndTrailingText() { // Arrange using (var target = new AuditDispatcher(null, null, options)) { var commandKey = "Test.#.Event"; var eventKey = "Test.test.tEst.Event"; // Act var result = target.isRoutingKeyMatch(commandKey, eventKey); // Assert Assert.IsTrue(result); } }
public void AuditDispatcher_isRoutingkeyMatch_CorrectMatchWithHashWildcardTwoLevels() { // Arrange using (var target = new AuditDispatcher(null, null, options)) { var commandKey = "#"; var eventKey = "Test.test"; // Act var result = target.isRoutingKeyMatch(commandKey, eventKey); // Assert Assert.IsTrue(result); } }
public void AuditDispatcher_isRoutingkeyMatch_IncorrectMatchWithStarWildcardMultipleLevels() { // Arrange using (var target = new AuditDispatcher(null, null, options)) { var commandKey = "Test.*.event"; var eventKey = "Test.test.anothertest.event"; // Act var result = target.isRoutingKeyMatch(commandKey, eventKey); // Assert Assert.IsFalse(result); } }
public void AuditDispatcher_isRoutingkeyMatch_correctMatchWithStarWildcardAndTrailingText() { // Arrange using (var target = new AuditDispatcher(null, null, options)) { var commandKey = "Test.*.event"; var eventKey = "Test.test.event"; // Act var result = target.isRoutingKeyMatch(commandKey, eventKey); // Assert Assert.IsTrue(result); } }
public void AuditDispatcher_isRoutingkeyMatch_IncorrectMatch() { // Arrange using (var target = new AuditDispatcher(null, null, options)) { var commandKey = "Test"; var eventKey = "Mismatch"; // Act var result = target.isRoutingKeyMatch(commandKey, eventKey); // Assert Assert.IsFalse(result); } }
public void AuditDispatcherCallsCorrectMethodsCount() { // Arrange var repoMock = new Mock <IRepository>(MockBehavior.Strict); repoMock.Setup(repo => repo.Insert(It.IsAny <SerializedEvent>())); var e = new SerializedEvent { Body = "AuditDispatcher.Test", TimeReceived = DateTime.Now }; repoMock.Setup(repo => repo.FindBy(It.IsAny <Expression <Func <SerializedEvent, bool> > >())) .Returns(() => new List <SerializedEvent>() { e, e, e }); var pubMock = new Mock <IPublisher>(MockBehavior.Strict); pubMock.Setup(pub => pub.Publish(It.IsAny <string>(), It.IsAny <SerializedEvent>())); options.ExchangeName = "TestExchange2"; using (var target = new AuditDispatcher(repoMock.Object, pubMock.Object, options)) { // Act var command = new SendAllEventCommand { returnQueueName = "Test.QueueName", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue }; target.OnReceived(command); // Assert repoMock.Verify(repo => repo.FindBy(It.IsAny <Expression <Func <SerializedEvent, bool> > >()), Times.Once()); pubMock.Verify(pub => pub.Publish(It.IsAny <string>(), It.IsAny <SerializedEvent>()), Times.Exactly(3)); } }