예제 #1
0
        public void SetUp()
        {
            _scheduler = new ManualTaskScheduler();
            _entries = new List<LogLine>();
            _logFile = new Mock<ILogFile>();
            _logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
                    .Callback(
                        (LogFileSection section, LogLine[] entries) =>
                        _entries.CopyTo((int)section.Index, entries, 0, section.Count));
            _logFile.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>()))
                    .Callback((ILogFileListener listener, TimeSpan unused, int max) =>
                        {
                            for (int i = 0; i < _entries.Count/max+1; ++i)
                            {
                                int from = i*max;
                                int to = Math.Min((i + 1)*max, _entries.Count);
                                listener.OnLogFileModified(_logFile.Object, new LogFileSection(from, to - from));
                            }
                        });
            _logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) => _entries[index]);
            _logFile.Setup(x => x.Count).Returns(() => _entries.Count);
            _logFile.Setup(x => x.EndOfSourceReached).Returns(true);

            _matches = new List<LogMatch>();
            _listener = new Mock<ILogFileSearchListener>();
            _listener.Setup(x => x.OnSearchModified(It.IsAny<ILogFileSearch>(), It.IsAny<List<LogMatch>>()))
                     .Callback((ILogFileSearch sender, IEnumerable<LogMatch> matches) =>
                         {
                             _matches.Clear();
                             _matches.AddRange(matches);
                         });
        }
예제 #2
0
        public void SetUp()
        {
            _control = new LogEntryListView
                {
                    Width = 1024,
                    Height = 768
                };
            var availableSize = new Size(1024, 768);
            _control.Measure(availableSize);
            _control.Arrange(new Rect(new Point(), availableSize));
            DispatcherExtensions.ExecuteAllEvents();

            _lines = new List<LogLine>();
            _listeners = new List<ILogFileListener>();

            _logFile = new Mock<ILogFile>();
            _logFile.Setup(x => x.Count).Returns(() => _lines.Count);
            _logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
                    .Callback((LogFileSection section, LogLine[] dest) =>
                              _lines.CopyTo((int) section.Index, dest, 0, section.Count));
            _logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) =>
                                                                    _lines[index]);
            _logFile.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>()))
                    .Callback((ILogFileListener listener, TimeSpan maximumTimeout, int maximumLines) =>
                        {
                            _listeners.Add(listener);
                            listener.OnLogFileModified(_logFile.Object,
                                                       new LogFileSection(0, _lines.Count));
                        });
        }
예제 #3
0
 public void CopyTo_CopiesToNewObject()
 {
     List<int> original = new List<int> { 1 };
     original.CopyTo<List<int>>()
         .ShouldNotReferTo(original)
         .And.ShouldMatch(new[] { 1 });
 }
예제 #4
0
        public void ShouldGetLastFiveReleases()
        {
            //given
            var releaseRepository = new ReleaseRepository();
            var expectedReleaseDetailsModels = new List<Release>
                                                   {
                                                       new ReleaseBuilder().WithReleaseNumber("REL05").WithReleaseDate(DateTime.Today.AddDays(-1)).Build(),
                                                       new ReleaseBuilder().WithReleaseNumber("REL04").WithReleaseDate(DateTime.Today.AddMonths(-1)).Build(),
                                                       new ReleaseBuilder().WithReleaseNumber("REL03").WithReleaseDate(DateTime.Today.AddMonths(-1)).Build(),
                                                       new ReleaseBuilder().WithReleaseNumber("REL02").WithReleaseDate(DateTime.Today.AddMonths(-2).AddDays(2)).Build(),
                                                       new ReleaseBuilder().WithReleaseNumber("REL01").WithReleaseDate(DateTime.Today.AddMonths(-2)).Build()
                                                   };

            var lastfiveReleases = new Release[expectedReleaseDetailsModels.Count];
            expectedReleaseDetailsModels.CopyTo(lastfiveReleases);

            expectedReleaseDetailsModels.Add(new ReleaseBuilder().WithReleaseNumber("REL06").WithReleaseDate(DateTime.Today.AddMonths(-3).AddDays(-1)).Build());

            //when
            foreach (Release expectedReleaseDetailsModel in expectedReleaseDetailsModels)
            {
                releaseRepository.SaveReleaseDetails(expectedReleaseDetailsModel);
            }

            // then
            IEnumerable<Release> releaseDetailsModels = releaseRepository.GetLastFiveReleases();
            IEnumerable<Release> expectedReleases = lastfiveReleases.ToList();
            Assert.That(releaseDetailsModels, Is.EqualTo(expectedReleases));
        }
