Ejemplo n.º 1
0
        public async Task GivenOneMachineWithThreeConditions_WhenReceivingItsStates_ThenTheResult_ShouldContainTheseConditions()
        {
            // Given
            var tokenProviderMock = new Mock <ITokenProvider>();

            tokenProviderMock
            .Setup(tp => tp.ReceiveTokenAsync(It.IsAny <TapioScope>()))
            .ReturnsAsync("foo");

            var responseContent = GetTestDataFromAssembly("SingleMachineWithSomeData.json");

            var handler = new Mock <HttpMessageHandler>();

            handler
            .SetupRequest(HttpMethod.Post, "https://core.tapio.one/api/machines/state")
            .ReturnsResponse(HttpStatusCode.OK, new StringContent(responseContent, new UTF8Encoding(false)))
            .Verifiable();

            var httpClient = handler.CreateClient();

            var cut = new MachineStateService(httpClient, tokenProviderMock.Object, Mock.Of <ILogger <MachineStateService> >());

            // When
            var result = await cut.GetMachineStateAsync("2f5b690df6c0406982d49fd9b7a8835b", CancellationToken.None);

            // Then
            result.Children().Should().HaveCount(3);
        }
Ejemplo n.º 2
0
        public async Task GivenOneMachineWithoutData_WhenReceivingItsStates_ThenOneRequest_ShouldBeSent()
        {
            // Given
            var tokenProviderMock = new Mock <ITokenProvider>();

            tokenProviderMock
            .Setup(tp => tp.ReceiveTokenAsync(It.IsAny <TapioScope>()))
            .ReturnsAsync("foo");

            var handler = new Mock <HttpMessageHandler>();

            handler
            .SetupRequest(HttpMethod.Post, "https://core.tapio.one/api/machines/state")
            .ReturnsResponse(HttpStatusCode.OK, new StringContent("[]", new UTF8Encoding(false)))
            .Verifiable();

            var httpClient = handler.CreateClient();

            var cut = new MachineStateService(httpClient, tokenProviderMock.Object, Mock.Of <ILogger <MachineStateService> >());

            // When
            _ = await cut.GetMachineStateAsync("2f5b690df6c0406982d49fd9b7a8835b", CancellationToken.None);

            // Then
            handler.VerifyAnyRequest(Times.Once());
        }