Exemplo n.º 1
0
        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]);
        }
Exemplo n.º 3
0
        public void ShouldEnqueueStreamAndNotifyIfSendIsRejected()
        {
            var q = new FileTransferQueue(QueueName);

            receivedEvents.Clear();

            A.CallTo(() => provider.Send(A <Stream> .Ignored, A <string> .Ignored)).Returns(false);
            A.CallTo(() => queueRepository.Load(QueueName)).Returns(q);
            A.CallTo(() => system.SaveStream(fakeStream)).Invokes(a => { Assert.True(a.GetArgument <Stream>(0).CanRead, "Stream should be opened to save it"); }).Returns(Identifier1);

            manager.Init();

            manager.TryToSend(fakeStream, DestFile1);
            A.CallTo(() => queueRepository.Load(QueueName)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => provider.Send(A <Stream> .Ignored, A <string> .Ignored)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => system.SaveStream(fakeStream)).MustHaveHappened(Repeated.Exactly.Once);

            Assert.NotNull(q);
            var list = q.FlushItems();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(Identifier1, list[0].Identifier);
            Assert.AreEqual(DestFile1, list[0].DestPath);

            AssertOnlyOneNotificationReceived(FileTransferQueueManager.NotificationType.Warn, Identifier1);
        }
        public void ShouldEmptyQueueReturnEmptyListWhenDequeue()
        {
            var queue = new FileTransferQueue(QueueName);
            var list  = queue.FlushItems();

            Assert.NotNull(list);
            Assert.AreEqual(0, list.Count);
        }
        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 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");
        }
Exemplo n.º 9
0
        public void ShouldNotifyIfFileSuccessfullySent()
        {
            var q = new FileTransferQueue(QueueName);

            receivedEvents.Clear();

            A.CallTo(() => provider.Send(A <Stream> .Ignored, A <string> .Ignored)).Returns(true);
            A.CallTo(() => queueRepository.Load(QueueName)).Returns(q);
            manager.Init();
            manager.TryToSend(SrcFile1, DestFile1);
            A.CallTo(() => queueRepository.Load(QueueName)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => provider.Send(A <Stream> .Ignored, A <string> .Ignored)).MustHaveHappened(Repeated.Exactly.Once);

            Assert.NotNull(q);
            var list = q.FlushItems();

            Assert.AreEqual(0, list.Count);

            AssertOnlyOneNotificationReceived(FileTransferQueueManager.NotificationType.Success, DestFile1);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        public void ShouldEnqueueFileAndNotifyIfSendIsRejected()
        {
            var q = new FileTransferQueue(QueueName);

            receivedEvents.Clear();

            A.CallTo(() => provider.Send(A <Stream> .Ignored, A <string> .Ignored)).Returns(false);
            A.CallTo(() => queueRepository.Load(QueueName)).Returns(q);
            manager.Init();
            manager.TryToSend(SrcFile1, DestFile1);
            A.CallTo(() => queueRepository.Load(QueueName)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => provider.Send(A <Stream> .Ignored, A <string> .Ignored)).MustHaveHappened(Repeated.Exactly.Once);

            Assert.NotNull(q);
            var list = q.FlushItems();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(SrcFile1, list[0].SrcPath);
            Assert.AreEqual(DestFile1, list[0].DestPath);

            AssertOnlyOneNotificationReceived(FileTransferQueueManager.NotificationType.Warn, DestFile1);
        }
        public void ShouldEmptyQueueReturnNullWhenDequeue()
        {
            var queue = new FileTransferQueue(QueueName);

            Assert.Null(queue.Dequeue());
        }
        public void ShouldFileTransferQueueHasAName()
        {
            var queue = new FileTransferQueue(QueueName);

            Assert.AreEqual(QueueName, queue.Name);
        }