예제 #1
0
        public async Task GetSchedule_CorrectId_ReturnsLessons()
        {
            const int teacherId        = 22222;
            var       correctStartDate = new DateTime(2019, 05, 14, 8, 20, 00);
            var       correctEndDate   = new DateTime(2019, 05, 14, 9, 55, 00);

            var timeout = TimeSpan.FromSeconds(5);
            var service = new TeachersSchedule(timeout);

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(await File.ReadAllTextAsync("TestData/Schedule/teachers.txt"));

                var result = await service.GetLessons(teacherId);

                var first = result.First();

                httpTest.ShouldHaveCalled(Constants.EndPoint)
                .WithVerb(HttpMethod.Get)
                .WithQueryParamValue("lecturer", teacherId)
                .Times(1);

                result.Should().NotBeEmpty().And
                .HaveCount(48);
                first.Address.Should().Be("наб. Северной Двины, д. 17");
                first.Auditory.Should().Be("ауд. 1255");
                first.EndTime.Should().Be(correctEndDate);
                first.Groups.Should().Be("Группа \"301713\"");
                first.Name.Should().Be("Физическая химия");
                first.Number.Should().Be(1);
                first.StartTime.Should().Be(correctStartDate);
                first.Teacher.Should().Be("Богданов Михаил Владиславович. Кафедра теоретической и прикладной химии");
                first.Type.Should().Be("Лабораторные занятия");
            }
        }
예제 #2
0
파일: NarfuApi.cs 프로젝트: equuskk/Goblin
    public NarfuApi(string groupsLink, IHttpClientFactory clientFactory)
    {
        var client = clientFactory.CreateClient("narfu-api");

        client.BaseAddress = new Uri("https://ruz.narfu.ru/");
        client.DefaultRequestHeaders.UserAgent.Clear();
        client.DefaultRequestHeaders.Add("UserAgent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0");
        client.Timeout = TimeSpan.FromSeconds(5);

        Teachers = new TeachersSchedule(client);
        Students = new StudentsSchedule(groupsLink, client);
    }
예제 #3
0
        public async void GetSchedule_IncorrectId_ReturnsLessons()
        {
            const int teacherId = 1;
            var       timeout   = TimeSpan.FromSeconds(5);
            var       service   = new TeachersSchedule(timeout);

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith("", 404);

                await Assert.ThrowsAsync <FlurlHttpException>(async() => await service.GetLessons(teacherId));

                httpTest.ShouldHaveCalled(Constants.EndPoint)
                .WithVerb(HttpMethod.Get)
                .WithQueryParamValue("lecturer", teacherId)
                .Times(1);
            }
        }
예제 #4
0
        public async void GetSchedule_CorrectId_ReturnsLessons()
        {
            const int teacherId = 22222;
            var       timeout   = TimeSpan.FromSeconds(5);
            var       service   = new TeachersSchedule(timeout);

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(File.ReadAllText("TestData/Schedule/teachers.txt"));

                var result = await service.GetLessons(teacherId);

                httpTest.ShouldHaveCalled(Constants.EndPoint)
                .WithVerb(HttpMethod.Get)
                .WithQueryParamValue("lecturer", teacherId)
                .Times(1);

                Assert.NotEmpty(result);
            }
        }
예제 #5
0
        static async Task Main(string[] args)
        {
            var timeout = TimeSpan.FromSeconds(5);

            var teacherSchedule = new TeachersSchedule(timeout);
            var teacherLessons  = await teacherSchedule.GetLessons(22914);

            var studentsSchedule = new StudentsSchedule(timeout);
            var studentsLessons  = await studentsSchedule.GetLessons(9092);

            var schoolsParser = new SchoolsParser(timeout);
            var schools       = await schoolsParser.GetSchools();

            var groupsParser = new GroupsParser(timeout);
            var groups       = await groupsParser.GetGroupsFromSchool(15);

            var teachersParser = new TeachersParser(timeout);
            var teachers       = await teachersParser.GetTeachersInRange(22913, 22917, 3, 1000);

            Console.ReadLine();
        }
예제 #6
0
 public ScheduleService(TimeSpan timeout)
 {
     Students = new StudentsSchedule(timeout);
     Teachers = new TeachersSchedule(timeout);
 }