public Neo4jDataService() { Client = new BoltGraphClient(new Uri(ServerAddress), User, Password); Client.Connect(); }
public void SerializesGuidsProperlyWhenAutoGeneratingParams() { var mockSession = new Mock <ISession>(); mockSession.Setup(s => s.Run("CALL dbms.components()")).Returns(new ServerInfo()); var mockDriver = new Mock <IDriver>(); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>())).Returns(mockSession.Object); mockDriver.Setup(d => d.Uri).Returns(new Uri("bolt://localhost")); var bgc = new BoltGraphClient(mockDriver.Object); bgc.Connect(); var cwg = new ClassWithGuid(); bgc.Cypher.Create("(c)").Where((ClassWithGuid c) => c.Id == cwg.Id).ExecuteWithoutResults(); var expectedParameters = new Dictionary <string, object> { { "p0", $"\"{cwg.Id}\"" } }; mockSession.Verify(x => x.Run("CREATE (c)\r\nWHERE (c.Id = {p0})", It.Is <IDictionary <string, object> >(c => CompareDictionaries(c, expectedParameters))), Times.Once); }
public void SerializesGuidsProperly() { var mockSession = new Mock <ISession>(); mockSession.Setup(s => s.Run("CALL dbms.components()")).Returns(new ServerInfo()); var mockDriver = new Mock <IDriver>(); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>())).Returns(mockSession.Object); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>(), It.IsAny <IEnumerable <string> >())).Returns(mockSession.Object); mockDriver.Setup(d => d.Uri).Returns(new Uri("bolt://localhost")); var bgc = new BoltGraphClient(mockDriver.Object); bgc.Connect(); var cwg = new ClassWithGuid(); var cfq = bgc.Cypher.Create("(c)").WithParam("testParam", cwg); var expectedParameters = new Dictionary <string, object> { { "testParam", new Dictionary <string, object> { { "Id", cwg.Id.ToString() } } } }; var query = cfq.Query; CompareDictionaries(query.ToNeo4jDriverParameters(bgc), expectedParameters).Should().BeTrue(); }
public List <long> CalcDepth(int depth) { List <long> esecList = new List <long>(); using (var client = new BoltGraphClient("bolt://localhost:7687", "neo4j", "test1234")) { client.Connect(); for (int i = 0; i < RandomIdList.Count; i++) { stopwatch.Reset(); stopwatch.Start(); var query = client.Cypher .Match("(a:person {pid:" + RandomIdList[i] + "})-[:Endorsments*1.." + depth + "]->(b:person)") .Return((b) => new { Person = b.As <PersonCLR>() }); var res = query.Results; stopwatch.Stop(); esecList.Add(stopwatch.ElapsedMilliseconds); //I've left this line of code inhere should you want to verify //System.Console.WriteLine($"\nFound relationships : {res.Count()} for person with id : {RandomIdList[i]}" ); } } return(esecList); }
public void SerializesDateTimesProperly() { var mockSession = new Mock <ISession>(); mockSession.Setup(s => s.Run("CALL dbms.components()")).Returns(new ServerInfo()); var mockDriver = new Mock <IDriver>(); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>())).Returns(mockSession.Object); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>(), It.IsAny <IEnumerable <string> >())).Returns(mockSession.Object); mockDriver.Setup(d => d.Uri).Returns(new Uri("bolt://localhost")); var bgc = new BoltGraphClient(mockDriver.Object); bgc.Connect(); var cwd = new ClassWithDateTime { Dt = new DateTime(2000, 1, 1) };; var cfq = bgc.Cypher.Create("(c)").WithParam("testParam", cwd); var expectedParameters = new Dictionary <string, object> { { "testParam", new Dictionary <string, object> { { "Dt", JsonConvert.SerializeObject(cwd.Dt).Trim('\"') } } } }; var query = cfq.Query; query.ToNeo4jDriverParameters(bgc).IsEqualTo(expectedParameters).Should().BeTrue(); }
public void SerializesGuidsProperlyWhenAutoGeneratingParams() { var mockSession = new Mock <ISession>(); mockSession.Setup(s => s.Run("CALL dbms.components()")).Returns(new ServerInfo()); var mockDriver = new Mock <IDriver>(); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>())).Returns(mockSession.Object); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>(), It.IsAny <IEnumerable <string> >())).Returns(mockSession.Object); mockDriver.Setup(d => d.Uri).Returns(new Uri("bolt://localhost")); var bgc = new BoltGraphClient(mockDriver.Object); bgc.Connect(); var cwg = new ClassWithGuid(); var cfq = bgc.Cypher.Create("(c)").Where((ClassWithGuid c) => c.Id == cwg.Id); var expectedParameters = new Dictionary <string, object> { { "p0", $"{cwg.Id}" } }; var query = cfq.Query; query.ToNeo4jDriverParameters(bgc).IsEqualTo(expectedParameters).Should().BeTrue(); }
//[Description("test bolt part of https://github.com/Readify/Neo4jClient/issues/336 https://github.com/Readify/Neo4jClient/pull/337 - see UserSuppliedSerializationTests for https part")] public void JsonSerializerShouldNotSerializeNeo4JIgnoreAttribute() { var mockSession = new Mock <ISession>(); mockSession.Setup(s => s.Run("CALL dbms.components()")).Returns(new ServerInfo()); var mockDriver = new Mock <IDriver>(); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>())).Returns(mockSession.Object); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>(), It.IsAny <IEnumerable <string> >())).Returns(mockSession.Object); mockDriver.Setup(d => d.Uri).Returns(new Uri("bolt://localhost")); var bgc = new BoltGraphClient(mockDriver.Object); bgc.Connect(); var cwa = new ClasseWithSomeNeo4JIgnoreAttributes() { Text = "foo", TextIgnore = "fooignore", TestInt = 42, TestNeo4jIntIgnore = 42, TestJsonIntgnore = 42 }; var cfq = bgc.Cypher.Create("(c)").WithParam("testParam", cwa); var expectedParameters = new Dictionary <string, object> { { "testParam", new Dictionary <string, object> { { "Text", "foo" }, { "TestInt", 42 } } } }; var query = cfq.Query; query.ToNeo4jDriverParameters(bgc).IsEqualTo(expectedParameters).Should().BeTrue(); }
public void SerializesDateTimesProperly() { var mockSession = new Mock <ISession>(); mockSession.Setup(s => s.Run("CALL dbms.components()")).Returns(new ServerInfo()); var mockDriver = new Mock <IDriver>(); mockDriver.Setup(d => d.Session(It.IsAny <AccessMode>())).Returns(mockSession.Object); mockDriver.Setup(d => d.Uri).Returns(new Uri("bolt://localhost")); var bgc = new BoltGraphClient(mockDriver.Object); bgc.Connect(); var cwd = new ClassWithDateTime { Dt = new DateTime(2000, 1, 1) };; bgc.Cypher.Create("(c)").WithParam("testParam", cwd).ExecuteWithoutResults(); var expectedParameters = new Dictionary <string, object> { { "testParam", new Dictionary <string, object> { { "Dt", JsonConvert.SerializeObject(cwd.Dt).Trim('\"') } } } }; mockSession.Verify(x => x.Run("CREATE (c)", It.Is <IDictionary <string, object> >(c => CompareDictionaries(c, expectedParameters))), Times.Once); }
public IRawGraphClient CreateAndConnectBoltGraphClient() { var bgc = new BoltGraphClient(MockDriver.Object); bgc.Connect(); return(bgc); }
public Neo4jConnector(IOptions <Neo4jOptions> options) { var opt = options.Value; var driver = GraphDatabase.Driver(opt.Uri, AuthTokens.Basic(opt.User, opt.Password)); _neo4j = new BoltGraphClient(driver); _neo4j.Connect(); }
static void Main(string[] args) { //New Bolt Graph Client var graphClient = new BoltGraphClient("bolt://localhost:7687/", "neo4j", "Myneo4j"); graphClient.Connect(); //Store the data from the DataProvider StoreData(graphClient, GetDataProvider()); Console.WriteLine("Done!"); }
private static void GetAndConnectGraphClient(out IGraphClient graphClient, out IDriver driver, out ISession session, out Neo4j.Driver.V1.ITransaction transaction) { GetDriverAndSession(out driver, out session, out transaction); var client = new BoltGraphClient(driver); client.Connect(); driver.ClearReceivedCalls(); session.ClearReceivedCalls(); graphClient = client; }
//register connect with graph client private void RegisterGraphClient(IServiceCollection services) { services.AddScoped(typeof(IGraphClient), resolver => { var neo4JSetting = Configuration.GetSection("Neo4j").Get <Data.Neo4j>(); var client = new BoltGraphClient( new Uri(neo4JSetting.Uri), neo4JSetting.User, neo4JSetting.Password); client.Connect(); return(client); }); }
public GraphDbContext() { var url = ConfigurationManager.AppSettings["GraphDBUrl"]; var user = ConfigurationManager.AppSettings["GraphDBUser"]; var password = ConfigurationManager.AppSettings["GraphDBPassword"]; var driver = GraphDatabase.Driver(url, AuthTokens.Basic(user, password), Config.Builder.WithEncryptionLevel(EncryptionLevel.None).ToConfig()); //Pass that driver to the BoltGraphClient var bgc = new BoltGraphClient(driver); //Connect. bgc.Connect(); GraphClient = bgc; }
public void Setup() { Driver = GraphDatabase.Driver("bolt://localhost:7687"); using (var session = Driver.Session()) { session.Run(Query.CreateMovies); } GraphClient = new GraphClient(new Uri("http://localhost:7474/db/data")); GraphClient.Connect(); BoltGraphClient = new BoltGraphClient(new Uri("bolt://localhost:7687")); BoltGraphClient.Connect(); }
public static IServiceCollection AddGraphDependencies(this IServiceCollection services, IConfiguration configuration) { services.Configure <Neo4jConfig>(configuration.GetSection("Neo4jConfig")); services.AddScoped(typeof(IGraphClient), provider => { var options = provider.GetService <IOptions <Neo4jConfig> >(); var client = new BoltGraphClient(new Uri(options.Value.uri), username: options.Value.username, password: options.Value.password); client.Connect(); return(client); }); return(services); }
public static BoltGraphClient Connection() { //Host_Name = "bolt://localhost:7687"; //User_Name = "neo4j"; //Password = "******"; //sanboxNeo4j Host_Name = "bolt://3.89.155.201:33737"; User_Name = "neo4j"; Password = "******"; var client = new BoltGraphClient(new Uri(Host_Name), User_Name, Password); { var JsonContractResolver = new CamelCasePropertyNamesContractResolver(); }; client.Connect(); return(client); }
static BoltGraphClient CoreGetGraphClient() { Uri uri = new Uri($"bolt+routing://{neo4jIP}:{neo4jPort}"); BoltGraphClient client = new BoltGraphClient(uri, neo4jLogin, neo4jPassword); int counter = 0; while (!client.IsConnected) { try { client.Connect(); } catch { if (counter++ > 10) { break; } } } return(client); }
public static BoltGraphClient GetClient() { if (client == null) { IDriver driver = GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.Basic("neo4j", "1234"), Config.Builder.WithEncryptionLevel(EncryptionLevel.None).ToConfig()); client = new BoltGraphClient(driver: driver); client.Connect(); var query1 = new Neo4jClient.Cypher.CypherQuery("MATCH (n:PocetniID) where n.ID=1 return n.ID", new Dictionary <string, object>(), CypherResultMode.Set); List <int> pom = ((IRawGraphClient)client).ExecuteGetCypherResults <int>(query1).ToList(); if (pom != null && pom.Count == 0) { var query = new Neo4jClient.Cypher.CypherQuery("CREATE (n:PocetniID {ID:" + 1 + "}) return n", new Dictionary <string, object>(), CypherResultMode.Set); ((IRawGraphClient)client).ExecuteCypher(query); } } return(client); }
public DbConnection() { Neo4jClient = new BoltGraphClient("bolt://localhost:11002", "neo4j", "watchtime"); Neo4jClient.Connect(); }