Beispiel #1
0
        public void ReplaceAssociation_NotEmptyCollection()
        {
            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var sessionOfExperts = new SessionOfExperts("baseNotion");
                GetRepository <SessionOfExperts>().AddOrUpdate(sessionOfExperts);

                var expert = new Expert("expertName", sessionOfExperts);
                expert.ReplaceAllAssociations(new[] { "notion1", "notion2" });
                GetRepository <Expert>().AddOrUpdate(expert);

                unitOfWork.Commit();
            }

            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var expert = LinqProvider.Query <Expert>().Single();
                expert.ReplaceAllAssociations(new[] { "notion3", "notion4" });
                GetRepository <Expert>().AddOrUpdate(expert);

                unitOfWork.Commit();
            }

            using (UnitOfWorkFactory.Create()) {
                var expert = LinqProvider.Query <Expert>().Single();

                expert.Associations.Should().BeEquivalentTo(
                    new[]
                {
                    new { Expert = expert, Notion = "notion3" },
                    new { Expert = expert, Notion = "notion4" }
                },
                    opt => opt.ExcludingMissingMembers());
            }
        }
Beispiel #2
0
        public void UpdateAssociationTypes()
        {
            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var sessionOfExperts = new SessionOfExperts("baseNotion");
                GetRepository <SessionOfExperts>().AddOrUpdate(sessionOfExperts);

                var expert = new Expert("expertName", sessionOfExperts);
                expert.ReplaceAllAssociations(new[] { "notion1", "notion2" });

                GetRepository <Expert>().AddOrUpdate(expert);

                unitOfWork.Commit();
            }

            Guid associationIdForUpdate;

            using (var unitOfWork = UnitOfWorkFactory.Create()) {
                var expert = LinqProvider.Query <Expert>().Single();
                associationIdForUpdate = LinqProvider.Query <Association>().First().Id;

                var type = new NotionType("NotionType");
                GetRepository <NotionType>().AddOrUpdate(type);

                expert.SetTypeForAssociation(associationIdForUpdate, type, "offer");
                GetRepository <Expert>().AddOrUpdate(expert);

                unitOfWork.Commit();
            }

            using (UnitOfWorkFactory.Create()) {
                var expert = LinqProvider.Query <Expert>().Single();
                var type   = LinqProvider.Query <NotionType>().Single();

                expert.Associations.Single(x => x.Id == associationIdForUpdate).Should().BeEquivalentTo(
                    new { Expert = expert, Type = type, OfferType = "offer" },
                    opt => opt.ExcludingMissingMembers());
            }
        }