public void MsgQueueFileStore_Corrupt_ExtraMessage() { MsgQueueFileStore store = null; int count; QueuedMsgInfo msgInfo; QueuedMsg msg; object persistID; Guid[] ids; // Create a store with a bunch of messages then close // it and explicitly add a message file. Then reopen // the store and verify that it loaded the metadata // for the new message. ClearFolders(); try { store = new MsgQueueFileStore(root); store.Open(); ids = new Guid[MessageCount]; for (int i = 0; i < MessageCount; i++) { msg = new QueuedMsg(); msg.TargetEP = "logical://test/" + i.ToString(); msg.Body = i; msgInfo = new QueuedMsgInfo(null, msg); store.Add(msgInfo, msg); ids[i] = msg.ID; } Assert.AreEqual(MessageCount, store.Count); count = 0; foreach (QueuedMsgInfo i in store) { count++; } Assert.AreEqual(MessageCount, count); for (int i = 0; i < ids.Length; i++) { Guid id = ids[i]; persistID = store.GetPersistID(id); Assert.IsNotNull(persistID); msgInfo = store.GetInfo(persistID); Assert.IsNotNull(msgInfo); Assert.AreEqual((MsgEP)("logical://test/" + i.ToString()), msgInfo.TargetEP); msg = store.Get(persistID); msg.DeserializedBody(); Assert.AreEqual(i, (int)msg.Body); } // Close the store and explicitly create a new message file. Guid newID = Helper.NewGuid(); string newPath = store.GetMessagePath(newID, true); msg = new QueuedMsg(); msg.ID = newID; msg.TargetEP = "logical://foo/bar"; msg.Body = "Hello World!"; msgInfo = new QueuedMsgInfo(null, msg); store.WriteMessage(newPath, msg, msgInfo); // I'm calling this internal write method // so that the metadata won't be saved to the index. store.Close(); // Reopen the store and verify that it loaded the metadata // for the new message and that the other message metadata is // still intact. store.Open(); Assert.AreEqual(MessageCount + 1, store.Count); persistID = store.GetPersistID(newID); Assert.IsNotNull(persistID); msgInfo = store.GetInfo(persistID); Assert.IsNotNull(msgInfo); Assert.AreEqual((MsgEP)"logical://foo/bar", msgInfo.TargetEP); msg = store.Get(persistID); msg.DeserializedBody(); Assert.AreEqual("Hello World!", (string)msg.Body); for (int i = 0; i < ids.Length; i++) { Guid id = ids[i]; persistID = store.GetPersistID(id); Assert.IsNotNull(persistID); msgInfo = store.GetInfo(persistID); Assert.IsNotNull(msgInfo); Assert.AreEqual((MsgEP)("logical://test/" + i.ToString()), msgInfo.TargetEP); msg = store.Get(persistID); msg.DeserializedBody(); Assert.AreEqual(i, (int)msg.Body); } } finally { if (store != null) { store.Close(); } } }