public void Add_New_Mapping() { // arrange var errorCode = "some_error_code"; // act ResultExceptionMapper.AddMapping(errorCode, result => new ResultException(result)); // assert Assert.NotNull(ResultExceptionMapper.GetMapping <ResultException>(errorCode)); }
public void Get_Null_For_Non_Existing_Mapping() { // arrange var errorCode = "non_existing_error_code"; // act var mapping = ResultExceptionMapper.GetMapping <ResultException>(errorCode); // assert Assert.Null(mapping); }
public void Convert_Result_To_Custom_Exception_And_Throw() { // arrange ResultExceptionMapper.AddMapping("customer_not_found", result => new CustomExceptionException(result)); var result = Result.Failure() .WithMessage("failed to complete the order, customer not found") .WithCode("customer_not_found"); // act // assert Assert.Throws <CustomExceptionException>(() => result.ToException().Throw()); }
public void Add_Custom_Exception_To_Mapping() { // arrange var errorCode = "some_error_code"; ResultExceptionMapper.AddMapping(errorCode, result => new CustomExceptionException(result)); // act var mapping = ResultExceptionMapper.GetMapping <CustomExceptionException>(errorCode); // assert Assert.NotNull(mapping); }
public void Get_Existing_Mapping() { // arrange var errorCode = "some_error_code"; ResultExceptionMapper.AddMapping(errorCode, result => new ResultException(result)); // act var mapping = ResultExceptionMapper.GetMapping <ResultException>(errorCode); // assert Assert.NotNull(mapping); }
public void Convert_Result_To_Custom_Exception_If_Mapping_Exist() { // arrange ResultExceptionMapper.AddMapping("customer_not_found", result => new CustomExceptionException(result)); var result = Result.Failure() .WithMessage("failed to complete the order, customer not found") .WithCode("customer_not_found"); // act var exception = result.ToException(); // assert Assert.IsType <CustomExceptionException>(exception); }