Merge pull request #17462 from abpframework/ReadOnlyRepository_Should_NoTracking_In_UOW

Add a new unit test for `ReadOnlyRepository`.
pull/17463/head
Halil İbrahim Kalkan 2 years ago committed by GitHub
commit 72d69d30fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,7 @@ using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;
@ -9,6 +10,7 @@ using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.TestApp.Domain;
using Volo.Abp.TestApp.EntityFrameworkCore;
using Volo.Abp.TestApp.Testing;
using Volo.Abp.Uow;
using Xunit;
namespace Volo.Abp.EntityFrameworkCore.Repositories;
@ -72,4 +74,39 @@ public class ReadOnlyRepository_Tests : TestAppTestBase<AbpEntityFrameworkCoreTe
});
});
}
[Fact]
public async Task ReadOnlyRepository_Should_NoTracking_In_UOW()
{
var repository = GetRequiredService<IRepository<Person, Guid>>();
var readonlyRepository = GetRequiredService<IReadOnlyRepository<Person, Guid>>();
await WithUnitOfWorkAsync(async () =>
{
await repository.InsertAsync(new Person(Guid.NewGuid(), "people1", 18));
await repository.InsertAsync(new Person(Guid.NewGuid(), "people2", 19));
});
using (var uow = GetRequiredService<IUnitOfWorkManager>().Begin())
{
var p1 = await repository.FirstOrDefaultAsync(x => x.Name == "people1");
p1.ShouldNotBeNull();
p1.ChangeName("people1-updated");
var p2 = await readonlyRepository.FirstOrDefaultAsync(x => x.Name == "people2");
p2.ShouldNotBeNull();
p2.ChangeName("people2-updated");
await uow.CompleteAsync();
}
await WithUnitOfWorkAsync(async () =>
{
(await repository.FirstOrDefaultAsync(x => x.Name == "people1")).ShouldBeNull();
(await repository.FirstOrDefaultAsync(x => x.Name == "people1-updated")).ShouldNotBeNull();
(await readonlyRepository.FirstOrDefaultAsync(x => x.Name == "people2")).ShouldNotBeNull();
(await readonlyRepository.FirstOrDefaultAsync(x => x.Name == "people2-updated")).ShouldBeNull();
});
}
}

Loading…
Cancel
Save