Example #1
0
        public void Entity_should_persist_successfully(Sprint sprint,
                                                       Ticket ticket1,
                                                       Ticket ticket2,
                                                       [FromDi] Lazy <ISessionFactory> sessionFactory,
                                                       [FromDi] Lazy <IResetsDatabase> dbResetter)
        {
            sprint.Tickets.Add(ticket1);
            sprint.Tickets.Add(ticket2);

            using (var provider = new CachingDataConnectionFactoryAdapter(new CSF.ORM.NHibernate.SessionFactoryAdapter(sessionFactory.Value)))
            {
                var result = TestPersistence.UsingConnectionProvider(provider)
                             .WithSetup(s => dbResetter.Value.ResetDatabase(), false)
                             .WithEntity(sprint)
                             .WithEqualityRule(builder => {
                    return(builder
                           .ForProperty(x => x.CreationDate, c => c.UsingComparer(ComparerFactory.GetDateTimeAccurateToSecondsComparer()))
                           .ForProperty(x => x.StartDate, c => c.UsingComparer(ComparerFactory.GetNullableDateTimeAccurateToSecondsComparer()))
                           .ForProperty(x => x.EndDate, c => c.UsingComparer(ComparerFactory.GetNullableDateTimeAccurateToSecondsComparer()))
                           .ForProperty(x => x.Tickets, c => c.UsingComparer(new SetEqualityComparer <Ticket>(new EntityIdentityEqualityComparer())))
                           .ForAllOtherProperties());
                });
                Assert.That(result, Persisted.Successfully());
            }
        }
Example #2
0
        public void Entity_should_persist_successfully(Label label,
                                                       Ticket ticket1,
                                                       Ticket ticket2,
                                                       [FromDi] Lazy <ISessionFactory> sessionFactory,
                                                       [FromDi] Lazy <IResetsDatabase> dbResetter)
        {
            label.Tickets.Add(ticket1);
            label.Tickets.Add(ticket2);

            using (var provider = new CachingDataConnectionFactoryAdapter(new CSF.ORM.NHibernate.SessionFactoryAdapter(sessionFactory.Value)))
            {
                var result = TestPersistence.UsingConnectionProvider(provider)
                             .WithSetup(s => {
                    dbResetter.Value.ResetDatabase();

                    // The many-to-many from Label to Ticket doesn't cascade from the Label side,
                    // so the tickets must be saved independently.
                    using (var tran = s.GetTransactionFactory().GetTransaction())
                    {
                        var persister = s.GetPersister();
                        persister.Add(ticket1);
                        persister.Add(ticket2);
                        tran.Commit();
                    }
                }, false)
                             .WithEntity(label)
                             .WithEqualityRule(builder => {
                    return(builder
                           .ForProperty(x => x.Tickets, c => c.UsingComparer(new SetEqualityComparer <Ticket>(new EntityIdentityEqualityComparer())))
                           .ForAllOtherProperties());
                });

                Assert.That(result, Persisted.Successfully());
            }
        }
Example #3
0
        public void Entity_should_persist_successfully(User user,
                                                       Project contrib1,
                                                       Project contrib2,
                                                       Project admin1,
                                                       Project admin2,
                                                       [FromDi] Lazy <ISessionFactory> sessionFactory,
                                                       [FromDi] Lazy <IResetsDatabase> dbResetter)
        {
            user.ContributorTo.Add(contrib1);
            user.ContributorTo.Add(contrib2);
            user.AdministratorOf.Add(admin1);
            user.AdministratorOf.Add(admin2);

            using (var provider = new CachingDataConnectionFactoryAdapter(new CSF.ORM.NHibernate.SessionFactoryAdapter(sessionFactory.Value)))
            {
                var result = TestPersistence.UsingConnectionProvider(provider)
                             .WithSetup(s => dbResetter.Value.ResetDatabase(), false)
                             .WithEntity(user)
                             .WithEqualityRule(builder => {
                    return(builder
                           .ForProperty(x => x.ContributorTo, c => c.UsingComparer(new SetEqualityComparer <Project>(new EntityIdentityEqualityComparer())))
                           .ForProperty(x => x.AdministratorOf, c => c.UsingComparer(new SetEqualityComparer <Project>(new EntityIdentityEqualityComparer())))
                           .ForAllOtherProperties());
                });
                Assert.That(result, Persisted.Successfully());
            }
        }
