Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        public void CannotCreateWithInvalidFolder() {
            var act = new Action(() => new SteamInfo(0, null));
            var act2 = new Action(() => new SteamInfo(0, ""));

            act.ShouldThrow<ArgumentNullException>();
            act2.ShouldThrow<ArgumentNullException>();
        }
Ejemplo n.º 4
0
        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>();
        }
Ejemplo n.º 5
0
 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>();
 }
        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);
            }
        }
        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>();
        }
Ejemplo n.º 8
0
 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>();
 }
        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();
        }
        public void ShouldTrackSingleCurrentSchoolYear()
        {
            GetNewSchoolYear(2000);
            GetNewSchoolYear(1999);
            GetNewSchoolYear(2001);

            SetSchoolYear(1999);
            GetSchoolYears().ShouldSatisfy(
                x => x.ShouldBeSchoolYear(1999, isCurrent: true),
                x => x.ShouldBeSchoolYear(2000),
                x => x.ShouldBeSchoolYear(2001));

            SetSchoolYear(2000);
            GetSchoolYears().ShouldSatisfy(
                x => x.ShouldBeSchoolYear(1999),
                x => x.ShouldBeSchoolYear(2000, isCurrent: true),
                x => x.ShouldBeSchoolYear(2001));

            SetSchoolYear(2001);
            GetSchoolYears().ShouldSatisfy(
                x => x.ShouldBeSchoolYear(1999),
                x => x.ShouldBeSchoolYear(2000),
                x => x.ShouldBeSchoolYear(2001, isCurrent: true));

            Action invalidYear = () => SetSchoolYear(-1234);

            invalidYear.ShouldThrow <Exception>().Message.ShouldBe("School year -1234 does not exist.");
        }
Ejemplo n.º 11
0
        public void CannotCreateInvalid() {
            var act = new Action(() => new GamespyServersQuery(""));
            var act2 = new Action(() => new GamespyServersQuery(null));

            act.ShouldThrow<ArgumentNullException>();
            act2.ShouldThrow<ArgumentNullException>();
        }
Ejemplo n.º 12
0
        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");
            }
        }
Ejemplo n.º 13
0
        public void ShouldPass_ExceptionTypePassedIn()
        {
            var action = new Action(() => { throw new NotImplementedException(); });

            var ex = action.ShouldThrow(typeof(NotImplementedException));
            ex.ShouldBeOfType<NotImplementedException>();
            ex.ShouldNotBe(null);
        }
Ejemplo n.º 14
0
        protected override void ShouldPass()
        {
            var action = new Action(() => { throw new NotImplementedException(); });

            var ex = action.ShouldThrow<NotImplementedException>();
            ex.ShouldBeOfType<NotImplementedException>();
            ex.ShouldNotBe(null);
        }
Ejemplo n.º 15
0
        public void C_TestNegativeLoggingLevel()
        {
            var action = new Action(() =>
            {
                var logger = new Logger("lkdldk", -1, new List<ILoggingEndpoint>());
            });

            action.ShouldThrow<ArgumentOutOfRangeException>();
        }
Ejemplo n.º 16
0
        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.");
        }
Ejemplo n.º 17
0
        public void TestGuardClauses()
        {
            var action = new Action(() =>
            {
                var test = new FileReader(null);
            });

            action.ShouldThrow<ArgumentNullException>();
        }
        public void TestGuardClauses()
        {
            var action = new Action(() =>
            {
                var test = new DelimitedFileProcessor<DummyFileClass>(null, Encoding.ASCII);
            });

            action.ShouldThrow<ArgumentNullException>();
        }
        public void C_TestNegativeLoggingLevel()
        {
            var action = new Action(() =>
            {
                var loggerFactory = new LoggingFactory(-1);
            });

            action.ShouldThrow<ArgumentOutOfRangeException>();
        }
