Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (RentalService rentalService = new RentalService())
            {
                DialogResult dr = MessageBox.Show("Kaydetmek istediğinize emin misiniz?", "Onay", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dr == DialogResult.Yes)
                {
                    RentalDTO rental = new RentalDTO
                    {
                        CustomerId = (int)(cmbCustomer.SelectedValue),
                        MovieId    = (int)(cmbMovieName.SelectedValue),
                        BeginDate  = dtpBegin.Value,
                        EndDate    = dtpEnd.Value,
                        TotalPrice = Convert.ToDecimal(txtPrice.Text),

                        CreatedBy = 2,
                    };

                    var result = rentalService.Add(rental);

                    if (result != null)
                    {
                        MessageBox.Show("Kayıt başarılı", "Durum", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Kayıt sırasında bir hata oluştu", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        public void ShouldAddRental()
        {
            var request = new CreateRentalRequestModel {
                StartDate = new DateTime(2022, 1, 1), EndDate = new DateTime(2022, 1, 3), ClientId = 1, VehicleId = 1
            };

            vehicleRepositoryMock.Setup(x => x.Find(It.IsAny <int>())).Returns(new Vehicle {
                Active = true, Id = 1, Brand = "brand", PricePerDay = 10, Year = 2022
            });
            clientRepositoryMock.Setup(x => x.Find(It.IsAny <int>())).Returns(new Client {
                Active = true, Id = 1, Name = "name", Phone = "1243"
            });
            rentalRepositoryMock.Setup(x => x.VerifyIfVehicleIsAvailableByRangeDates(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(true);

            Response response = rentalService.Add(request);

            rentalRepositoryMock.Verify(x => x.VerifyIfVehicleIsAvailableByRangeDates(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()), Times.Once);
            rentalRepositoryMock.Verify(x => x.Add(It.IsAny <Rental>()));
            repositoryMock.Verify(x => x.Save(), Times.Once);

            Assert.False(response.HasErrors());
            Assert.AreEqual(response.Messages.Count(x => x.Type == MessageType.Error), 0);
            Assert.AreEqual(response.Messages.Count(x => x.Type == MessageType.Success), 1);
            Assert.AreEqual(response.Messages.Count(x => x.Code == Constants.RENTAL_SAVED), 1);
        }
Пример #3
0
        public void Add_Rental_To_Db()
        {
            var mockDbSet   = new Mock <DbSet <Rental> >();
            var mockContext = new Mock <RentalContext>();

            mockContext.Setup(r => r.Rentals).Returns(mockDbSet.Object);
            var svc = new RentalService(mockContext.Object);

            svc.Add(new Rental());

            mockContext.Verify(a => a.Add(It.IsAny <Rental>()), Times.Once);
            mockContext.Verify(s => s.SaveChanges(), Times.Once);
        }
Пример #4
0
        public void Save()
        {
            RentalDTO rental = new RentalDTO
            {
                CustomerId     = 1,
                MovieId        = 1,
                BeginDate      = new DateTime(2019, 03, 15),
                EndDate        = new DateTime(2019, 03, 30),
                TotalPrice     = 20,
                CreatedDate    = DateTime.Now,
                CreatedBy      = 2,
                RecordStatusId = 1
            };

            var result = rentalService.Add(rental);

            Assert.IsNotNull(result);
        }