Example #4
0
        public void Entity_should_persist_successfully(Ticket ticket,
                                                       Comment comment1,
                                                       Comment comment2,
                                                       Label label1,
                                                       Label label2,
                                                       DirectionalRelationship rel1,
                                                       DirectionalRelationship rel2,
                                                       NonDirectionalRelationship rel3,
                                                       Ticket otherTicket,
                                                       TicketWorkLog log1,
                                                       TicketWorkLog log2,
                                                       [FromDi] Lazy <ISessionFactory> sessionFactory,
                                                       [FromDi] Lazy <IResetsDatabase> dbResetter)
        {
            ticket.Comments.Add(comment1);
            ticket.Comments.Add(comment2);
            ticket.Labels.Add(label1);
            ticket.Labels.Add(label2);
            ticket.PrimaryRelationships.Add(new TicketRelationship {
                Relationship = rel1, SecondaryTicket = otherTicket
            });
            ticket.PrimaryRelationships.Add(new TicketRelationship {
                Relationship = rel3, SecondaryTicket = otherTicket
            });
            ticket.SecondaryRelationships.Add(new TicketRelationship {
                Relationship = rel2, PrimaryTicket = otherTicket
            });
            ticket.WorkLogs.Add(log1);
            ticket.WorkLogs.Add(log2);

            using (var provider = new CachingDataConnectionFactoryAdapter(new CSF.ORM.NHibernate.SessionFactoryAdapter(sessionFactory.Value)))
            {
                var result = TestPersistence.UsingConnectionProvider(provider)
                             .WithSetup(s => dbResetter.Value.ResetDatabase(), false)
                             .WithEntity(ticket)
                             .WithEqualityRule(builder => {
                    return(builder
                           .ForProperty(x => x.CreationTimestamp, c => c.UsingComparer(ComparerFactory.GetDateTimeAccurateToSecondsComparer()))

                           .ForProperty(x => x.Comments, c => c.UsingComparer(new SetEqualityComparer <Comment>(new EntityIdentityEqualityComparer())))
                           .ForProperty(x => x.Labels, c => c.UsingComparer(new SetEqualityComparer <Label>(new EntityIdentityEqualityComparer())))
                           .ForProperty(x => x.PrimaryRelationships, c => c.UsingComparer(new SetEqualityComparer <TicketRelationship>(new EntityIdentityEqualityComparer())))
                           .ForProperty(x => x.SecondaryRelationships, c => c.UsingComparer(new SetEqualityComparer <TicketRelationship>(new EntityIdentityEqualityComparer())))
                           .ForProperty(x => x.WorkLogs, c => c.UsingComparer(new SetEqualityComparer <TicketWorkLog>(new EntityIdentityEqualityComparer())))
                           .ForAllOtherProperties());
                });
                Assert.That(result, Persisted.Successfully());
            }
        }
Example #5
0
        public void Entity_should_persist_successfully(Project project,
                                                       Ticket ticket1,
                                                       Ticket ticket2,
                                                       Sprint sprint1,
                                                       Sprint sprint2,
                                                       User contrib1,
                                                       User contrib2,
                                                       User admin1,
                                                       User admin2,
                                                       [FromDi] Lazy <ISessionFactory> sessionFactory,
                                                       [FromDi] Lazy <IResetsDatabase> dbResetter)
        {
            project.Tickets.Add(ticket1);
            project.Tickets.Add(ticket2);
            project.Sprints.Add(sprint1);
            project.Sprints.Add(sprint2);
            project.Contributors.Add(contrib1);
            project.Contributors.Add(contrib2);
            project.Administrators.Add(admin1);
            project.Administrators.Add(admin2);

            using (var provider = new CachingDataConnectionFactoryAdapter(new CSF.ORM.NHibernate.SessionFactoryAdapter(sessionFactory.Value)))
            {
                var result = TestPersistence.UsingConnectionProvider(provider)
                             .WithSetup(s => {
                    dbResetter.Value.ResetDatabase();
                    using (var tran = s.GetTransactionFactory().GetTransaction())
                    {
                        var p = s.GetPersister();
                        p.Add(contrib1);
                        p.Add(contrib2);
                        p.Add(admin1);
                        p.Add(admin2);
                        tran.Commit();
                    }
                }, false)
                             .WithEntity(project)
                             .WithEqualityRule(builder => {
                    return(builder
                           .ForProperty(x => x.Tickets, c => c.UsingComparer(new SetEqualityComparer <Ticket>(new EntityIdentityEqualityComparer())))
                           .ForProperty(x => x.Sprints, c => c.UsingComparer(new SetEqualityComparer <Sprint>(new EntityIdentityEqualityComparer())))
                           .ForProperty(x => x.Contributors, c => c.UsingComparer(new SetEqualityComparer <User>(new EntityIdentityEqualityComparer())))
                           .ForProperty(x => x.Administrators, c => c.UsingComparer(new SetEqualityComparer <User>(new EntityIdentityEqualityComparer())))
                           .ForAllOtherProperties());
                });
                Assert.That(result, Persisted.Successfully());
            }
        }
Example #6
0
 public void Entity_should_persist_successfully(NonDirectionalRelationship relationship,
                                                [FromDi] Lazy <ISessionFactory> sessionFactory,
                                                [FromDi] Lazy <IResetsDatabase> dbResetter)
 {
     using (var provider = new CachingDataConnectionFactoryAdapter(new CSF.ORM.NHibernate.SessionFactoryAdapter(sessionFactory.Value)))
     {
         var result = TestPersistence.UsingConnectionProvider(provider)
                      .WithSetup(s => dbResetter.Value.ResetDatabase(), false)
                      .WithEntity(relationship)
                      .WithEqualityRule(builder => {
             return(builder
                    .ForAllOtherProperties());
         });
         Assert.That(result, Persisted.Successfully());
     }
 }
Example #7
0
 public void Entity_should_persist_successfully(TicketWorkLog log,
                                                [FromDi] Lazy <ISessionFactory> sessionFactory,
                                                [FromDi] Lazy <IResetsDatabase> dbResetter)
 {
     using (var provider = new CachingDataConnectionFactoryAdapter(new CSF.ORM.NHibernate.SessionFactoryAdapter(sessionFactory.Value)))
     {
         var result = TestPersistence.UsingConnectionProvider(provider)
                      .WithSetup(s => dbResetter.Value.ResetDatabase(), false)
                      .WithEntity(log)
                      .WithEqualityRule(builder => {
             return(builder
                    .ForProperty(x => x.TimeStarted, c => c.UsingComparer(ComparerFactory.GetDateTimeAccurateToSecondsComparer()))
                    .ForAllOtherProperties());
         });
         Assert.That(result, Persisted.Successfully());
     }
 }