Exemplo n.º 1
0
        public async Task LotService_AddAsync_AddsLot()
        {
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(m => m.LotRepository.Add(It.IsAny <Lot>()));
            var lotService = new LotService(mockUnitOfWork.Object, UnitTestHelper.CreateMapperProfile());
            var lot        = new LotModel
            {
                TurnkeyPrice = 5000,
                SellerId     = "1",
                SaleType     = SaleTypeDto.BrandNew,
                StartPrice   = 1000,
                Car          = new CarModel
                {
                    Brand             = "CarBrand",
                    Model             = "CarModel",
                    Year              = 2014,
                    Mileage           = 100000,
                    EngineType        = "2.3",
                    TechnicalPassport = new TechnicalPassportModel
                    {
                        VIN          = "4Y1SL65848Z411439",
                        HasKeys      = true,
                        Transmission = TransmissionDto.MT,
                        DriveUnit    = DriveUnitDto.FourWheelDrive,
                        BodyType     = BodyTypeDto.PeopleMover
                    }
                }
            };

            var result = await lotService.AddAsync(lot);

            Assert.IsTrue(result.Succedeed);
            mockUnitOfWork.Verify(
                m => m.LotRepository.Add(It.Is <Lot>(
                                             l => l.Car.Brand == lot.Car.Brand &&
                                             l.TurnkeyPrice == lot.TurnkeyPrice &&
                                             l.SaleType == SaleType.BrandNew)),
                Times.Once);
            mockUnitOfWork.Verify(
                m => m.SaveAsync(),
                Times.Once);
        }
Exemplo n.º 2
0
        public async Task LotService_AddAsync_ReturnErrorsWithInvalidModel()
        {
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(m => m.LotRepository.Add(It.IsAny <Lot>()));
            var lotService = new LotService(mockUnitOfWork.Object, UnitTestHelper.CreateMapperProfile());
            var lot        = new LotModel
            {
                TurnkeyPrice = 5000,
                SellerId     = "1",
                SaleType     = SaleTypeDto.BrandNew,
                Car          = new CarModel
                {
                    Brand             = "",
                    Model             = "CarModel",
                    Year              = 2022,
                    Mileage           = 100000,
                    TechnicalPassport = new TechnicalPassportModel
                    {
                        VIN          = "4Y1SL65848Z411439",
                        HasKeys      = true,
                        Transmission = TransmissionDto.AT,
                        DriveUnit    = DriveUnitDto.FourWheelDrive,
                    }
                }
            };

            var result = await lotService.AddAsync(lot);

            Assert.IsFalse(result.Succedeed);
            mockUnitOfWork.Verify(
                m => m.LotRepository.Add(It.Is <Lot>(
                                             l => l.Car.Brand == lot.Car.Brand &&
                                             l.TurnkeyPrice == lot.TurnkeyPrice &&
                                             l.SaleType == SaleType.BrandNew)),
                Times.Never);
            mockUnitOfWork.Verify(
                m => m.SaveAsync(),
                Times.Never);
        }