public void SetMyNumber(SampleApiData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } myNumber = data.NewNumber; }
public void Using_CheckData_does_not_raise_exception_for_valid_data(ICast cast) { // Arrange var joe = cast.Get <Joe>(); var theData = new SampleApiData { Name = ExecutionController.ValidName, DateAndTime = DateTime.Today }; // Act & assert Assert.That(() => When(joe).AttemptsTo(Invoke.TheJsonWebService <CheckData>().WithTheData(theData).AndVerifyItSucceeds()), Throws.Nothing); }
public void CheckData(SampleApiData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (data.Name != ValidName) { throw new HttpResponseException(HttpStatusCode.BadRequest); } }
public void Using_CheckData_raises_exception_for_invalid_data(ICast cast) { // Arrange var joe = cast.Get <Joe>(); var theData = new SampleApiData { Name = "Invalid, crash expected", DateAndTime = DateTime.Today }; // Act & assert Assert.That(() => When(joe).AttemptsTo(Invoke.TheJsonWebService <CheckData>().WithTheData(theData).AndVerifyItSucceeds()), Throws.InstanceOf <WebApiException>()); }
public void Using_SetTheNumber_does_not_raise_exception(ICast cast) { // Arrange var joe = cast.Get <Joe>(); var theData = new SampleApiData() { NewNumber = 5 }; // Act & assert Assert.That(() => When(joe).AttemptsTo(Invoke.TheJsonWebService <SetNumber>().WithTheData(theData).AndVerifyItSucceeds()), Throws.Nothing); }
public void Using_SetTheNumber_then_GetTheNumber_returns_the_correct_number(ICast cast) { // Arrange var theNumber = 42; var theData = new SampleApiData() { NewNumber = theNumber }; var joe = cast.Get <Joe>(); Given(joe).WasAbleTo(Invoke.TheJsonWebService <SetNumber>().WithTheData(theData).AndVerifyItSucceeds()); // Act var result = When(joe).AttemptsTo(Invoke.TheJsonWebService <GetNumber>().AndReadTheResultAs <int>()); // Assert Assert.That(result, Is.EqualTo(theNumber)); }