public async Task SendsCommandWithCorrectTimeout() { const string queryText = "MATCH n SET n.Value = 'value'"; const int expectedMaxExecutionTime = 100; var cypherQuery = new CypherQuery(queryText, new Dictionary <string, object>(), CypherResultMode.Set, CypherResultFormat.DependsOnEnvironment, "neo4j", maxExecutionTime: expectedMaxExecutionTime); var transactionApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot20() }, { MockRequest.PostObjectAsJson("/transaction/commit", transactionApiQuery), MockResponse.Http((int)HttpStatusCode.OK) } }) { var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri); var graphClient = new GraphClient(new Uri(testHarness.BaseUri), httpClient); await graphClient.ConnectAsync(); httpClient.ClearReceivedCalls(); await((IRawGraphClient)graphClient).ExecuteCypherAsync(cypherQuery); var call = httpClient.ReceivedCalls().Single(); var requestMessage = (HttpRequestMessage)call.GetArguments()[0]; var maxExecutionTimeHeader = requestMessage.Headers.Single(h => h.Key == "max-execution-time"); Assert.Equal(expectedMaxExecutionTime.ToString(CultureInfo.InvariantCulture), maxExecutionTimeHeader.Value.Single()); } }
public async Task DoesntSetHeaders_WhenNotSet() { const string queryText = "MATCH n SET n.Value = 'value'"; var cypherQuery = new CypherQuery(queryText, new Dictionary <string, object>(), CypherResultMode.Set, "neo4j"); var transactionApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot20() }, { MockRequest.PostObjectAsJson("/transaction/commit", transactionApiQuery), MockResponse.Http((int)HttpStatusCode.OK) } }) { var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri); var graphClient = new GraphClient(new Uri(testHarness.BaseUri), httpClient); await graphClient.ConnectAsync(); httpClient.ClearReceivedCalls(); await((IRawGraphClient)graphClient).ExecuteCypherAsync(cypherQuery); var call = httpClient.ReceivedCalls().Single(); var requestMessage = (HttpRequestMessage)call.GetArguments()[0]; Assert.False(requestMessage.Headers.Any(h => h.Key == "max-execution-time")); } }
public async Task PassesCorrectStreamHeader_WhenUseStreamIsTrue() { var httpClient = Substitute.For <IHttpClient>(); httpClient .SendAsync(Arg.Any <HttpRequestMessage>()) .Throws(new NotImplementedException()); var graphClient = new GraphClient(new Uri("http://*****:*****@foo/db/data"), httpClient); try { await graphClient.ConnectAsync(); } // ReSharper disable EmptyGeneralCatchClause catch (NotImplementedException) { // This will fail because we're not giving it the right // HTTP response, but we only care about the request for now } // ReSharper restore EmptyGeneralCatchClause var httpCall = httpClient.ReceivedCalls().Last(); var httpRequest = (HttpRequestMessage)httpCall.GetArguments()[0]; Assert.IsTrue(httpRequest.Headers.Contains("X-Stream")); Assert.Contains("true", httpRequest.Headers.GetValues("X-Stream").ToList()); }
public async Task CredentialsPreservedAllTheWayThroughToHttpStack() { var httpClient = Substitute.For <IHttpClient>(); httpClient .SendAsync(Arg.Any <HttpRequestMessage>()) .Throws(new NotImplementedException()); var graphClient = new GraphClient(new Uri("http://*****:*****@foo/db/data"), httpClient); try { await graphClient.ConnectAsync(); } // ReSharper disable EmptyGeneralCatchClause catch (NotImplementedException) { // This will fail because we're not giving it the right // HTTP response, but we only care about the request for now } // ReSharper restore EmptyGeneralCatchClause var httpCall = httpClient.ReceivedCalls().Last(); var httpRequest = (HttpRequestMessage)httpCall.GetArguments()[0]; StringAssert.AreEqualIgnoringCase("Basic", httpRequest.Headers.Authorization.Scheme); StringAssert.AreEqualIgnoringCase("dXNlcm5hbWU6cGFzc3dvcmQ=", httpRequest.Headers.Authorization.Parameter); }
public async Task PassesCorrectStreamHeader_WhenUseStreamIsTrue() { var httpClient = Substitute.For<IHttpClient>(); httpClient .SendAsync(Arg.Any<HttpRequestMessage>()) .Returns(callInfo => { throw new NotImplementedException(); }); var graphClient = new GraphClient(new Uri("http://*****:*****@foo/db/data"), httpClient); try { await graphClient.ConnectAsync(); } // ReSharper disable EmptyGeneralCatchClause catch (NotImplementedException) { // This will fail because we're not giving it the right // HTTP response, but we only care about the request for now } // ReSharper restore EmptyGeneralCatchClause var httpCall = httpClient.ReceivedCalls().Last(); var httpRequest = (HttpRequestMessage) httpCall.GetArguments()[0]; Assert.IsTrue(httpRequest.Headers.Contains("X-Stream")); Assert.Contains("true", httpRequest.Headers.GetValues("X-Stream").ToList()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <GraphConnection>(Configuration.GetSection("GraphConnection")); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <ApplicationDbContext>(); var neo4JClient = new GraphClient(new Uri($"{Configuration.GetSection("GraphConnection:Host").Value}:{Configuration.GetSection("GraphConnection:Port").Value}"), Configuration.GetSection("GraphConnection:User").Value, Configuration.GetSection("GraphConnection:Password").Value); neo4JClient.ConnectAsync().Wait(); services.AddSingleton <IGraphClient>(neo4JClient); var pool = new SingleNodeConnectionPool(new Uri(Configuration.GetSection("ElasticSearch:BaseUrl").Value)); var settings = new ConnectionSettings(pool).DefaultIndex("carshop"); var client = new ElasticClient(settings); services.AddSingleton(client); services.AddServices(lifetime: ServiceLifetime.Transient); services.AddControllersWithViews(); services.AddRazorPages(); }
private Neo4j() { string url = ConfigurationManager.AppSettings["neo4j-url"]; _client = new GraphClient(new Uri(url)); _client.ConnectAsync().Wait(); }
public async Task CredentialsPreservedAllTheWayThroughToHttpStack() { var httpClient = Substitute.For<IHttpClient>(); httpClient .SendAsync(Arg.Any<HttpRequestMessage>()) .Returns(callInfo => { throw new NotImplementedException(); }); var graphClient = new GraphClient(new Uri("http://*****:*****@foo/db/data"), httpClient); try { await graphClient.ConnectAsync(); } // ReSharper disable EmptyGeneralCatchClause catch (NotImplementedException) { // This will fail because we're not giving it the right // HTTP response, but we only care about the request for now } // ReSharper restore EmptyGeneralCatchClause var httpCall = httpClient.ReceivedCalls().Last(); var httpRequest = (HttpRequestMessage) httpCall.GetArguments()[0]; StringAssert.AreEqualIgnoringCase("Basic", httpRequest.Headers.Authorization.Scheme); StringAssert.AreEqualIgnoringCase("dXNlcm5hbWU6cGFzc3dvcmQ=", httpRequest.Headers.Authorization.Parameter); }
public async Task LoadGraphAsync(ObjectList graph) { using (var client = new GraphClient( new Uri(ConfigurationManager.AppSettings["neo4jUri"]), new HttpClientWrapper( ConfigurationManager.AppSettings["dbUser"], ConfigurationManager.AppSettings["dbPassword"], new HttpClient() { Timeout = TimeSpan.FromMinutes(20) }))) { await client.ConnectAsync(); await client.Cypher.Match("(n)").DetachDelete("n").ExecuteWithoutResultsAsync(); await client.Cypher .Unwind(graph.Objects, "object") .Merge("(o:Object {name:object.Name, type:object.Type})") .Set("o = object") .With("o, object") .Unwind("object.Dependencies", "Uses") .Merge("(o1:Object {name:Uses})") .Merge("(o)-[:USES]->(o1)") .With("o, object") .Unwind("object.Dependents", "UsedBy") .Merge("(o2:Object {name:UsedBy})") .Merge("(o2)<-[:USEDBY]-(o)") .ExecuteWithoutResultsAsync(); } }
//public ISession GetSession //{ // get // { // return _driver.Session(); // } //} public async Task <bool> Connect() { if (!_client.IsConnected) { await _client.ConnectAsync(); } return(_client.IsConnected); }
public async Task DoesntSendMaxExecutionTime_WhenNotAddedToQuery() { const string queryText = @"START d=node($p0), e=node($p1) MATCH p = allShortestPaths( d-[*..15]-e ) RETURN p"; var parameters = new Dictionary <string, object> { { "p0", 215 }, { "p1", 219 } }; var cypherQuery = new CypherQuery(queryText, parameters, CypherResultMode.Set, "neo4j"); var cypherApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot20() }, { MockRequest.PostObjectAsJson("/transaction/commit", cypherApiQuery), MockResponse.Json(HttpStatusCode.OK, @"{ 'data' : [ [ { 'start' : 'http://foo/db/data/node/215', 'nodes' : [ 'http://foo/db/data/node/215', 'http://foo/db/data/node/0', 'http://foo/db/data/node/219' ], 'length' : 2, 'relationships' : [ 'http://foo/db/data/relationship/247', 'http://foo/db/data/relationship/257' ], 'end' : 'http://foo/db/data/node/219' } ], [ { 'start' : 'http://foo/db/data/node/215', 'nodes' : [ 'http://foo/db/data/node/215', 'http://foo/db/data/node/1', 'http://foo/db/data/node/219' ], 'length' : 2, 'relationships' : [ 'http://foo/db/data/relationship/248', 'http://foo/db/data/relationship/258' ], 'end' : 'http://foo/db/data/node/219' } ] ], 'columns' : [ 'p' ] }") } }) { var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri); var graphClient = new GraphClient(new Uri(testHarness.BaseUri), httpClient); await graphClient.ConnectAsync(); httpClient.ClearReceivedCalls(); await((IRawGraphClient)graphClient).ExecuteGetCypherResultsAsync <object>(cypherQuery); var call = httpClient.ReceivedCalls().Single(); var requestMessage = (HttpRequestMessage)call.GetArguments()[0]; Assert.False(requestMessage.Headers.Any(h => h.Key == "max-execution-time")); } }
public static void RegisterRepository(this IServiceCollection service, string url, string user, string password) { var client = new GraphClient(new Uri(url), user, password); client.ConnectAsync(); service.AddSingleton <IGraphClient>(client); service.AddTransient <IBaseRepository, BaseRepository>(); }
public DatabaseFixture() { id++; var client = new GraphClient(new Uri("http://localhost:7474"), "neo4j", "123"); client.ConnectAsync().Wait(); Crud = new Crud(client); Crud.CleanDatabase().Wait(); }
static async Task Main(string[] args) { var client = new GraphClient(new Uri("http://localhost:7474"), "neo4j", "123"); client.ConnectAsync().Wait(); Crud crud = new Crud(client); await crud.CleanDatabase(); await crud.SavePet(new Animal { Name = "Happy Tails1", Sex = "Female", Specie = "Dog", Color = "White", Breed = "Lhasa Apso", Age = 13 }); }
public static IServiceCollection AddDatabaseNeo4J(this IServiceCollection services, IConfiguration configuration) { var config = configuration.GetSection("Neo4jConnectionSettings"); var neo4jClient = new GraphClient(new Uri(config.GetSection("Server").Value), config.GetSection("User").Value, config.GetSection("Pass").Value); neo4jClient.ConnectAsync().Wait(); services.AddSingleton <IGraphClient>(neo4jClient); return(services); }
static void Main(string[] args) { //https://github.com/neo4j-examples/movies-dotnet-neo4jclient //docker run --name testneo4j -p7474:7474 -p7687:7687 -d -v c:/neo4j/data:/data -v c:/neo4j/logs:/logs -v c:/neo4j/import:/var/lib/neo4j/import -v c:/neo4j/plugins:/plugins --env NEO4J_AUTH=neo4j/test neo4j:latest var url = "http://localhost:7474"; var user = "******"; var password = "******"; var client = new GraphClient(new Uri("http://localhost:7474"), "neo4j", "test"); client.ConnectAsync().Wait(); var yy = client.IsConnected; var query = client.Cypher.Match("(m:Movie)<-[:ACTED_IN]-(a:Person)") .Return((m, a) => new { movie = m.As <Movie>().title, cast = Return.As <string>("collect(a.name)") }).Limit(100); var data = query.ResultsAsync.Result.ToList(); //You can see the cypher query here when debugging var nodes = new List <NodeResult>(); var rels = new List <object>(); int i = 0, target; foreach (var item in data) { nodes.Add(new NodeResult { title = item.movie, label = "movie" }); target = i; i++; if (!string.IsNullOrEmpty(item.cast)) { var casts = JsonConvert.DeserializeObject <JArray>(item.cast); foreach (var cast in casts) { var source = nodes.FindIndex(c => c.title == cast.Value <string>()); if (source == -1) { nodes.Add(new NodeResult { title = cast.Value <string>(), label = "actor" }); source = i; i += 1; } rels.Add(new { source = source, target = target }); } } } var result = (new { nodes = nodes, links = rels }); Console.ReadKey(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.Configure <Neo4jDbSettings>(Configuration.GetSection("Neo4jDbSettings")); services.AddScoped <IGraphClient, GraphClient>(provider => { var options = provider.GetService <IOptions <Neo4jDbSettings> >(); var client = new GraphClient(new Uri(options.Value.uri), options.Value.username, options.Value.password); client.ConnectAsync().Wait(); return(client); }); services.AddNeo4jAnnotations <ApplicationContext>(); //services.AddNeo4jAnnotations(); services.AddIdentity <ApplicationUser, IdentityRole>(options => { //var dataProtectionPath = Path.Combine(HostingEnvironment.WebRootPath, "identity-artifacts"); //options.Cookies.ApplicationCookie.AuthenticationScheme = "ApplicationCookie"; //options.Cookies.ApplicationCookie.DataProtectionProvider = DataProtectionProvider.Create(dataProtectionPath); options.Lockout.AllowedForNewUsers = true; // User settings options.User.RequireUniqueEmail = true; }) .AddUserStore <UserStore <ApplicationUser> >() .AddRoleStore <RoleStore <IdentityRole> >() .AddDefaultTokenProviders(); //// Services used by identity ////services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme); //services.AddAuthentication(options => //{ // // This is the Default value for ExternalCookieAuthenticationScheme // options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; //new IdentityCookieOptions().ExternalCookieAuthenticationScheme; //}); // Hosting doesn't add IHttpContextAccessor by default services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddOptions(); services.AddDataProtection(); services.AddMvc(); // Add application services. services.AddTransient <IEmailSender, AuthMessageSender>(); services.AddTransient <ISmsSender, AuthMessageSender>(); services.AddApplicationInsightsTelemetry(); }
static IntegrationTest() { var connectionString = ConfigurationManager.AppSettings["Neo4jConnectionString"]; GraphClient = new GraphClient(new Uri(connectionString)); GraphClient.JsonConverters.Add(new AreaJsonConverter()); GraphClient.ConnectAsync().Wait(); NeoConfig.ConfigureModel(); }
public async Task ShouldParseRootApiResponseFromAuthenticatedConnection() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot() } }) { var httpClient = testHarness.GenerateHttpClient("http://foo/db/data"); var graphClient = new GraphClient(new Uri("http://*****:*****@foo/db/data"), httpClient); await graphClient.ConnectAsync(); Assert.AreEqual("/node", graphClient.RootApiResponse.Node); } }
static Task Main(string[] args) { return(Host.CreateDefaultBuilder(args) .ConfigureServices((context, services) => { services.AddLogging(builder => { builder.ClearProviders(); builder.AddSerilog(new LoggerConfiguration().WriteTo.Console().CreateLogger()); }); var neo4jConfiguration = new Neo4jConfiguration(); context.Configuration.Bind("neo4j", neo4jConfiguration); var neo4jClient = new GraphClient(new Uri(neo4jConfiguration.HttpEndpoint), neo4jConfiguration.Username, neo4jConfiguration.Password); neo4jClient.ConnectAsync(); services.AddSingleton <IGraphClient>(neo4jClient); services.AddHostedService <Neo4jService>(); }) .RunConsoleAsync()); }
public async Task ShouldSendCustomUserAgent() { // Arrange var httpClient = Substitute.For <IHttpClient>(); var graphClient = new GraphClient(new Uri("http://localhost"), httpClient); var expectedUserAgent = graphClient.ExecutionConfiguration.UserAgent; httpClient .SendAsync(Arg.Do <HttpRequestMessage>(message => { // Assert Assert.IsTrue(message.Headers.Contains("User-Agent"), "Contains User-Agent header"); var userAgent = message.Headers.GetValues("User-Agent").Single(); Assert.AreEqual(expectedUserAgent, userAgent, "User-Agent header value is correct"); })) .Returns(ci => { var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ 'cypher' : 'http://foo/db/data/cypher', 'batch' : 'http://foo/db/data/batch', 'node' : 'http://foo/db/data/node', 'node_index' : 'http://foo/db/data/index/node', 'relationship_index' : 'http://foo/db/data/index/relationship', 'reference_node' : 'http://foo/db/data/node/123', 'neo4j_version' : '1.5.M02', 'extensions_info' : 'http://foo/db/data/ext', 'extensions' : { 'GremlinPlugin' : { 'execute_script' : 'http://foo/db/data/ext/GremlinPlugin/graphdb/execute_script' } } }") }; var task = new Task <HttpResponseMessage>(() => response); task.Start(); return(task); }); // Act await graphClient.ConnectAsync(); }
public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) { try { using (var connection = new GraphClient(new Uri(_connectionString), _username, _password)) { await connection.ConnectAsync(); if (!connection.IsConnected) { return(new HealthCheckResult(context.Registration.FailureStatus, description: $"The {nameof(Neo4jHealthCheck)} check fail.")); } } return(HealthCheckResult.Healthy()); } catch (Exception ex) { return(new HealthCheckResult(context.Registration.FailureStatus, exception: ex)); } }
public void ShouldFireOnCompletedEvenWhenException() { var httpClient = Substitute.For <IHttpClient>(); httpClient .SendAsync(Arg.Any <HttpRequestMessage>()) .Throws(new NotImplementedException()); var graphClient = new GraphClient(new Uri("http://foo/db/data"), httpClient); OperationCompletedEventArgs operationCompletedArgs = null; graphClient.OperationCompleted += (s, e) => { operationCompletedArgs = e; }; // act Assert.Throws <AggregateException>(() => graphClient.ConnectAsync().Wait()); Assert.NotNull(operationCompletedArgs); Assert.That(operationCompletedArgs.HasException); Assert.AreEqual(typeof(NotImplementedException), operationCompletedArgs.Exception.GetType()); }
public void ConfigureServices(IServiceCollection services) { services.AddControllers().AddNewtonsoftJson(options => { options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }); services.AddCors(options => options.AddPolicy("CorsPolicy", builder => builder .WithOrigins("http://localhost:4200", "http://localhost:4201") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() )); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("AppSettings:Secret").Value)), ValidateIssuer = false, ValidateAudience = false }; }); var neo4jClient = new GraphClient(new Uri("http://localhost:7474"), "neo4j", "neo4"); Task task = Task.Run(async() => await neo4jClient.ConnectAsync()); task.Wait(); services.AddSingleton <IGraphClient>(neo4jClient); services.AddScoped <IAuthentication, Authentication>(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //var client = new GraphClient(new Uri("bolt://localhost:7687"), "neo4j", "123"); var client = new GraphClient(new Uri("http://localhost:7474"), "neo4j", "123"); client.ConnectAsync().Wait(); var createQuery = client.Cypher .Create("(j:Book {Title: 'debora test', PageCount:250})<-[rel:HAS_BOOK]-(m:Person {Name: 'John Doe'})") .Return((j, m) => new { Book = j.As <Book>(), Person = m.As <Person>(), }).ResultsAsync; foreach (var item in createQuery.Result) { Console.WriteLine(item.Book.Title); } //var test = new ConnectCoolWay(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); var neo4jClient = new GraphClient(new Uri("http://localhost:7474/"), "neo4j", "sharetolearn"); neo4jClient.ConnectAsync(); services.AddSingleton <IGraphClient>(neo4jClient); services.AddSingleton <IRedisConnectionBuilder, RedisConnectionBuilder>(); services.AddScoped <IMessageRepository, MessageRepository>(); services.AddScoped <IDocumentRepository, DocumentRepository>(); services.AddScoped <IPostRepository, PostRepository>(); services.AddScoped <IStudentRepository, StudentRepository>(); services.AddScoped <IGroupRepository, GroupRepository>(); services.AddScoped <ISharedRepository, SharedRepository>(); services.AddMvc().AddJsonOptions(options => { options.JsonSerializerOptions.WriteIndented = true; options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; }).AddMvcOptions(options => { options.EnableEndpointRouting = false; }); services.AddCors(options => { options.AddPolicy("CORS", builder => { builder.AllowAnyHeader() .AllowAnyMethod() .SetIsOriginAllowed((host) => true) .AllowCredentials(); }); }); services.AddSignalR(options => { options.EnableDetailedErrors = true; }); }
public async Task ShouldParseRootApiResponseFromA4xServer() { // Arrange var httpClient = Substitute.For <IHttpClient>(); var graphClient = new GraphClient(new Uri("http://*****:*****@"{ 'bolt_direct': 'neo4j://localhost:7687/bolt', 'bolt_routing': 'neo4j://localhost:7687/route', 'cluster': 'http://localhost:7474/db/{databaseName}/cluster', 'transaction': 'http://localhost:7474/db/{databaseName}/tx', 'neo4j_version': '4.0.0', 'neo4j_edition': 'enterprise' }") }; var task = new Task <HttpResponseMessage>(() => response); task.Start(); return(task); }); // Act await graphClient.ConnectAsync(); graphClient.RootApiResponse.BoltDirect.Should().Be("neo4j://localhost:7687/bolt"); graphClient.RootApiResponse.BoltRouting.Should().Be("neo4j://localhost:7687/route"); graphClient.RootApiResponse.Cluster.Should().Be("/db/{databaseName}/cluster"); graphClient.RootApiResponse.Transaction.Should().Be("/db/{databaseName}/tx"); graphClient.RootApiResponse.Neo4jVersion.Should().Be("4.0.0"); graphClient.RootApiResponse.Neo4jEdition.Should().Be("enterprise"); }
public async Task ShouldParseRootApiResponseFromAuthenticatedConnection() { using (var testHarness = new RestTestHarness { {MockRequest.Get(""), MockResponse.NeoRoot()} }) { var httpClient = testHarness.GenerateHttpClient("http://foo/db/data"); var graphClient = new GraphClient(new Uri("http://*****:*****@foo/db/data"), httpClient); await graphClient.ConnectAsync(); Assert.AreEqual("/node", graphClient.RootApiResponse.Node); } }
public Neo4jWriter(Uri uri) { client = new GraphClient(uri); client.ConnectAsync().Wait(); }
public Neo4JExperimental(string host, string port, string login, string password) { _client = new GraphClient(new Uri($"http://{host}:{port}/db/data"), login, password); _client.ConnectAsync().GetAwaiter().GetResult(); }
public async Task Initialise() { client = new GraphClient(new Uri("http://localhost:7474/"), "neo4j", "pass"); await client.ConnectAsync(); }
public Neo4jRepository() { client = new GraphClient(new Uri("http://localhost:7474/db/SocialNetwork")); client.ConnectAsync(); }
public void ShouldFireOnCompletedEvenWhenException() { var httpClient = Substitute.For<IHttpClient>(); httpClient .SendAsync(Arg.Any<HttpRequestMessage>()) .Returns(callInfo => { throw new NotImplementedException(); }); var graphClient = new GraphClient(new Uri("http://foo/db/data"), httpClient); OperationCompletedEventArgs operationCompletedArgs = null; graphClient.OperationCompleted += (s, e) => { operationCompletedArgs = e; }; // act Assert.Throws<AggregateException>(() => graphClient.ConnectAsync().Wait()); Assert.NotNull(operationCompletedArgs); Assert.That(operationCompletedArgs.HasException); Assert.AreEqual(typeof(NotImplementedException), operationCompletedArgs.Exception.GetType()); }
public DALNeo4j() { client = new GraphClient(new Uri("http://localhost:7474/db/data/"), "Maria", "12345"); client.ConnectAsync(); }
public async Task ShouldSendCustomUserAgent() { // Arrange var httpClient = Substitute.For<IHttpClient>(); var graphClient = new GraphClient(new Uri("http://localhost"), httpClient); var expectedUserAgent = graphClient.ExecutionConfiguration.UserAgent; httpClient .SendAsync(Arg.Do<HttpRequestMessage>(message => { // Assert Assert.IsTrue(message.Headers.Contains("User-Agent"), "Contains User-Agent header"); var userAgent = message.Headers.GetValues("User-Agent").Single(); Assert.AreEqual(expectedUserAgent, userAgent, "User-Agent header value is correct"); })) .Returns(ci => { var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ 'cypher' : 'http://foo/db/data/cypher', 'batch' : 'http://foo/db/data/batch', 'node' : 'http://foo/db/data/node', 'node_index' : 'http://foo/db/data/index/node', 'relationship_index' : 'http://foo/db/data/index/relationship', 'reference_node' : 'http://foo/db/data/node/123', 'neo4j_version' : '1.5.M02', 'extensions_info' : 'http://foo/db/data/ext', 'extensions' : { 'GremlinPlugin' : { 'execute_script' : 'http://foo/db/data/ext/GremlinPlugin/graphdb/execute_script' } } }") }; var task = new Task<HttpResponseMessage>(() => response); task.Start(); return task; }); // Act await graphClient.ConnectAsync(); }