private async Task GetCarsAsync() { IsBusy = true; var result = await CarsService.GetAllCarsAsync(""); MyCars = result.Values.ToList(); IsBusy = false; }
public void CarsService_ShouldCreateInstanceOfCarsService_WhenPassedRepositoryIsCorrectly() { var mockedRepository = new Mock <IRepository <Car> >(); var service = new CarsService(mockedRepository.Object); Assert.IsInstanceOf <CarsService>(service); }
public void CarsService_ShouldImplementsInterfaceICarsService_WhenPassedRepositoryIsCorrectly() { var mockedRepository = new Mock <IRepository <Car> >(); var service = new CarsService(mockedRepository.Object); Assert.IsInstanceOf <ICarsService>(service); }
public async Task GetAllForUserAsync_WithCorrectUser_WorksCorrectly() { // Arrange const int expectedCount = 2; var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var model = new CarModel { Model = "Test Model", Manufacturer = new CarManufacturer() }; await context.CarModels.AddAsync(model); var user = new PoolItUser { UserName = "******" }; await context.Users.AddAsync(user); await context.Cars.AddRangeAsync( new Car { Colour = "Test Colour 1", ModelId = model.Id, OwnerId = user.Id }, new Car { Colour = "Test Colour 2", ModelId = model.Id, OwnerId = user.Id }, new Car { Colour = "Test Colour 3", ModelId = model.Id, Owner = new PoolItUser { UserName = "******" } } ); await context.SaveChangesAsync(); var carsService = new CarsService(new EfRepository <Car>(context), null, new EfRepository <PoolItUser>(context)); // Act var actualCount = (await carsService.GetAllForUserAsync(user.UserName)).Count(); // Assert Assert.Equal(expectedCount, actualCount); }
public async Task GetAsync_WithCorrectCarId_WorksCorrectly() { // Arrange var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var model = new CarModel { Model = "Test Model", Manufacturer = new CarManufacturer() }; await context.CarModels.AddAsync(model); var user = new PoolItUser { UserName = "******" }; await context.Users.AddAsync(user); var car = new Car { Colour = "Test Colour 1", ModelId = model.Id, OwnerId = user.Id }; await context.Cars.AddRangeAsync( car, new Car { Colour = "Test Colour 2", ModelId = model.Id, OwnerId = user.Id }, new Car { Colour = "Test Colour 3", ModelId = model.Id, OwnerId = user.Id } ); await context.SaveChangesAsync(); var carsService = new CarsService(new EfRepository <Car>(context), null, null); // Act var result = await carsService.GetAsync(car.Id); // Assert Assert.NotNull(result); Assert.Equal(car.Colour, result.Colour); }
public void Add() { var carRepositoryMock = new CarRepositoryMock(); var carsService = new CarsService(carRepositoryMock); carsService.Add(12, 1234, "anrej", "anrej", "anrej", 12); Assert.IsNotNull(carRepositoryMock.MockedCars.FirstOrDefault()); }
public void CanRemoveCar() { Car car_to_get = null; var car_to_remove = Cars[0]; var try_get_value_called = false; var try_remove_called = false; var expected_try_get_value_result = false; var expected_try_remove_result = false; var mock_repository = new Mock <ICarsRepository>(); mock_repository.Setup(v => v.TryGetValue(It.IsAny <Guid>(), out car_to_get)) .Returns((Guid _g, Car _c) => { try_get_value_called = true; return(expected_try_get_value_result); }); mock_repository.Setup(v => v.TryRemove(It.IsAny <Guid>(), out car_to_remove)) .Returns((Guid _g, Car _c) => { try_remove_called = true; return(expected_try_remove_result); }); var cars_service = new CarsService(mock_repository.Object); try_get_value_called = false; (var car, var maybe_error) = cars_service.RemoveCar(Clients[0], Guid.NewGuid()); Assert.That(try_get_value_called); Assert.That(!try_remove_called); Assert.That(car, Is.Null); Assert.That(maybe_error?.Reason, Does.Match("not under control .* does not exist")); Assert.That(maybe_error?.StatusCode, Is.EqualTo(403)); (car, maybe_error) = cars_service.RemoveCar(Clients[0], Cars[1].Id); Assert.That(try_get_value_called); Assert.That(!try_remove_called); Assert.That(car, Is.Null); Assert.That(maybe_error?.Reason, Does.Match("not under control .* does not exist")); Assert.That(maybe_error?.StatusCode, Is.EqualTo(403)); car_to_get = Cars[0]; mock_repository.Setup(v => v.TryGetValue(It.IsAny <Guid>(), out car_to_get)) .Returns((Guid _g, Car _c) => { try_get_value_called = true; return(expected_try_get_value_result); }); try_get_value_called = false; expected_try_get_value_result = true; (car, maybe_error) = cars_service.RemoveCar(Clients[0], Cars[0].Id); Assert.That(try_get_value_called); Assert.That(try_remove_called); Assert.That(car, Is.Null); Assert.That(maybe_error?.Reason, Does.Match("Car .* was already removed")); Assert.That(maybe_error?.StatusCode, Is.EqualTo(410)); try_get_value_called = false; expected_try_get_value_result = true; try_remove_called = false; expected_try_remove_result = true; (car, maybe_error) = cars_service.RemoveCar(Clients[0], Cars[0].Id); Assert.That(try_get_value_called); Assert.That(try_remove_called); Assert.That(maybe_error, Is.Null); Assert.That(car, Is.SameAs(Cars[0])); }
public CarsControllerIntegrationTests() { var connection = Effort.DbConnectionFactory.CreateTransient(); context = new WhereIsItContext(connection); CreateTestData(context); ICarsService carsService = new CarsService(context); this.carsController = new CarsController(carsService); }
private async void CarsBtn_Click(object sender, RoutedEventArgs e) { var cts = new CancellationTokenSource(TimeSpan.FromMinutes(CTS_TIMEOUT_DEFAULT)); var ct = cts.Token; this.CarsList.ItemsSource = new string[] { "...loading..." }; var data = await CarsService.GetCarsAsync($"{App.API_BASE_URL}/cars", ct, captureContext : false); this.CarsList.ItemsSource = data; }
public void CheckIfGetCarByIdReturnsCorrectCar() { var dbContext = new AutomobileDbContext(); var service = new CarsService(dbContext); var carFromDb = dbContext.CarOffers.FirstOrDefault(); var carFromService = service.GetCarById(carFromDb.Id); Assert.Equal(carFromDb.Id, carFromService.Id); }
public DateTimeOffsetController(IMapper mapper, CarsService service) { this.mapper = mapper; this.service = service; if (cars == null) { cars = service.GetAllCars(); } }
public void CheckIfCarsForVisualizationAreEqualToCarsInDb() { var dbContext = new AutomobileDbContext(); var service = new CarsService(dbContext); var carsCollection = service.CarsForVisualization(); var carsAvailableInDb = dbContext.CarOffers.ToList(); Assert.True(carsCollection.Count == carsAvailableInDb.Count); }
private static ICarsService InitializeService( EfDeletableEntityRepository <ElectricCar> carsRepo, EfDeletableEntityRepository <Make> makesRepo, EfDeletableEntityRepository <Model> modelsRepo, EfDeletableEntityRepository <CarType> carTypesRepo, EfDeletableEntityRepository <Image> imageRepo) { var service = new CarsService(carsRepo, modelsRepo, makesRepo, carTypesRepo, imageRepo); return(service); }
public void CheckIfGetOnlyUserCarsReturnsTheCarsForThatParticularUserOnly() { var dbContext = new AutomobileDbContext(); var service = new CarsService(dbContext); var serviceOnlyUserCars = service.GetOnlyUserCars("e4bf2992-cc46-4ebb-baf2-667f245a3582"); var dbOnlyUserCars = dbContext.CarOffers.Where(x => x.UserId == "e4bf2992-cc46-4ebb-baf2-667f245a3582"); Assert.Equal(dbOnlyUserCars.Count(), serviceOnlyUserCars.Count()); }
/// <summary> /// Konstruktor klasy tworzący nowy obiekt CarService i otwiera formularz wraz z zaczytaniem danych do dataGridView1 /// </summary> /// <param name="clientId"> Jest to id klienta które przekazujemy</param> /// <param name="clientName">Imię klienta które przekazujemy</param> public AddCarForm(int clientId, string clientName) { carsService = new CarsService(new CarRepository()); ClientId = clientId; InitializeComponent(); label1.Text += clientName; var cars = new CarRepository().GetByClientId(clientId); dataGridView1.DataSource = cars; }
public void GetAllVehicleModel_shouldgivelistandanumber() { //Arange list expected; //Act list actual = CarsService.GetAllVehicleModel(Brand_desc, 90, 0, 10); //Assert Assert.Equal(expected, actual); }
public void ImplementsInterfaceICarsService_WhenPassedRepositoryIsCorrectly() { // Arrange var mockedRepository = new Mock <IEfGenericRepository <Car> >(); // Act var service = new CarsService(mockedRepository.Object); // Assert Assert.IsInstanceOf <ICarsService>(service); }
public void GetDetailsAdmin_GivenNegativeId_ShouldThrowNegativeInException() { // arrange int id = -1; CarsService service = new CarsService(null, null); // act // assert service.Invoking(x => x.GetAllCarsIndex(id)) .Should().ThrowExactly <NegativeIntException>(); }
public async Task GetDetailsAsync() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfDeletableEntityRepository <Car>(new ApplicationDbContext(options.Options)); var carOne = new Car { Model = "Форд Фиеста", LicensePlate = "CO1212KA", CompanyId = "72804eudajhkhfvs-dasfa", FuelType = PatniListi.Data.Models.Enums.Fuel.Дизел, TankCapacity = 55, AverageConsumption = 4, InitialFuel = 10, StartKilometers = 234987 }; var carUserOne = new CarUser { CarId = carOne.Id, UserId = "242hds-78dsd-7823dsds" }; carOne.CarUsers.Add(carUserOne); var carTwo = new Car { Model = "Форд Фиеста", LicensePlate = "CO4312KA", CompanyId = "72804eud-3464-hfvs-dasfa", FuelType = PatniListi.Data.Models.Enums.Fuel.Бензин, TankCapacity = 55, AverageConsumption = 6, InitialFuel = 10, StartKilometers = 230444 }; var carUserTwo = new CarUser { CarId = carTwo.Id, UserId = "242hds-78dhgf-7823dsds" }; carTwo.CarUsers.Add(carUserTwo); var carUserTwoOne = new CarUser { CarId = carTwo.Id, UserId = "242tre-78dhgf-7823dsds" }; carTwo.CarUsers.Add(carUserTwoOne); var carThree = new Car { Model = "Форд Фиеста 8", LicensePlate = "CO9812KA", CompanyId = "72804eudajhkhfvs-dasfa", FuelType = PatniListi.Data.Models.Enums.Fuel.Дизел, TankCapacity = 55, AverageConsumption = 5, InitialFuel = 10, StartKilometers = 234957 }; var carUserThree = new CarUser { CarId = carThree.Id, UserId = "242tre-78dhgf-7823dsds" }; carThree.CarUsers.Add(carUserThree); await repository.AddAsync(carOne); await repository.AddAsync(carTwo); await repository.AddAsync(carThree); await repository.SaveChangesAsync(); var carsService = new CarsService(repository); AutoMapperConfig.RegisterMappings(typeof(CarDetailsViewModel).Assembly); var car = await carsService.GetDetailsAsync <CarDetailsViewModel>(carThree.Id); Assert.Equal(carThree.Model, car.Model); Assert.Equal(carThree.LicensePlate, car.LicensePlate); Assert.Equal(carThree.CarUsers.Count(), car.AllDrivers.Count()); }
public async Task UpdateAsync_WithValidModel_WorksCorrectly() { // Arrange var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var model = new CarModel { Model = "Test Model" }; await context.CarModels.AddAsync(model); var user = new PoolItUser { UserName = "******" }; await context.Users.AddAsync(user); var car = new Car { ModelId = model.Id, Colour = "Test Colour", OwnerId = user.Id }; await context.Cars.AddAsync(car); await context.SaveChangesAsync(); var carsService = new CarsService(new EfRepository <Car>(context), null, null); var serviceModel = new CarServiceModel { Id = car.Id, ModelId = car.ModelId, OwnerId = car.OwnerId, Colour = "Updated Colour", Details = "Updated Details" }; // Act var result = await carsService.UpdateAsync(serviceModel); // Assert Assert.True(result); var dbModel = await context.Cars.SingleAsync(); Assert.Equal(serviceModel.Colour, dbModel.Colour); Assert.Equal(serviceModel.Details, dbModel.Details); }
public void GetAllCarsIndex_GivenNullUserId_ShouldReturnNull() { // arrange CarsService service = new CarsService(null, null); // act var result = service.GetAllCarsIndex(null); // assert result.Should().BeNull(); }
public void GetById_GivenNegativeCarId_ShouldThrowNegativeIntException() { // arrange int carId = -1; CarsService service = new CarsService(null, null); // act // assert service .Invoking(x => x.GetById(carId)) .Should().ThrowExactly <NegativeIntException>(); }
public void Edit_GivenNullViewModel_ShouldThrowNullObjectException() { // arrange int carId = 1; CarsService service = new CarsService(null, null); // act Func <Task> action = () => service.Edit(carId, null); // assert action.Should().ThrowExactly <NullObjectException>(); }
public void Edit_GivenNegativeId_ShouldThrowNegativeIntException() { // arrange int carId = -1; CarsService service = new CarsService(null, null); // act Func <Task> action = () => service.Edit(carId, null); // assert action.Should().ThrowExactly <NegativeIntException>(); }
public void AddShould_ThrowException_WhenPassedNullAlbum() { // Arrange var carRepo = new Mock <IEfRepository <Car> >(); var uow = new Mock <IUnitOfWork>(); // Act var carsService = new CarsService(carRepo.Object, uow.Object); // Assert Assert.ThrowsException <ArgumentNullException>(() => carsService.Add(null)); }
public void CreateInstance_OfTypeICarsService() { // Arrange CarsSystemDbContext context = new CarsSystemDbContext(); EfGenericRepository <Car> carRepo = new EfGenericRepository <Car>(context); // Act var carsService = new CarsService(carRepo); // Assert Assert.IsInstanceOf <ICarsService>(carsService); }
public void AddShould_NotThrow_WhenValuesAreCorrect() { // Arrange var carRepo = new Mock <IEfRepository <Car> >(); var uow = new Mock <IUnitOfWork>(); var car = new Mock <Car>(); // Act var carsService = new CarsService(carRepo.Object, uow.Object); // Assert carsService.Add(car.Object); }
public async System.Threading.Tasks.Task WhenGetManufacturersAsyncIsCalled_RepositoryGetManufacturersShouldBeCalledAsync() { //Arrange var fakeRepository = new Mock <ICarsRepository>(); var service = new CarsService(fakeRepository.Object); //Act var result = await service.GetManufacturersAsync(); //Assert fakeRepository.Verify(x => x.GetManufacturers()); }
public async System.Threading.Tasks.Task WhenGetUserAsyncIsCalled_RepositoryGetCarsShouldBeCalledAsync() { //Arrange var fakeRepository = new Mock <ICarsRepository>(); var service = new CarsService(fakeRepository.Object); //Act var result = await service.GetUserDetailsByIdAsync(It.IsAny <int>()); //Assert fakeRepository.Verify(x => x.GetCars()); }
private static async Task <string> GetAccessToken() { var client = new CarsService( MachineLearningServer.Url, new BasicAuthenticationCredentials()); var loginRequest = new LoginRequest( MachineLearningServer.User, MachineLearningServer.Password); var loginResponse = await client.LoginAsync(loginRequest); return(loginResponse.AccessToken); }
public void CanAddCar() { var called = false; var expected_try_add_result = false; var mock_repository = new Mock <ICarsRepository>(); mock_repository.Setup(v => v.TryAdd(It.IsAny <Guid>(), It.IsAny <Car>())) .Returns((Guid _g, Car _c) => { called = true; return(expected_try_add_result); }); var cars_service = new CarsService(mock_repository.Object); (var car, var maybe_error) = cars_service.AddCar(Clients[0], new NewCar { Year = 1885 }); Assert.That(!called); Assert.That(car, Is.Null); Assert.That(maybe_error?.Reason, Does.Match("1886. .* is earlier than that")); Assert.That(maybe_error?.StatusCode, Is.EqualTo(400)); (car, maybe_error) = cars_service.AddCar(Clients[1], new NewCar { Year = DateTime.Now.Year + 1 }); Assert.That(!called); Assert.That(car, Is.Null); Assert.That(maybe_error?.Reason, Does.Match("Your car's built year .* is in the future.")); Assert.That(maybe_error?.StatusCode, Is.EqualTo(400)); (car, maybe_error) = cars_service.AddCar(Clients[2], new NewCar { Year = DateTime.Now.Year - 1 }); Assert.That(called); Assert.That(car, Is.Null); Assert.That(maybe_error?.Reason, Does.Match("Unexpected error: failed to add new car")); Assert.That(maybe_error?.StatusCode, Is.EqualTo(500)); called = false; expected_try_add_result = true; (car, maybe_error) = cars_service.AddCar(Clients[3], new NewCar { Year = DateTime.Now.Year - 1, Model = "Model 1", Make = "Make 1", Stock = 20 }); Assert.That(called); Assert.That(car.Model, Is.EqualTo("Model 1")); Assert.That(car.Make, Is.EqualTo("Make 1")); Assert.That(car.Stock, Is.EqualTo(20)); Assert.That(car.Id, Is.Not.EqualTo(Guid.Empty)); Assert.That(Cars.Where(c => c.Id == car.Id), Is.Empty); Assert.That(maybe_error, Is.Null); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Session["CurrentPage"] = "Home"; Session["PageName"] = ""; Session["CurrentPageConfig"] = null; GeneralFunc.SaveSiteVisit(); GeneralFunc.SetPageDefaults(Page); string Make = Request.QueryString[Request.QueryString.Count - 1]; //string Name = Request.Cookies.Get("UserSettings").Values.Get("Name"); //string Phone = Request.Cookies.Get("UserSettings").Values.Get("Phone"); if (Make != null) { string[] strCarid = Make.Split('-'); if(strCarid.Length >= 4) Hadd.Value = strCarid[3].ToString(); CarsService obj = new CarsService(); List<CarsInfo.UsedCarsInfo> objCarInfo = new List<CarsInfo.UsedCarsInfo>(); ServiceReference objServiceReference = new ServiceReference(); ScriptReference objScriptReference = new ScriptReference(); //objServiceReference.Path = "http://cars.hugomirad.com/CarsService.asmx"; //objScriptReference.Path = "http://cars.hugomirad.com/Static/JS/CarsJScriptNew.js"; //objServiceReference.Path = "http://localhost:1460/Cars/CarsService.asmx"; //objScriptReference.Path = "http://localhost:1460/Cars/Static/JS/CarsJScriptNew.js"; objServiceReference.Path = "../CarsService.asmx"; objScriptReference.Path = "../Static/Js/CarsJScriptNew.js"; scrptmgr.Services.Add(objServiceReference); scrptmgr.Scripts.Add(objScriptReference); if (p == 0) { if (strCarid.Length > 1) { string sCarid = strCarid[strCarid.Length - 1]; if (GeneralFunc.IsNumeric(sCarid)) { if (Request.Cookies.Get("UserSettings") == null) { // ClientScript.RegisterStartupScript(typeof(Page), "KyAUIDFCS", "<script language='javascript' type='text/javascript'>Subscribe();</script>"); } objCarInfo = obj.FindCarIDNew(sCarid); FillCarDetails(objCarInfo, sCarid); } } } } else { Response.Redirect("errorpage.aspx"); } } }