本文整理汇总了C#中MindTouch.Dream.XUri.At方法的典型用法代码示例。如果您正苦于以下问题:C# XUri.At方法的具体用法?C# XUri.At怎么用?C# XUri.At使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MindTouch.Dream.XUri
的用法示例。
在下文中一共展示了XUri.At方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportManager_chains_exporter_to_packager
public void ExportManager_chains_exporter_to_packager() {
// Arrange
XUri dekiApiUri = new XUri("http://mock/@api/deki");
XDoc exportDocument = new XDoc("export");
XUri item1Uri = dekiApiUri.At("foo", "bar", "abc");
XDoc item1Doc = new XDoc("item1");
XUri item2Uri = dekiApiUri.At("foo", "bar", "def");
XDoc item2Doc = new XDoc("item2");
XDoc exportResponse = new XDoc("export")
.Start("requests")
.Start("request")
.Attr("method", "GET")
.Attr("dataid", "abc")
.Attr("href", item1Uri)
.Start("header").Attr("name", "h_1").Attr("value", "v_1").End()
.Start("header").Attr("name", "h_2").Attr("value", "v_2").End()
.End()
.Start("request")
.Attr("method", "GET")
.Attr("dataid", "def")
.Attr("href", item2Uri)
.End()
.End()
.Start("manifest")
.Start("foo").Attr("dataid", "abc").End()
.Start("bar").Attr("dataid", "def").End()
.End();
AutoMockPlug mock = MockPlug.Register(dekiApiUri);
mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "export").With("relto", "0")).RequestDocument(exportDocument).Response(DreamMessage.Ok(exportResponse));
mock.Expect().Verb("GET").Uri(item1Uri).RequestHeader("h_1", "v_1").RequestHeader("h_2", "v_2").Response(DreamMessage.Ok(item1Doc));
mock.Expect().Verb("GET").Uri(item2Uri).Response(DreamMessage.Ok(item2Doc));
var writes = new List<string>();
var mockPackageWriter = new Mock<IPackageWriter>();
mockPackageWriter.Setup(x => x.WriteDataAsync(It.IsAny<ExportItem>(), It.IsAny<Result>()))
.Returns(() => new Result().WithReturn())
.Callback((ExportItem item, Result result) => writes.Add(item.DataId))
.AtMost(2)
.Verifiable();
mockPackageWriter.Setup(x => x.WriteManifest(It.IsAny<XDoc>(), It.IsAny<Result>()))
.Returns(() => new Result().WithReturn())
.AtMostOnce()
.Verifiable();
// Act
ExportManager manager = ExportManager.CreateAsync(Plug.New(dekiApiUri), exportDocument, 0, mockPackageWriter.Object, new Result<ExportManager>()).Wait();
manager.ExportAsync(new Result()).Wait();
// Assert
Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)), mock.VerificationFailure);
Assert.AreEqual(2, manager.TotalItems);
Assert.AreEqual(2, manager.CompletedItems);
Assert.AreEqual(new[] { "abc", "def" }, writes.ToArray());
mockPackageWriter.Verify(x => x.Dispose(), Times.Once());
mockPackageWriter.VerifyAll();
}
示例2: Exporter_hits_export_feature_on_creation_using_relto
public void Exporter_hits_export_feature_on_creation_using_relto() {
// Arrange
XUri dekiApiUri = new XUri("http://mock/@api/deki");
XDoc exportDocument = new XDoc("export")
.Start("page")
.Attr("path", "/")
.Attr("recursive", "true")
.Attr("exclude", "all")
.End();
XDoc exportResponse = new XDoc("export")
.Start("requests")
.End()
.Start("manifest")
.Elem("justanode")
.End();
AutoMockPlug mock = MockPlug.Register(dekiApiUri);
mock.Expect("POST", dekiApiUri.At("site", "export").With("relto", 5.ToString()), exportDocument, DreamMessage.Ok(exportResponse));
// Act
Exporter exporter = Exporter.CreateAsync(Plug.New(dekiApiUri), exportDocument, 5, new Result<Exporter>()).Wait();
//Assert
Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)));
Assert.AreEqual(exportResponse["manifest"], exporter.Manifest);
}
示例3: ImportManager_chains_reader_to_importer
public void ImportManager_chains_reader_to_importer() {
// Arrange
var dekiApiUri = new XUri("http://mock/@api/deki");
var importManifest = new XDoc("manifest");
var item1Uri = dekiApiUri.At("foo", "bar", "abc");
var item1Doc = new XDoc("item1");
var item2Uri = dekiApiUri.At("foo", "bar", "def");
var item2Doc = new XDoc("item2");
var importResponse = new XDoc("requests")
.Start("request")
.Attr("method", "POST")
.Attr("dataid", "abc")
.Attr("href", item1Uri)
.Start("header").Attr("name", "h_1").Attr("value", "v_1").End()
.Start("header").Attr("name", "h_2").Attr("value", "v_2").End()
.End()
.Start("request")
.Attr("method", "PUT")
.Attr("dataid", "def")
.Attr("href", item2Uri)
.End();
var mock = MockPlug.Register(dekiApiUri);
mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "import").With("relto", "0")).RequestDocument(importManifest).Response(DreamMessage.Ok(importResponse));
mock.Expect().Verb("POST").Uri(item1Uri).RequestHeader("h_1", "v_1").RequestHeader("h_2", "v_2").RequestDocument(item1Doc);
mock.Expect().Verb("PUT").Uri(item2Uri).RequestDocument(item2Doc);
var mockPackageReader = new Mock<IPackageReader>();
mockPackageReader.Setup(x => x.ReadManifest(It.IsAny<Result<XDoc>>())).Returns(importManifest.AsResult()).Verifiable("didn't get manifest");
var item1stream = new MemoryStream(item1Doc.ToBytes());
mockPackageReader.Setup(x => x.ReadData(It.Is<ImportItem>(y => y.DataId == "abc"), It.IsAny<Result<ImportItem>>()))
.Returns(() => new ImportItem("abc", importResponse["request[@dataid='abc']"], null, item1stream, item1stream.Length).AsResult())
.Verifiable();
var item2stream = new MemoryStream(item2Doc.ToBytes());
mockPackageReader.Setup(x => x.ReadData(It.Is<ImportItem>(y => y.DataId == "def"), It.IsAny<Result<ImportItem>>()))
.Returns(() => new ImportItem("def", importResponse["request[@dataid='def']"], null, item2stream, item2stream.Length).AsResult())
.Verifiable();
mockPackageReader.Setup(x => x.Dispose()).Verifiable();
// Act
var manager = ImportManager.CreateAsync(Plug.New(dekiApiUri), 0, mockPackageReader.Object, new Result<ImportManager>()).Wait();
manager.ImportAsync(new Result()).Wait();
//Assert
Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)), mock.VerificationFailure);
mockPackageReader.VerifyAll();
}
示例4: Importer_hits_import_feature_with_reltopath
public void Importer_hits_import_feature_with_reltopath() {
// Arrange
XUri dekiApiUri = new XUri("http://mock/@api/deki");
XDoc importManifest = new XDoc("manifest");
XDoc importResponse = new XDoc("requests")
.Start("request").Attr("dataid", "a").End()
.Start("request").Attr("dataid", "b").End()
.Start("request").Attr("dataid", "c").End();
AutoMockPlug mock = MockPlug.Register(dekiApiUri);
mock.Expect("POST", dekiApiUri.At("site", "import").With("reltopath", "/foo/bar"), importManifest, DreamMessage.Ok(importResponse));
// Act
Importer importer = Importer.CreateAsync(Plug.New(dekiApiUri), importManifest, "/foo/bar", new Result<Importer>()).Wait();
//Assert
Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)));
Assert.AreEqual(importManifest, importer.Manifest);
Assert.AreEqual(new[] { "a", "b", "c" }, importer.Items.Select(x => x.DataId).ToArray());
}
示例5: GetUserXml
public static XDoc GetUserXml(UserBE user, string relation, bool showPrivateInfo) {
XDoc userXml = new XDoc(string.IsNullOrEmpty(relation) ? "user" : "user." + relation);
userXml.Attr("id", user.ID);
userXml.Attr("href", DekiContext.Current.ApiUri.At("users", user.ID.ToString()));
userXml.Elem("nick", user.Name);
userXml.Elem("username", user.Name);
userXml.Elem("fullname", user.RealName ?? String.Empty);
// check if we can add the email address
if(showPrivateInfo) {
userXml.Elem("email", user.Email);
} else {
userXml.Start("email").Attr("hidden", true).End();
}
// add gravatar
if(!IsAnonymous(user) && !string.IsNullOrEmpty(user.Email)) {
DekiContext context = DekiContext.CurrentOrNull;
XUri gravatar = new XUri("http://www.gravatar.com/avatar");
string hash = string.Empty;
if(context != null) {
DekiInstance deki = context.Instance;
string secure = context.Instance.GravatarSalt ?? string.Empty;
if(!secure.EqualsInvariantIgnoreCase("hidden")) {
hash = StringUtil.ComputeHashString(secure + (user.Email ?? string.Empty).Trim().ToLowerInvariant(), System.Text.Encoding.UTF8);
}
// add size, if any
string size = deki.GravatarSize;
if(size != null) {
gravatar = gravatar.With("s", size);
}
// add rating, if any
string rating = deki.GravatarRating;
if(rating != null) {
gravatar = gravatar.With("r", rating);
}
// add default icon, if any
string def = deki.GravatarDefault;
if(def != null) {
gravatar = gravatar.With("d", def);
}
}
if(!string.IsNullOrEmpty(hash)) {
userXml.Elem("hash.email", hash);
userXml.Elem("uri.gravatar", gravatar.At(hash + ".png"));
} else {
userXml.Elem("hash.email", string.Empty);
userXml.Elem("uri.gravatar", gravatar.At("no-email.png"));
}
}
return userXml;
}
示例6: MakeUserObject
internal Hashtable MakeUserObject(UserBE user) {
// initialize gravatar link
DekiInstance deki = DekiContext.Current.Instance;
XUri gravatar = new XUri("http://www.gravatar.com/avatar");
// add size, if any
string size = deki.GravatarSize;
if(size != null) {
gravatar = gravatar.With("s", size);
}
// add rating, if any
string rating = deki.GravatarRating;
if(rating != null) {
gravatar = gravatar.With("r", rating);
}
// add default icon, if any
string def = deki.GravatarDefault;
if(def != null) {
gravatar = gravatar.With("d", def);
}
// initialize user object
Hashtable result = new Hashtable(StringComparer.OrdinalIgnoreCase);
string hash = string.Empty;
if(user != null) {
var env = DreamContext.Current.GetState<DekiScriptEnv>();
string secure = deki.GravatarSalt ?? string.Empty;
if(!secure.EqualsInvariantIgnoreCase("hidden") && !string.IsNullOrEmpty(user.Email)) {
hash = StringUtil.ComputeHashString(secure + (user.Email ?? string.Empty).Trim().ToLowerInvariant(), Encoding.UTF8);
}
PageBE homePage = UserBL.GetHomePage(user);
result.Add("id", user.ID);
result.Add("name", user.Name);
result.Add("fullname", !string.IsNullOrEmpty(user.RealName) ? user.RealName : null);
result.Add("uri", Utils.AsPublicUiUri(homePage.Title));
result.Add("api", Utils.AsPublicApiUri("users", user.ID).ToString());
result.Add("homepage", PropertyAt("$page", homePage.ID, true));
result.Add("anonymous", UserBL.IsAnonymous(user));
result.Add("admin", PermissionsBL.IsUserAllowed(user, Permissions.ADMIN));
result.Add("feed", Utils.AsPublicApiUri("users", user.ID).At("feed").ToString());
result.Add("authtoken", (!env.IsSafeMode && DekiContext.Current.User.ID == user.ID) ? DekiContext.Current.AuthToken : null);
result.Add("properties", PropertyAt("$userprops", user.ID));
result.Add("comments", PropertyAt("$usercomments", user.ID));
result.Add("timezone", DekiScriptLibrary.RenderTimeZone(DekiScriptLibrary.ParseTimeZone(user.Timezone)));
result.Add("language", DekiScriptExpression.Constant(string.IsNullOrEmpty(user.Language) ? null : user.Language));
result.Add("metrics", PropertyAt("$usermetrics", user.ID));
if(Utils.ShowPrivateUserInfo(user)) {
result.Add("email", user.Email);
}
result.Add("groups", PropertyAt("$usergroups", user.ID));
} else {
result.Add("id", 0);
result.Add("name", null);
result.Add("fullname", null);
result.Add("uri", null);
result.Add("api", null);
result.Add("homepage", null);
result.Add("anonymous", true);
result.Add("admin", false);
result.Add("feed", null);
result.Add("authtoken", null);
result.Add("properties", new Hashtable(StringComparer.OrdinalIgnoreCase));
result.Add("comments", new ArrayList());
result.Add("timezone", "GMT");
result.Add("language", DekiScriptNil.Value);
result.Add("metrics", new Hashtable(StringComparer.OrdinalIgnoreCase));
result.Add("groups", new Hashtable(StringComparer.OrdinalIgnoreCase));
}
// set the emailhash and gravatar values
if(!string.IsNullOrEmpty(hash)) {
result.Add("emailhash", hash);
result.Add("gravatar", gravatar.At(hash + ".png"));
} else {
result.Add("emailhash", string.Empty);
result.Add("gravatar", gravatar.At("no-email.png"));
}
return result;
}
示例7: GetPropertyXml
private XDoc GetPropertyXml(IList<ResourceBE> properties, XUri parentResourceUri, bool collection, string propSuffix, bool? explicitRevisionInfo, uint? contentCutoff, XDoc doc) {
bool requiresEnd = false;
if(collection) {
string rootPropertiesNode = string.IsNullOrEmpty(propSuffix) ? "properties" : "properties." + propSuffix;
if(doc == null) {
doc = new XDoc(rootPropertiesNode);
} else {
doc.Start(rootPropertiesNode);
requiresEnd = true;
}
doc.Attr("count", properties.Count);
if(parentResourceUri != null) {
//Note: this assumes that the property collection of a resource is always accessed by appending "properties" to the parent URI
doc.Attr("href", parentResourceUri.At("properties"));
}
} else {
doc = XDoc.Empty;
}
//Batch retrieve users for user.modified and user.deleted
Dictionary<uint, UserBE> usersById = new Dictionary<uint, UserBE>();
foreach(ResourceBE r in properties) {
usersById[r.UserId] = null;
}
if(!ArrayUtil.IsNullOrEmpty(properties)) {
usersById = DbUtils.CurrentSession.Users_GetByIds(usersById.Keys.ToArray()).AsHash(e => e.ID);
}
foreach(ResourceBE p in properties) {
doc = AppendPropertyXml(doc, p, parentResourceUri, propSuffix, explicitRevisionInfo, contentCutoff, usersById);
}
if(requiresEnd) {
doc.End();
}
return doc;
}
示例8: Uri
//--- Methods ---
public XUri Uri(XUri parentUri) {
return parentUri.At("properties", XUri.DoubleEncodeSegment(Name));
}
示例9: User_without_proper_page_permission_gets_forbidden_on_subscribe_attempt
public void User_without_proper_page_permission_gets_forbidden_on_subscribe_attempt() {
// set up mocks for all the support service calls
XUri deki = new XUri("http://mock/deki");
MockPlug.Register(deki, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
_log.DebugFormat("deki: {0}", u);
DreamMessage msg;
if(u.Path.StartsWith("/deki/pages")) {
msg = DreamMessage.Ok(new XDoc("users"));
} else {
msg = DreamMessage.Ok(new XDoc("user")
.Attr("id", "1")
.Elem("email", "[email protected]")
.Elem("language", "en")
.Start("permissions.user")
.Elem("operations", "READ,SUBSCRIBE,LOGIN")
.End());
}
msg.Headers.Add("X-Deki-Site", "id=wicked");
r2.Return(msg);
});
XUri subscribe = new XUri("http://mock/sub");
MockPlug.Register(subscribe, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
if(u == subscribe.At("subscribers")) {
_log.Debug("creating subscription");
DreamMessage msg = DreamMessage.Ok(new XDoc("x"));
msg.Headers.Location = subscribe.At("testsub");
r2.Return(msg);
} else {
_log.Debug("updating subscription");
r2.Return(DreamMessage.Ok());
}
});
XUri storage = new XUri("http://mock/store");
MockPlug.Register(storage, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
_log.DebugFormat("storage: {0}", u);
r2.Return(DreamMessage.Ok(new XDoc("foo")));
});
// set up service
_log.Debug("set up service");
DreamServiceInfo serviceInfo = DreamTestHelper.CreateService(
_hostInfo,
typeof(DekiChangeSubscriptionService),
"email",
new XDoc("config")
.Elem("uri.emailer", new XUri("http://mock/email"))
.Elem("uri.deki", deki)
.Elem("uri.pubsub", subscribe)
.Elem("uri.storage", storage)
);
Plug service = serviceInfo.WithInternalKey().AtLocalHost;
// post a subscription
_log.Debug("post page 10 subscription");
DreamMessage response = service
.At("pages", "10")
.With("depth", "infinity")
.WithHeader("X-Deki-Site", "id=wicked")
.PostAsync()
.Wait();
Assert.IsFalse(response.IsSuccessful);
Assert.AreEqual(DreamStatus.Forbidden, response.Status);
}
示例10: Initialize_service_with_persisted_subscriptions
public void Initialize_service_with_persisted_subscriptions() {
XUri email = new XUri("http://mock/email");
XUri deki = new XUri("http://mock/deki");
MockPlug.Register(deki, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
_log.DebugFormat("deki: {0}", u);
DreamMessage msg = DreamMessage.Ok(new XDoc("user")
.Attr("id", "1")
.Elem("email", "[email protected]")
.Start("permissions.user")
.Elem("operations", "READ,SUBSCRIBE,LOGIN")
.End());
msg.Headers.Add("X-Deki-Site", "id=wicked");
r2.Return(msg);
});
XUri subscribe = new XUri("http://mock/sub");
int subscribeCalled = 0;
MockPlug.Register(subscribe, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
_log.DebugFormat("subscribe: {0}", u);
subscribeCalled++;
DreamMessage msg = DreamMessage.Ok(new XDoc("foo"));
msg.Headers.Location = subscribe;
r2.Return(msg);
});
XUri storage = new XUri("http://mock/store");
int storageListCalled = 0;
int storageFileCalled = 0;
int storageBadCalled = 0;
MockPlug.Register(storage, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
_log.DebugFormat("storage: {0}", u);
if(v == "GET") {
if(u == storage.At("subscriptions")) {
storageListCalled++;
r2.Return(DreamMessage.Ok(new XDoc("files")
.Start("folder").Elem("name", "wicked").End()
));
return;
} else if(u == storage.At("subscriptions", "wicked")) {
storageListCalled++;
r2.Return(DreamMessage.Ok(new XDoc("files")
.Start("file").Elem("name", "user_1.xml").End()
.Start("file").Elem("name", "bar.txt").End()
));
return;
} else if(u == storage.At("subscriptions", "wicked", "user_1.xml")) {
storageFileCalled++;
r2.Return(DreamMessage.Ok(new XDoc("user")
.Attr("userid", 1)
.Elem("email", "foo")
.Start("subscription.page").Attr("id", 1).Attr("depth", 0).End()
));
return;
}
}
storageBadCalled++;
throw new DreamBadRequestException("unexpected call");
});
DreamServiceInfo serviceInfo = DreamTestHelper.CreateService(
_hostInfo,
typeof(DekiChangeSubscriptionService),
"email",
new XDoc("config")
.Elem("uri.emailer", email)
.Elem("uri.deki", deki)
.Elem("uri.pubsub", subscribe)
.Elem("uri.storage", storage)
);
Assert.AreEqual(1, subscribeCalled);
Assert.AreEqual(2, storageListCalled);
Assert.AreEqual(1, storageFileCalled);
Assert.AreEqual(0, storageBadCalled);
_log.Debug("get all subscriptions");
DreamMessage response = serviceInfo.AtLocalHost
.At("subscriptions")
.WithHeader("X-Deki-Site", "id=wicked")
.GetAsync()
.Wait();
Assert.IsTrue(response.IsSuccessful);
XDoc subscriptions = response.ToDocument();
XDoc sub = subscriptions["subscription.page"];
Assert.AreEqual(1, sub.ListLength);
Assert.AreEqual("1", sub["@id"].AsText);
Assert.AreEqual("0", sub["@depth"].AsText);
}
示例11: Request_without_valid_user_headers_results_in_not_authorized
public void Request_without_valid_user_headers_results_in_not_authorized() {
// set up mocks for all the support service calls
XUri deki = new XUri("http://mock/deki");
MockPlug.Register(deki, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
_log.DebugFormat("deki: {0}", u);
r2.Return(DreamMessage.AccessDenied("deki", "bad puppy"));
});
XUri subscribe = new XUri("http://mock/sub");
MockPlug.Register(subscribe, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
if(u == subscribe.At("subscribers")) {
_log.Debug("creating subscription");
DreamMessage msg = DreamMessage.Ok(new XDoc("x"));
msg.Headers.Location = subscribe.At("testsub");
r2.Return(msg);
} else {
_log.Debug("updating subscription");
r2.Return(DreamMessage.Ok());
}
});
XUri storage = new XUri("http://mock/store");
MockPlug.Register(storage, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
_log.DebugFormat("storage: {0}", u);
r2.Return(DreamMessage.Ok(new XDoc("foo")));
});
// set up service
_log.Debug("set up service");
DreamServiceInfo serviceInfo = DreamTestHelper.CreateService(
_hostInfo,
typeof(DekiChangeSubscriptionService),
"email",
new XDoc("config")
.Elem("uri.emailer", new XUri("http://mock/email"))
.Elem("uri.deki", deki)
.Elem("uri.pubsub", subscribe)
.Elem("uri.storage", storage)
);
Plug service = serviceInfo.WithInternalKey().AtLocalHost;
// post a subscription
_log.Debug("post page 10 subscription");
DreamMessage response = service
.At("pages", "10")
.With("depth", "infinity")
.WithHeader("X-Deki-Site", "id=wicked")
.PostAsync()
.Wait();
Assert.IsFalse(response.IsSuccessful);
Assert.AreEqual(DreamStatus.Unauthorized, response.Status);
}
示例12: Uses_deki_to_prune_recipients
public void Uses_deki_to_prune_recipients() {
XUri mockDeki = new XUri("http://mock/deki");
int dekiCalled = 0;
int dekipage42authCalled = 0;
bool dekiArgsGood = false;
int dekipage43authCalled = 0;
MockPlug.Register(mockDeki, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
_log.DebugFormat("mockDeki called at: {0}", u);
dekiCalled++;
dekiArgsGood = false;
List<int> users = new List<int>();
foreach(XDoc user in r.ToDocument()["user/@id"]) {
users.Add(user.AsInt.Value);
}
if(users.Count == 4 && users.Contains(1) && users.Contains(2) && users.Contains(3) && users.Contains(4)) {
dekiArgsGood = true;
}
DreamMessage msg = DreamMessage.Ok();
if(u.WithoutQuery() == mockDeki.At("pages", "42", "allowed")) {
dekipage42authCalled++;
msg = DreamMessage.Ok(new XDoc("users")
.Start("user").Attr("id", 1).End()
.Start("user").Attr("id", 2).End());
} else if(u.WithoutQuery() == mockDeki.At("pages", "43", "allowed")) {
dekipage43authCalled++;
msg = DreamMessage.Ok(new XDoc("users")
.Start("user").Attr("id", 3).End()
.Start("user").Attr("id", 4).End());
}
r2.Return(msg);
});
XUri mockRecipient = new XUri("http://mock/r1");
int mockRecipientCalled = 0;
XDoc received = null;
List<string> recipients = new List<string>();
AutoResetEvent are = new AutoResetEvent(false);
MockPlug.Register(mockRecipient, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
_log.DebugFormat("mockRecipient called at: {0}", u);
mockRecipientCalled++;
received = r.ToDocument();
recipients.Clear();
recipients.AddRange(r.Headers.DreamEventRecipients);
are.Set();
r2.Return(DreamMessage.Ok());
});
DreamServiceInfo serviceInfo = DreamTestHelper.CreateService(
_hostInfo,
"sid://mindtouch.com/dream/2008/10/pubsub",
"whitelist",
new XDoc("config")
.Elem("uri.deki", mockDeki)
.Start("components")
.Attr("context", "service")
.Start("component")
.Attr("implementation", typeof(DekiDispatcher).AssemblyQualifiedName)
.Attr("type", typeof(IPubSubDispatcher).AssemblyQualifiedName)
.End()
.End()
);
XDoc sub = new XDoc("subscription-set")
.Elem("uri.owner", mockRecipient)
.Start("subscription")
.Attr("id", "1")
.Elem("uri.resource", "http://mock/resource/x")
.Elem("channel", "channel:///foo/*")
.Elem("uri.proxy", mockRecipient)
.Start("recipient").Attr("userid", "1").Elem("uri", "http://recipient/a").End()
.Start("recipient").Attr("userid", "2").Elem("uri", "http://recipient/b").End()
.Start("recipient").Attr("userid", "3").Elem("uri", "http://recipient/c").End()
.Start("recipient").Attr("userid", "4").Elem("uri", "http://recipient/d").End()
.End()
.Start("subscription")
.Attr("id", "2")
.Elem("uri.resource", "http://mock/resource/y")
.Elem("channel", "channel:///foo/*")
.Elem("uri.proxy", mockRecipient)
.Start("recipient").Attr("userid", "1").Elem("uri", "http://recipient/a").End()
.Start("recipient").Attr("userid", "2").Elem("uri", "http://recipient/b").End()
.Start("recipient").Attr("userid", "3").Elem("uri", "http://recipient/c").End()
.Start("recipient").Attr("userid", "4").Elem("uri", "http://recipient/d").End()
.End();
DreamMessage result = serviceInfo.WithInternalKey().AtLocalHost.At("subscribers").PostAsync(sub).Wait();
Assert.IsTrue(result.IsSuccessful);
XDoc ev = new XDoc("event").Elem("pageid", 42);
result = serviceInfo.WithInternalKey()
.AtLocalHost
.At("publish")
.WithHeader(DreamHeaders.DREAM_EVENT_CHANNEL, "channel:///foo/bar")
.WithHeader(DreamHeaders.DREAM_EVENT_ORIGIN, mockDeki.ToString())
.WithHeader(DreamHeaders.DREAM_EVENT_RESOURCE, "http://mock/resource/x")
.PostAsync(ev).Wait();
Assert.IsTrue(result.IsSuccessful);
Assert.IsTrue(are.WaitOne(500, true));
Assert.AreEqual(1, dekiCalled);
Assert.AreEqual(1, dekipage42authCalled);
Assert.IsTrue(dekiArgsGood);
Assert.AreEqual(ev, received);
Assert.AreEqual(2, recipients.Count);
Assert.Contains("http://recipient/a", recipients);
//.........这里部分代码省略.........
示例13: Exporter_can_retrieve_items_by_dataid
public void Exporter_can_retrieve_items_by_dataid() {
// Arrange
XUri dekiApiUri = new XUri("http://mock/@api/deki");
XDoc exportDocument = new XDoc("export");
XUri item1Uri = dekiApiUri.At("foo", "bar", "abc");
XDoc item1Doc = new XDoc("item1");
XUri item2Uri = dekiApiUri.At("foo", "bar", "def");
XDoc item2Doc = new XDoc("item2");
XDoc exportResponse = new XDoc("export")
.Start("requests")
.Start("request")
.Attr("method", "GET")
.Attr("dataid", "abc")
.Attr("href", item1Uri)
.Start("header").Attr("name", "h_1").Attr("value", "v_1").End()
.Start("header").Attr("name", "h_2").Attr("value", "v_2").End()
.End()
.Start("request")
.Attr("method", "GET")
.Attr("dataid", "def")
.Attr("href", item2Uri)
.End()
.End()
.Start("manifest")
.Start("foo").Attr("dataid", "abc").End()
.Start("bar").Attr("dataid", "def").End()
.End();
AutoMockPlug mock = MockPlug.Register(dekiApiUri);
mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "export").With("relto", "0")).RequestDocument(exportDocument).Response(DreamMessage.Ok(exportResponse));
mock.Expect().Verb("GET").Uri(item1Uri).RequestHeader("h_1", "v_1").RequestHeader("h_2", "v_2").Response(DreamMessage.Ok(item1Doc));
mock.Expect().Verb("GET").Uri(item2Uri).Response(DreamMessage.Ok(item2Doc));
// Act
Exporter exporter = Exporter.CreateAsync(Plug.New(dekiApiUri), exportDocument, 0, new Result<Exporter>()).Wait();
ExportItem item1 = exporter.GetItemAsync("abc", new Result<ExportItem>()).Wait();
ExportItem item2 = exporter.GetItemAsync("def", new Result<ExportItem>()).Wait();
//Assert
Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)));
Assert.AreEqual(exportResponse["manifest"], exporter.Manifest);
Assert.AreEqual(new string[] { "abc", "def" }, exporter.DataIds);
Assert.AreEqual(exporter.Manifest["*[@dataid='abc']"], item1.ItemManifest);
Assert.AreEqual(exporter.Manifest["*[@dataid='def']"], item2.ItemManifest);
Assert.AreEqual(item1Doc, XDocFactory.From(new StreamReader(item1.Data), MimeType.TEXT_XML));
Assert.AreEqual(item2Doc, XDocFactory.From(new StreamReader(item2.Data), MimeType.TEXT_XML));
}
示例14: New
//--- Class Methods ---
internal static AMedia New(XUri uri, XDoc config) {
// check if the uri is a viddler video
if(uri.Scheme.EqualsInvariantIgnoreCase("kaltura")) {
if(uri.Segments.Length >= 1) {
string entryID = uri.Segments[0];
string partnerID = config["kaltura/partner-id"].AsText;
// check if extension is configured for kaltura integration
if(!string.IsNullOrEmpty(partnerID)) {
bool remix = !(uri.GetParam("edit", null) ?? uri.GetParam("remix", "no")).EqualsInvariantIgnoreCase("no");
// verify that user has permission to remix content on current page
if(remix) {
Plug dekiApi = GetDekiApi(config);
if(dekiApi != null) {
try {
DekiScriptMap env = DreamContext.Current.GetState<DekiScriptMap>();
string pageid = env.GetAt("page.id").AsString();
string userid = env.GetAt("user.id").AsString();
XDoc users = dekiApi.At("pages", pageid, "allowed").With("permissions", "UPDATE").Post(new XDoc("users").Start("user").Attr("id", userid).End()).ToDocument();
remix = !users[string.Format(".//user[@id='{0}']", userid)].IsEmpty;
} catch(Exception e) {
_log.Error("unable to verify user permission on page", e);
}
}
}
// check if SEO links are explicitly disabled
bool seo = !(config["kaltura/seo-links"].AsText ?? "enabled").EqualsInvariantIgnoreCase("disabled");
// determin which UI configuration to use based on user's permissions and embed settings for video
string uiConfID = remix ? config["kaltura/uiconf/player-mix"].AsText : config["kaltura/uiconf/player-nomix"].AsText;
if(!string.IsNullOrEmpty(uiConfID)) {
uri = config["kaltura/server-uri"].AsUri ?? new XUri("http://www.kaltura.com");
uri = uri.At("index.php", "kwidget", "wid", "_" + partnerID, "uiconf_id", uiConfID, "entry_id", entryID);
return new KalturaVideo(uri, remix, seo);
}
}
}
}
return null;
}
示例15: Importer_Items_are_populated_with_request_and_manifest_docs
public void Importer_Items_are_populated_with_request_and_manifest_docs() {
// Arrange
var dekiApiUri = new XUri("http://mock/@api/deki");
var importManifest = new XDoc("manifest")
.Start("item").Attr("dataid", "abc").Elem("foo", "bar").End()
.Start("item").Attr("dataid", "def").Elem("baz", "flip").End();
var item1Uri = dekiApiUri.At("foo", "bar", "abc");
var item2Uri = dekiApiUri.At("foo", "bar", "def");
var importResponse = new XDoc("requests")
.Start("request")
.Attr("method", "POST")
.Attr("dataid", "abc")
.Attr("href", item1Uri)
.Start("header").Attr("name", "h_1").Attr("value", "v_1").End()
.Start("header").Attr("name", "h_2").Attr("value", "v_2").End()
.End()
.Start("request")
.Attr("method", "PUT")
.Attr("dataid", "def")
.Attr("href", item2Uri)
.End();
var mock = MockPlug.Register(dekiApiUri);
mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "import").With("relto", "0")).RequestDocument(importManifest).Response(DreamMessage.Ok(importResponse));
// Act
var importer = Importer.CreateAsync(Plug.New(dekiApiUri), importManifest, 0, new Result<Importer>()).Wait();
//Assert
Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)));
var item1 = importer.Items.Where(x => x.DataId == "abc").FirstOrDefault();
Assert.IsNotNull(item1);
Assert.IsNotNull(item1.Manifest);
Assert.AreEqual(importManifest[".//*[@dataid='abc']"], item1.Manifest);
Assert.IsNotNull(item1.Request);
Assert.AreEqual(importResponse[".//*[@dataid='abc']"], item1.Request);
var item2 = importer.Items.Where(x => x.DataId == "def").FirstOrDefault();
Assert.IsNotNull(item2);
Assert.IsNotNull(item2.Manifest);
Assert.AreEqual(importManifest[".//*[@dataid='def']"], item2.Manifest);
Assert.IsNotNull(item1.Request);
Assert.AreEqual(importResponse[".//*[@dataid='def']"], item2.Request);
}