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("Лабораторные занятия"); } }
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); }
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); } }
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); } }
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(); }
public ScheduleService(TimeSpan timeout) { Students = new StudentsSchedule(timeout); Teachers = new TeachersSchedule(timeout); }