Example #1
0
        public void IEnumerableCountNamedGraphTest()
        {
            EntityGraph gr = a.EntityGraph(EntityGraphs.CircularGraphShape1);

            a.BSet.Add(new B());
            Assert.IsTrue(gr.Count() == 4, "Graph contains unexpected number of elements");
        }
Example #2
0
        public void AddToEntityCollectionTest()
        {
            EntityGraph gr = a.EntityGraph(EntityGraphs.CircularGraphFull);
            var         b  = new B();

            a.BSet.Add(b);
            Assert.IsTrue(gr.Contains(b), "Entity graph does not contain entity b");
        }
		public void EntGraph_OrderItems()
		{
			var entGraph = new EntityGraph(typeof(Order), new List<Order>());
			var orderItemsNode = entGraph.ElementAt(1);

			string path = orderItemsNode.EntityTypePath;

			Assert.AreEqual("OrderItem-OrderItems", path);
		}
        public void SaveGraph(EntityGraph graph, string fileName)
        {
            fileName = PathUtils.Decode(fileName);
            InitializeStreamWriter(fileName);
            _graph = graph;

            PrintHeader();

            //Printing Classes
            SW.WriteLine(@"#concepts");
            foreach (IClassEntity entity in graph.Classes.GetItems())
            {
                Print(entity);
            }

            //Printing Properties
            SW.WriteLine(@"#properties");
            foreach (IPropertyEntity entity in graph.Properties.GetItems())
            {
                Print(entity);
            }

            foreach (IRelationship relationship in graph.Relationships.GetItems())
            {
                if (relationship is ClassToClassRelationship)
                {
                    PrintClassToClassRelationship(relationship as ClassToClassRelationship);
                }
            }

            //Printing Rules
            if (graph.ConditionalRuleRelationships.Count != 0)
            {
                SW.WriteLine(@"#rules");
                SW.WriteLine("ruleset {0}", new Regex(@"\s").Replace(OntologyName, "_"));
                SW.WriteLine("{");

                foreach (ConditionalRuleRelationship rule in graph.ConditionalRuleRelationships.GetItems())
                {
                    PrintConditionalRuleRelationship(rule);
                }

                SW.WriteLine("}");
            }



            //Printing Individuals
            SW.WriteLine(@"#individuals");
            foreach (IIndividualEntity entity in graph.Individuals.GetItems())
            {
                Print(entity);
            }

            PrintFooter();
            SW.Close();
        }
        public void AddAssociationTest()
        {
            B           newB = new B();
            EntityGraph gr   = a.EntityGraph(EntityGraphs.CircularGraphFull);

            Assert.IsFalse(gr.Contains(newB));

            a.B = newB;
            Assert.IsTrue(gr.Contains(newB));
        }
Example #6
0
        public void RemoveFromEntityCollectionTest()
        {
            var b = new B();

            a.BSet.Add(b);
            EntityGraph gr = a.EntityGraph(EntityGraphs.CircularGraphFull);

            a.BSet.Remove(b);
            Assert.IsFalse(gr.Contains(b), "Entity graph still contains entity b");
        }
		public void EntGraph_BuildEntityTypePath_All()
		{
			var entGraph = new EntityGraph(typeof(Order), new List<Order>());

			string[] paths = entGraph.Select(g => g.EntityTypePath).ToArray();

			Assert.AreEqual(3, paths.Length);
			Assert.AreEqual("", paths[0]);
			Assert.AreEqual("OrderItem-OrderItems", paths[1]);
			Assert.AreEqual("OrderItem-OrderItems-Receipt-ItemReceipt", paths[2]);
		}
Example #8
0
        public void CloneIntoPreservesEntityStateNewTest()
        {
            EntityGraphTestsDomainContext ctx    = new EntityGraphTestsDomainContext();
            EntityGraphTestsDomainContext ctxNew = new EntityGraphTestsDomainContext();

            ctx.As.Add(a);
            var gr    = new EntityGraph(a, new FullEntityGraphShape());
            var clone = gr.Clone(ctxNew);

            Assert.IsTrue(a.EntityState == EntityState.New);
            Assert.IsTrue(clone.Source.EntityState == EntityState.New);
        }
Example #9
0
        public void ICollectionChangedTest()
        {
            bool        collectionChangedHandlerVisited = false;
            EntityGraph gr = a.EntityGraph(EntityGraphs.CircularGraphFull);

            gr.CollectionChanged += (sender, args) =>
            {
                collectionChangedHandlerVisited = true;
            };
            a.BSet.Add(new B());
            Assert.IsTrue(collectionChangedHandlerVisited, "CollectionChanged handler not called");
        }
Example #10
0
        public void Prospect(EntityGraph entityGraph, IArticle article)
        {
            AssertUtils.AssertParamNotNull(article, "article");

            if (article is TextArticle)
            {
                Prospect(entityGraph, article as TextArticle);
            }
            else
            {
                throw new Exception(string.Format("Unsupported article type for this prospector: {0}", article.GetType()));
            }
        }
		public void RelationshipToLoad_ParseEntireEntGraph_BuildEntityTypePaths()
		{
			var entGraph = new EntityGraph(typeof(Order), new List<Order>());

			var relationshipsToLoad = entGraph
				.Where(g => g.Member != null)				
				.Select(g => new RelationshipLoadRequest(g)).ToArray();
			string[] paths = relationshipsToLoad.Select(rtl => rtl.EntityTypePath).ToArray();

			Assert.AreEqual(2, paths.Length);
			Assert.AreEqual("OrderItem-OrderItems", paths[0]);
			Assert.AreEqual("OrderItem-OrderItems-Receipt-ItemReceipt", paths[1]);
		}
        public void INotifyPropertyChangedTest()
        {
            bool propertyChangedHandlerVisited = false;

            EntityGraph gr = a.EntityGraph(EntityGraphs.CircularGraphFull);

            gr.PropertyChanged += (sender, args) =>
            {
                propertyChangedHandlerVisited = true;
            };
            d.name = "Hello";
            Assert.IsTrue(propertyChangedHandlerVisited, "PropertyChanged handler not called");
        }
