Пример #1
0
        public void ParseIncorrectPage()
        {
            var downloaderMock = new Mock <IWebDownloader>();

            downloaderMock.Setup(d => d.GetLoadStream(It.IsAny <string>()))
            .Returns(new MemoryStream(Encoding.UTF8.GetBytes("<!doctype html><html>Some random text</html>")));
            var studentSelectionParser = new StudentSelectionUpdater("123", downloaderMock.Object);

            Assert.That(() => studentSelectionParser.Update(), Throws.ArgumentException);
        }
Пример #2
0
        public void ParseCorrectPage()
        {
            var downloaderMock = new Mock <IWebDownloader>();

            downloaderMock.Setup(d => d.GetLoadStream(It.IsAny <string>()))
            .Returns(new MemoryStream(Encoding.UTF8.GetBytes(CorrectPage)));
            var studentSelectionParser = new StudentSelectionUpdater("123", downloaderMock.Object);

            var readOnlyList = studentSelectionParser.Update();

            Assert.That(readOnlyList.GroupBy(s => s.SpecCourseName).Count(), Is.EqualTo(4));
            Assert.That(readOnlyList.Count(s => s.Name == "Лихачев Александр Евгеньевич" &&
                                           s.SpecCourseName == "Коллективная разработка программного обеспечения" &&
                                           s.Group == "14202"), Is.EqualTo(1));
        }
Пример #3
0
        static void Main()
        {
            var httpClient = new HttpClient();

            if (!httpClient.DefaultRequestHeaders.TryAddWithoutValidation(
                    "Authorization", Environment.GetEnvironmentVariable("ScheduleStealerAuth")))
            {
                Console.Error.WriteLine("Can't add authorization");
            }


            var scheduleUpdater           = new ScheduleUpdater(BaseUri, new ScheduleParser(), new WebDownloader());
            var studentSelectionUpdater   = new StudentSelectionUpdater("http://fit.nsu.ru/uch/bak/4-kurs-raspredelenie-po-distsiplinam-po-vyboru", new WebDownloader());
            var individualScheduleBuilder = new IndividualScheduleBuilder(scheduleUpdater, studentSelectionUpdater);

            for (;;)
            {
                try
                {
                    var res  = individualScheduleBuilder.UpdateIndividualSchedule(Groups);
                    var json = JsonConvert.SerializeObject(res);

                    var stringContent       = new StringContent(json, Encoding.UTF8, "application/json");
                    var httpResponseMessage = httpClient.PostAsync("https://nsutable.ru/api/schedule/", stringContent).Result;
                    Console.Out.WriteLine("{0:HH:mm:ss tt}: {1}", DateTime.Now, httpResponseMessage.Content.ReadAsStringAsync().Result);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("{0:HH:mm:ss tt}: {1}", DateTime.Now, e.Message);
                    Thread.Sleep(new TimeSpan(0, 5, 0));
                }
                if (Console.KeyAvailable && Console.ReadLine() == "exit")
                {
                    return;
                }
                Thread.Sleep(new TimeSpan(0, 5, 0));
            }
        }