Пример #1
0
        public async Task GetStudentsWithExpansionTest()
        {
            var item = Factories.StudentCourseFactory(Factories.StudentFactory(), Factories.CourseFactory(), Factories.SchoolFactory());

            using var srv = new TestServer(TestHostBuilder <Startup, UnigrationTestStartup>()
                                           .ConfigureTestServices(x =>
            {
                ExecuteOnContext <DatabaseContext>(x, db =>
                {
                    _ = db.Students.Add(item.Student);
                    _ = db.Courses.Add(item.Course);
                    _ = db.StudentCourses.Add(item);
                });
            })
                                           );
            var client = srv.CreateClient();

            GenerateAuthHeader(client, GenerateTestToken());

            var resp = await client.GetStringAsync($"odata/v1/{nameof(Student)}s?$count=true&$expand={nameof(StudentCourse)}s");

            TestContext.WriteLine($"Server Reponse: {resp}");
            Assert.IsFalse(resp.ToLower().Contains("updatedby"));
            var envelope = JsonConvert.DeserializeObject <ODataEnvelope <Student> >(resp);

            Assert.AreEqual(item.Student.FirstName, envelope.Value.First().FirstName);
            Assert.AreEqual(item.Id, envelope.Value.First().StudentCourses.First().Id);
        }
Пример #2
0
        public async Task GetGroupByStudentsTest()
        {
            var item = Factories.StudentFactory();

            using var srv = new TestServer(TestHostBuilder <Startup, UnigrationTestStartup>()
                                           .ConfigureTestServices(x =>
            {
                ExecuteOnContext <DatabaseContext>(x, db =>
                {
                    _ = db.Students.Add(item);
                });
            })
                                           );
            var client = srv.CreateClient();

            GenerateAuthHeader(client, GenerateTestToken());

            var resp = await client.GetStringAsync($"odata/v1/{nameof(Student)}s?$apply=groupby(({nameof(item.FirstName)},{nameof(item.Id)}),aggregate(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.FirstName);
        }