-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test projesi eklendi ve extention test edilebilir hale getirildi
- Loading branch information
1 parent
d5d164e
commit 6326d83
Showing
8 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/> | ||
<PackageReference Include="xunit" Version="2.4.1"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Xunit; | ||
|
||
namespace EnLock.Tesr; | ||
|
||
public class UnitTest1 | ||
{ | ||
[Fact] | ||
public void Test1() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\EnLock\EnLock.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace EnLock.Test; | ||
|
||
public class TestContext: DbContext | ||
{ | ||
public TestContext() { } | ||
public TestContext(DbContextOptions<TestContext> options): base(options) { } | ||
public DbSet<TestModel> TestDbSet { get; set; } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace EnLock.Test; | ||
|
||
public class TestModel | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public string Surname { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace EnLock.Test; | ||
|
||
public class UnitTest1 | ||
{ | ||
private readonly TestContext _testContext; | ||
|
||
public UnitTest1() | ||
{ | ||
_testContext = new TestContext(CreateNewContextOptions()); | ||
} | ||
|
||
private static DbContextOptions<TestContext> CreateNewContextOptions() | ||
{ | ||
// Create a fresh service provider, and therefore a fresh | ||
// InMemory database instance. | ||
var serviceProvider = new ServiceCollection() | ||
.AddEntityFrameworkInMemoryDatabase() | ||
.BuildServiceProvider(); | ||
|
||
// Create a new options instance telling the context to use an | ||
// InMemory database and the new service provider. | ||
var builder = new DbContextOptionsBuilder<TestContext>(); | ||
builder.UseInMemoryDatabase( "TestDbInMemory") | ||
.UseInternalServiceProvider(serviceProvider); | ||
|
||
return builder.Options; | ||
} | ||
|
||
public IEnumerable<TestModel> GetDbSet() | ||
{ | ||
var list = new List<TestModel>(); | ||
|
||
list.Add(new TestModel() {Name = "Enis", Surname = "Gürkan"}); | ||
list.Add(new TestModel() {Name = "Enes", Surname = "Gürkan"}); | ||
list.Add(new TestModel() {Name = "Filiz", Surname = "Gürkan"}); | ||
return list; | ||
} | ||
|
||
[Fact] | ||
public async Task AddTest() | ||
{ | ||
using (var context = new TestContext(CreateNewContextOptions())) | ||
{ | ||
await _testContext.TestDbSet.AddRangeAsync(GetDbSet()); | ||
await _testContext.SaveChangesAsync(); | ||
|
||
int count = await _testContext.TestDbSet.CountAsync(); | ||
Assert.Equal(count,3); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task FirstOrDefault_Test() | ||
{ | ||
using (var context = new TestContext(CreateNewContextOptions())) | ||
{ | ||
await _testContext.TestDbSet.AddRangeAsync(GetDbSet()); | ||
await _testContext.SaveChangesAsync(); | ||
|
||
|
||
var model = await _testContext | ||
.TestDbSet | ||
.Where(s=> s.Name == "Enis") | ||
.ToFirstOrDefaultWithNoLockAsync(); | ||
|
||
Assert.Equal(model.Name, "Enis"); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task List_Test() | ||
{ | ||
using (var context = new TestContext(CreateNewContextOptions())) | ||
{ | ||
await _testContext.TestDbSet.AddRangeAsync(GetDbSet()); | ||
await _testContext.SaveChangesAsync(); | ||
|
||
|
||
var list = await _testContext | ||
.TestDbSet | ||
.ToListWithNoLockAsync(); | ||
|
||
Assert.Equal(list.Count(), 3); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Any_Test() | ||
{ | ||
using (var context = new TestContext(CreateNewContextOptions())) | ||
{ | ||
await _testContext.TestDbSet.AddRangeAsync(GetDbSet()); | ||
await _testContext.SaveChangesAsync(); | ||
|
||
|
||
var status = await _testContext | ||
.TestDbSet | ||
.Where(s=> s.Name == "Enis") | ||
.ToAnyWithNoLockAsync(); | ||
|
||
Assert.Equal(status, true); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task RemoveTest() | ||
{ | ||
using (var context = new TestContext(CreateNewContextOptions())) | ||
{ | ||
await _testContext.TestDbSet.AddRangeAsync(GetDbSet()); | ||
await _testContext.SaveChangesAsync(); | ||
|
||
var model = await _testContext.TestDbSet.FirstOrDefaultAsync(s => s.Name == "Enis"); | ||
_testContext.TestDbSet.Remove(model); | ||
await _testContext.SaveChangesAsync(); | ||
int count = await _testContext.TestDbSet.CountAsync(); | ||
|
||
Assert.Equal(count, 2); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters