public void Can_Save_Lazy_Content() { var unitOfWork = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); var contentType = ServiceContext.ContentTypeService.GetContentType("umbTextpage"); var root = ServiceContext.ContentService.GetById(1046); var c = new Lazy <IContent>(() => MockedContent.CreateSimpleContent(contentType, "Hierarchy Simple Text Page", root.Id)); var c2 = new Lazy <IContent>(() => MockedContent.CreateSimpleContent(contentType, "Hierarchy Simple Text Subpage", c.Value.Id)); var list = new List <Lazy <IContent> > { c, c2 }; var repository = RepositoryResolver.Current.ResolveByType <IContentRepository>(unitOfWork); foreach (var content in list) { repository.AddOrUpdate(content.Value); unitOfWork.Commit(); } Assert.That(c.Value.HasIdentity, Is.True); Assert.That(c2.Value.HasIdentity, Is.True); Assert.That(c.Value.Id > 0, Is.True); Assert.That(c2.Value.Id > 0, Is.True); Assert.That(c.Value.ParentId > 0, Is.True); Assert.That(c2.Value.ParentId > 0, Is.True); }
void MigrationRunner_Migrated(MigrationRunner sender, Core.Events.MigrationEventArgs e) { var target = new Version(6, 0, 0); if (e.ConfiguredVersion < target) { var sql = new Sql(); sql.Select("*") .From <DocumentDto>() .InnerJoin <ContentVersionDto>() .On <DocumentDto, ContentVersionDto>(left => left.VersionId, right => right.VersionId) .InnerJoin <ContentDto>() .On <ContentVersionDto, ContentDto>(left => left.NodeId, right => right.NodeId) .InnerJoin <NodeDto>() .On <ContentDto, NodeDto>(left => left.NodeId, right => right.NodeId) .Where <NodeDto>(x => x.NodeObjectType == new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972")) .Where <NodeDto>(x => x.Path.StartsWith("-1")); var uow = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); var dtos = uow.Database.Fetch <DocumentDto, ContentVersionDto, ContentDto, NodeDto>(sql); var toUpdate = new List <DocumentDto>(); var versionGroup = dtos.GroupBy(x => x.NodeId); foreach (var grp in versionGroup) { var published = grp.FirstOrDefault(x => x.Published); var newest = grp.FirstOrDefault(x => x.Newest); if (newest != null) { double timeDiff = new TimeSpan(newest.UpdateDate.Ticks - newest.ContentVersionDto.VersionDate.Ticks).TotalMilliseconds; var hasPendingChanges = timeDiff > 2000; if (hasPendingChanges == false && published != null) { published.Published = false; toUpdate.Add(published); newest.Published = true; toUpdate.Add(newest); } } } //Commit the updated entries for the cmsDocument table using (var transaction = uow.Database.GetTransaction()) { //Loop through the toUpdate foreach (var dto in toUpdate) { uow.Database.Update(dto); } transaction.Complete(); } } }
public void ResolveRepository(Type repoType) { var method = typeof(RepositoryResolver).GetMethod("ResolveByType", BindingFlags.NonPublic | BindingFlags.Instance); var gMethod = method.MakeGenericMethod(repoType); var repo = gMethod.Invoke(RepositoryResolver.Current, new object[] { PetaPocoUnitOfWorkProvider.CreateUnitOfWork() }); Assert.IsNotNull(repo); Assert.IsTrue(TypeHelper.IsTypeAssignableFrom(repoType, repo.GetType())); repo.DisposeIfDisposable(); }
public void Can_Verify_UOW_In_Repository() { // Arrange var uow = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); // Act var repository = RepositoryResolver.Current.ResolveByType <IContentRepository>(uow); // Assert Assert.That(repository, Is.Not.Null); Assert.That(uow.Key, Is.EqualTo(((RepositoryBase <int, IContent>)repository).UnitKey)); repository.Dispose(); }
public void Type_Checking() { var repositoryType = typeof(IContentRepository); bool isSubclassOf = repositoryType.IsSubclassOf(typeof(IRepository <int, IContent>)); bool isAssignableFrom = typeof(IRepository <int, IContent>).IsAssignableFrom(repositoryType); Assert.That(isSubclassOf, Is.False); Assert.That(isAssignableFrom, Is.True); var uow = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); var repository = RepositoryResolver.Current.ResolveByType <IContentRepository>(uow); bool subclassOf = repository.GetType().IsSubclassOf(typeof(IRepository <int, IContent>)); Assert.That(subclassOf, Is.False); Assert.That((typeof(IRepository <int, IContent>).IsInstanceOfType(repository)), Is.True); repository.Dispose(); }