public async Task <IActionResult> GetCoffeeMachineStatusAsync()
        {
            this._logger.LogInformation("Gathering the current coffee machines status for requesting user.");
            CoffeeMachineStatusResponse response = this._coffeeMachineService.GetStatus();

            await this._auditService.AddAuditEntryForRequest(this.Request, response,
                                                             AuditActionType.GetMachineState).ConfigureAwait(false);

            return(this.StatusCode(response.Status, response));
        }
Esempio n. 2
0
        public async Task GetStatus_Matches_MachineStatus()
        {
            using IServiceScope scope = this._factory.Services.CreateScope();
            var coffeeMachine = (CoffeeMachineTestStub)scope.ServiceProvider.GetRequiredService <ICoffeeMachine>();

            coffeeMachine.Reset();

            coffeeMachine.WasteCoffeeState = State.Alert;
            coffeeMachine.IsOn             = true;

            HttpResponseMessage response = await this.Client.GetAsync($"{this._baseUrl}/status").ConfigureAwait(false);

            CoffeeMachineStatusResponse resultBody = JsonConvert.DeserializeObject <CoffeeMachineStatusResponse>(await response.Content.ReadAsStringAsync());

            Assert.True(response.IsSuccessStatusCode);

            Assert.Equal(coffeeMachine.IsOn, resultBody.IsOn);
            Assert.Equal(coffeeMachine.WasteCoffeeState, resultBody.WasteCoffeeState);
        }
        /// <summary>
        /// Turns the off safety asynchronous.
        /// </summary>
        /// <inheritdoc/>
        public async Task <BaseResponse> TurnOffSafeAsync()
        {
            // if we are already off, you should not be able to attempt to turn it off again.
            if (!this._coffeeMachine.IsOn)
            {
                return(new CoffeeMachineOfflineErrorResponse("turn off"));
            }

            // if we are making or descaling, we cannot just turn off.
            if (this._coffeeMachine.IsDescaling || this._coffeeMachine.IsMakingCoffee)
            {
                return(new CoffeeMachineRunningErrorResponse("turn off"));
            }

            CoffeeMachineStatusResponse statusBeforeTurnOff = this.GetStatus();

            await this._coffeeMachine.TurnOffAsync().ConfigureAwait(false);

            statusBeforeTurnOff.CurrentState = CoffeeStatusState.Off;

            return(statusBeforeTurnOff);
        }