public async Task GetClassroomAsync_DoesntExist_ReturnNull()
		{
			var database = new TestDatabaseBuilder()
				.AddClassroom("Class1")
				.Build();

			var classroomService = new ClassroomService(database.Context);
			var classroom = await classroomService.GetClassroomAsync("Class2");

			Assert.Null(classroom);
		}
		public async Task GetClassroomsAsync_ReturnsAllClassrooms()
		{
			var database = new TestDatabaseBuilder()
				.AddClassroom("Class1")
				.AddClassroom("Class2")
				.Build();

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

			Assert.Equal(2, classrooms.Count);
			Assert.Equal("Class1", classrooms[0].Name);
			Assert.Equal("Class1", classrooms[0].Name);
		}
		public async Task GetClassroomAsync_Exists_ReturnsClassroom()
		{
			var database = new TestDatabaseBuilder()
				.AddClassroom("Class1")
				.AddClassroom("Class2")
				.Build();

			var classroomId = database.Context.Classrooms.First().Id;

			database.Reload();

			var classroomService = new ClassroomService(database.Context);
			var classroom = await classroomService.GetClassroomAsync("Class1");

			Assert.Equal("Class1", classroom.Name);
		}
		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);
		}
		public async Task DeleteClassroomAsync_ClassroomDeleted()
		{
			var database = new TestDatabaseBuilder()
				.AddClassroom("Class1")
				.Build();

			var classroomId = database.Context.Classrooms.First().Id;

			database.Reload();

			var classroomService = new ClassroomService(database.Context);
			await classroomService.DeleteClassroomAsync("Class1");

			database.Reload();

			Assert.Equal(0, database.Context.Classrooms.Count());
		}
		public async Task UpdateClassroomAsync_ClassroomUpdated()
		{
			var database = new TestDatabaseBuilder()
				.AddClassroom("Class1")
				.Build();

			var classroom = database.Context.Classrooms.Single();

			// Update the classroom
			database.Context.Entry(classroom).State = EntityState.Detached;
			classroom.DisplayName = "New Display Name";

			// Apply the update
			var classroomService = new ClassroomService(database.Context);
			await classroomService.UpdateClassroomAsync(classroom);

			database.Reload();

			classroom = database.Context.Classrooms.Single();

			Assert.Equal("Class1", classroom.Name);
			Assert.Equal("New Display Name", classroom.DisplayName);
		}
		public async Task CreateClassroomAsync_ClassroomCreated()
		{
			var database = new TestDatabaseBuilder().Build();

			var classroomService = new ClassroomService(database.Context);
			await classroomService.CreateClassroomAsync
			(
				new Classroom()
				{
					Name = "Class1"
				}
			);

			database.Reload();

			var classroom = database.Context.Classrooms.Single();

			Assert.Equal("Class1", classroom.Name);
		}
		public async Task GetClassroomAdminsAsync_ReturnsAdmins()
		{
			var database = new TestDatabaseBuilder()
				.AddClassroom("Class1")
				.AddClassroom("Class2")
				.AddAdmin("User1", "Last", "First", "Class1", superUser: false)
				.AddAdmin("User2", "Last", "First", "Class1", superUser: false)
				.AddAdmin("User3", "Last", "First", "Class2", superUser: false)
				.Build();

			var users = database.Context.Users
				.OrderBy(u => u.UserName)
				.ToList();

			database.Reload();

			var classroomService = new ClassroomService(database.Context);
			var admins = await classroomService.GetClassroomAdminsAsync("Class1");
			admins = admins.OrderBy(a => a.UserId).ToList();

			Assert.Equal(2, admins.Count);
			Assert.Equal(users[0].Id, admins[0].UserId);
			Assert.Equal(users[1].Id, admins[1].UserId);
		}
		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);
		}