public Task TransmitAsync(DrinkRecipeViewModel drink) { var data = drink.ToByteArray(); if (_bluetoothService.IsConnected()) { return(_bluetoothService.WriteAsync(data, 0, 0)); } return(Task.CompletedTask); }
public void AfterExecuting_ToByteArray_ResultsBottleIndexes_ShouldBeOrderedAscending(params int[] bottleIndexes) { // arrange var drink = CreateDrinkRecipe(bottleIndexes); var drinkVm = new DrinkRecipeViewModel(drink); // act var result = drinkVm.ToByteArray(); // assert var expected = new byte[] { 255, 255, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 255, 255, 0 }; CollectionAssert.AreEqual(expected, result); }
public EditDrinkRecipePageViewModel( IUserInteraction userInteraction, IDrinkRecipeBuilder drinkRecipeBuilder, INavigationService navigationService, IDrinkRecipesRepository drinkRecipesRepository, ICrossMediaService crossMediaService, ISelectionHost <DrinkIngredientViewModel> selectionHost, DrinkRecipeViewModel drinkRecipeViewModel) : base(userInteraction, navigationService, drinkRecipeBuilder, crossMediaService, selectionHost) { _userInteraction = userInteraction; _drinkRecipeBuilder = drinkRecipeBuilder; _drinkRecipesRepository = drinkRecipesRepository; _drinkIngredient = drinkRecipeViewModel; DrinkName = drinkRecipeViewModel.Name; ByteImage = drinkRecipeViewModel.ByteImage; DrinkIngredients.AddRange(drinkRecipeViewModel.IngredientViewModels); }
public async Task DrinkSelectedAsync(DrinkRecipeViewModel drinkRecipeViewModel) { var selection = new List <string>() { "Edit", "Delete", "Make drink" }; var result = await _userInteraction.DisplayActionSheetAsync($"{drinkRecipeViewModel.Name} selected!", "Cancel", null, selection.ToArray()); if (result == null) { return; } if (result.Equals("Edit")) { var parmeter = new TypedParameter(typeof(DrinkRecipeViewModel), drinkRecipeViewModel); await _navigationService.PushAsync <EditDrinkRecipePageViewModel>(parmeter); } else if (result.Equals("Delete")) { await _drinkRecipeRepository.DeleteAsync(drinkRecipeViewModel.DrinkRecipe); Drinks.Remove(drinkRecipeViewModel); } else if (result.Equals("Make drink")) { if (!_bluetoothService.IsConnected()) { await _userInteraction .DisplayAlertAsync("Info", "Cannot send data to the cocktail machine. \n" + "You are not connected with the bluetooth module of the cocktail machine. \n" + "Navigate back to the welcomepage and connect with the device!", "Ok"); return; } await TransmitAsync(drinkRecipeViewModel); } }
public void AfterExecuting_ToByteArray_ExceedingUpperMilliliterBoundary_ShouldBeSplit() { // arrange var parameters = new IngredientParameter[] { new IngredientParameter(1, 500), new IngredientParameter(2, 500), new IngredientParameter(3, 500), new IngredientParameter(4, 500), new IngredientParameter(5, 500), new IngredientParameter(6, 500), }; var drink = CreateDrinkRecipe(parameters); var drinkVm = new DrinkRecipeViewModel(drink); // act var result = drinkVm.ToByteArray(); // assert var expected = new byte[] { 255, 255, 1, 250, 250, 2, 250, 250, 3, 250, 250, 4, 250, 250, 5, 250, 250, 6, 250, 250, 255, 255, 0 }; CollectionAssert.AreEqual(expected, result); }