public void TestFixtureSetUp() { TestUtil.CleanUpData(); using (KoalaBlogDbContext dbContext = new KoalaBlogDbContext()) { PersonHandler perHandler = new PersonHandler(dbContext); testPerson = new Person(); testPerson.RealName = "testRealName"; testPerson.NickName = "testPerson"; testPerson.RealNameAccessLevel = PersonInfoAccessInfo.MyselfOnly; testPerson.SexualTrendAccessLevel = PersonInfoAccessInfo.MyselfOnly; testPerson.MaritalStatusAccessLevel = PersonInfoAccessInfo.MyselfOnly; testPerson.QQAccessLevel = PersonInfoAccessInfo.MyselfOnly; testPerson.DOBAccessLevel = PersonInfoAccessInfo.MyselfOnly; testPerson.BloodTypeAccessLevel = PersonInfoAccessInfo.MyselfOnly; testPerson.HomePageAccessLevel = PersonInfoAccessInfo.MyselfOnly; perHandler.Add(testPerson); perHandler.SaveChanges(); commentPerson = new Person(); commentPerson.RealName = "testCommentRealName"; commentPerson.NickName = "testCommentPerson"; commentPerson.RealNameAccessLevel = PersonInfoAccessInfo.All; commentPerson.SexualTrendAccessLevel = PersonInfoAccessInfo.All; commentPerson.MaritalStatusAccessLevel = PersonInfoAccessInfo.All; commentPerson.QQAccessLevel = PersonInfoAccessInfo.All; commentPerson.DOBAccessLevel = PersonInfoAccessInfo.All; commentPerson.BloodTypeAccessLevel = PersonInfoAccessInfo.All; commentPerson.HomePageAccessLevel = PersonInfoAccessInfo.All; perHandler.Add(commentPerson); perHandler.SaveChanges(); } }
private Person CreatePerson(string realName, string nickName) { using (KoalaBlogDbContext dbContext = new KoalaBlogDbContext()) { PersonHandler perHandler = new PersonHandler(dbContext); Person p = new Person(); p = new Person(); p.RealName = realName; p.NickName = nickName; p.RealNameAccessLevel = PersonInfoAccessInfo.MyselfOnly; p.SexualTrendAccessLevel = PersonInfoAccessInfo.MyselfOnly; p.MaritalStatusAccessLevel = PersonInfoAccessInfo.MyselfOnly; p.QQAccessLevel = PersonInfoAccessInfo.MyselfOnly; p.DOBAccessLevel = PersonInfoAccessInfo.MyselfOnly; p.BloodTypeAccessLevel = PersonInfoAccessInfo.MyselfOnly; p.HomePageAccessLevel = PersonInfoAccessInfo.MyselfOnly; perHandler.Add(p); perHandler.SaveChanges(); return p; } }
public async Task Test_03_ModifyPersonInfoAsync() { using(KoalaBlogDbContext dbContext = new KoalaBlogDbContext()) { //1. Create a test person obj. PersonHandler perHandler = new PersonHandler(dbContext); Person p = new Person() { RealName = "testJay", NickName = "testMayBeJay", Gender = Gender.Female, DOB = new DateTime(2015, 8, 23), RealNameAccessLevel = PersonInfoAccessInfo.MyselfOnly, SexualTrendAccessLevel = PersonInfoAccessInfo.MyselfOnly, MaritalStatusAccessLevel = PersonInfoAccessInfo.MyselfOnly, QQAccessLevel = PersonInfoAccessInfo.MyselfOnly, DOBAccessLevel = PersonInfoAccessInfo.MyselfOnly, BloodTypeAccessLevel = PersonInfoAccessInfo.MyselfOnly, HomePageAccessLevel = PersonInfoAccessInfo.MyselfOnly }; perHandler.Add(p); await perHandler.SaveChangesAsync(); Assert.AreNotEqual(p.ID, 0); //2. Modify person info. Person beModifiedPerson = await perHandler.GetByIdAsync(p.ID); beModifiedPerson.RealName = "testGoodMan"; beModifiedPerson.NickName = "testIAMGoodMan"; beModifiedPerson.Gender = Gender.Male; beModifiedPerson.DOB = new DateTime(2015, 8, 21); beModifiedPerson.RealNameAccessLevel = PersonInfoAccessInfo.All; beModifiedPerson.DOBAccessLevel = PersonInfoAccessInfo.FollowerOnly; await perHandler.ModifyPersonInfoAsync(beModifiedPerson); //3. Test the modified person. Person modifiedPerson = await perHandler.GetByIdAsync(p.ID); Assert.IsNotNull(modifiedPerson); Assert.AreEqual(modifiedPerson.RealName, "testGoodMan"); Assert.AreEqual(modifiedPerson.NickName, "testIAMGoodMan"); Assert.AreEqual(modifiedPerson.Gender, Gender.Male); Assert.AreEqual(modifiedPerson.RealNameAccessLevel, PersonInfoAccessInfo.All); Assert.AreEqual(modifiedPerson.DOBAccessLevel, PersonInfoAccessInfo.FollowerOnly); Assert.AreEqual(modifiedPerson.HomePageAccessLevel, PersonInfoAccessInfo.MyselfOnly); } }
public async Task Test_02_ModifyPersonNickNameAsync() { using(KoalaBlogDbContext dbContext = new KoalaBlogDbContext()) { //1. Create a test person obj. PersonHandler perHandler = new PersonHandler(dbContext); Person p = new Person() { RealName = "testMike", NickName = "testIAMMike", Gender = Gender.Male, DOB = new DateTime(2015, 7, 15), RealNameAccessLevel = PersonInfoAccessInfo.MyselfOnly, SexualTrendAccessLevel = PersonInfoAccessInfo.MyselfOnly, MaritalStatusAccessLevel = PersonInfoAccessInfo.MyselfOnly, QQAccessLevel = PersonInfoAccessInfo.MyselfOnly, DOBAccessLevel = PersonInfoAccessInfo.MyselfOnly, BloodTypeAccessLevel = PersonInfoAccessInfo.MyselfOnly, HomePageAccessLevel = PersonInfoAccessInfo.MyselfOnly }; perHandler.Add(p); await perHandler.SaveChangesAsync(); Assert.AreNotEqual(p.ID, 0); //2. Modify the person nick name and test it. bool isSucceed = await perHandler.ModifyPersonNickNameAsync(p.ID, "testIAMShy"); Assert.IsTrue(isSucceed); //2.1 Get the person by id Person modifiedPerson = await perHandler.GetByIdAsync(p.ID); Assert.IsNotNull(modifiedPerson); Assert.AreEqual(modifiedPerson.NickName, "testIAMShy"); Assert.AreEqual(modifiedPerson.RealName, "testMike"); Assert.AreEqual(modifiedPerson.Gender, Gender.Male); Assert.AreEqual(modifiedPerson.DOB, new DateTime(2015, 7, 15)); Assert.AreEqual(modifiedPerson.RealNameAccessLevel, PersonInfoAccessInfo.MyselfOnly); //3. Give the error parameter and test it. bool isChecked = false; try { isSucceed = await perHandler.ModifyPersonNickNameAsync(0, "testSorryShy"); } catch (Exception ex) { isChecked = true; Assert.AreEqual(ex.GetType(), typeof(AssertException)); Assert.AreEqual(ex.Message, "personId must be greater than zero"); } Assert.IsTrue(isChecked); isChecked = false; try { isSucceed = await perHandler.ModifyPersonNickNameAsync(0, ""); } catch (Exception ex) { isChecked = true; Assert.AreEqual(ex.GetType(), typeof(AssertException)); AssertException assertException = ex as AssertException; Assert.IsNotNull(assertException.ExceptionMessageList); Assert.AreEqual(assertException.ExceptionMessageList.Count, 2); Assert.AreEqual(assertException.ExceptionMessageList[0], "personId must be greater than zero"); Assert.AreEqual(assertException.ExceptionMessageList[1], "nickName can't be empty"); } Assert.IsTrue(isChecked); isChecked = false; try { isSucceed = await perHandler.ModifyPersonNickNameAsync(99999999, "testIAMShy"); } catch (Exception ex) { isChecked = true; Assert.AreEqual(ex.GetType(), typeof(AssertException)); Assert.AreEqual(ex.Message, "This person doesn't exist"); } Assert.IsTrue(isChecked); } }