Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Result.Net/Result.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,54 @@ public static TResult WithErrors<TResult>(this TResult result, params ResultErro
/// <param name="key">the key of the data</param>
/// <param name="data">the data instance</param>
/// <returns>the instance of result to enable method chaining</returns>
[Obsolete("Use 'WithMetadata' instead")]
public static TResult WithMataData<TResult>(this TResult result, string key, object data) where TResult : Result
{
result.MetaData.Add(key, data);
return result;
}

/// <summary>
/// adds an element with the provided key and data to the data list of the result instance
/// </summary>
/// <typeparam name="TResult">the type of result instance</typeparam>
/// <param name="result">the result object instance</param>
/// <param name="key">the key of the data</param>
/// <param name="data">the data instance</param>
/// <returns>the instance of result to enable method chaining</returns>
public static TResult WithMetadata<TResult>(this TResult result, string key, object data) where TResult : Result
{
result.MetaData.Add(key, data);
return result;
}

/// <summary>
/// adds an element with the provided key and data to the data list of the result instance
/// </summary>
/// <param name="error">the result object instance</param>
/// <param name="key">the key of the data</param>
/// <param name="data">the data instance</param>
/// <returns>the instance of result to enable method chaining</returns>
[Obsolete("Use 'WithMetadata' instead")]
public static ResultError WithMataData(this ResultError error, string key, object data)
{
error.MetaData.Add(key, data);
return error;
}

/// <summary>
/// adds an element with the provided key and data to the data list of the result instance
/// </summary>
/// <param name="error">the result object instance</param>
/// <param name="key">the key of the data</param>
/// <param name="data">the data instance</param>
/// <returns>the instance of result to enable method chaining</returns>
public static ResultError WithMetadata(this ResultError error, string key, object data)
{
error.MetaData.Add(key, data);
return error;
}

/// <summary>
/// Determines whether the Result object instance has any errors associated with it.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion tests/Result.Net.Tests/ExceptionShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Convert_Result_Exception_To_Result()
var result = Result.Failure()
.WithMessage("some message")
.WithCode("some_code")
.WithMataData("some_key", new { key = 1});
.WithMetadata("some_key", new { key = 1});

var exception = result.ToException();

Expand Down
4 changes: 2 additions & 2 deletions tests/Result.Net.Tests/FailedResultShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public void Create_Failed_Result_With_MetaData()

// act
var result = Result.Failure()
.WithMataData("test1", new { key = 1 })
.WithMataData("test2", new { key = 2 });
.WithMetadata("test1", new { key = 1 })
.WithMetadata("test2", new { key = 2 });

// assert
Assert.Equal(expectedMetaDataCount, result.MetaData.Count);
Expand Down
2 changes: 1 addition & 1 deletion tests/Result.Net.Tests/ResultCastExtensionsShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Cast_Failure_Result_To_Result_Data()
var result = Result.Failure()
.WithCode("test_code")
.WithMessage("failed message")
.WithMataData("test1", new { key = 1 })
.WithMetadata("test1", new { key = 1 })
.WithErrors(new ResultError("test", "test_code", "source")); ;

// act
Expand Down
4 changes: 2 additions & 2 deletions tests/Result.Net.Tests/SuccessResultShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void Create_Success_Result_With_MetaData()

// act
var result = Result.Success()
.WithMataData("test1", new { key = 1 })
.WithMataData("test2", new { key = 2 });
.WithMetadata("test1", new { key = 1 })
.WithMetadata("test2", new { key = 2 });

// assert
Assert.Equal(expectedMetaDataCount, result.MetaData.Count);
Expand Down