public void Create_OK() { CreateTempDirs(); FileSystemNotificationQueue Q = new FileSystemNotificationQueue (INBOX_DIR, INPROCESS_DIR, SUCCESS_DIR, FAILURE_DIR); Assert.AreEqual(0, Q.GetLength()); }
public void ProcessFiles() { CreateTempDirs(); WriteFile(INBOX_DIR, FILENAME1, XML, 40); WriteFile(INBOX_DIR, FILENAME2, XML, 50); WriteFile(INBOX_DIR, FILENAME3, XML, 60); FileSystemNotificationQueue Q = new FileSystemNotificationQueue (INBOX_DIR, INPROCESS_DIR, SUCCESS_DIR, FAILURE_DIR); Assert.AreEqual(3, Q.GetLength()); NotificationQueueMessage M = Q.Receive(); Assert.AreEqual("charge-amount-notification", M.Type); Assert.AreEqual("345475345", M.OrderId); Assert.AreEqual("3rcf-f4wtvgw-gwg5", M.Id); Assert.AreEqual(2, Q.GetLength()); Assert.AreEqual(2, Directory.GetFiles(INBOX_DIR).Length); Assert.AreEqual(1, Directory.GetFiles(INPROCESS_DIR).Length); Assert.AreEqual(GetFullFileName(INPROCESS_DIR, FILENAME3), Directory.GetFiles(INPROCESS_DIR)[0]); Assert.AreEqual(0, Directory.GetFiles(SUCCESS_DIR).Length); Assert.AreEqual(0, Directory.GetFiles(FAILURE_DIR).Length); Q.ProcessingSucceeded(M); Assert.AreEqual(2, Directory.GetFiles(INBOX_DIR).Length); Assert.AreEqual(0, Directory.GetFiles(INPROCESS_DIR).Length); Assert.AreEqual(1, Directory.GetFiles(SUCCESS_DIR).Length); Assert.AreEqual(GetFullFileName(SUCCESS_DIR, FILENAME3), Directory.GetFiles(SUCCESS_DIR)[0]); Assert.AreEqual(0, Directory.GetFiles(FAILURE_DIR).Length); M = Q.Receive(); Assert.AreEqual("order-state-change-notification", M.Type); Assert.AreEqual("245629824", M.OrderId); Assert.AreEqual("345g-3w4f-6yg4", M.Id); Assert.AreEqual(1, Q.GetLength()); Assert.AreEqual(1, Directory.GetFiles(INBOX_DIR).Length); Assert.AreEqual(1, Directory.GetFiles(INPROCESS_DIR).Length); Assert.AreEqual(GetFullFileName(INPROCESS_DIR, FILENAME2), Directory.GetFiles(INPROCESS_DIR)[0]); Assert.AreEqual(1, Directory.GetFiles(SUCCESS_DIR).Length); Assert.AreEqual(0, Directory.GetFiles(FAILURE_DIR).Length); Q.ProcessingFailed(M); Assert.AreEqual(1, Directory.GetFiles(INBOX_DIR).Length); Assert.AreEqual(0, Directory.GetFiles(INPROCESS_DIR).Length); Assert.AreEqual(1, Directory.GetFiles(SUCCESS_DIR).Length); Assert.AreEqual(1, Directory.GetFiles(FAILURE_DIR).Length); Assert.AreEqual(GetFullFileName(FAILURE_DIR, FILENAME2), Directory.GetFiles(FAILURE_DIR)[0]); }
public void GetLength() { CreateTempDirs(); FileSystemNotificationQueue Q = new FileSystemNotificationQueue (INBOX_DIR, INPROCESS_DIR, SUCCESS_DIR, FAILURE_DIR); WriteFile(INBOX_DIR, FILENAME1, XML, 60); WriteFile(INBOX_DIR, FILENAME2, XML, 60); WriteFile(INBOX_DIR, FILENAME3, XML, 10); Assert.AreEqual(2, Q.GetLength()); }
static void Main(string[] args) { INotificationQueue Q = new FileSystemNotificationQueue( GetPathFromConfigFile("InboxDir"), GetPathFromConfigFile("InProcessDir"), GetPathFromConfigFile("SuccessDir"), GetPathFromConfigFile("FailureDir")); while (true) { Console.WriteLine("\nWaiting for the next notification."); NotificationQueueMessage M = Q.Receive(); Console.WriteLine("Processing {0} for order {1}.", M.Type, M.OrderId); try { ProcessNotification(M.Type, M.Xml); Q.ProcessingSucceeded(M); } catch (Exception e) { Console.WriteLine(e.ToString()); Q.ProcessingFailed(M); } Console.WriteLine("{0} notifications in queue.", Q.GetLength()); } }