public async Task Call_ValidateUnsuccessfulResponse() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var task = httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); var error = new DaprError() { ErrorCode = "ERR_STATE_STORE", Message = "State Store Error" }; var message = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(JsonSerializer.Serialize(error)) }; entry.Completion.SetResult(message); await FluentActions.Awaiting(async() => await task).Should().ThrowAsync <DaprApiException>(); }
public void Call_WithoutApiToken() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var task = httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); entry.Request.Headers.TryGetValues("dapr-api-token", out var headerValues); headerValues.Should().BeNull(); }
public void Call_WithApiTokenEnvVar() { Environment.SetEnvironmentVariable("DAPR_API_TOKEN", "test_token"); var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var task = httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); entry.Request.Headers.TryGetValues("dapr-api-token", out var headerValues); headerValues.Count().Should().Be(1); headerValues.First().Should().Be("test_token"); }
public async Task Call_ValidateUnauthorizedResponse() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var task = httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); var message = new HttpResponseMessage(HttpStatusCode.Unauthorized); entry.Completion.SetResult(message); await FluentActions.Awaiting(async() => await task).Should().ThrowAsync <AuthenticationException>(); }
public void UnregisterTimer_ValidateRequest() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var task = httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); var actualPath = entry.Request.RequestUri.LocalPath.TrimStart('/'); var expectedPath = string.Format(CultureInfo.InvariantCulture, Constants.ActorTimerRelativeUrlFormat, actorType, actorId, timerName); actualPath.Should().Be(expectedPath); entry.Request.Method.Should().Be(HttpMethod.Delete); }