public async Task GetQuote_ReturnOkDiscount20() { using (var context = new BeerContext(ContextOptions)) { var service = new WholesalerService(context); var quoteCommand = new GetQuoteCommand { CommandLines = new List <BeerQuantity>() { new BeerQuantity { BeerId = 1, Quantity = 12 }, new BeerQuantity { BeerId = 2, Quantity = 12 } } }; var quote = await service.GetQuote(1, quoteCommand); Assert.Equal(12, quote.Discount); Assert.Equal(60, quote.Total); Assert.Equal(48, quote.Price); } }
public ActionResult Details(int?id) { using (var beerContext = new BeerContext()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var beerDetail = beerContext.Beers.SingleOrDefault(b => b.BeerId == id); var beerViewModel = new BeerViewModel { BeerId = beerDetail.BeerId, BeerName = beerDetail.BeerName, WhereTried = beerDetail.WhereTried, WhenTried = beerDetail.WhenTried, StyleOfBeer = beerDetail.StyleOfBeer, Country = beerDetail.Country, PercentABV = beerDetail.PercentABV, Rating = beerDetail.Rating, Description = beerDetail.Description }; return(View(beerViewModel)); } }
public GraphQLController() { _db = new BeerContext(); _schema = GraphQL <BeerContext> .CreateDefaultSchema(() => new BeerContext()); InitializeBeerSchema(_schema); InitializeMutationSchema(_schema); _schema.Complete(); // Queries //var query = @"{ // Beer(id:9) { // id // name // averageRatings // }}"; //var query = @"{ // Beers { // id // name // averageRatings // beerType // }}"; //var query = @"{ // FindBeer(match: ""as"") { // id : id // name : name // }}"; //var query = @"mutation { addBeer(id : 0, name:""shit kaam"", averageRatings : 4, beerTypeId :0) { id } }"; //var query = @"mutation { deleteBeer(id : 0) { id } }"; //var query = @"mutation { addBeerRating(id : 0, rating : 4, beerId :0) { id } }"; }
public ActionResult Edit(BeerViewModel beerViewModel) { if (ModelState.IsValid) { using (var beerContext = new BeerContext()) { var beerToUpdate = beerContext.Beers.SingleOrDefault(b => b.BeerId == beerViewModel.BeerId); if (beerToUpdate != null) { beerToUpdate.BeerName = beerViewModel.BeerName; beerToUpdate.WhereTried = beerViewModel.WhereTried; beerToUpdate.WhenTried = beerViewModel.WhenTried; beerToUpdate.BeerStyleId = beerViewModel.BeerStyleId; beerToUpdate.Country = beerViewModel.Country; beerToUpdate.PercentABV = beerViewModel.PercentABV; beerToUpdate.Rating = beerViewModel.Rating; beerToUpdate.Description = beerViewModel.Description; beerContext.SaveChanges(); return(RedirectToAction("Index")); } } } return(new HttpNotFoundResult()); }
private void SetUpPreset() { // Set the default URL of API to default Settings.URLSetting = default; StatusViewModel.timerOn = false; //This was moved to improve reliability of the tests - potentially moving some time //MockTempReadings.StartCounting(); // Instantiate a new Context (Database) BeerContext context = new BeerContext(); //Instantiate a new API Manager APIManager apiManager = new APIManager(); // Connect to the API and store Beverages/Brands in the Database #if DEBUG //LoadFixtures(context); //FetchData(context, apiManager); #elif RELEASE //Release mode breaks, but can swap these for API usage //FetchData(context, apiManager); #endif //MainPage = new MainPage(context); //MainPage = new MainPage(); }
public AuthService(ICryptoService cryptoService, BeerContext context, AppConfig appConig, UserRepository userRepository) { _cryptoService = cryptoService; _beerContext = context; _appConfig = appConig; _userRepository = userRepository; }
protected override void Down(MigrationBuilder migrationBuilder) { using (var db = new BeerContext()) { db.Orders.RemoveRange(db.Orders); db.Clients.RemoveRange(db.Clients); db.Beers.RemoveRange(db.Beers); db.SaveChanges(); } }
public async Task GetQuote_NotOk_ListIsNull() { using (var context = new BeerContext(ContextOptions)) { var service = new WholesalerService(context); var quoteCommand = new GetQuoteCommand { }; await Assert.ThrowsAsync <CustomBadRequestException>(() => service.GetQuote(1, quoteCommand)); } }
public async Task AddBeerWholesaler_BeerNotExist() { var command = new AddBeerToWholesalerCommand { BeerId = 100, WholesalerId = 1, Stock = 20 }; using (var context = new BeerContext(ContextOptions)) { var service = new WholesalerService(context); await Assert.ThrowsAsync <CustomBadRequestException>(() => service.AddBeer(command)); } }
public async Task GetQuote_NotOk_EmptyList() { using (var context = new BeerContext(ContextOptions)) { var service = new WholesalerService(context); var quoteCommand = new GetQuoteCommand { CommandLines = new List <BeerQuantity>() }; await Assert.ThrowsAsync <CustomBadRequestException>(() => service.GetQuote(1, quoteCommand)); } }
public void SetupDatabase() { // Set the default URL of API to default Settings.URLSetting = default; StatusViewModel.timerOn = false; APIManager apiManager = new APIManager(); BeerContext context = new BeerContext(); FetchData(); }
public ActionResult Delete(int id) { using (var beerContext = new BeerContext()) { var beerToDelete = beerContext.Beers.SingleOrDefault(b => b.BeerId == id); if (beerToDelete != null) { beerContext.Beers.Remove(beerToDelete); beerContext.SaveChanges(); } return(RedirectToAction("Index")); } }
public ActionResult Create() { BeerViewModel beerViewModel = new BeerViewModel(); using (var beerContext = new BeerContext()) { ViewBag.BeerStyles = beerContext.BeerStyles.Select(b => new SelectListItem { Value = b.BeerStyleId.ToString(), Text = b.StyleOfBeer }).ToList(); } return(View("Create", beerViewModel)); }
public App() { InitializeComponent(); //Instantiate context & API Manager Context = new BeerContext(); APIManager = new APIManager(); // Reset the local user object in settings ResetUser(); SetupDatabase(); MainPage = new NavigationPage(new BeverageSelectPage()); }
public ActionResult Delete(int?id) { using (var beerContext = new BeerContext()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var beerViewModel = beerContext.Beers.SingleOrDefault(b => b.BeerId == id); if (beerViewModel == null) { return(HttpNotFound()); } return(View(beerViewModel)); } }
public async Task AddBeerWholesaler_ReturnOk() { var command = new AddBeerToWholesalerCommand { BeerId = 5, WholesalerId = 2, Stock = 20 }; using (var context = new BeerContext(ContextOptions)) { var service = new WholesalerService(context); await service.AddBeer(command); var wholesaler = await context.Wholesalers .Include(w => w.WholesalerBeers) .SingleOrDefaultAsync(w => w.Id == command.WholesalerId); Assert.Contains(wholesaler.WholesalerBeers, wb => wb.BeerId == 5); } }
public ActionResult Create(Beer beer) { if (ModelState.IsValid) { using (var beerContext = new BeerContext()) { ViewBag.BeerStyles = beerContext.BeerStyles.Select(b => new SelectListItem { Value = b.BeerStyleId.ToString(), Text = b.StyleOfBeer }).ToList(); beerContext.Beers.Add(beer); beerContext.SaveChanges(); return(RedirectToAction("Index")); } } return(View(beer)); }
/// <summary> /// This method will write changes to the Database for any changes that have happened. /// </summary> /// <param name="context">Database</param> public async void UpdatePreference(BeerContext context) { try { // Set the Temperature of the Preferred beverage to the StatusViewModel's Temperature, // Do a calculation if the temperature is currently set to fahrenheit preferredBeverage.Temperature = svm.IsCelsius ? svm.Temperature.Value : ((svm.Temperature.Value - 32) / 1.8); } catch (Exception) { throw; } try { // Write Changes to Database when it is not busy. svm.Context.Preference.Update(preferredBeverage); await context.SaveChangesAsync(); } catch (SqliteException) { throw; } }
protected async Task SaveBeer() { Beer beer; if (CurrentBeer.Id == 0) { beer = new Beer(); BeerContext.Beers.Add(beer); } else { beer = await BeerContext.Beers.FindAsync(int.Parse(Id)); } beer.Name = CurrentBeer.Name; beer.Description = CurrentBeer.Description; await BeerContext.SaveChangesAsync(); NavigationManager.NavigateTo("/"); }
public async Task GetQuote_NotOk_WholesalerNotFound() { using (var context = new BeerContext(ContextOptions)) { var service = new WholesalerService(context); var quoteCommand = new GetQuoteCommand { CommandLines = new List <BeerQuantity>() { new BeerQuantity { BeerId = 1, Quantity = 3 }, new BeerQuantity { BeerId = 2, Quantity = 4 } } }; await Assert.ThrowsAsync <CustomBadRequestException>(() => service.GetQuote(5, quoteCommand)); } }
public ActionResult Index() { using (var beerContext = new BeerContext()) { var beerListViewModel = new BeerListViewModel(); beerListViewModel.Beers = beerContext.Beers.Select(f => new BeerViewModel { BeerId = f.BeerId, BeerName = f.BeerName, WhereTried = f.WhereTried, WhenTried = f.WhenTried, Country = f.Country, StyleOfBeer = f.StyleOfBeer, PercentABV = f.PercentABV, Rating = f.Rating, Description = f.Description }).ToList(); return(View(beerListViewModel)); } }
private void Seed() { using var context = new BeerContext(ContextOptions); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); ProductDto one = new ProductDto { ProductNo = "P001", Category = "Beer", EAN = "1", Name = "Name 1 Beer" }; ProductDto two = new ProductDto { ProductNo = "P002", Category = "Beer", EAN = "1", Name = "Name 2 Beer" }; ProductDto three = new ProductDto { ProductNo = "P003", Category = "Beer", EAN = "1", Name = "Name 3 Beer" }; var productTranslator = new ProductTranslator(); context.Products.AddRange(productTranslator.ToModel(one), productTranslator.ToModel(two), productTranslator.ToModel(three)); context.SaveChanges(); }
public ActionResult Edit(int?id) { using (var beerContext = new BeerContext()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var beerViewModel = beerContext.Beers.SingleOrDefault(b => b.BeerId == id); if (beerViewModel == null) { return(HttpNotFound()); } ViewBag.BeerStyles = beerContext.BeerStyles.Select(b => new SelectListItem { Value = b.BeerStyleId.ToString(), Text = b.StyleOfBeer }).ToList(); return(View(beerViewModel)); } }
public BeerService(BeerContext context) { _context = context; }
public BreweriesController(BeerContext context, IUrlHelper helper) { _context = context; _urlHelper = helper; }
public BeerStylesController(BeerContext context) { _context = context; }
public BeerRepository(BeerContext context) { _context = context; }
public BeerService(BeerContext beerContext, ILogger <BeerService> logger, BeerRepository beerRepository) { _logger = logger; _beerContext = beerContext; _beerRepository = beerRepository; }
public BeerManagerEntity(BeerContext context) { _context = context; }
public CustomerRepository(BeerContext dbContext) { _context = dbContext; _customers = dbContext.Customers; }