public void AsUnqualifiedTopicName() { UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision("LocalName(Revision)"); Assert.AreEqual("LocalName", revision.AsUnqualifiedTopicName().DottedName, "Checking that the right name was returned."); }
public void Name() { UnqualifiedTopicName name = new UnqualifiedTopicName("LocalName"); UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision(name); Assert.AreEqual("LocalName", revision.Name.DottedName, "Checking that name is recorded correctly."); }
public void ConstructDefault() { UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision(); Assert.IsNull(revision.LocalName, "Checking that local name is null on a default UnqualifiedTopicRevision"); Assert.IsNull(revision.Namespace, "Checking that namespace is null on a default UnqualifiedTopicRevision"); Assert.IsNull(revision.Version, "Checking that version is null on a default UnqualifiedTopicRevision"); }
public void ConstructByUnqualifiedTopicNameAndVersion() { UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision(new UnqualifiedTopicName("LocalName"), "Version"); Assert.AreEqual("LocalName(Version)", revision.DottedNameWithVersion, "Checking that name and version were set properly"); }
public void ConstructByStringFromLocalName() { UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision("LocalName(Version)"); Assert.AreEqual("LocalName", revision.LocalName, "Checking that local name is correct."); Assert.AreEqual("Version", revision.Version, "Checking that version is correct."); Assert.IsNull(revision.Namespace, "Checking that namespace is correct."); }
public ParsedTopic GetParsedTopic(UnqualifiedTopicRevision topicRevision) { using (CreateRecursionContext()) { return _next.GetParsedTopic(topicRevision); } }
public void TextReaderForTopic() { DoTest(delegate(TestParameters<TopicCacheProvider> parameters) { UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision("TopicOne"); ClearCache(parameters.Cache); parameters.Store.TextReaderForTopicCalled = false; string firstRetrieval = parameters.Provider.TextReaderForTopic(revision).ToString(); Assert.IsTrue(parameters.Store.TextReaderForTopicCalled, "Checking that first retrieval does not come from cache."); parameters.Store.TextReaderForTopicCalled = false; string secondRetrieval = parameters.Provider.TextReaderForTopic(revision).ToString(); Assert.IsFalse(parameters.Store.TextReaderForTopicCalled, "Checking that second retrieval comes from cache."); parameters.Manager.WriteTopicAndNewVersion(revision.AsUnqualifiedTopicName(), "New content", "test"); parameters.Store.TextReaderForTopicCalled = false; string thirdRetrieval = parameters.Provider.TextReaderForTopic(revision).ToString(); Assert.IsTrue(parameters.Store.TextReaderForTopicCalled, "Checking that a retrieval after a write of a new topic does not come from cache."); parameters.Manager.DeleteTopic(revision.AsUnqualifiedTopicName(), false); parameters.Store.TextReaderForTopicCalled = false; TextReader fourthRetrieval = parameters.Provider.TextReaderForTopic(revision); Assert.IsTrue(parameters.Store.TextReaderForTopicCalled, "Checking that a retrieval after a delete of a topic does not come from cache."); parameters.Manager.DeleteAllTopicsAndHistory(); parameters.Store.TextReaderForTopicCalled = false; TextReader fifthRetrieval = parameters.Provider.TextReaderForTopic(revision); Assert.IsTrue(parameters.Store.TextReaderForTopicCalled, "Checking that a retrieval after a delete of all namespace content does not come from cache."); }); }
public override void WriteTopic(UnqualifiedTopicRevision topicRevision, string content) { Next.WriteTopic(topicRevision, content); }
public override System.IO.TextReader TextReaderForTopic(UnqualifiedTopicRevision revision) { RegisterCall(MethodInfo.GetCurrentMethod()); throw new NotImplementedException(); }
public override TextReader TextReaderForTopic(UnqualifiedTopicRevision revision) { _textReaderForTopicCalled = true; MockTopic topic = GetTopic(revision.LocalName, ExistencePolicy.ExistingOnly); if (topic == null) { return null; } MockTopicRevision history = topic[revision.Version]; if (history == null) { return null; } return new StringReader(history.Contents); }
public void GetTopicCreationTimeModifiedVersion() { Federation federation = WikiTestUtilities.SetupFederation("test://NamespaceManagerTests", TestContentSets.MultipleVersions); NamespaceManager manager = federation.NamespaceManagerForNamespace("NamespaceOne"); // Flip through the history and get the oldest version UnqualifiedTopicName topicName = new UnqualifiedTopicName("TopicOne"); TopicChangeCollection changes = manager.AllChangesForTopic(topicName); UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision(topicName.LocalName, changes[0].Version); manager.WriteTopic(revision, "Modified content"); DateTime creationTime = manager.GetTopicCreationTime(revision); Assert.AreEqual(new DateTime(2004, 10, 28, 14, 11, 02), creationTime, "Checking that the creation time for the first version doesn't change even when modified."); }
public void ReadSpecificVersion() { Federation federation = WikiTestUtilities.SetupFederation("test://NamespaceManagerTests/", TestContentSets.MultipleVersions); NamespaceManager manager = federation.NamespaceManagerForNamespace("NamespaceOne"); UnqualifiedTopicName topic = new UnqualifiedTopicName("TopicOne"); TopicChangeCollection changes = manager.AllChangesForTopic(topic); UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision(topic, changes[1].Version); string content = manager.Read(revision); Assert.AreEqual("content2", content, "Checking that the right content was retrieved."); }
public void TextReaderForTopic() { Federation federation = WikiTestUtilities.SetupFederation("test://BuiltInTopicsProviderTests/", TestContentSets.SingleEmptyNamespace); NamespaceManager manager = federation.NamespaceManagerForNamespace("NamespaceOne"); BuiltinTopicsProvider provider = (BuiltinTopicsProvider)manager.GetProvider(typeof(BuiltinTopicsProvider)); string content = provider.TextReaderForTopic(new UnqualifiedTopicRevision(manager.HomePage)).ReadToEnd(); Assert.AreEqual(BuiltinTopicsProvider.DefaultHomePageContent.Length, GetContent(provider, manager.HomePage).Length, "Checking that home page has correct default content."); Assert.AreEqual(BuiltinTopicsProvider.DefaultNormalBordersContent.Length, GetContent(provider, NamespaceManager.BordersTopicLocalName).Length, "Checking that borders topic has correct default content."); WriteBuiltInTopics(manager); Assert.AreEqual(20, GetContent(provider, manager.HomePage).Length, "Checking that home page has correct non-default content."); Assert.AreEqual(19, GetContent(provider, NamespaceManager.BordersTopicLocalName).Length, "Checking that borders topic has correct non-default content."); Assert.AreEqual(BuiltinTopicsProvider.DefaultHomePageContent.Length, GetDefaultContent(provider, manager.HomePage).Length, "Checking that home page has correct default content."); Assert.AreEqual(BuiltinTopicsProvider.DefaultNormalBordersContent.Length, GetDefaultContent(provider, NamespaceManager.BordersTopicLocalName).Length, "Checking that borders topic has correct default content."); UnqualifiedTopicRevision homePageDefaultRevision = new UnqualifiedTopicRevision( manager.HomePage, TopicRevision.NewVersionStringForUser("FlexWiki", DateTime.MinValue)); UnqualifiedTopicRevision bordersDefaultRevision = new UnqualifiedTopicRevision( manager.BordersTopicName.LocalName, TopicRevision.NewVersionStringForUser("FlexWiki", DateTime.MinValue)); UnqualifiedTopicRevision homePageNewRevision = new UnqualifiedTopicRevision( manager.HomePage, TopicRevision.NewVersionStringForUser("Test", new DateTime(2004, 10, 28, 14, 11, 01))); UnqualifiedTopicRevision bordersNewRevision = new UnqualifiedTopicRevision( manager.BordersTopicName.LocalName, TopicRevision.NewVersionStringForUser("Test", new DateTime(2004, 10, 28, 14, 11, 04))); UnqualifiedTopicRevision homePageNoSuchRevison = new UnqualifiedTopicRevision( manager.HomePage, "NoSuchVersion"); UnqualifiedTopicRevision bordersNoSuchRevision = new UnqualifiedTopicRevision( manager.BordersTopicName.LocalName, "NoSuchVersion"); Assert.AreEqual(BuiltinTopicsProvider.DefaultHomePageContent.Length, GetContent(provider, homePageDefaultRevision).Length, "Checking that home page has correct content when retrieving default content revision explicitly."); Assert.AreEqual(20, GetContent(provider, homePageNewRevision).Length, "Checking that home page has correct content when retrieiving new content revision explicitly."); Assert.IsNull(provider.TextReaderForTopic(homePageNoSuchRevison), "Checking that home page returns null when retrieving non existent revision."); Assert.AreEqual(BuiltinTopicsProvider.DefaultNormalBordersContent.Length, GetContent(provider, bordersDefaultRevision).Length, "Checking that borders topic has correct content when retrieving default content revision explicitly."); Assert.AreEqual(19, GetContent(provider, bordersNewRevision).Length, "Checking that borders topic has correct content when retrieiving new content revision explicitly."); Assert.IsNull(provider.TextReaderForTopic(bordersNoSuchRevision), "Checking that borders topic returns null when retrieving non existent revision."); manager.WriteTopicAndNewVersion("NewTopic", "Some new content", "Test"); UnqualifiedTopicRevision newTopicRevision = new UnqualifiedTopicRevision("NewTopic", TopicRevision.NewVersionStringForUser("Test", new DateTime(2004, 10, 28, 14, 11, 07))); UnqualifiedTopicRevision newTopicNoSuchRevision = new UnqualifiedTopicRevision("NewTopic", TopicRevision.NewVersionStringForUser("Test", DateTime.MinValue)); Assert.AreEqual(16, GetContent(provider, "NewTopic").Length, "Checking that the provider doesn't interfere with non-built-in topics."); Assert.AreEqual(16, GetContent(provider, newTopicRevision).Length, "Checking that the provider doesn't interfere with non-built-in topics when retreived by explicit version."); Assert.IsNull(provider.TextReaderForTopic(newTopicNoSuchRevision), "Checking that the provider returns null when a nonexistent version of a non-built-in topic is requested."); }
public void ConstructByQualifiedNameFromNameAndVersion() { UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision("Namespace.LocalName", "Version"); }
public TextReader TextReaderForTopic(UnqualifiedTopicRevision topicRevision) { AssertTransportSecurityRequirement(TransportSecurityContext.Content); using (CreateRecursionContext()) { return _next.TextReaderForTopic(topicRevision); } }
private static string GetContent(BuiltinTopicsProvider provider, UnqualifiedTopicRevision revision) { using (TextReader reader = provider.TextReaderForTopic(revision)) { if (reader == null) { return null; } return reader.ReadToEnd(); } }
public void WriteTopic(UnqualifiedTopicRevision topicRevision, string content) { using (CreateRecursionContext()) { _next.WriteTopic(topicRevision, content); } }
public void WriteNewTopicDenied() { FederationConfiguration configuration = new FederationConfiguration(); Federation federation = WikiTestUtilities.SetupFederation("test://AuthorizationProviderTests", TestContentSets.SingleEmptyNamespace, configuration); NamespaceManager manager = WikiTestUtilities.GetNamespaceManagerBypassingSecurity(federation, "NamespaceOne"); AuthorizationProvider provider = GetSecurityProvider(manager); // Set it up so we have Read AuthorizationRule allow = new AuthorizationRule(new AuthorizationRuleWho(AuthorizationRuleWhoType.User, "someuser"), AuthorizationRulePolarity.Allow, AuthorizationRuleScope.Namespace, SecurableAction.Read, 0); WikiTestUtilities.WriteTopicAndNewVersionBypassingSecurity(manager, manager.DefinitionTopicName.LocalName, allow.ToString("T"), "test"); UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision("NewTopic"); string content = "New content to be written"; using (new TestSecurityContext("someuser", "somerole")) { provider.WriteTopic(revision, content); } }
public void WriteTopicSpecificVersion() { Federation federation = WikiTestUtilities.SetupFederation("test://NamespaceManagerTests", TestContentSets.MultipleVersions); NamespaceManager manager = federation.NamespaceManagerForNamespace("NamespaceOne"); UnqualifiedTopicName topicName = new UnqualifiedTopicName("TopicOne"); TopicChangeCollection changes = manager.AllChangesForTopic(topicName); UnqualifiedTopicRevision revision = new UnqualifiedTopicRevision(topicName, changes[1].Version); string newContents = "New contents"; manager.WriteTopic(revision, newContents); string actualContents = manager.Read(revision); Assert.AreEqual(changes.Count, manager.AllChangesForTopic(topicName).Count, "Checking that no new versions were created."); Assert.AreEqual(newContents, actualContents, "Checking that content was updated correctly."); }
public void WriteTopicRegularTopicDenied() { FederationConfiguration configuration = new FederationConfiguration(); // Grant the Read permission, which should not be enough. AuthorizationRule allow = new AuthorizationRule(new AuthorizationRuleWho(AuthorizationRuleWhoType.User, "someuser"), AuthorizationRulePolarity.Allow, AuthorizationRuleScope.Wiki, SecurableAction.Read, 0); configuration.AuthorizationRules.Add(new WikiAuthorizationRule(allow)); Federation federation = WikiTestUtilities.SetupFederation("test://AuthorizationProviderTests", TestContentSets.SingleTopicNoImports, configuration); NamespaceManager manager = WikiTestUtilities.GetNamespaceManagerBypassingSecurity(federation, "NamespaceOne"); AuthorizationProvider provider = GetSecurityProvider(manager); using (new TestSecurityContext("someuser", "somerole")) { UnqualifiedTopicRevision topic = new UnqualifiedTopicRevision("TopicOne"); provider.WriteTopic(topic, "New content"); Assert.Fail("A security exception should have been thrown."); } }
public override ParsedTopic GetParsedTopic(UnqualifiedTopicRevision topicRevision) { return null; }
public abstract ParsedTopic GetParsedTopic(UnqualifiedTopicRevision topicRevision);
public override void WriteTopic(UnqualifiedTopicRevision revision, string content) { MockTopic topic = RetrieveOrCreateTopic(revision.LocalName); MockTopicRevision revisionToWrite = null; if (revision.Version == null) { if (topic.IsDeleted) { revisionToWrite = new MockTopicRevision(content, "", Federation.TimeProvider.Now); topic.WriteLatest(revisionToWrite); } else { revisionToWrite = topic.Latest; } } else { revisionToWrite = topic[revision.Version]; if (revisionToWrite == null) { VersionInfo versionInfo = TopicRevision.ParseVersion(revision.Version); revisionToWrite = new MockTopicRevision(content, versionInfo.Author, versionInfo.Timestamp); topic.History.Add(revisionToWrite); } revisionToWrite.Modified = Federation.TimeProvider.Now; } revisionToWrite.Contents = content; }
public abstract TextReader TextReaderForTopic(UnqualifiedTopicRevision topicRevision);
public override void WriteTopic(UnqualifiedTopicRevision revision, string content) { RegisterCall(MethodInfo.GetCurrentMethod()); throw new NotImplementedException(); }
public abstract void WriteTopic(UnqualifiedTopicRevision topicRevision, string content);
public override TextReader TextReaderForTopic(UnqualifiedTopicRevision topicRevision) { AddDependency(new TopicContentsDependency(topicRevision.ResolveRelativeTo(Namespace).AsQualifiedTopicName())); return Next.TextReaderForTopic(topicRevision); }
public override void WriteTopic(UnqualifiedTopicRevision revision, string content) { MockTopic topic = RetrieveOrCreateTopic(revision.LocalName); MockTopicHistory history = null; if (topic.History.Count == 0) { history = new MockTopicHistory(content, "", Federation.TimeProvider.Now); topic.History.Add(history); } else if (revision.Version != null) { foreach (MockTopicHistory h in topic.History) { if (revision.Version == h.Version) { history = h; } } } else { history = topic.Latest; } history.Contents = content; history.Modified = Federation.TimeProvider.Now; topic.IsDeleted = false; }