예제 #5
0
        public void MainTest()
        {
            string curDir = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(TestUtility.TempDir);

            if (Directory.Exists(TestUtility.TempDir + @"NewDir"))
                Directory.Delete(TestUtility.TempDir + @"NewDir", true);

            List<string> al = new List<string>();
            al.Add(@"-bf:TestTool.xml");
            al.Add(@"-bc:JavaApp;TestLibrary");
            al.Add(@"-prop:OutputDir=C:\Temp\NewDir");
            al.Add(@"-log:xml");

            string[] args = new string[al.Count];
            al.CopyTo(args, 0);

            Program.Main(args);

            Assert.IsTrue(Directory.Exists(TestUtility.TempDir + @"NewDir"));
            Assert.IsTrue(File.Exists(TestUtility.TempDir + @"NewDir\JavaApp.class"));
            Assert.IsTrue(File.Exists(TestUtility.TempDir + @"NewDir\TestLibrary.dll"));
            Assert.IsTrue(File.Exists(TestUtility.TempDir + @"TestTool.log.xml"));

            DateTime dateModTestLibrary = File.GetLastWriteTime(TestUtility.TempDir + @"NewDir\TestLibrary.dll");
            DateTime dateModJavaApp = File.GetLastWriteTime(TestUtility.TempDir + @"NewDir\JavaApp.class");

            al.Add(@"-rebuild:JavaApp");
            args = new string[al.Count];
            al.CopyTo(args, 0);

            Program.Main(args);

            Assert.AreEqual(dateModTestLibrary, File.GetLastWriteTime(TestUtility.TempDir + @"NewDir\TestLibrary.dll"));
            Assert.AreNotEqual(dateModJavaApp, File.GetLastWriteTime(TestUtility.TempDir + @"NewDir\JavaApp.class"));

            // cleanup
            if (Directory.Exists(TestUtility.TempDir + @"NewDir"))
                Directory.Delete(TestUtility.TempDir + @"NewDir", true);

            File.Delete(TestUtility.TempDir + @"TestTool.log.xml");

            Directory.SetCurrentDirectory(curDir);
        }
 public void Setup()
 {
     _entries = new List<LogLine>();
     _logFile = new Mock<ILogFile>();
     _listeners = new LogFileListenerCollection(_logFile.Object);
     _logFile.Setup(x => x.EndOfSourceReached).Returns(true);
     _logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
             .Callback(
                 (LogFileSection section, LogLine[] entries) =>
                 _entries.CopyTo((int)section.Index, entries, 0, section.Count));
     _logFile.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>()))
             .Callback((ILogFileListener listener, TimeSpan maximumWaitTime, int maximumLineCount) => _listeners.AddListener(listener, maximumWaitTime, maximumLineCount));
     _logFile.Setup(x => x.RemoveListener(It.IsAny<ILogFileListener>()))
             .Callback((ILogFileListener listener) => _listeners.RemoveListener(listener));
     _logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) => _entries[index]);
     _logFile.Setup(x => x.Count).Returns(() => _entries.Count);
 }
예제 #7
0
        public void SetUp()
        {
            _taskScheduler = new ManualTaskScheduler();
            _entries = new List<LogLine>();
            _logFile = new Mock<ILogFile>();
            _logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
                    .Callback(
                        (LogFileSection section, LogLine[] entries) =>
                        _entries.CopyTo((int) section.Index, entries, 0, section.Count));
            _logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) => _entries[index]);
            _logFile.Setup(x => x.Count).Returns(() => _entries.Count);
            _logFile.Setup(x => x.EndOfSourceReached).Returns(true);

            _sections = new List<LogFileSection>();
            _listener = new Mock<ILogFileListener>();
            _listener.Setup(x => x.OnLogFileModified(It.IsAny<ILogFile>(), It.IsAny<LogFileSection>()))
                     .Callback((ILogFile l, LogFileSection s) => _sections.Add(s));
        }
예제 #8
0
 private static Mock<ILogFile> CreateLogFile(List<LogLine> lines)
 {
     var source = new Mock<ILogFile>();
     source.Setup(x => x.GetLine(It.IsAny<int>()))
           .Returns((int index) => lines[index]);
     source.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
           .Callback((LogFileSection section, LogLine[] data) => lines.CopyTo((int) section.Index, data, 0, section.Count));
     source.Setup(x => x.EndOfSourceReached).Returns(true);
     return source;
 }
예제 #9
0
        public void TestCopyTo()
        {
            using (var map = new MemoryMapStream())
            {
                var list = new List<int>(map);
                for (var i = 0; i < 10; i++)
                {
                    list.Add(i);
                }

                var array = new int[20];
                list.CopyTo(array, 0);

                for (var i = 0; i < 10; i++)
                {
                    Assert.AreEqual(i, array[i]);
                }

                list.CopyTo(array, 10);

                for (var i = 10; i < 20; i++)
                {
                    Assert.AreEqual(i - 10, array[i]);
                }
            }
        }
