Exemple #1
0
        public async void GetSchools_SiteIsNotAvailable_ThrowsException()
        {
            var timeout = TimeSpan.FromSeconds(5);
            var service = new SchoolsParser(timeout);

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

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

                httpTest.ShouldHaveCalled(Constants.EndPoint)
                .WithVerb(HttpMethod.Get)
                .Times(1);
            }
        }
Exemple #2
0
        public async void GetSchools_SiteIsAvailable_ReturnsSchools()
        {
            var timeout = TimeSpan.FromSeconds(5);
            var service = new SchoolsParser(timeout);

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(File.ReadAllText("TestData/Parsers/schools.html"));

                var result = await service.GetSchools();

                httpTest.ShouldHaveCalled(Constants.EndPoint)
                .WithVerb(HttpMethod.Get)
                .Times(1);

                Assert.NotEmpty(result);
            }
        }
Exemple #3
0
        public async Task GetSchools_SiteIsNotAvailable_ThrowsException()
        {
            var timeout = TimeSpan.FromSeconds(5);
            var service = new SchoolsParser(timeout);

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

                Func <Task> func = async() => await service.GetSchools();

                await func.Should().ThrowAsync <FlurlHttpException>();

                httpTest.ShouldHaveCalled(Constants.EndPoint)
                .WithVerb(HttpMethod.Get)
                .Times(1);
            }
        }
Exemple #4
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();
        }
Exemple #5
0
        public async Task GetSchools_SiteIsAvailable_ReturnsSchools()
        {
            var timeout = TimeSpan.FromSeconds(5);
            var service = new SchoolsParser(timeout);

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(await File.ReadAllTextAsync("TestData/Parsers/schools.html"));

                var result = await service.GetSchools();

                var first = result.First();

                httpTest.ShouldHaveCalled(Constants.EndPoint)
                .WithVerb(HttpMethod.Get)
                .Times(1);

                result.Should().NotBeEmpty().And
                .HaveCount(13);
                first.Id.Should().Be(15);
                first.Name.Should().Be("Высшая инженерная школа");
                first.Url.Should().Be("https://ruz.narfu.ru/?groups&institution=15");
            }
        }