/// <summary> /// Tests that executing a function that returns a failure result returns the underlying result without wrapping it. /// </summary> public virtual void executeFailureResultValue() { SupplierFunction <Result <string> > fn = SupplierFunction.of(() => Result.failure(FailureReason.NOT_APPLICABLE, "bar")); CalculationTaskCell cell = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD); CalculationTask task = CalculationTask.of(TARGET, fn, cell); ScenarioMarketData marketData = ScenarioMarketData.empty(); CalculationResults calculationResults = task.execute(marketData, REF_DATA); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculationResults.getCells().get(0).getResult(); Result <object> result = calculationResults.Cells.get(0).Result; assertThat(result).isFailure(FailureReason.NOT_APPLICABLE).hasFailureMessageMatching("bar"); }
/// <summary> /// Tests that executing a function that returns a success result returns the underlying result without wrapping it. /// </summary> public virtual void executeSuccessResultValue() { SupplierFunction <Result <ScenarioArray <string> > > fn = SupplierFunction.of(() => Result.success(ScenarioArray.of("foo"))); CalculationTaskCell cell = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD); CalculationTask task = CalculationTask.of(TARGET, fn, cell); ScenarioMarketData marketData = ImmutableScenarioMarketData.builder(date(2011, 3, 8)).build(); CalculationResults calculationResults = task.execute(marketData, REF_DATA); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculationResults.getCells().get(0).getResult(); Result <object> result = calculationResults.Cells.get(0).Result; assertThat(result).hasValue(ScenarioArray.of("foo")); }
/// <summary> /// Test the result is returned unchanged if using ReportingCurrency.NONE. /// </summary> public virtual void convertResultCurrencyNoConversionRequested() { SupplierFunction <CurrencyAmount> fn = SupplierFunction.of(() => CurrencyAmount.of(EUR, 1d)); CalculationTaskCell cell = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, ReportingCurrency.NONE); CalculationTask task = CalculationTask.of(TARGET, fn, cell); ScenarioMarketData marketData = ImmutableScenarioMarketData.builder(date(2011, 3, 8)).build(); CalculationResults calculationResults = task.execute(marketData, REF_DATA); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculationResults.getCells().get(0).getResult(); Result <object> result = calculationResults.Cells.get(0).Result; assertThat(result).hasValue(ScenarioArray.of(CurrencyAmount.of(EUR, 1d))); }
/// <summary> /// Tests that executing a function that throws an unsupported exception wraps the exception in a failure result. /// </summary> public virtual void executeException_unsupported() { SupplierFunction <string> fn = SupplierFunction.of(() => { throw new System.NotSupportedException("foo"); }); CalculationTaskCell cell = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD); CalculationTask task = CalculationTask.of(TARGET, fn, cell); ScenarioMarketData marketData = ScenarioMarketData.empty(); CalculationResults calculationResults = task.execute(marketData, REF_DATA); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculationResults.getCells().get(0).getResult(); Result <object> result = calculationResults.Cells.get(0).Result; assertThat(result).isFailure(FailureReason.UNSUPPORTED).hasFailureMessageMatching("Unsupported operation when invoking function 'SupplierFunction' for ID '123': foo"); }