/** * Asserts that the items stored in the storeAssertedRequests call * are still in the cache * @param cache The RequestCache class to assert * @param testRemoval True if the items in the cache should be removed * and asserted that they are removed */ private void assertStoredRequests(RequestCache cache, Boolean testRemoval) { Assertion.AssertEquals("Active request count", fMsgIds.Length, cache.ActiveRequestCount); // Lookup each setting, for (int i = 0; i < fMsgIds.Length; i++) { IRequestInfo reqInfo = cache.LookupRequestInfo(fMsgIds[i], null); Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType); Assertion.AssertEquals("User Data is missing for " + i, fStateObjects[i], (String) ((TestState) reqInfo.UserData).State); } if (testRemoval) { // Lookup each setting, for (int i = 0; i < fMsgIds.Length; i++) { IRequestInfo reqInfo = cache.GetRequestInfo(fMsgIds[i], null); Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType); Assertion.AssertEquals("User Data is missing for " + i, fStateObjects[i], (String) ((TestState) reqInfo.UserData).State); } // all messages should now be removed from the queue Assertion.AssertEquals("Cache should be empty", 0, cache.ActiveRequestCount); } }
public void testWithLegacyFile() { //assertStoredRequests(fRC, true); // Copy the legacy requests.adk file to the agent work directory //FileInfo legacyFile = new FileInfo("requests.adk"); //Assertion.Assert("Saved legacy file does [not?] exist", legacyFile.Exists); //FileInfo copiedFile = new FileInfo(fAgent.HomeDir + Path.DirectorySeparatorChar + "work" + Path.DirectorySeparatorChar + "requests.adk"); //if (copiedFile.Exists) //{ // copiedFile.Delete(); //} //// Copy the file //legacyFile.CopyTo(copiedFile.FullName, true); // Now open up an instance of the request cache and verify that the contents are there fRC = RequestCache.GetInstance(fAgent); SIF_QueryObject obj = new SIF_QueryObject(""); SIF_Query query = new SIF_Query(obj); SIF_Request request = new SIF_Request(); request.SIF_Query = query; Query q; TestState ts; fMsgIds = new String[10]; fStateObjects = new String[10]; // Add 10 entries to the cache for (int i = 0; i < 10; i++) { ts = new TestState(); ts.State = Adk.MakeGuid(); fStateObjects[i] = (String) ts.State; q = new Query(StudentDTD.STUDENTPERSONAL); q.UserData = ts; fMsgIds[i] = Adk.MakeGuid(); storeRequest(fRC, request, q, fMsgIds[i], "Object_" + i.ToString()); } Assertion.AssertEquals("Active request count", 10, fRC.ActiveRequestCount); // Lookup each setting, for (int i = 0; i < 10; i++) { IRequestInfo reqInfo = fRC.LookupRequestInfo(fMsgIds[i], null); Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType); } // Lookup each setting, for (int i = 0; i < 10; i++) { IRequestInfo reqInfo = fRC.GetRequestInfo(fMsgIds[i], null); Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType); } // all messages should now be removed from the queue Assertion.AssertEquals("Cache should be empty", 0, fRC.ActiveRequestCount); // Now run one of our other tests testPersistence(); }