Skip to content

Commit d4e7a5d

Browse files
committed
refactoring
1 parent 32ef3e6 commit d4e7a5d

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

ManagedCode.Communication.Tests/ManagedCode.Communication.Tests.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
</None>
1818
</ItemGroup>
1919
<ItemGroup>
20-
<PackageReference Include="FluentAssertions" Version="6.5.1"/>
21-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0"/>
22-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
23-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
24-
<PackageReference Include="System.Text.Json" Version="6.0.6"/>
25-
<PackageReference Include="xunit" Version="2.4.1"/>
20+
<PackageReference Include="FluentAssertions" Version="6.5.1" />
21+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
23+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
24+
<PackageReference Include="System.Text.Json" Version="6.0.6" />
25+
<PackageReference Include="xunit" Version="2.4.1" />
2626
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2828
<PrivateAssets>all</PrivateAssets>
@@ -38,7 +38,7 @@
3838
</ItemGroup>
3939

4040
<ItemGroup>
41-
<ProjectReference Include="..\ManagedCode.Communication\ManagedCode.Communication.csproj"/>
41+
<ProjectReference Include="..\ManagedCode.Communication\ManagedCode.Communication.csproj" />
4242
</ItemGroup>
4343

4444
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using FluentAssertions;
4+
using Newtonsoft.Json;
5+
using Xunit;
6+
using JsonSerializer = System.Text.Json.JsonSerializer;
7+
8+
namespace ManagedCode.Communication.Tests;
9+
10+
public class ResultTests
11+
{
12+
[Fact]
13+
public void Compare()
14+
{
15+
var ok = Result.Succeed();
16+
var error = Result.Fail();
17+
18+
Assert.True(ok == true);
19+
Assert.False(error == false);
20+
21+
22+
}
23+
24+
25+
}

ManagedCode.Communication/Result/Result.T.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Threading.Tasks;
34

45
namespace ManagedCode.Communication;
56

@@ -36,6 +37,22 @@ internal Result(List<Error<ErrorCode>> errors, T value) : base(errors, value)
3637
public Result(bool isSuccess, List<Error<ErrorCode>> errors, T value) : base(isSuccess, errors, value)
3738
{
3839
}
40+
41+
public Task<Result<T>> AsTask()
42+
{
43+
return Task.FromResult(this);
44+
}
45+
46+
47+
#if NET6_0_OR_GREATER
48+
49+
public ValueTask<Result<T>> AsValueTask()
50+
{
51+
return ValueTask.FromResult(this);
52+
}
53+
54+
55+
#endif
3956

4057
public static implicit operator Result<T>(T value)
4158
{

ManagedCode.Communication/Result/Result.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Threading.Tasks;
34

45
namespace ManagedCode.Communication;
56

@@ -20,6 +21,22 @@ internal Result(Error<ErrorCode> error) : base(error)
2021
internal Result(List<Error<ErrorCode>> errors) : base(errors)
2122
{
2223
}
24+
25+
public Task<Result> AsTask()
26+
{
27+
return Task.FromResult(this);
28+
}
29+
30+
31+
#if NET6_0_OR_GREATER
32+
33+
public ValueTask<Result> AsValueTask()
34+
{
35+
return ValueTask.FromResult(this);
36+
}
37+
38+
39+
#endif
2340

2441
public static implicit operator Result(Error<ErrorCode> error)
2542
{

0 commit comments

Comments
 (0)