本文整理汇总了C#中DbSet.PostAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DbSet.PostAsync方法的具体用法?C# DbSet.PostAsync怎么用?C# DbSet.PostAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbSet
的用法示例。
在下文中一共展示了DbSet.PostAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DbSetPostAsyncResourceAttributeNull
public async Task DbSetPostAsyncResourceAttributeNull()
{
//Arrange
var mockRestClient = new Mock<IRestClient>();
var dbSet = new DbSet<MockDbsetContact>(mockRestClient.Object);
//Act
await dbSet.PostAsync(new MockDbsetContact());
//Assert - throws
}
示例2: DbSetPostAsyncTest
public async Task DbSetPostAsyncTest()
{
//Arrange
var mockRestResponse = new Mock<IRestResponse>();
mockRestResponse.SetupGet(o => o.ResponseStatus).Returns(ResponseStatus.Completed);
mockRestResponse.SetupGet(o => o.StatusCode).Returns(HttpStatusCode.OK);
mockRestResponse.SetupGet(o => o.Content).Returns(@"{
""contactId"": ""48620"",
""id"": ""10002"",
""fieldValues"": [
{
""id"": ""824"",
""value"": ""transxId12321321321321""
}
],
""name"": ""Bob Tester"",
""uri"": ""/data/customObject""
}
");
var mockRestClient = new Mock<IRestClient>();
mockRestClient.Setup(o => o.ExecuteTaskAsync(It.IsAny<IRestRequest>())).ReturnsAsync(mockRestResponse.Object);
var dbSet = new DbSet<MockDbsetWithDataContact>(mockRestClient.Object);
var mockContact = new MockDbsetWithDataContact
{
Name = "Bob Tester",
ContactId = 48620,
CustomField = "Custuom Rims",
Uri = "/contact/id"
};
//Act
var contact = await dbSet.PostAsync(mockContact);
//Assert
Assert.AreEqual(48620, contact.ContactId);
}