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"); }
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); } }
public void CannotCreateWithInvalidFolder() { var act = new Action(() => new SteamInfo(0, null)); var act2 = new Action(() => new SteamInfo(0, "")); act.ShouldThrow<ArgumentNullException>(); act2.ShouldThrow<ArgumentNullException>(); }
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>(); }
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>(); }
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."); }
public void CannotCreateInvalid() { var act = new Action(() => new GamespyServersQuery("")); var act2 = new Action(() => new GamespyServersQuery(null)); act.ShouldThrow<ArgumentNullException>(); act2.ShouldThrow<ArgumentNullException>(); }
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"); } }
public void ShouldPass_ExceptionTypePassedIn() { var action = new Action(() => { throw new NotImplementedException(); }); var ex = action.ShouldThrow(typeof(NotImplementedException)); ex.ShouldBeOfType<NotImplementedException>(); ex.ShouldNotBe(null); }
protected override void ShouldPass() { var action = new Action(() => { throw new NotImplementedException(); }); var ex = action.ShouldThrow<NotImplementedException>(); ex.ShouldBeOfType<NotImplementedException>(); ex.ShouldNotBe(null); }
public void C_TestNegativeLoggingLevel() { var action = new Action(() => { var logger = new Logger("lkdldk", -1, new List<ILoggingEndpoint>()); }); action.ShouldThrow<ArgumentOutOfRangeException>(); }
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."); }
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>(); }
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)); }
[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>(); }
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>(); }
//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>"); }
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>(); }
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>()); }
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>(); }
public void AsValidEmail_InvalidEmail_Throws () { // arrange var email = "aaa"; // act var action = new Action (() => email.AsValidEmail ("email")); // assert action.ShouldThrow<FormatException> (); }
public void AsValidEntityUrl_InvalidUrl_Throws () { // arrange var url = "+aaa"; // act var action = new Action (() => url.AsValidEntityUrl ("url")); // assert action.ShouldThrow<FormatException> (); }
private void AssertThrowsObjectDisposedException(Action action) { vertexArray.Dispose(); action.ShouldThrow<ObjectDisposedException>() .ObjectName.ShouldBe(vertexArray.GetType().FullName); }
public void ShouldNotAllowNullSearchModel() { Action act = () => this.CreateTestee(null); act.ShouldThrow <ArgumentNullException>(); }