public void Init() { queueRepository = A.Fake <IQueueRepository>(); system = A.Fake <IFileSystem>(); provider = A.Fake <ISendingProvider>(); CreateFile(SrcFile1); CreateFile(StreamFile1); fakeStream = new FileStream(StreamFile1, FileMode.Open, FileAccess.Read); queue = new FileTransferQueue(QueueName); queue.Enqueue(new FileItem { DestPath = DestFile1, SrcPath = SrcFile1 }); queue.Enqueue(new FileItem { DestPath = "./1.txt", Identifier = Identifier1 }); queue.Enqueue(new FileItem { DestPath = "./2.txt", Identifier = Identifier2 }); A.CallTo(() => queueRepository.Load(QueueName)).Returns(queue); A.CallTo(() => system.GetStream(A <string> .Ignored)).Returns(fakeStream); A.CallTo(() => provider.Send(A <Stream> .Ignored, A <string> .Ignored)).Returns(true); manager = new FileTransferQueueManager(QueueName, queueRepository, system, provider); manager.NotificationRaised += manager_NotificationRaised; }
public void ShouldListAllEnqueuedFileItemsInTheSameOrder() { var queue = new FileTransferQueue(QueueName); var item = new FileItem { DestPath = "./1.txt", Identifier = "1" }; var item2 = new FileItem { DestPath = "./2.txt", Identifier = "2" }; var item3 = new FileItem { DestPath = "./3.txt", Identifier = "3" }; queue.Enqueue(item); queue.Enqueue(item2); queue.Enqueue(item3); var list = queue.FlushItems(); Assert.Null(queue.Dequeue(), "Queue should be empty after a flush"); Assert.AreEqual(3, list.Count); Assert.AreSame(item, list[0]); Assert.AreSame(item2, list[1]); Assert.AreSame(item3, list[2]); }
public void ShouldRetrieveEnqueuedFileItemsInTheSameOrder() { var queue = new FileTransferQueue(QueueName); var item = new FileItem { DestPath = "./1.txt", Identifier = "1" }; var item2 = new FileItem { DestPath = "./2.txt", Identifier = "2" }; queue.Enqueue(item); queue.Enqueue(item2); Assert.AreSame(item, queue.Dequeue()); Assert.AreSame(item2, queue.Dequeue()); Assert.Null(queue.Dequeue(), "Only two values were in the queue"); }
public void ShouldEnqueueThrowExceptionIfDestinationFilenameNotDefined() { var queue = new FileTransferQueue(QueueName); var item = new FileItem { DestPath = "./", Identifier = "1" }; Assert.Throws <ArgumentException>(() => queue.Enqueue(item)); }
public void ShouldRetrieveEnqueuedFileItem() { var queue = new FileTransferQueue(QueueName); var item = new FileItem { DestPath = "./1.txt", Identifier = "1" }; queue.Enqueue(item); Assert.AreSame(item, queue.Dequeue()); Assert.Null(queue.Dequeue(), "Only one value was in the queue"); }
public void ShouldCheckIfQueueContainsADestinationFilename() { const string filename = "mysamplefilename.zip"; var queue = new FileTransferQueue(QueueName); var item = new FileItem { DestPath = "./" + filename, Identifier = "1" }; queue.Enqueue(item); Assert.True(queue.Contains(filename)); }
public void ShouldSaveAQueue() { const string queueName = "MySampleSaveQueue"; const string jsonString = @"[ { ""SrcPath"": ""srcfile.txt"", ""DestPath"": ""./destfile.txt"" }, { ""Identifier"": ""1"", ""DestPath"": ""./1.txt"" }, { ""Identifier"": ""2"", ""DestPath"": ""./1.txt"" } ]"; filename = GetFileName(queueName); var queue = new FileTransferQueue(queueName); queue.Enqueue(new FileItem { DestPath = "./destfile.txt", SrcPath = "srcfile.txt" }); queue.Enqueue(new FileItem { DestPath = "./1.txt", Identifier = "1" }); queue.Enqueue(new FileItem { DestPath = "./1.txt", Identifier = "2" }); repository.Save(queue); Assert.AreEqual(0, queue.FlushItems().Count, "After a save, the queue should be empty"); Assert.True(File.Exists(filename)); Assert.AreEqual(jsonString, File.ReadAllText(filename)); File.Delete(filename); }