public async Task GetCoursesWithExpansionTest() { var item = Factories.SchoolCourseFactory(Factories.SchoolFactory(), Factories.CourseFactory()); using var srv = new TestServer(TestHostBuilder <Startup, UnigrationTestStartup>() .ConfigureTestServices(x => { ExecuteOnContext <DatabaseContext>(x, db => { _ = db.Courses.Add(item.Course); _ = db.Schools.Add(item.School); _ = db.SchoolCourses.Add(item); }); }) ); var client = srv.CreateClient(); GenerateAuthHeader(client, GenerateTestToken()); var resp = await client.GetStringAsync($"odata/v1/{nameof(Course)}s?$count=true&$expand={nameof(SchoolCourse)}s"); TestContext.WriteLine($"Server Reponse: {resp}"); Assert.IsFalse(resp.ToLower().Contains("updatedby")); var envelope = JsonConvert.DeserializeObject <ODataEnvelope <Course> >(resp); Assert.AreEqual(item.Course.Title, envelope.Value.First().Title); Assert.AreEqual(item.Id, envelope.Value.First().SchoolCourses.First().Id); }
public async Task GetGroupByCoursesTest() { var item = Factories.CourseFactory(); using var srv = new TestServer(TestHostBuilder <Startup, UnigrationTestStartup>() .ConfigureTestServices(x => { ExecuteOnContext <DatabaseContext>(x, db => { _ = db.Courses.Add(item); }); }) ); var client = srv.CreateClient(); GenerateAuthHeader(client, GenerateTestToken()); var resp = await client.GetStringAsync($"odata/v1/{nameof(Course)}s?$apply=groupby(({nameof(item.Title)},{nameof(item.Id)}),aggregate({nameof(item.Id)} with countdistinct as total))"); TestContext.WriteLine($"Server Reponse: {resp}"); Assert.IsFalse(resp.ToLower().Contains("updatedby")); StringAssert.Contains(resp, item.Id.ToString()); StringAssert.Contains(resp, item.Title); }