예제 #1
0
        public void FolderPollServiceFileInitWithoutImpersonationTest()
        {
            string testPath = @"C:\FolderPoll";
            string configPath = Path.Combine(testPath, "ExampleConfiguration.xml");
            string firstPollPath = Path.Combine(testPath, "FirstPoll");
            string secondPollPath = Path.Combine(testPath, "SecondPoll");
            string firstFilter = "*.txt";
            string secondFilter = "*.xml";
            string firstName = "firstNewFile";
            string secondName = "secondNewFile";
            string copyPath = Path.Combine(testPath, "PollCopy");
            string movePath = Path.Combine(testPath, "PollMove");

            if (Directory.Exists(testPath))
            {
                Directory.Delete(testPath, true);
            }

            if (!Directory.Exists(testPath))
            {
                Directory.CreateDirectory(testPath);
            }
            if (!Directory.Exists(firstPollPath))
            {
                Directory.CreateDirectory(firstPollPath);
            }
            if (!Directory.Exists(secondPollPath))
            {
                Directory.CreateDirectory(secondPollPath);
            }
            if (!Directory.Exists(copyPath))
            {
                Directory.CreateDirectory(copyPath);
            }
            if (!Directory.Exists(movePath))
            {
                Directory.CreateDirectory(movePath);
            }

            var polls = new List<Poll>
            {
                new Poll
                {
                    Folder = firstPollPath,
                    NewFile = new NewFile
                    {
                        Filter = firstFilter,
                        Copy = new NewFileCopy
                        {
                            TargetFolder = copyPath
                        }
                    }
                },
                new Poll
                {
                    Folder = secondPollPath,
                    NewFile = new NewFile
                    {
                        Filter = secondFilter,
                        Move = new NewFileMove
                        {
                            TargetFolder = movePath
                        }
                    }
                }
            };

            var folderPollConfig = new FolderPollConfig
            {
                Poll = polls.ToArray()
            };

            var serializer = new XmlSerializer(typeof(FolderPollConfig));
            TextWriter writer = new StreamWriter(configPath);
            serializer.Serialize(writer, folderPollConfig);
            writer.Close();

            var folderPollService = new FolderPollService(configPath, true);

            folderPollService.Run();

            File.Create(Path.Combine(firstPollPath, string.Concat(firstName, Path.GetExtension(firstFilter)))).Dispose();
            File.Create(Path.Combine(secondPollPath, string.Concat(secondName, Path.GetExtension(secondFilter)))).Dispose();

            folderPollService.Stop();

            Assert.AreEqual(true, File.Exists(Path.Combine(copyPath, string.Concat(firstName, Path.GetExtension(firstFilter)))));
            Assert.AreEqual(true, File.Exists(Path.Combine(movePath, string.Concat(secondName, Path.GetExtension(secondFilter)))));

            if (Directory.Exists(testPath))
            {
                Directory.Delete(testPath, true);
            }
        }
예제 #2
0
        public void WithImpersonationTest()
        {
            WithImpersonationMessage = string.Empty;

            this.PrepareTestEnviroment(true);  // prepare polls, creation of all test folders

            var folderPollConfig = new FolderPollConfig
            {
                Poll = polls.ToArray()
            };

            var serializer = new XmlSerializer(typeof(FolderPollConfig));
            TextWriter writer = new StreamWriter(xmlConfigPath);
            serializer.Serialize(writer, folderPollConfig);
            writer.Close();

            var folderPollService = new FolderPollService(xmlConfigPath, true);
            folderPollService.Run();

            EmulateService(true);

            Thread.Sleep(7000);

            FilesExistsTest();

            folderPollService.Stop();

            Assert.AreEqual("passed", WithImpersonationMessage);
        }