Ejemplo n.º 1
0
        //TODO: Fix this -> issue when we're generating a guid id, if you get the GraphVertex object twice, you'll get 2 different id properties so you can't create the edge.
        //[TestMethod]
        public void GenerateGraphEdgeWithVertexReferencesNoIdProperty()
        {
            //Initialize Objects
            var movieTitle  = "The Network";
            var movie       = MovieGraph.GetTestModel(movieTitle);
            var rating      = Rating.GetTestRating(movieTitle);
            var cast        = Cast.GetTestMovieCast(movieTitle);
            var movieRating = new MovieRatingEdge {
                SiteName = rating.SiteName
            };

            var movieGraph  = CosmosEntitySerializer.Default.ToGraphVertex(movie) as IDictionary <string, object>;
            var ratingGraph = CosmosEntitySerializer.Default.ToGraphVertex(rating) as IDictionary <string, object>;
            var castGraph   = CosmosEntitySerializer.Default.ToGraphVertex(cast) as IDictionary <string, object>;

            Assert.IsNotNull(movieGraph, "Failed to convert movie to Graph Vertex");
            Assert.IsNotNull(ratingGraph, "Failed to convert rating to Graph Vertex");
            Assert.IsNotNull(castGraph, "Failed to convert cast to Graph Vertex");

            //Generate an edge
            var movieRatingEdgeSingle  = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movie, rating, true) as IDictionary <string, object>;
            var movieRatingEdgeSingle2 = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movie, rating, true) as IDictionary <string, object>;

            Assert.IsNotNull(movieRatingEdgeSingle, "Failed to convert movie to Graph Vertex");
            Assert.IsNotNull(movieRatingEdgeSingle2, "Failed to convert movie to Graph Vertex");
            //Ensure all properties are present in the result
            AssertGraphEdgeHasBaseProperties(movieRatingEdgeSingle);
            //Ensure properties have proper values
            Assert.AreEqual($"{movieGraph["id"]}-{ratingGraph["id"]}", movieRatingEdgeSingle["id"], "id not matching");
            Assert.AreEqual(movieRating.GetType().Name, movieRatingEdgeSingle["label"], "label not matching");
            Assert.IsTrue(movieRatingEdgeSingle.ContainsKey("SiteName"), "Edge missing SiteName Property");
            Assert.AreEqual(movieRating.SiteName, movieRatingEdgeSingle["SiteName"], "SiteName not matching");
            AssertGraphEdgeValues(movieRatingEdgeSingle, movieGraph, ratingGraph);
            //Ensure that 2 single edges have the same Ids
            Assert.AreEqual(movieRatingEdgeSingle["id"], movieRatingEdgeSingle2["id"], "Ids for 2 single edges should match");

            var movieRatingEdgeMulti  = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movie, rating, false) as IDictionary <string, object>;
            var movieRatingEdgeMulti2 = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movie, rating, false) as IDictionary <string, object>;

            Assert.IsNotNull(movieRatingEdgeMulti, "Failed to convert movie to Graph Vertex");
            Assert.IsNotNull(movieRatingEdgeMulti2, "Failed to convert movie to Graph Vertex");
            //Ensure all properties are present in the result
            AssertGraphEdgeHasBaseProperties(movieRatingEdgeSingle);
            //Ensure properties have proper values
            Assert.AreEqual(movieRating.GetType().Name, movieRatingEdgeMulti["label"], "label not matching");
            Assert.IsTrue(movieRatingEdgeMulti.ContainsKey("SiteName"), "Edge missing SiteName Property");
            Assert.AreEqual(movieRating.SiteName, movieRatingEdgeMulti["SiteName"], "SiteName not matching");
            AssertGraphEdgeValues(movieRatingEdgeMulti, movieGraph, ratingGraph);
            //Ensure that when we don't request a single edge, that the ids generated are different every time.
            Assert.AreNotEqual(movieRatingEdgeMulti["id"], movieRatingEdgeMulti2["id"], "id should be dynamic");
        }
Ejemplo n.º 2
0
        public void GenerateGraphEdgeWithGraphItemBase()
        {
            //Initialize Objects
            var movieTitle         = "The Network";
            var movieGraphItemBase = new GraphItemBase {
                Id = "movieId", Label = "Movie", PartitionKey = movieTitle
            };
            var ratingItemBase = new GraphItemBase {
                Id = "ratingId", Label = "Rating", PartitionKey = movieTitle
            };
            var movieRating = new MovieRatingEdge {
                SiteName = "SiteName"
            };

            //Generate a single edge
            var movieRatingEdgeSingle  = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movieGraphItemBase, ratingItemBase, single: true) as IDictionary <string, object>;
            var movieRatingEdgeSingle2 = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movieGraphItemBase, ratingItemBase, single: true) as IDictionary <string, object>;

            Assert.IsNotNull(movieRatingEdgeSingle, "Failed to convert movie to Graph Vertex");
            Assert.IsNotNull(movieRatingEdgeSingle2, "Failed to convert movie to Graph Vertex");

            //Ensure all properties are present in the result
            AssertGraphEdgeHasBaseProperties(movieRatingEdgeSingle);
            //Ensure all property values match the inputs
            AssertGraphEdgeValues(movieRatingEdgeSingle, movieGraphItemBase, ratingItemBase);
            Assert.AreEqual($"{movieGraphItemBase.Id}-{ratingItemBase.Id}", movieRatingEdgeSingle["id"], "id not matching");
            Assert.AreEqual(movieRating.GetType().Name, movieRatingEdgeSingle["label"], "label not matching");
            Assert.IsTrue(movieRatingEdgeSingle.ContainsKey("SiteName"), "Edge missing SiteName Property");
            Assert.AreEqual(movieRating.SiteName, movieRatingEdgeSingle["SiteName"], "SiteName not matching");
            //Ensure that 2 single edges have the same Ids
            Assert.AreEqual(movieRatingEdgeSingle["id"], movieRatingEdgeSingle2["id"], "Ids for 2 single edges should match");


            //Generate a multi edge
            var movieRatingEdgeMulti1 = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movieGraphItemBase, ratingItemBase, false) as IDictionary <string, object>;
            var movieRatingEdgeMulti2 = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movieGraphItemBase, ratingItemBase, false) as IDictionary <string, object>;

            Assert.IsNotNull(movieRatingEdgeMulti1, "Failed to convert movie to Graph Vertex");
            Assert.IsNotNull(movieRatingEdgeMulti2, "Failed to convert movie to Graph Vertex");
            //Ensure all properties are present in the result
            AssertGraphEdgeHasBaseProperties(movieRatingEdgeMulti1);
            //Ensure all property values match the inputs
            AssertGraphEdgeValues(movieRatingEdgeMulti1, movieGraphItemBase, ratingItemBase);
            Assert.AreEqual(movieRating.GetType().Name, movieRatingEdgeMulti1["label"], "label not matching");
            Assert.IsTrue(movieRatingEdgeSingle.ContainsKey("SiteName"), "Edge missing SiteName Property");
            Assert.AreEqual(movieRating.SiteName, movieRatingEdgeSingle["SiteName"], "SiteName not matching");
            //Ensure that 2 multi edges have the different Ids
            Assert.AreNotEqual(movieRatingEdgeMulti1["id"], movieRatingEdgeMulti2["id"], "id should be dynamic");
        }