コード例 #1
0
        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());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
ファイル: AddCar.cs プロジェクト: jRaczy/Car-Workshop-Desktop
        /// <summary>
        /// Metoda sprawdza czy wprowadzone dane są poprawnie zwalidowane oraz wywołuje metodę która dodaje obiekt do bazy danych oraz zaczytuje nowe wartości do dataGridView1
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (new CarValidator(tbModel.Text, tbVin.Text, tbBrand.Text, tbYearOfProduction.Text).IsDataValid() is false)
            {
                MessageBox.Show("Uzupełnij wszystkie pola!");
                return;
            }

            carsService.Add(Convert.ToInt32(tbVin.Text), Convert.ToInt32(tbYearOfProduction.Text), tbBrand.Text, tbModel.Text, tbComments.Text, ClientId);

            ClearTextValue();
            var cars = new CarRepository().GetByClientId(ClientId);

            dataGridView1.DataSource = cars;
        }
コード例 #5
0
        public async Task given_car_domain_obj_add_api_should_add_it_to_repository()
        {
            // setup
            var givenCarDomain = new CarDomain(1, "blue", "japan", "subaru", "outback", 10000m, 2009);

            _mockCarsRepository.Setup(c => c.Add(givenCarDomain)).ReturnsAsync(1);
            _mockCarsRepository.Setup(c => c.GetAll()).ReturnsAsync(new List <CarDomain>());

            // act
            var result = await _carsService.Add(givenCarDomain);

            // assert
            _mockCarsRepository.Verify(c => c.Add(givenCarDomain), Times.Once);
            _mockCarsRepository.Verify(c => c.GetAll(), Times.Once);
            Assert.True(result.IsSuccess);
            Assert.Empty(result.Message);
        }