U4-6147 - repositories are not disposable (in progress)

This commit is contained in:
Stephan
2016-04-29 10:53:19 +02:00
parent 8ab61039ed
commit 578cb6eafb
38 changed files with 1678 additions and 1784 deletions

View File

@@ -40,10 +40,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
// Act
var relationType = repositoryType.Get(1);
@@ -62,10 +62,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
// Act
var relation = repository.Get(1);
@@ -87,10 +87,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
// Act
var relation = repository.Get(2);
@@ -109,10 +109,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
// Act
var relation = repository.Get(1);
@@ -131,10 +131,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
// Act
var relations = repository.GetAll();
@@ -152,10 +152,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
// Act
var relations = repository.GetAll(1, 2);
@@ -173,10 +173,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
// Act
var exists = repository.Exists(2);
@@ -193,10 +193,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
// Act
var query = new Query<IRelation>(SqlSyntax, MappingResolver).Where(x => x.ParentId == NodeDto.NodeIdSeed + 1);
@@ -212,11 +212,11 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
// Act
var query = new Query<IRelation>(SqlSyntax, MappingResolver).Where(x => x.RelationTypeId == RelationTypeDto.NodeIdSeed);
var relations = repository.GetByQuery(query);
@@ -234,10 +234,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Arrange
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
RelationTypeRepository repositoryType;
using (var repository = CreateRepository(unitOfWork, out repositoryType))
using (var unitOfWork = provider.GetUnitOfWork())
{
RelationTypeRepository repositoryType;
var repository = CreateRepository(unitOfWork, out repositoryType);
var content = ServiceContext.ContentService.GetById(NodeDto.NodeIdSeed + 2);
ServiceContext.ContentService.Delete(content, 0);
@@ -264,35 +264,37 @@ namespace Umbraco.Tests.Persistence.Repositories
var relateContentType = new RelationType(new Guid(Constants.ObjectTypes.DocumentType), new Guid("A2CB7800-F571-4787-9638-BC48539A0EFB"), "relateContentTypeOnCopy") { IsBidirectional = true, Name = "Relate ContentType on Copy" };
var provider = new NPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
var relationTypeRepository = new RelationTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), MappingResolver);
var relationRepository = new RelationRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), relationTypeRepository, MappingResolver);
using (var unitOfWork = provider.GetUnitOfWork())
{
var relationTypeRepository = new RelationTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), MappingResolver);
var relationRepository = new RelationRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), relationTypeRepository, MappingResolver);
relationTypeRepository.AddOrUpdate(relateContent);
relationTypeRepository.AddOrUpdate(relateContentType);
unitOfWork.Commit();
relationTypeRepository.AddOrUpdate(relateContent);
relationTypeRepository.AddOrUpdate(relateContentType);
unitOfWork.Commit();
//Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed)
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage");
ServiceContext.ContentTypeService.Save(contentType);
//Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed)
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage");
ServiceContext.ContentTypeService.Save(contentType);
//Create and Save Content "Homepage" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 1)
Content textpage = MockedContent.CreateSimpleContent(contentType);
ServiceContext.ContentService.Save(textpage, 0);
//Create and Save Content "Homepage" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 1)
Content textpage = MockedContent.CreateSimpleContent(contentType);
ServiceContext.ContentService.Save(textpage, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 2)
Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
ServiceContext.ContentService.Save(subpage, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 2)
Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
ServiceContext.ContentService.Save(subpage, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 3)
Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id);
ServiceContext.ContentService.Save(subpage2, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 3)
Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id);
ServiceContext.ContentService.Save(subpage2, 0);
var relation = new Relation(textpage.Id, subpage.Id, relateContent) { Comment = string.Empty };
var relation2 = new Relation(textpage.Id, subpage2.Id, relateContent) { Comment = string.Empty };
relationRepository.AddOrUpdate(relation);
relationRepository.AddOrUpdate(relation2);
unitOfWork.Commit();
var relation = new Relation(textpage.Id, subpage.Id, relateContent) { Comment = string.Empty };
var relation2 = new Relation(textpage.Id, subpage2.Id, relateContent) { Comment = string.Empty };
relationRepository.AddOrUpdate(relation);
relationRepository.AddOrUpdate(relation2);
unitOfWork.Commit();
}
}
}
}