public void ValuesAreRight() { Assert.AreEqual( true, GraphValue.BuildBoolValue(true).BoolValue); Assert.AreEqual( new byte[] { 0x20, 0x20, 0x20 }, GraphValue.BuildBytesValue(new byte[] { 0x20, 0x20, 0x20 }).Bytesvalue); var now = DateTime.Now; Assert.AreEqual( Encoding.UTF8.GetBytes( now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo)), GraphValue.BuildDateValue( Encoding.UTF8.GetBytes( now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo))).DateValue); var valNow = GraphValue.BuildDateValue(now); Assert.AreEqual( now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo), Encoding.UTF8.GetString(valNow.DateValue, 0, valNow.DateValue.Length)); Assert.AreEqual( "blaa", GraphValue.BuildDefaultValue("blaa").DefaultValue); Assert.AreEqual( 123, GraphValue.BuildDoubleValue(123).DoubleValue); Assert.AreEqual( Encoding.UTF8.GetBytes("{'type':'Point','coordinates':[-122.4220186,37.772318]}"), GraphValue.BuildGeoValue( Encoding.UTF8.GetBytes("{'type':'Point','coordinates':[-122.4220186,37.772318]}")).GeoValue); var geojson = "{'type':'Point','coordinates':[-122.4220186,37.772318]}"; var geojsonVal = GraphValue.BuildGeoValue(geojson); Assert.AreEqual( geojson, Encoding.UTF8.GetString(geojsonVal.GeoValue, 0, geojsonVal.GeoValue.Length)); Assert.AreEqual( 123, GraphValue.BuildIntValue(123).IntValue); Assert.AreEqual( "secret", GraphValue.BuildPasswordValue("secret").PasswordValue); Assert.AreEqual( "something", GraphValue.BuildStringValue("something").StringValue); }
public void ValuesAreRightType() { Assert.IsTrue(GraphValue.BuildBoolValue(true).IsBoolValue); Assert.IsTrue(GraphValue.BuildBytesValue(new byte[] { 0x20, 0x20, 0x20 }).IsBytesValue); Assert.IsTrue(GraphValue.BuildDateValue( Encoding.UTF8.GetBytes( DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo))) .IsDateValue); Assert.IsTrue(GraphValue.BuildDateValue(DateTime.Now).IsDateValue); Assert.IsTrue(GraphValue.BuildDefaultValue("blaa").IsDefaultValue); Assert.IsTrue(GraphValue.BuildDoubleValue(123).IsDoubleValue); Assert.IsTrue(GraphValue.BuildGeoValue( Encoding.UTF8.GetBytes("{'type':'Point','coordinates':[-122.4220186,37.772318]}")) .IsGeoValue); Assert.IsTrue(GraphValue.BuildGeoValue("{'type':'Point','coordinates':[-122.4220186,37.772318]}").IsGeoValue); Assert.IsTrue(GraphValue.BuildIntValue(123).IsIntValue); Assert.IsTrue(GraphValue.BuildPasswordValue("secret").IsPasswordValue); Assert.IsTrue(GraphValue.BuildStringValue("something").IsStringValue); }
public void MutationContainsAllSubmittedEdges() { List <Edge> edges = new List <Edge>(); List <Property> properties = new List <Property>(); var transaction = Substitute.For <ITransactionWithMutations>(); IMutation mut = new Mutation(); for (int i = 0; i < 10; i++) { edges.Add(new Edge(new NamedNode((ulong)i, "N" + i), "AnEdge", new NamedNode((ulong)i + 1, "N" + i))); properties.Add(new Property(new NamedNode((ulong)i, "N" + i), "AnEdge", GraphValue.BuildIntValue(i))); } for (int i = 0; i < 5; i++) { mut.AddEdge(edges[i]); mut.AddProperty(properties[i]); } for (int i = 5; i < 10; i++) { mut.DeleteEdge(edges[i]); mut.DeleteProperty(properties[i]); } transaction.When(x => x.ApiMutate(Arg.Any <Api.Mutation>())) .Do(x => { Assert.True(AllEdgesInMutation(edges, x.Arg <Api.Mutation>())); }); mut.SubmitTo(transaction); }
private Task ProcessUsers(IDgraphBatchingClient client) { return(Task.Run(() => { // Each line in the user file looks like // // userID|age|genre|occupation|ZIPcode // // We'll use a node named "user<userID>" to identify each user node using (FileStream fs = new FileStream(userFile, FileMode.Open)) { using (StreamReader users = new StreamReader(fs)) { string line; while ((line = users.ReadLine()) != null) { Interlocked.Increment(ref numProcessed); var split = line.Split(new char[] { '|' }); if (split.Length == 5 && long.TryParse(split[1], out long age)) { var node = client.GetOrCreateNode("user" + split[0]); if (node.IsSuccess) { var ageEdge = Clients.BuildProperty(node.Value, "age", GraphValue.BuildIntValue(age)); var gender = Clients.BuildProperty(node.Value, "gender", GraphValue.BuildStringValue(split[2])); var occupation = Clients.BuildProperty(node.Value, "occupation", GraphValue.BuildStringValue(split[3])); var zipcode = Clients.BuildProperty(node.Value, "zipcode", GraphValue.BuildStringValue(split[4])); if (ageEdge.IsSuccess && gender.IsSuccess && occupation.IsSuccess && zipcode.IsSuccess) { client.BatchAddProperty(ageEdge.Value); client.BatchAddProperty(gender.Value); client.BatchAddProperty(occupation.Value); client.BatchAddProperty(zipcode.Value); } } } } } } })); }