-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathExceptionTests.cs
99 lines (91 loc) · 3.29 KB
/
ExceptionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using System;
using Tests.Framework;
using Tests.Framework.Integration;
using Tests.Framework.MockData;
using Xunit;
namespace Tests.ClientConcepts.Exceptions
{
[Collection(IntegrationContext.Indexing)]
public class ExceptionTests
{
private readonly int _port;
public ExceptionTests(IndexingCluster cluster, EndpointUsage usage)
{
_port = cluster.Node.Port;
}
[I]
public void ServerTestWhenThrowExceptionsEnabled()
{
var settings = new ConnectionSettings(new Uri($"http://{TestClient.Host}:{_port}"))
.ThrowExceptions();
var client = new ElasticClient(settings);
var exception = Assert.Throws<ElasticsearchClientException>(() => client.GetMapping<Project>(s => s.Index("doesntexist")));
#if DOTNETCORE
// HttpClient does not throw on "known error" status codes (i.e. 404) thus the inner exception should not be set
exception.InnerException.Should().BeNull();
#else
exception.InnerException.Should().NotBeNull();
#endif
exception.Response.Should().NotBeNull();
exception.Response.ServerError.Should().NotBeNull();
exception.Response.ServerError.Status.Should().BeGreaterThan(0);
}
[I]
public void ClientTestWhenThrowExceptionsEnabled()
{
var settings = new ConnectionSettings(new Uri("http://doesntexist:9200"))
.ThrowExceptions();
var client = new ElasticClient(settings);
var exception = Assert.Throws<ElasticsearchClientException>(() => client.RootNodeInfo());
var inner = exception.InnerException;
#if DOTNETCORE
// HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set
inner.Should().BeNull();
#else
inner.Should().NotBeNull();
#endif
}
[I]
public void ServerTestWhenThrowExceptionsDisabled()
{
var settings = new ConnectionSettings(new Uri($"http://{TestClient.Host}:{_port}"));
var client = new ElasticClient(settings);
var response = client.GetMapping<Project>(s => s.Index("doesntexist"));
#if DOTNETCORE
// HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set
response.CallDetails.OriginalException.Should().BeNull();
#else
response.CallDetails.OriginalException.Should().NotBeNull();
#endif
response.CallDetails.ServerError.Should().NotBeNull();
response.CallDetails.ServerError.Status.Should().BeGreaterThan(0);
}
[I]
public void ClientTestWhenThrowExceptionsDisabled()
{
var settings = new ConnectionSettings(new Uri("http://doesntexist:9200"));
var client = new ElasticClient(settings);
var response = client.RootNodeInfo();
#if DOTNETCORE
// HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set
response.CallDetails.OriginalException.Should().BeNull();
#else
response.CallDetails.OriginalException.Should().NotBeNull();
#endif
response.CallDetails.ServerError.Should().BeNull();
}
[U]
public void DispatchIndicatesMissingRouteValues()
{
var settings = new ConnectionSettings(new Uri("http://doesntexist:9200"));
var client = new ElasticClient(settings);
Action dispatch = () => client.Index(new Project());
var ce = dispatch.ShouldThrow<ArgumentException>();
ce.Should().NotBeNull();
ce.Which.Message.Should().Contain("index=<NULL>");
}
}
}