Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MockAsynchronousMethods.Repository.Tests.Mock;
using MockAsynchronousMethods.Tests.Mock;
using Moq;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -45,5 +46,17 @@ public async Task GivenAMockedDatabase_WhenRequestingAListOfArticleAsynchronousl
Assert.NotNull(result);
Assert.True(result.Any());
}

[Fact]
public async Task GivenAMockedDatabase_WhenDeletingAnArticleAsynchronously_ThenTheDeleteIsCalledOnce()
{
var mockArticleRepository = new FakeDbArticleMock()
.DeleteAsync();

var articleRepository = new ArticleRepository(mockArticleRepository.Object);
await articleRepository.DeleteArticleAsync(1);

mockArticleRepository.Verify(x => x.DeleteAsync(1), Times.Once);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MockAsynchronousMethods.Tests.Mock;
using Moq;
using System.Linq;
using System.Threading.Tasks;

namespace MockAsynchronousMethods.Repository.Tests.Mock
{
Expand Down Expand Up @@ -31,5 +32,13 @@ public FakeDbArticleMock GetAllAsync()

return this;
}

public FakeDbArticleMock DeleteAsync()
{
Setup(x => x.DeleteAsync(It.IsAny<int>()))
.Returns(Task.CompletedTask);

return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.8.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="10.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ public async Task<IEnumerable<ArticleDbModel>> GetAllArticlesAsync()
{
return await _fakeDbArticle.GetAsync();
}

public async Task DeleteArticleAsync(int id)
{
await _fakeDbArticle.DeleteAsync(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ public async Task<IEnumerable<ArticleDbModel>> GetAsync()
{
return await Task.FromResult(_articles.FirstOrDefault(x => x.Id == id));
}

public Task DeleteAsync(int id)
{
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public interface IArticleRepository
{
Task<ArticleDbModel?> GetArticleAsync(int id);
Task<IEnumerable<ArticleDbModel>> GetAllArticlesAsync();
Task DeleteArticleAsync(int id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public interface IFakeDbArticles
{
Task<IEnumerable<ArticleDbModel>> GetAsync();
Task<ArticleDbModel?> GetByIdAsync(int id);
Task DeleteAsync(int id);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Loading