public ServiceJSONResult MyMethod(ServiceJSONInput input) { //controls if input data is not null, otherwise it returns if (input == null) { return(new ServiceJSONResult { Customer = null, Exception = new Exception("Invalid input data"), Message = "Sevice Cannnot perform your request" }); } //defines a ret var ServiceJSONResult ret = new ServiceJSONResult { Customer = input.Customer, Exception = null }; try{ //do something with input data ret.Message = "Your request has been performed"; } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } ret.Exception = new Exception(ex.Message); ret.Message = "Sevice Cannnot perform your request"; } return(ret); }
public void Call_MyMethod_With_No_Input_Data() { ServiceJSON service = new ServiceJSON(); ServiceJSONResult response = service.MyMethod(null); Assert.True(response.Exception != null); }
public void Call_MyMethod_With_Input_Data() { ServiceJSON service = new ServiceJSON(); Customer customer = new Customer { FirstName = "Steve", LastName = "Jobs" }; Account account = new Account { UserName = "******", Password = "******" }; ServiceJSONInput inputData = new ServiceJSONInput { Customer = customer, Account = account }; ServiceJSONResult response = service.MyMethod(inputData); Assert.True(response.Exception == null); Assert.True(response.Customer == customer); Assert.True(response.Message != null); }
static void MyMethodCompleted(object sender, MyMethodCompletedEventArgs e) { ServiceJSONResult result = (ServiceJSONResult)e.Result; Console.WriteLine("Service Message: {0}", result.Message); }