|
|
|
@ -177,44 +177,6 @@ namespace RedisStudyTest
|
|
|
|
|
Assert.False(redisDatabase.KeyDelete(preHashKey + studentId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void QueryOneStudentTest()
|
|
|
|
|
{
|
|
|
|
|
//hashStudy.AddStudent(this.student);
|
|
|
|
|
|
|
|
|
|
//var queryStudent = hashStudy.QueryOneStudent(this.student.Id);
|
|
|
|
|
|
|
|
|
|
//Assert.NotNull(queryStudent);
|
|
|
|
|
//Assert.True(this.student.Id==queryStudent.Id);
|
|
|
|
|
//Assert.True(this.student.Name == queryStudent.Name);
|
|
|
|
|
//Assert.True(this.student.Age == queryStudent.Age);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ExistStudentTest()
|
|
|
|
|
{
|
|
|
|
|
//Assert.True(hashStudy.ExistStudent(students[0].Id));
|
|
|
|
|
//Assert.True(hashStudy.ExistStudent(students[1].Id));
|
|
|
|
|
//Assert.True(hashStudy.ExistStudent(students[2].Id));
|
|
|
|
|
//Assert.True(hashStudy.ExistStudent(students[3].Id));
|
|
|
|
|
//Assert.True(hashStudy.ExistStudent(students[4].Id));
|
|
|
|
|
|
|
|
|
|
//Assert.False(hashStudy.ExistStudent(-1000));
|
|
|
|
|
//Assert.False(hashStudy.ExistStudent(-2000));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询所有学生
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void QueryAllStudent()
|
|
|
|
|
{
|
|
|
|
|
//List<Student> students = hashStudy.QueryAllStudents();
|
|
|
|
|
|
|
|
|
|
//Assert.NotNull(students);
|
|
|
|
|
//Assert.Equal(students.Count(), students.Count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 清理
|
|
|
|
|
/// </summary>
|
|
|
|
@ -230,57 +192,5 @@ namespace RedisStudyTest
|
|
|
|
|
redisDatabase.KeyDelete(preHashKey + temp.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 辅助方法
|
|
|
|
|
public HashEntry[] StudentsToHashEntrys(Student student)
|
|
|
|
|
{
|
|
|
|
|
if (student == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entrys = new List<HashEntry>()
|
|
|
|
|
{
|
|
|
|
|
new HashEntry("Id",student.Id),
|
|
|
|
|
new HashEntry("Name",student.Name),
|
|
|
|
|
new HashEntry("Age",student.Age),
|
|
|
|
|
};
|
|
|
|
|
return entrys.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Student HashEntrysToStudent(HashEntry[] hashEntrys)
|
|
|
|
|
{
|
|
|
|
|
if (hashEntrys == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hashEntrys.Length <= 0)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var student = new Student();
|
|
|
|
|
foreach (var entry in hashEntrys)
|
|
|
|
|
{
|
|
|
|
|
switch (entry.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Id":
|
|
|
|
|
student.Id = entry.Value.IsInteger ? (int)entry.Value : default(int); ;
|
|
|
|
|
break;
|
|
|
|
|
case "Name":
|
|
|
|
|
student.Name = entry.Value.ToString();
|
|
|
|
|
break;
|
|
|
|
|
case "Age":
|
|
|
|
|
student.Age = entry.Value.IsInteger ? (int)entry.Value : default(int);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return student;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|