当前位置: 首页>>代码示例>>C#>>正文


C# Action.ShouldThrow方法代码示例

本文整理汇总了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");
        }
开发者ID:codito,项目名称:oshell,代码行数:8,代码来源:KeyMapTests.cs

示例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);
            }
        }
开发者ID:iambmelt,项目名称:Vipr,代码行数:25,代码来源:Given_A_Query_For_EntitySet.cs

示例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");
            }
        }
开发者ID:iambmelt,项目名称:Vipr,代码行数:26,代码来源:Given_A_ReadOnlyQueryableSet.cs

示例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>();
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:7,代码来源:RegistryInfoTest.cs

示例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>();
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:7,代码来源:SteamInfoTest.cs

示例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>();
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:7,代码来源:SteamInfoTest.cs

示例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);
            }
        }
开发者ID:iambmelt,项目名称:Vipr,代码行数:29,代码来源:Given_A_Query_For_Single_EntityType.cs

示例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>();
 }
开发者ID:moradifx,项目名称:SharpMTProto,代码行数:7,代码来源:MessageCodecFacts.cs

示例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();
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:7,代码来源:RegistryInfoTest.cs

示例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>();
 }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:7,代码来源:InvariantTest.cs

示例11: CannotCreateInvalid

        public void CannotCreateInvalid() {
            var act = new Action(() => new GamespyServersQuery(""));
            var act2 = new Action(() => new GamespyServersQuery(null));

            act.ShouldThrow<ArgumentNullException>();
            act2.ShouldThrow<ArgumentNullException>();
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:7,代码来源:ServerQueryInfoTest.cs

示例12: ShouldPass

        protected override void ShouldPass()
        {
            var action = new Action(() => { throw new NotImplementedException(); });

            var ex = action.ShouldThrow<NotImplementedException>();
            ex.ShouldBeOfType<NotImplementedException>();
            ex.ShouldNotBe(null);
        }
开发者ID:JulienFiaffe,项目名称:shouldly,代码行数:8,代码来源:ActionDelegateScenario.cs

示例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);
        }
开发者ID:shouldly,项目名称:shouldly,代码行数:8,代码来源:ActionDelegateScenario.cs

示例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.");
        }
开发者ID:aaubry,项目名称:YamlDotNet,代码行数:9,代码来源:YamlStreamTests.cs

示例15: C_TestNegativeLoggingLevel

        public void C_TestNegativeLoggingLevel()
        {
            var action = new Action(() =>
            {
                var logger = new Logger("lkdldk", -1, new List<ILoggingEndpoint>());
            });

            action.ShouldThrow<ArgumentOutOfRangeException>();
        }
开发者ID:UCL-Genomics,项目名称:genomics-common,代码行数:9,代码来源:LoggerTests.cs


注:本文中的System.Action.ShouldThrow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。