public void GivenIdOf1ThenReturnAsynchronouslyGangMemberFromDbToMatchExpected() { // Instantiate the DataLayer which we are to use. DataLayer dataLayer = new DataLayer(); // Declare the actual gang member. GangMember actualMember = null; // Decide on which gang member we want from the database int memberID = 1; // Create a task this goes and gets us the gang member we are after on // a separate thread. Because I/O can take some time we can now move on // and do other stuff. Task<GangMember> actualMemberTask = dataLayer.GetGangMemberByIDAsync(memberID); // In the mean time while I/O is happening we can instantiate our // expected gang member, this is what we will test against. GangMember expectedMember = new GangMember() { MemberID = 1, MemberName = "Gentleman Jack", MemberRank = "Bootlegger" }; // We have created our expected gang member, I/O could still be occurring. // To block any further execution on the calling thread and force us to wait // until I/O finishes we call the .Result property (the same as the Wait method) // Note: We wouldn't want to call .Result before we instantiate the expected // member because this would defeat the purpose of doing async I/O. actualMember = actualMemberTask.Result; // Here we test that the expectedMember and actualMember match. Assert.AreEqual(expectedMember.MemberID, actualMember.MemberID); Assert.AreEqual(expectedMember.MemberName, actualMember.MemberName); Assert.AreEqual(expectedMember.MemberRank, actualMember.MemberRank); }