Ejemplo n.º 20
0
        public void ActionWithAbility_WhenAbilityIsNotRegistered_ShouldThrow(System.Action <Actor, IFixture> action)
        {
            //arrange
            var fixture = new Fixture().Customize(new ActorCustomization()).Customize(new AutoConfiguredMoqCustomization());
            var sut     = fixture.Create <Actor>();

            System.Action testedAction = () => action(sut, fixture);
            //act and assert
            testedAction.ShouldThrow <InvalidOperationException>().Where(ex => ex.Message.Contains(typeof(AbilityTest).Name));
        }
Ejemplo n.º 21
0
        [U] public void RespectsMaxDepth()
        {
            var expectedDateString = "12-06-06 12:32:01";
            var jsonResponse       = $@"{{ ""_id"": ""1"", ""_source"": {{ ""dateString"": ""{expectedDateString}"" }}}}";
            var client             = this.CreateClient(jsonResponse, (jsonSettings, nestSettings) => jsonSettings.MaxDepth = 1);

            System.Action act = () => client.Get <HasDateString>(1);
            act.ShouldThrow <UnexpectedElasticsearchClientException>()
            .WithMessage("The reader's MaxDepth of 1 has been exceeded. Path '_source', line 1, position 26.");
        }
        public void Draw_ShouldThrowException_IfDeckIsEmpty()
        {
            var deck = new Deck<StandartCard>(OpositeOrderShufflerMock().Object, new[] { new StandartCard(Suit.Clubs, Rank.Ace) });

            deck.Draw();

            var act = new Action(() => deck.Draw());

            act.ShouldThrow<InvalidOperationException>();
        }
Ejemplo n.º 23
0
        public void CreatingAResultWithGuidEmptyShouldThrow()
        {
            var action = new Action(() => { var result = new Result(Guid.Empty, Guid.NewGuid()); });
            action.ShouldThrow<ArgumentException>();

            action = new Action(() => { var result = new Result(Guid.NewGuid(), Guid.Empty); });
            action.ShouldThrow<ArgumentException>();

            action = new Action(() => { var result = new Result(Guid.Empty, Guid.Empty); });
            action.ShouldThrow<ArgumentException>();
        }
Ejemplo n.º 24
0
        //TODO figure out a way to trigger this again
        //[U]
        public void DispatchIndicatesMissingRouteValues()
        {
            var settings = new ConnectionSettings(new Uri("http://doesntexist:9200"));
            var client   = new ElasticClient(settings);

            System.Action dispatch = () => client.Index(new Project(), p => p.Index(null));
            var           ce       = dispatch.ShouldThrow <ArgumentException>();

            ce.Should().NotBeNull();
            ce.Which.Message.Should().Contain("index=<NULL>");
        }
Ejemplo n.º 25
0
        public void CreateUserShouldThrowOnMissingParamaters()
        {
            var act = new Action(() => { var user = new User(null, 0); });
            act.ShouldThrow<ArgumentNullException>();

            act = new Action(() => { var user = new User("", 0); });
            act.ShouldThrow<ArgumentException>();

            act = new Action(() => { var user = new User("Jörgen Lidholm", -1); });
            act.ShouldThrow<ArgumentException>();
        }
