public async Task Call_ValidateUnsuccessfulResponse()
        {
            await using var client = TestClient.CreateForDaprHttpInterator();

            var actorType = "ActorType_Test";
            var actorId   = "ActorId_Test";
            var timerName = "TimerName";

            var request = await client.CaptureHttpRequestAsync(async httpInteractor =>
            {
                await httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName);
            });

            request.Dismiss();

            var error = new DaprError()
            {
                ErrorCode = "ERR_STATE_STORE",
                Message   = "State Store Error"
            };

            var message = new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent(JsonSerializer.Serialize(error))
            };

            await Assert.ThrowsAsync <DaprApiException>(async() =>
            {
                await request.CompleteAsync(message);
            });
        }
Beispiel #2
0
        public async Task InvokeActorMethodOmitsReentrancyIdIfNotSet_ValidateHeaders()
        {
            await using var client = TestClient.CreateForDaprHttpInterator();

            var actorType  = "ActorType_Test";
            var actorId    = "ActorId_Test";
            var methodName = "MethodName";
            var payload    = "JsonData";

            var request = await client.CaptureHttpRequestAsync(async httpInteractor =>
            {
                await httpInteractor.InvokeActorMethodWithoutRemotingAsync(actorType, actorId, methodName, payload);
            });

            request.Dismiss();
            Assert.False(request.Request.Headers.Contains(Constants.ReentrancyRequestHeaderName));
        }
        public async Task Call_WithoutApiToken()
        {
            await using var client = TestClient.CreateForDaprHttpInterator();

            var actorType = "ActorType_Test";
            var actorId   = "ActorId_Test";
            var timerName = "TimerName";

            var request = await client.CaptureHttpRequestAsync(async httpInteractor =>
            {
                await httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName);
            });

            request.Dismiss();

            request.Request.Headers.TryGetValues("dapr-api-token", out var headerValues);
            headerValues.Should().BeNull();
        }
        public async Task Call_ValidateUnauthorizedResponse()
        {
            await using var client = TestClient.CreateForDaprHttpInterator();

            var actorType = "ActorType_Test";
            var actorId   = "ActorId_Test";
            var timerName = "TimerName";

            var request = await client.CaptureHttpRequestAsync(async httpInteractor =>
            {
                await httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName);
            });

            var message = new HttpResponseMessage(HttpStatusCode.Unauthorized);

            await Assert.ThrowsAsync <AuthenticationException>(async() =>
            {
                await request.CompleteAsync(message);
            });
        }
        public async Task SaveStateTransactionally_ValidateRequest()
        {
            await using var client = TestClient.CreateForDaprHttpInterator();

            var actorType = "ActorType_Test";
            var actorId   = "ActorId_Test";
            var data      = "StateData";

            var request = await client.CaptureHttpRequestAsync(async httpInteractor =>
            {
                await httpInteractor.SaveStateTransactionallyAsync(actorType, actorId, data);
            });

            request.Dismiss();

            var actualPath   = request.Request.RequestUri.LocalPath.TrimStart('/');
            var expectedPath = string.Format(CultureInfo.InvariantCulture, Constants.ActorStateRelativeUrlFormat, actorType, actorId);

            actualPath.Should().Be(expectedPath);
            request.Request.Method.Should().Be(HttpMethod.Put);
        }
        public async Task GetState_ValidateRequest()
        {
            await using var client = TestClient.CreateForDaprHttpInterator();

            var actorType = "ActorType_Test";
            var actorId   = "ActorId_Test";
            var keyName   = "StateKey_Test";

            var request = await client.CaptureHttpRequestAsync(async httpInteractor =>
            {
                await httpInteractor.GetStateAsync(actorType, actorId, keyName);
            });

            request.Dismiss();

            var actualPath   = request.Request.RequestUri.LocalPath.TrimStart('/');
            var expectedPath = string.Format(CultureInfo.InvariantCulture, Constants.ActorStateKeyRelativeUrlFormat, actorType, actorId, keyName);

            actualPath.Should().Be(expectedPath);
            request.Request.Method.Should().Be(HttpMethod.Get);
        }
        public async Task RegisterReminder_ValidateRequest()
        {
            await using var client = TestClient.CreateForDaprHttpInterator();

            var actorType    = "ActorType_Test";
            var actorId      = "ActorId_Test";
            var reminderName = "ReminderName";
            var payload      = "JsonData";

            var request = await client.CaptureHttpRequestAsync(async httpInteractor =>
            {
                await httpInteractor.RegisterReminderAsync(actorType, actorId, reminderName, payload);
            });

            request.Dismiss();

            var actualPath   = request.Request.RequestUri.LocalPath.TrimStart('/');
            var expectedPath = string.Format(CultureInfo.InvariantCulture, Constants.ActorReminderRelativeUrlFormat, actorType, actorId, reminderName);

            actualPath.Should().Be(expectedPath);
            request.Request.Method.Should().Be(HttpMethod.Put);
        }