本文整理汇总了C#中XDoc.AsResult方法的典型用法代码示例。如果您正苦于以下问题:C# XDoc.AsResult方法的具体用法?C# XDoc.AsResult怎么用?C# XDoc.AsResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XDoc
的用法示例。
在下文中一共展示了XDoc.AsResult方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: ImportManager_only_tries_to_read_from_package_when_there_is_a_dataid
public void ImportManager_only_tries_to_read_from_package_when_there_is_a_dataid() {
var dekiApiUri = new XUri("http://mock/@api/deki");
var importManifest = new XDoc("manifest");
var item1Uri = dekiApiUri.At("foo", "bar", "abc");
var importResponse = new XDoc("requests")
.Start("request")
.Attr("method", "GET")
.Attr("href", item1Uri)
.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("GET").Uri(item1Uri);
var mockPackageReader = new Mock<IPackageReader>();
mockPackageReader.Setup(x => x.ReadManifest(It.IsAny<Result<XDoc>>())).Returns(() => importManifest.AsResult());
// 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.Verify(x => x.ReadManifest(It.IsAny<Result<XDoc>>()), Times.Once());
mockPackageReader.Verify(x => x.ReadData(It.IsAny<ImportItem>(), It.IsAny<Result<ImportItem>>()), Times.Never());
}