Example #13
0
        public void IEnumerableNamedGraphTest()
        {
            B newB = new B();

            a.BSet.Add(newB);
            EntityGraph eg = a.EntityGraph(EntityGraphs.CircularGraphShape1);

            Assert.AreEqual(a, eg.OfType <A>().Single());
            Assert.AreEqual(b, eg.OfType <B>().Single());
            Assert.AreEqual(c, eg.OfType <C>().Single());
            Assert.AreEqual(d, eg.OfType <D>().Single());

            Assert.IsTrue(eg.Count() == 4);
        }
Example #14
0
        public void CloneIntoPreservesEntityStateModifiedTest()
        {
            EntityGraphTestsDomainContext ctx    = new EntityGraphTestsDomainContext();
            EntityGraphTestsDomainContext ctxNew = new EntityGraphTestsDomainContext();

            ctx.As.Attach(a);
            a.name = "Hello World";

            var gr    = new EntityGraph(a, new FullEntityGraphShape());
            var clone = gr.Clone(ctxNew);

            Assert.IsTrue(a.EntityState == EntityState.Modified);
            Assert.IsTrue(clone.Source.EntityState == EntityState.Modified);
        }
        public void PartialSaveTest()
        {
            EntityGraphTestsDomainContext context = new EntityGraphTestsDomainContext();
            var a = new A {
                Id = 1
            };
            var b = new B {
                Id = 1
            };

            context.As.Attach(a);
            context.Bs.Attach(b);
            context.Bs.Attach(new B {
                Id = 2, AId = 1
            });
            context.Bs.Attach(new B {
                Id = 3, AId = 1
            });

            a.name = "Modified Task 1";

            EntityGraphTestsDomainContext tempContext = new EntityGraphTestsDomainContext();

            var shape = new FullEntityGraphShape();

            var graph = new EntityGraph(a, shape);

            Assert.IsTrue(context.HasChanges);
            Assert.IsTrue(graph.HasChanges);
            Assert.IsTrue(graph.IsChanged);

            var clone = graph.Clone(tempContext);

            Assert.IsTrue(tempContext.HasChanges);
            Assert.IsTrue(clone.HasChanges);
            Assert.IsTrue(clone.IsChanged);

            clone.AcceptChanges();
            graph.Synchronize(clone);

            Assert.IsFalse(context.HasChanges);
            Assert.IsFalse(graph.HasChanges);
            Assert.IsFalse(graph.IsChanged);

            Assert.IsFalse(tempContext.HasChanges);
            Assert.IsFalse(clone.HasChanges);
            Assert.IsFalse(clone.IsChanged);
        }
Example #16
0
        public void IEnumerableTest()
        {
            B newB = new B();

            a.BSet.Add(newB);
            EntityGraph eg = a.EntityGraph(EntityGraphs.CircularGraphFull);

            Assert.AreEqual(a, eg.OfType <A>().Single());
            Assert.AreEqual(c, eg.OfType <C>().Single());
            Assert.AreEqual(d, eg.OfType <D>().Single());

            Assert.IsTrue(eg.OfType <B>().Contains(b));
            Assert.IsTrue(eg.OfType <B>().Contains(newB));

            Assert.IsTrue(eg.Count() == 5);
        }
		internal RelationshipLoadRequest(EntityGraph entGraphNode)
		{
			TypePath = new List<string>();
			EntGraphNode = entGraphNode;

			// Populate MemberPath and TypePath
			var node = entGraphNode;
			while (node != null)
			{
				if (node.Parent != null) // Do not add root entity type
				{
					TypePath.Add(node.Member.Name);
					TypePath.Add(node.EntityType.Name);					
				}

				node = node.Parent;
			}
			TypePath.Reverse();
			EntityTypePath = BuildEntityTypePath();
		}
        /// <summary>
        /// Called when the parent RecurringService's details are loaded.
        /// </summary>
        /// <param name="recurringService">The loaded recurring service parent for this ServiceHolder.</param>
        public void OnLoadRecurringServiceDetails(RecurringService recurringService)
        {
            ClearPreviouslyLoadedDetails();

            var generatedService = recurringService.GenerateServiceOnDate(OccurDate);
            generatedService.ParentServiceHolder = this;

            _entityGraph = generatedService.EntityGraph();

            //Detach the generated service. Then manually add it to the DomainContext if there are changes
            Manager.Data.DetachEntities(_entityGraph);

            //Track the generated service's entity changes manually because it is detached
            _entityGraph.PropertyChanged += IfChangesAddToDomainContext;
            generatedService.PropertyChanged += OnSaveConvertToExistingService;
            Manager.CoreDomainContext.ChangesRejected += OnRejectChangedReloadDetails;

            Service = generatedService;
            DetailsLoaded = true;
        }
        /// <summary>
        /// Called when the Service details are loaded.
        /// </summary>
        /// <param name="service">The loaded service for this ServiceHolder.</param>
        public void OnLoadServiceDetails(Service service)
        {
            ClearPreviouslyLoadedDetails();

            this.Service = service;
            _entityGraph = this.Service.EntityGraph();

            this.OccurDate = Service.ServiceDate;
            this.RecurringServiceId = Service.RecurringServiceId;

            DetailsLoaded = true;
        }