Ejemplo n.º 26
0
        public async Task DelKMapCommandHandlerExecuteShouldDeleteAKeyMapWithGivenName()
        {
            var delkmapHandler = new DelKMapCommandHandler(this.keyMapService);
            var newkmapHandler = new NewKMapCommandHandler(this.keyMapService);
            (await newkmapHandler.Execute(new NewKMapCommand { Args = "dummyKeyMap" })).Should().BeTrue();

            var result = await delkmapHandler.Execute(new DelKMapCommand { Args = "dummyKeyMap" });
            result.Should().BeTrue();

            var getKeyMap = new Action(() => this.keyMapService.GetKeyMapByName("dummyKeyMap"));
            getKeyMap.ShouldThrow<KeyNotFoundException>();
        }
        public void Name_AccessedWhenModelNotPresent_ThrowsMissingModelException()
        {
            //	Arrange
            var repository = Substitute.For<INewspaperAdRepository>();
            var vm = new AdvertisementItemViewModel(repository);
            vm.Model.Should().BeNull("Because vm.Model not set during object instantiation.");

            //	Act
            var action = new Action(() => { var name = vm.Name; });

            //	Assert
            action.ShouldThrow<MissingModelException>("Cannot access any properties if Model not present.");
            var ex = Assert.Throws<MissingModelException>(() => vm.Name);
        }
        public void When_action_does_not_throw_exception_but_one_was_expected_it_should_throw_with_clear_description()
        {
            try
            {
                var act = new Action(() => { });

                act.ShouldThrow<Exception>();

                Assert.Fail("ShouldThrow() dit not throw");
            }
            catch (AssertFailedException ex)
            {
                ex.Message.Should().Be(
                    "Expected System.Exception, but no exception was thrown.");
            }
        }
            public void Scenario(Action action)
            {
                var subject = default(Subject);

                "Given a subject"
                    .f(() => subject = new Subject());

                "And the subject is updated"
                    .f(() => subject.Update());

                "And the subject is destroyed"
                    .f(() => subject.Destroy());

                "When the subject is updated again"
                    .f(() => action = () => subject.Update());

                "Then that action should throw an exception"
                    .f(() => action.ShouldThrow<dddlib.BusinessException>());
            }
Ejemplo n.º 30
0
        public void GenerateImages_IfAnErrorOccured_ThrowsException()
        {
            // Arrange
            ShimDirectory.ExistsString          = (directoryPath) => { return(true); };
            ShimDirectory.CreateDirectoryString = (directoryPath) => { return(null); };

            ShimPDFDraw.AllInstances.ExportPageStringStringObj = (_, __, ___, ____, _____) =>
            {
                throw new Exception();
            };

            var generateImagesAction = default(ActionDelegate);

            using (var pdfDoc = new PDFDoc())
            {
                pdfDoc.PagePushBack(pdfDoc.PageCreate());

                // Act
                generateImagesAction = new ActionDelegate(() => { _testEntityPrivate.Invoke(GenerateImagesMethodName, pdfDoc); });
            }

            // Assert
            generateImagesAction.ShouldThrow <Exception>();
        }
 public void CreatingWithNullServicesShouldThrow() {
     var act = new Action(() => new ListGamesQueryHandler(null, A.Fake<IGameMapperConfig>()));
     var act2 = new Action(() => new ListGamesQueryHandler(A.Fake<IGameContext>(), null));
     act.ShouldThrow<ArgumentNullException>();
     act2.ShouldThrow<ArgumentNullException>();
 }
        public void When_action_throws_expected_exception_it_should_not_do_anything()
        {
            var act = new Action(() => { throw new InvalidOperationException("Some exception"); });

            act.ShouldThrow<InvalidOperationException>();
        }
Ejemplo n.º 33
0
		public void AsValidEmail_InvalidEmail_Throws ()
		{
			// arrange
			var email = "aaa";


			// act
			var action = new Action (() => email.AsValidEmail ("email"));


			// assert
			action.ShouldThrow<FormatException> ();
		}
Ejemplo n.º 34
0
		public void AsValidEntityUrl_InvalidUrl_Throws ()
		{
			// arrange
			var url = "+aaa";


			// act
			var action = new Action (() => url.AsValidEntityUrl ("url"));


			// assert
			action.ShouldThrow<FormatException> ();
		}
Ejemplo n.º 35
0
 private void AssertThrowsObjectDisposedException(Action action)
 {
     vertexArray.Dispose();
     action.ShouldThrow<ObjectDisposedException>()
           .ObjectName.ShouldBe(vertexArray.GetType().FullName);
 }
Ejemplo n.º 36
0
        public void ShouldNotAllowNullSearchModel()
        {
            Action act = () => this.CreateTestee(null);

            act.ShouldThrow <ArgumentNullException>();
        }