public async Task DetailsAsyncReturnsInformationAboutCorrectBike() { const int searchedBikeId = 1; //Arrange var db = this.GetDatabase(); var dragBike = new Bike { Id = 1, Make = Make.Drag, Model = "Master Pro", Price = 780.90m }; var pinarelloBike = new Bike { Id = 2, Make = Make.Pinarello, Model = "Dogma F10", Price = 15000.790m }; db.AddRange(dragBike, pinarelloBike); await db.SaveChangesAsync(); var bikeService = new BikeService(db); //Act var searchedBike = await bikeService.DetailsAsync(searchedBikeId); //Assert searchedBike .Model .Should() .Be("Master Pro"); }
public async Task DeleteAsyncShouldRemoveBikeFromDatabase() { //Arrange var db = this.GetDatabase(); var dragBike = new Bike { Id = 1, Make = Make.Drag, Model = "Master Pro", Price = 780.90m }; var pinarelloBike = new Bike { Id = 2, Make = Make.Pinarello, Model = "Dogma F10", Price = 15000.790m }; var bianchiBike = new Bike { Id = 3, Make = Make.Bianchi, Model = "Via Niorne", Price = 7800.90m }; db.Bikes.AddRange(dragBike, pinarelloBike, bianchiBike); await db.SaveChangesAsync(); var bikeService = new BikeService(db); //Act db.Remove(dragBike); await db.SaveChangesAsync(); //Assert db .Bikes .Count() .Should() .Be(2); }
public async Task AllAsyncShouldReturnCorrectOrder() { //Arrange var db = this.GetDatabase(); var dragBike = new Bike { Id = 1, Make = Make.Drag, Model = "Master Pro", Price = 780.90m }; var pinarelloBike = new Bike { Id = 2, Make = Make.Pinarello, Model = "Dogma F10", Price = 15000.790m }; var bianchiBike = new Bike { Id = 3, Make = Make.Bianchi, Model = "Via Niorne", Price = 7800.90m }; db.AddRange(dragBike, pinarelloBike, bianchiBike); await db.SaveChangesAsync(); var bikeService = new BikeService(db); //Act var bikes = await bikeService.AllAsync(); //Assert bikes .Should() .Match(b => b.ElementAt(0).Id == 3 && b.ElementAt(1).Id == 2 && b.ElementAt(2).Id == 1) .And .HaveCount(3); }
static void Main() { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //connect to database connecter = SQLConnecter.GetInstance(); //init services bikeService = new BikeService(connecter); cardService = new CardService(connecter); electricBikeService = new ElectricBikeService(connecter); stationService = new StationService(connecter); tandemService = new TandemService(connecter); transactionService = new TransactionService(connecter); userService = new UserService(connecter); //init controllers rentBikeController = new RentBikeController(); bikeStationController = new BikeStationController(); returnBikeController = new ReturnBikeController(); //init the presentation homePageForm = new HomePageForm(); stationDetailForm = new StationDetailForm(); bikeDetailForm = new BikeDetailForm(); cardInformationForm = new CardInformationForm(); listBikeForm = new ListBikeForm(); rentBikeForm = new RentBikeForm(); returnBikeForm = new ReturnBikeForm(); transactionInformationForm = new TransactionInformationForm(); Application.Run(homePageForm); }
public BikesController( ICallContext callContext, AppConfig appConfig, ITelemetryLogger logger, BikeService bikeService ) : base(callContext, appConfig, logger) { this.BikeService = bikeService; }
public void GetBikeTypeByID_ReturnsABikeType() { //Arrange var bikeService = new BikeService(_mockQueries.Object, _mockStorage.Object); //Act var result = bikeService.GetBikeTypeByID(1); //Assert Assert.IsInstanceOfType(result, typeof(BikeType)); _mockQueries.Verify(x => x.GetBikeTypeByID(It.IsAny <int>()), Times.Once); }
public void GetBikeTypes_ReturnsArrayOfBikeType() { //Arrange var bikeService = new BikeService(_mockQueries.Object, _mockStorage.Object); //Act var result = bikeService.GetBikeTypes(); //Assert Assert.IsInstanceOfType(result, typeof(BikeType[])); _mockQueries.Verify(x => x.GetBikeTypes(), Times.Once); }
public async Task CreateBike_AddsOneBike() { //Arrange var bikeService = new BikeService(_mockQueries.Object, _mockStorage.Object); //Act var result = await bikeService.CreateBike(_bike); //Assert Assert.IsInstanceOfType(result, typeof(Bike)); _mockQueries.Verify(x => x.CreateBike(It.IsAny <Bike>()), Times.Once); _mockStorage.Verify(x => x.SaveFile(It.IsAny <Stream>(), It.IsAny <string>()), Times.Once); }
public static void Main(string[] args) { IRepository <Client> clientRepository = new Repository <Client>(); IRepository <Employee> employeeRepository = new Repository <Employee>(); IRepository <Bike> bikeRepository = new Repository <Bike>(); INameVerifier bikeNameVerifier = new NameVerifier(bikeRepository); IBikeService bikeService = new BikeService(bikeRepository, bikeNameVerifier); App app = new App(clientRepository, employeeRepository, bikeRepository, bikeService); app.AddBike("Кама", 50); app.AddBike("Кама", 100); }
public void DeleteBike_CallsDeleteOnce() { //Arrange _mockQueries.Setup(x => x.GetBikeByID(It.IsAny <int>())).Returns(_bike); var bikeService = new BikeService(_mockQueries.Object, _mockStorage.Object); //Act bikeService.DeleteBike(1); //Assert _mockQueries.Verify(x => x.DeleteBike(It.IsAny <Bike>()), Times.Once); _mockStorage.Verify(x => x.DeleteFile(It.IsAny <string>()), Times.Once); }
static void Main(string[] args) { var bikeData = BikeService.GetBikeDataAsync().GetAwaiter().GetResult(); var filtered = from d in bikeData where d.sarea == "汐止區" && int.Parse(d.sbi) > 1 select new { AREA = d.sarea, SBI = d.sbi }; //bikeData.FindAll(x => x.sarea == "汐止區" && int.Parse(x.sbi) > 0); foreach (var entry in filtered) { Console.WriteLine(entry); } Console.ReadLine(); }
public async System.Threading.Tasks.Task Fail_GetAllAsync() { // Arrange var options = new DbContextOptionsBuilder <CarSalesDbContext>().UseInMemoryDatabase(databaseName: "CarSales_Mini").Options; // Insert seed data into the database using one instance of the context using (var context = new CarSalesDbContext(options)) { context.Vehicle.RemoveRange(await context.Vehicle.ToListAsync()); context.SaveChanges(); context.Vehicle.Add(GetCar("Toyota")); context.Vehicle.Add(GetCar("BMW")); context.Vehicle.Add(GetCar("Mec")); context.Vehicle.Add(GetBike("Bike1")); context.Vehicle.Add(GetBike("Bike2")); context.SaveChanges(); } // Use a clean instance of the context to run the test using (var context = new CarSalesDbContext(options)) { // Set var appSettings = Options.Create(new AppSettings { BikeController = "BikeService", CarController = "BikeService" }); List <IVehicleService> _vehicleService = new List <IVehicleService>(); IVehicleService carService = new CarService(context); IVehicleService bikeService = new BikeService(context); _vehicleService.Add(carService); _vehicleService.Add(bikeService); CarController carController = new CarController(_vehicleService, appSettings); // Act var result = await carController.GetCarListAsync(); var viewResult = Assert.IsType <ActionResult <List <Vehicle> > >(result); var model = Assert.IsAssignableFrom <List <Vehicle> >(viewResult.Value); // Assert Assert.Equal(3, model.Count()); } }
public async ValueTask <ApiResponse <IList <BasicBike> > > Get(Guid userId) { try { var userBikes = await BikeService.BikesOrderedByUserAsync(userId); return(ApiUtils.CreateSuccessResponse(userBikes)); } catch (Exception ex) { Logger.LogError(ex.Message); return(ApiUtils.CreateErrorResponse <IList <BasicBike> >(ex)); } }
public async ValueTask <ApiResponse <BasicBike> > Post([FromBody] BasicBike bike) { try { var orderedBike = await BikeService.OrderAsync(bike); return(ApiUtils.CreateSuccessResponse(orderedBike)); } catch (Exception ex) { Logger.LogError(ex.Message); return(ApiUtils.CreateErrorResponse <BasicBike>(ex)); } }
public async ValueTask <ApiResponse <List <BasicBike> > > GetAvailableBikes() { try { var allBikess = await BikeService.GetAvailableBikes(); return(ApiUtils.CreateSuccessResponse(allBikess)); } catch (Exception ex) { Logger.LogError(ex.Message); return(ApiUtils.CreateErrorResponse <List <BasicBike> >(ex)); } }
public async ValueTask <ApiResponse <Dictionary <Guid, IList <BasicBike> > > > Get() { try { var allBikess = await BikeService.AllBikesOrderedAsync(); return(ApiUtils.CreateSuccessResponse(allBikess)); } catch (Exception ex) { Logger.LogError(ex.Message); return(ApiUtils.CreateErrorResponse <Dictionary <Guid, IList <BasicBike> > >(ex)); } }
public void GetBikes_ReturnsPageOfBikes() { //Arrange var bikeService = new BikeService(_mockQueries.Object, _mockStorage.Object); //Act var result = bikeService.GetBikes("", "", new PageParams { PageNo = 1, PageSize = 10 }); //Assert Assert.IsInstanceOfType(result, typeof(Task <Page <Bike> >)); _mockQueries.Verify(x => x.GetBikes(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <PageParams>()), Times.Once); }
public async ValueTask <ApiResponse <List <UserOrder> > > Get() { try { var allBikes = await BikeService.AllBikesOrderedAsync(); var result = allBikes.Keys.Select(x => new UserOrder(x, allBikes[x])).ToList(); return(ApiUtils.CreateSuccessResponse(result)); } catch (Exception ex) { Logger.LogError(ex.Message); return(ApiUtils.CreateErrorResponse <List <UserOrder> > (ex)); } }
public async Task UpdateBike_ReturnsOneUpdatedBike() { //Arrange _mockQueries.Setup(x => x.GetBikeByID(It.IsAny <int>())).Returns(_bike); var bikeService = new BikeService(_mockQueries.Object, _mockStorage.Object); //Act var result = await bikeService.UpdateBike(1, _bike); //Assert Assert.IsInstanceOfType(result, typeof(Bike)); _mockQueries.Verify(x => x.UpdateBike(It.IsAny <Bike>()), Times.Once); _mockStorage.Verify(x => x.SaveFile(It.IsAny <Stream>(), It.IsAny <string>()), Times.Once); _mockStorage.Verify(x => x.DeleteFile(It.IsAny <string>()), Times.Once); }
public async Task UpdateBike_UpdatesWhenImageIsNull() { //Arrange var bike = _bike; bike.Image = null; _mockQueries.Setup(x => x.GetBikeByID(It.IsAny <int>())).Returns(bike); var bikeService = new BikeService(_mockQueries.Object, _mockStorage.Object); //Act var result = await bikeService.UpdateBike(1, bike); //Assert Assert.IsInstanceOfType(result, typeof(Bike)); _mockQueries.Verify(x => x.UpdateBike(It.IsAny <Bike>()), Times.Once); }
public async Task CreateBike_SavesWhenImageIsNull() { //Arrange Bike bike = _bike; bike.Image = null; var bikeService = new BikeService(_mockQueries.Object, _mockStorage.Object); //Act var result = await bikeService.CreateBike(bike); //Assert Assert.IsInstanceOfType(result, typeof(Bike)); _mockQueries.Verify(x => x.CreateBike(It.IsAny <Bike>()), Times.Once); _mockStorage.Verify(x => x.SaveFile(It.IsAny <Stream>(), It.IsAny <string>()), Times.Never); }
public async Task UpdateBike_ThrowsExceptionWhenSaveFileFails() { //Arrange _mockQueries.Setup(x => x.GetBikeByID(It.IsAny <int>())).Returns(_bike); _mockStorage.Setup(x => x.SaveFile(It.IsAny <Stream>(), It.IsAny <string>())).Throws(new Exception()); var bikeService = new BikeService(_mockQueries.Object, _mockStorage.Object); //Act try { var result = await bikeService.UpdateBike(1, _bike); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(Exception)); _mockStorage.Verify(x => x.SaveFile(It.IsAny <Stream>(), It.IsAny <string>()), Times.Once); } }
public async Task ElectricAsyncReturnsOnlyElctricBikesAndOrderThemCorrectly() { //Arrange var db = this.GetDatabase(); var electricBikeOne = new Bike { Id = 1, Make = Make.Drag, Model = "Dragomir Electric", Price = 1700.90m, BatteryMake = "Toshiba", BatteryPower = 1400 }; var electricBikeTwo = new Bike { Id = 2, Make = Make.Drag, Model = "Shock", Price = 1800.90m, BatteryMake = "Toshiba", BatteryPower = 1400 }; var electricBikeThree = new Bike { Id = 3, Make = Make.Drag, Model = "Byung", Price = 1760.90m, BatteryMake = "Toshiba", BatteryPower = 1400 }; var nonElectric = new Bike { Id = 4, Make = Make.Pinarello, Model = "Dogma F8", Price = 18000.790m }; db.AddRange(electricBikeOne, electricBikeTwo, electricBikeThree, nonElectric); await db.SaveChangesAsync(); var bikeService = new BikeService(db); //Act var electrics = await bikeService.ElectricAsync(); //Assert electrics .Should() .Match(b => b.ElementAt(0).Id == 3 && b.ElementAt(1).Id == 2 && b.ElementAt(2).Id == 1) .And .HaveCount(3); }
public async Task EditBikeAsyncShouldSaveBikeWithTheEditedParameters() { const int bikeId = 1; const Make bikeMake = Make.Pinarello; const string bikeModel = "Dogma F10"; const decimal bikePrice = 15000.790m; const int bikeQuantity = 1; const int bikeFrameSize = 550; //Arrange var db = this.GetDatabase(); var bike = new Bike { Id = bikeId, Make = bikeMake, Model = bikeModel, Price = bikePrice, Quantity = bikeQuantity, FrameSize = bikeFrameSize }; db.Add(bike); await db.SaveChangesAsync(); var bikeService = new BikeService(db); //Act var editedBike = await bikeService.EditAsync(bikeId, Make.Drag, "Bluebird", 870.76m, null, 3, 550, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); //Assert editedBike .Should() .Be(true); }
public BikeController(BikeService bikeService) { _bikeService = bikeService; }
public void Setup() { bikeService = new BikeService(connecter); }