コード例 #1
0
		public async Task GetClassroomsWithAccessAsync_Student_ReturnsClassrooms()
		{
			var database = new TestDatabaseBuilder()
				.AddClassroom("Class1")
				.AddSection("Class1", "Section1")
				.AddClassroom("Class2")
				.AddSection("Class2", "Section2")
				.AddStudent("User1", "Last", "First", "Class2", "Section2")
				.Build();

			var userId = database.Context.Users.First().Id;
			var classroomId = database.Context.Classrooms
				.Single(c => c.Name == "Class2")
				.Id;

			database.Reload();

			var classroomService = new ClassroomService(database.Context);
			var classrooms = await classroomService.GetClassroomsWithAccessAsync(userId);

			Assert.Equal(1, classrooms.Count);
			Assert.Equal(userId, classrooms[0].UserId);
			Assert.Equal(classroomId, classrooms[0].ClassroomId);
		}
コード例 #2
0
		public async Task GetClassroomsWithAccessAsync_SuperUser_ReturnsClassrooms()
		{
			var database = new TestDatabaseBuilder()
				.AddClassroom("Class1")
				.AddClassroom("Class2")
				.AddAdmin("User1", "Last", "First", "Class2", superUser: true)
				.Build();

			var userId = database.Context.Users.First().Id;
			var expectedClassrooms = database.Context.Classrooms
				.OrderBy(c => c.Id)
				.ToList();

			database.Reload();

			var classroomService = new ClassroomService(database.Context);
			var classrooms = await classroomService.GetClassroomsWithAccessAsync(userId);
			classrooms = classrooms.OrderBy(c => c.ClassroomId).ToList();

			Assert.Equal(2, classrooms.Count);
			Assert.Equal(userId, classrooms[0].UserId);
			Assert.Equal(expectedClassrooms[0].Id, classrooms[0].ClassroomId);
			Assert.Equal(userId, classrooms[1].UserId);
			Assert.Equal(expectedClassrooms[1].Id, classrooms[1].ClassroomId);
		}