> Also, I have made progress on creating Unit Tests as promised with a
> number for NamespaceManager and FileSystemStore. I was less than
> successful when I tried to add some to the TopicCacheProvider. The
> existing tests there are not easy to follow and replicate. Could you
> provide some hints.

Not easy to follow? Sorry about that. Let me try to explain them a bit. 

The first slightly confusing bit is the use of DoTest. This is just me
trying to reduce what would otherwise be massive code duplication. I'm using
an anonymous delegate that forms a closure, which is somewhat unusual for
many C# developers. If you're not familiar, just think of it as a callback:
DoTest does a bunch of setup, then calls back to the block inside the
braces, passing in a TestParameters that contains references to the
Federation, NamespaceManager, TopicCacheProvider, etc. etc. 

As far as the structure of the tests themselves, basically the trick is to
make multiple calls against a particular operation, and then to verify that
the first one comes from the store and the second one comes from cache. We
also verify that the various "write operations" (i.e. DeleteTopic,
WriteTopic, LockTopic, etc.) cause the cache to flush, and for subsequent
operations to go all the way to the store again. 

The way that I determine whether a retrieval comes from the store is pretty
simple. All the tests run against MockContentStore, which has a series of
Boolean flags that correspond to the methods of IContentProvider. When a
method is called, the corresponding flag is set. So, for example, the
implementation of MockContentStore.AllTopics looks like this [1]. The key is
that first line where we set _allTopicsCalled to true. There's a
corresponding property on MockCnotentStore called AllTopicsCalled [2] that
just returns this value. So if I clear the value, then call AllTopics, then
check this value, I can tell whether the operation returned a value from
cache, or whether the call made it all the way through the pipeline to the
content store. Which is what I want to test. 

Does that make sense? 


[1]
public override QualifiedTopicNameCollection AllTopics()
{
    _allTopicsCalled = true; // Note this line!!!

    QualifiedTopicNameCollection topics = new
QualifiedTopicNameCollection();

    foreach (MockTopic topic in AllTopics(ExistencePolicy.ExistingOnly))
    {
        topics.Add(new QualifiedTopicName(topic.Name, this.Namespace));
    }

    return topics;
}

[2] 
internal bool AllTopicsCalled
{
    get { return _allTopicsCalled; }
    set { _allTopicsCalled = value; }
}



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Flexwiki-users mailing list
Flexwiki-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flexwiki-users

Reply via email to