Пример #1
0
        public void GenerateGraphVertexFromModelWithNoPartitionKey()
        {
            var movie = MovieNoAttributes.GetTestModel("The Network");

            CosmosEntitySerializer.Default.ToGraphVertex(movie);
        }
Пример #2
0
        public void GenerateGraphVertexFromModelWithNoAttributesProvidingId()
        {
            var movie = MovieNoAttributes.GetTestModel("The Network");

            Assert.ThrowsException <Exception>(() => CosmosEntitySerializer.Default.ToGraphVertex(movie));

            //Using the
            var movieGraph = CosmosEntitySerializer.Default.ToGraphVertex(movie, pkProperty: model => model.Title, idProp: model => movie.MovieId) as IDictionary <string, object>;

            Assert.IsNotNull(movieGraph, "Failed to convert to Graph Vertex");

            //Test that properties are present in the output document
            var errors = new List <string>();

            if (!movieGraph.ContainsKey("id"))
            {
                errors.Add("Document missing Id property");
            }
            if (!movieGraph.ContainsKey("label"))
            {
                errors.Add("Document missing Label property");
            }
            if (!movieGraph.ContainsKey(PartitionKeyPropertyName))
            {
                errors.Add("Document missing PartitionKey property");
            }
            if (!movieGraph.ContainsKey("Budget"))
            {
                errors.Add("Document missing Budget property");
            }
            if (!movieGraph.ContainsKey("ReleaseDate"))
            {
                errors.Add("Document missing ReleaseDate property");
            }
            if (!movieGraph.ContainsKey("Runtime"))
            {
                errors.Add("Document missing Runtime property");
            }
            if (!movieGraph.ContainsKey("Rating"))
            {
                errors.Add("Document missing Rating property");
            }
            if (!movieGraph.ContainsKey("Cast"))
            {
                errors.Add("Document missing Cast property");
            }

            Assert.IsFalse(errors.Any(), string.Join(Environment.NewLine, errors.ToArray()));
            Assert.AreEqual(10, movieGraph.Keys.Count(), "Document has extra properties");

            //Test values
            Assert.AreEqual(movie.MovieId, movieGraph["id"], "id not matching");
            Assert.AreEqual(movie.GetType().Name, movieGraph["label"], "label not matching");
            Assert.AreEqual(movie.Title, movieGraph[PartitionKeyPropertyName], "partitionKey not matching");

            AssertGraphProperty(JsonConvert.SerializeObject(movie.Rating), movieGraph, "Rating");
            AssertGraphProperty(JsonConvert.SerializeObject(movie.Cast), movieGraph, "Cast");
            AssertGraphProperty(movie.MovieId, movieGraph, "MovieId");
            AssertGraphProperty(movie.Title, movieGraph, "Title");

            AssertGraphProperty(movie.Budget, movieGraph, "Budget");
            AssertGraphProperty(movie.ReleaseDate, movieGraph, "ReleaseDate");
            AssertGraphProperty(movie.Runtime, movieGraph, "Runtime");
        }
Пример #3
0
        public void GenerateCosmosDocumentFromModelWithNoPartitionKey()
        {
            var movie = MovieNoAttributes.GetTestModel("The Network");

            CosmosEntitySerializer.Default.ToCosmosDocument(movie);
        }