예제 #10
0
        public void Parallel_ForEach_Can_Be_Used_To_Put_And_Get_Objects()
        {
            /* NB: this example assumes a 4-node devrel available
             * with localhost PB ports at 10017, 10027, 10037 and 10047 */
            const int numNodes = 4;
            const int poolSize = 8;
            const int totalConnectionCount = poolSize * numNodes;
            const ushort portInterval = 10;
            const ushort startingPort = 10017;
            const ushort endingPort = startingPort + ((numNodes - 1) * portInterval);
            const int totalObjects = 65536;

            byte[] data = new byte[65536];
            Random.NextBytes(data);

            int batchSize = totalConnectionCount;
            int totalBatches = totalObjects / batchSize;
            Assert.AreEqual(0, totalObjects % batchSize);
            Debug.WriteLine("batchSize: {0}, totalBatches: {1}", batchSize, totalBatches);

            string riakHost = Environment.GetEnvironmentVariable("RIAK_HOST");
            if (String.IsNullOrWhiteSpace(riakHost))
            {
                riakHost = "riak-test";
            }

            Debug.WriteLine("Riak host: {0}", riakHost);

            Assert.AreEqual(10047, endingPort);

            var objs = new List<RiakObject>();
            for (int i = 0; i < totalObjects; i++)
            {
                var key = String.Format("{0}_{1}", TestKey, i);
                var id = new RiakObjectId(TestBucket, key);
                var obj = new RiakObject(id, data, RiakConstants.ContentTypes.ApplicationOctetStream, null);
                objs.Add(obj);
            }

            IRiakClusterConfiguration clusterConfig = new RiakClusterConfiguration();

            for (ushort port = startingPort; port <= endingPort; port += portInterval)
            {
                IRiakNodeConfiguration nc = new RiakNodeConfiguration();
                nc.PoolSize = poolSize;
                nc.HostAddress = riakHost;
                nc.PbcPort = port;
                nc.Name = String.Format("dev_{0}", port);
                clusterConfig.AddNode(nc);
            }

            var batchObjs = new RiakObject[batchSize];
            var p = new int[] { 1, batchSize };

            foreach (int parallelism in p)
            {
                var parallelOptions = new ParallelOptions();
                parallelOptions.MaxDegreeOfParallelism = parallelism;

                using (var cluster = new RiakCluster(clusterConfig))
                {
                    var client = cluster.CreateClient();

                    var sw = new Stopwatch();
                    sw.Start();

                    for (int i = 0; i < totalObjects; i += batchSize)
                    {
                        objs.CopyTo(i, batchObjs, 0, batchSize);
                        Parallel.ForEach(batchObjs, parallelOptions, (obj) =>
                        {
                            try
                            {
                                client.Put(obj);
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine("[ERROR] put exception: {0}", e.ToString());
                            }
                        });
                    }

                    sw.Stop();
                    Debug.WriteLine("parallelism: {0} - put {1} objects in {2}", parallelism, totalObjects, sw.Elapsed);

                    sw.Reset();

                    sw.Start();
                    for (int i = 0; i < totalObjects; i += batchSize)
                    {
                        objs.CopyTo(i, batchObjs, 0, batchSize);
                        Parallel.ForEach(batchObjs, parallelOptions, (obj) =>
                        {
                            try
                            {
                                var id = new RiakObjectId(obj.Bucket, obj.Key);
                                client.Get(id);
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine("[ERROR] put exception: {0}", e.ToString());
                            }
                        });
                    }

                    sw.Stop();
                    Debug.WriteLine("parallelism: {0} - fetched {1} objects in {2}", parallelism, totalObjects, sw.Elapsed);
                }
            }
        }
예제 #11
0
		private static void HandleEmailProperties(string messageSubject, string messageBody, string formattedMessageBody, string emailClient, Request request)
		{
			List<CustomProperty> propList = new List<CustomProperty>();
			propList.Add(new CustomProperty(SMTPPropertyTags.Subject, messageSubject));
			propList.Add(new CustomProperty(SMTPPropertyTags.Body, messageBody));
			propList.Add(new CustomProperty(SMTPPropertyTags.FormattedBody, formattedMessageBody));
			propList.Add(new CustomProperty(SMTPPropertyTags.FileHeader, string.Empty));
			propList.Add(new CustomProperty(SMTPRoutingPropertyTags.RequestChannel, emailClient));
			propList.Add(new CustomProperty(SMTPPropertyTags.xPriority, "2"));
			request.Properties = new CustomProperty[propList.Count];
			propList.CopyTo(request.Properties);
		}
예제 #12
0
		private static void HandleEmailSender(Request request, string sender)
		{
			List<CustomProperty> propList = new List<CustomProperty>();
			propList.Add(new CustomProperty(SMTPRoutingPropertyTags.DisplayName, sender));
			propList.Add(new CustomProperty(SMTPRoutingItemPropertyKeys.AddressType, AddressType.From));
			propList.Add(new CustomProperty(SMTPRoutingItemPropertyKeys.Internal, bool.TrueString));

			RoutingItem senderItem = new RoutingItem();
			senderItem.Content = sender;
			senderItem.Properties = new CustomProperty[propList.Count];
			
			propList.CopyTo(senderItem.Properties);

			request.Source.Items = new RoutingItem[] { senderItem };
		}
        private List<char> ShiftAlpha(string cipher)
        {
            var alpha = new List<char>(new char[26].Select((a, b) => (char)(b + 97)).ToArray());
            var startIndex = alpha.IndexOf(Convert.ToChar(cipher));

            var alphaNew = new char[alpha.Count];
            alpha.CopyTo(alphaNew);

            alpha.InsertRange(alpha.Count, alphaNew.Take(startIndex));
            return alpha.Skip(startIndex).ToList();
        }