本文整理汇总了C#中System.Action.ShouldThrow方法的典型用法代码示例。如果您正苦于以下问题:C# Action.ShouldThrow方法的具体用法?C# Action.ShouldThrow怎么用?C# Action.ShouldThrow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Action
的用法示例。
在下文中一共展示了Action.ShouldThrow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KeyMapThrowsForAnEmptyName
public void KeyMapThrowsForAnEmptyName()
{
var action = new Action(() => new KeyMap(null));
action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("name");
action = () => new KeyMap(string.Empty);
action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("name");
}
示例2: using
public void When_Querying_For_NonExistent_EntitySet_Then_Throw_DataServiceQueryException_With_NotFound_Status_Code()
{
using (var scenario =
new ODataScenario()
.WithProducts(Any.Products())
.Start())
{
var context = GetDataServiceContext(scenario.GetBaseAddress());
var action = new Action(() =>
{
var dQuery = context.CreateQuery<Product>("/" + "RandomEntitySet");
var products = context.ExecuteAsync<Product, IProduct>(dQuery).Result;
});
//check for AggregateException with DataServiceQueryException as InnerException.
//Also retrieve the DataServiceQueryException InnerException.
DataServiceQueryException innerException = action.ShouldThrow<AggregateException>()
.WithInnerException<DataServiceQueryException>()
.And.InnerException as DataServiceQueryException;
//Check for 'Not Found' code.
innerException.Response.StatusCode.Should().Be(404);
}
}
示例3: When_Query_Matches_Multiple_EntityTypes_Then_Using_ExecuteSingleAsync_Must_Fail
public void When_Query_Matches_Multiple_EntityTypes_Then_Using_ExecuteSingleAsync_Must_Fail()
{
using (var scenario =
new ODataScenario()
.WithProducts(Any.Products(8))
.Start())
{
var context = GetDataServiceContext(scenario.GetBaseAddress());
var dQuery = context.CreateQuery<Product>("/" + "Products");
IReadOnlyQueryableSet<IProduct> readOnlySet = new ReadOnlyQueryableSet<IProduct>(dQuery, context);
//Query using linq
var linqQuery = from prod in readOnlySet
orderby prod.Category
select prod;
var action = new Action(() =>
{
var product = linqQuery.ExecuteSingleAsync().Result;
});
action.ShouldThrow<AggregateException>().
WithInnerException<InvalidOperationException>().
WithInnerMessage("Sequence contains more than one element");
}
}
示例4: CannotCreateWithInvalidAppId
public void CannotCreateWithInvalidAppId() {
var act = new Action(() => new RegistryInfo(null, "some key"));
var act2 = new Action(() => new RegistryInfo("", "some key"));
act.ShouldThrow<ArgumentNullException>();
act2.ShouldThrow<ArgumentNullException>();
}
示例5: CannotCreateWithInvalidAppId
public void CannotCreateWithInvalidAppId() {
var act = new Action(() => new SteamInfo(-1, "some folder"));
var act2 = new Action(() => new SteamInfo(-500, "some folder"));
act.ShouldThrow<ArgumentOutOfRangeException>();
act2.ShouldThrow<ArgumentOutOfRangeException>();
}
示例6: CannotCreateWithInvalidFolder
public void CannotCreateWithInvalidFolder() {
var act = new Action(() => new SteamInfo(0, null));
var act2 = new Action(() => new SteamInfo(0, ""));
act.ShouldThrow<ArgumentNullException>();
act2.ShouldThrow<ArgumentNullException>();
}
示例7: When_Querying_For_Non_Existent_EntityType_Then_Throw_Exception
public void When_Querying_For_Non_Existent_EntityType_Then_Throw_Exception()
{
using (var scenario =
new ODataScenario()
.WithProducts(Any.Products())
.Start())
{
var context = GetDataServiceContext(scenario.GetBaseAddress());
var action = new Action(() =>
{
//query for a missing product based on the 'Id'
var dQuery = context.CreateQuery<Product>("/" + "Products(7)");
// this should ideally return null or thrown an exception that reflects 404.
Product missingProd = context.ExecuteSingleAsync<Product, IProduct>(dQuery).Result as Product;
//Product missingProd = dQuery.Where(p => p.Id == 7).First();
});
//check for AggregateException with DataServiceQueryException as InnerException.
//Also retrieve the DataServiceQueryException InnerException.
DataServiceQueryException innerException = action.ShouldThrow<AggregateException>()
.WithInnerException<DataServiceQueryException>()
.And.InnerException as DataServiceQueryException;
//Check for 'Not Found' code.
innerException.Response.StatusCode.Should().Be(404);
}
}
示例8: Should_throw_on_unwrap_plain_message_with_wrong_body_length
public void Should_throw_on_unwrap_plain_message_with_wrong_body_length()
{
IMessageCodec messageCodec = GetMessageCodec();
byte[] messageBytes = ("0000000000000000" + "0807060504030201" + "11000000" + "9EB6EFEB" + "09" + "000102030405060708" + "0000").HexToBytes();
var action = new Action(() => messageCodec.DecodePlainMessage(messageBytes));
action.ShouldThrow<InvalidMessageException>();
}
示例9: CannotCreateWithInvalidFolder
public void CannotCreateWithInvalidFolder() {
var act = new Action(() => new RegistryInfo("some path", null));
var act2 = new Action(() => new RegistryInfo("some path", ""));
act.ShouldThrow<ArgumentNullException>();
act2.ShouldNotThrow();
}
示例10: Test
public void Test() {
var c = new ModLocalContent("@testmod", Guid.Empty, "1.0");
var act2 = new Action(() => c.PackageName = "");
act2.ShouldThrow<Exception>();
//var act = new Action(() => c.Name = "");
//act.ShouldThrow<Exception>();
}
示例11: CannotCreateInvalid
public void CannotCreateInvalid() {
var act = new Action(() => new GamespyServersQuery(""));
var act2 = new Action(() => new GamespyServersQuery(null));
act.ShouldThrow<ArgumentNullException>();
act2.ShouldThrow<ArgumentNullException>();
}
示例12: ShouldPass
protected override void ShouldPass()
{
var action = new Action(() => { throw new NotImplementedException(); });
var ex = action.ShouldThrow<NotImplementedException>();
ex.ShouldBeOfType<NotImplementedException>();
ex.ShouldNotBe(null);
}
示例13: ShouldPass_ExceptionTypePassedIn
public void ShouldPass_ExceptionTypePassedIn()
{
var action = new Action(() => { throw new NotImplementedException(); });
var ex = action.ShouldThrow(typeof(NotImplementedException));
ex.ShouldBeOfType<NotImplementedException>();
ex.ShouldNotBe(null);
}
示例14: AccessingAllNodesOnInfinitelyRecursiveDocumentThrows
public void AccessingAllNodesOnInfinitelyRecursiveDocumentThrows()
{
var stream = new YamlStream();
stream.Load(Yaml.ParserForText("&a [*a]"));
var accessAllNodes = new Action(() => stream.Documents.Single().AllNodes.ToList());
accessAllNodes.ShouldThrow<MaximumRecursionLevelReachedException>("because the document is infinitely recursive.");
}
示例15: C_TestNegativeLoggingLevel
public void C_TestNegativeLoggingLevel()
{
var action = new Action(() =>
{
var logger = new Logger("lkdldk", -1, new List<ILoggingEndpoint>());
});
action.ShouldThrow<ArgumentOutOfRangeException>();
}