public ViewResult List(string category) { string _category = category; IEnumerable <Coffee> coffees; string currentCategory = string.Empty; if (string.IsNullOrEmpty(category)) { coffees = _coffeeRepository.Coffees.OrderBy(n => n.CoffeeId); currentCategory = "All products"; } else { if (string.Equals("White coffees", _category, StringComparison.OrdinalIgnoreCase)) { coffees = _coffeeRepository.Coffees.Where(p => p.Category.CategoryName.Equals("White Coffees")).OrderBy(p => p.Name); } else { coffees = _coffeeRepository.Coffees.Where(p => p.Category.CategoryName.Equals("Black Coffees")).OrderBy(p => p.Name); currentCategory = _category; } } var coffeeListViewModel = new CoffeeListViewModel { Coffees = coffees, CurrentCategory = currentCategory }; return(View(coffeeListViewModel)); }
public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); isTypeList = this.Arguments.GetBoolean("isList"); viewModel = App.ServiceLocator.CoffeeListViewModel; }
public ViewResult List() { CoffeeListViewModel obj = new CoffeeListViewModel(); obj.allCoffes = _allProducts.Coffes; obj.currCategory = "Товары"; return(View(obj)); }
public async Task Should_load_all_coffee_on_init() { _viewModel = new CoffeeListViewModel( new CoffeeService(httpProvider), new FavoriteServiceMock() ); await dbProvider.InitializeDb(); await _viewModel.Initialize(); Assert.IsTrue(_viewModel.AllCoffees.Any()); foreach (var coffee in _viewModel.AllCoffees) { Assert.IsFalse(string.IsNullOrEmpty(coffee.Name)); Assert.IsFalse(string.IsNullOrEmpty(coffee.Id)); } }
public async Task Should_load_favorite_coffees_at_init() { _viewModel = new CoffeeListViewModel( new CoffeeServiceMock(new List <CoffeeShop> { new CoffeeShop { Id = "test" } }), new FavoriteService(dbProvider) ); await dbProvider.InitializeDb(); await dbProvider.GetConnection().AddToDb(new FavoriteRow { FavoriteId = "test" }); await _viewModel.Initialize(); Assert.IsTrue(_viewModel.FavoriteCoffees.Count(f => f.Id == "test") == 1); }
public void ViewModelShouldLoadCoffeesWhenClickingOnLoadCommandAndSayingYes() { var alertServiceStub = Substitute.For <IAlertService>(); alertServiceStub .ShowAlertAsync(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(Task.FromResult(true)); SimpleIoc.Default.Register <IAlertService>(() => alertServiceStub); var alertService = SimpleIoc.Default.GetInstance <IAlertService>(); var serviceSub = Substitute.For <ICoffeeService>(); var viewModel = new CoffeeListViewModel(serviceSub, alertService); viewModel.LoadCoffeesCommand.Execute(null); serviceSub.Received().GetCoffeesDataAsync(); }
public CoffeeController(IntPtr handle) : base(handle) { this.ViewModel = new CoffeeListViewModel(null, null); }