public CoffeeMachineShould()
 {
     _mockedBeverageQuantityChecker = new Mock <IBeverageQuantityChecker>();
     _mockedEmailNotifier           = new Mock <IEmailNotifier>();
     _repository    = new Repository();
     _coffeeMachine = new CoffeeMachine(_repository, _mockedBeverageQuantityChecker.Object, _mockedEmailNotifier.Object);
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Opti Coffee Shop!");
            var            serviceProvider = DIConfig.DIConfigurator.ConfigureDI();
            ICoffeeMachine machine         = serviceProvider.GetRequiredService <ICoffeeMachine>();

            machine.HandleUserInput();
        }
Exemplo n.º 3
0
            private CoffeeServiceLocator()
            {
                // configure and instantiate a CoffeeMachine
                var beans = new Dictionary <CoffeeSelection, CoffeeBean>();

                beans.Add(CoffeeSelection.ESPRESSO, new CoffeeBean("My favorite espresso bean", 1000));
                beans.Add(CoffeeSelection.FILTER_COFFEE, new CoffeeBean("My favorite filter coffee bean", 1000));

                coffeeMachine = new PremiumCoffeeMachine(beans);
            }
        /// <summary>
        /// Initializes a new instance of the <see cref="CoffeeMachineStatusResponse"/> class.
        /// </summary>
        /// <param name="coffeeMachine">The coffee machine used to pull the state from.</param>
        public CoffeeMachineStatusResponse(ICoffeeMachine coffeeMachine)
        {
            this.IsOn             = coffeeMachine.IsOn;
            this.IsMakingCoffee   = coffeeMachine.IsMakingCoffee;
            this.IsDescaling      = coffeeMachine.IsDescaling;
            this.WaterLevelState  = coffeeMachine.WaterLevelState;
            this.BeanFeedState    = coffeeMachine.BeanFeedState;
            this.WasteCoffeeState = coffeeMachine.WasteCoffeeState;
            this.WaterTrayState   = coffeeMachine.WaterTrayState;
            this.DescaleState     = coffeeMachine.DescaleState;

            this.IsAlerting = new State[]
            {
                this.WaterLevelState,
                this.BeanFeedState,
                this.WasteCoffeeState,
                this.WaterTrayState,
                this.DescaleState
            }.Any(e => e == State.Alert);

            if (!this.IsOn)
            {
                return;
            }

            this.CurrentState = CoffeeStatusState.Idle;

            if (this.IsMakingCoffee || this.IsDescaling)
            {
                this.CurrentState = CoffeeStatusState.Active;
            }
            else if (this.IsAlerting)
            {
                this.CurrentState = CoffeeStatusState.Alert;
            }
        }
Exemplo n.º 5
0
        // !!! LOOK HERE !!!
        // ICoffeeMachine is injected as a simple dependency (not a distributed service).

        public BaristaWorker(ICoffeeMachine coffeeMachine)
        {
            _coffeeMachine = coffeeMachine;
        }
Exemplo n.º 6
0
        public async Task RunTest()
        {
            bool halted = true;

            while (this.RunForever || this.Iterations <= 1)
            {
                this.Log.WriteLine("#################################################################");

                // Create a new CoffeeMachine instance
                string error = null;
                if (halted)
                {
                    this.Log.WriteLine("starting new CoffeeMachine iteration {0}.", this.Iterations);
                    this.IsInitialized = false;
                    this.CoffeeMachine = new CoffeeMachine();
                    halted             = false;
                    this.IsInitialized = await this.CoffeeMachine.InitializeAsync(this.Sensors);

                    if (!this.IsInitialized)
                    {
                        error = "init failed";
                    }
                }

                if (error == null)
                {
                    // Setup a timer to randomly kill the coffee machine.   When the timer fires
                    // we will restart the coffee machine and this is testing that the machine can
                    // recover gracefully when that happens.
                    this.HaltTimer = new ControlledTimer("HaltTimer", TimeSpan.FromSeconds(this.RandomGenerator.NextInteger(7) + 1), new Action(this.OnStopTest));

                    // Request a coffee!
                    var shots = this.RandomGenerator.NextInteger(3) + 1;
                    error = await this.CoffeeMachine.MakeCoffeeAsync(shots);
                }

                if (string.Compare(error, "<halted>", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // then OnStopTest did it's thing, so it is time to create new coffee machine.
                    this.Log.WriteWarning("CoffeeMachine is halted.");
                    halted = true;
                }
                else if (!string.IsNullOrEmpty(error))
                {
                    this.Log.WriteWarning("CoffeeMachine reported an error.");
                    this.RunForever = false; // no point trying to make more coffee.
                    this.Iterations = 10;
                }
                else
                {
                    // in this case we let the same CoffeeMachine continue on then.
                    this.Log.WriteLine("CoffeeMachine completed the job.");
                }

                this.Iterations++;
            }

            // Shutdown the sensors because test is now complete.
            this.Log.WriteLine("Test is complete, press ENTER to continue...");
            await this.Sensors.TerminateAsync();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CoffeeMachineService"/> class.
 /// </summary>
 /// <param name="coffeeMachine">The coffee machine.</param>
 public CoffeeMachineService(ICoffeeMachine coffeeMachine)
 {
     this._coffeeMachine = coffeeMachine;
 }
Exemplo n.º 8
0
 public OrderController(IPreferenceService preferenceService, ICoffeeMachine coffeeMachine, IDrinkService drinkService)
 {
     _preferenceService = preferenceService;
     _coffeeMachine     = coffeeMachine;
     _drinkService      = drinkService;
 }
Exemplo n.º 9
0
 public virtual void SetUp() => CoffeeMachine = new CoffeeMachine();
Exemplo n.º 10
0
 public AddMoneyState(ICoffeeMachine coffeeMachine)
 {
     _coffeeMachine = coffeeMachine;
 }
Exemplo n.º 11
0
 public ReadyState(ICoffeeMachine coffeeMachine)
 {
     _coffeeMachine = coffeeMachine;
 }
Exemplo n.º 12
0
 public CoffeeApp(ICoffeeMachine coffeeMachine)
 {
     this.coffeeMachine = coffeeMachine;
 }