Example #1
0
        public async void UpdateVehicle(
            EStatusCode expectedStatus,
            UpdateVehicle mutation,
            bool?withModel = false
            )
        {
            if (expectedStatus != EStatusCode.NotFound)
            {
                EntitiesFactory.NewVehicle(id: mutation.Id).Save();
            }
            if (withModel.Value)
            {
                EntitiesFactory.NewModel(id: mutation.ModelId).Save();
            }

            var result = await MutationsHandler.Handle(mutation);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == EStatusCode.Success)
            {
                var vehicleDb = await MutationsDbContext.Vehicles
                                .Where(v => v.Id == mutation.Id)
                                .FirstOrDefaultAsync();

                Assert.NotNull(vehicleDb);
                Assert.Equal(mutation.Year, vehicleDb.Year);
                Assert.Equal(mutation.Board, vehicleDb.Board);
                Assert.Equal(mutation.ColorId, vehicleDb.Color);
                Assert.Equal(mutation.FuelId, vehicleDb.Fuel);
                Assert.Equal(mutation.ModelId, vehicleDb.Model.Id);
            }
        }
Example #2
0
        public async void CreateAnnouncement(
            EStatusCode expectedStatus,
            CreateAnnouncement mutation,
            bool?withVehicle = false
            )
        {
            if (withVehicle.Value)
            {
                EntitiesFactory.NewVehicle(id: mutation.VehicleId).Save();
            }
            var result = await MutationsHandler.Handle(mutation);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == EStatusCode.Success)
            {
                var announcementDb = await MutationsDbContext.Announcements
                                     .Where(a => a.Id == mutation.Id)
                                     .FirstOrDefaultAsync();

                Assert.NotNull(announcementDb);
                Assert.Equal(mutation.PricePurchase, announcementDb.PricePurchase);
                Assert.Equal(mutation.PriceSale, announcementDb.PriceSale);
                Assert.Equal(mutation.VehicleId, announcementDb.Vehicle.Id);
                Assert.Null(announcementDb.DateSale);
            }
        }
Example #3
0
        public async void GetVehicle(
            EStatusCode expectedStatus,
            GetVehicle query
            )
        {
            var vehicle = null as Questor.Vehicle.Domain.Mutations.Vehicles.Entities.Vehicle;

            if (expectedStatus != EStatusCode.NotFound)
            {
                vehicle = EntitiesFactory.NewVehicle(id: query.Id).Save();
            }

            var(status, result) = await Request.Get <QueryResultOneTest <VehicleDetail> >(new Uri($"{Uri}/{query.Id}"), query);

            Assert.Equal(expectedStatus, status);
            if (expectedStatus == EStatusCode.Success)
            {
                Assert.NotNull(result.Data);
                var vehicleResult = result.Data;
                Assert.Equal(vehicle.Year, vehicleResult.Year);
                Assert.Equal(vehicle.Model.BrandId, vehicleResult.BrandId);
                Assert.Equal(vehicle.Model.Brand.Name, vehicleResult.BrandName);
                Assert.Equal(vehicle.ModelId, vehicleResult.ModelId);
                Assert.Equal(vehicle.Model.Name, vehicleResult.ModelName);
                Assert.Equal(vehicle.Fuel, vehicleResult.FuelId);
                Assert.Equal(vehicle.Color, vehicleResult.ColorId);
            }
        }
        public async void ListVehicles(
            EStatusCode expectedStatus,
            ListVehicles query
            )
        {
            var vehicle = EntitiesFactory.NewVehicle(
                brandId: query.BrandId,
                modelId: query.ModelId,
                fuel: query.FuelId,
                color: query.ColorId
                ).Save();

            var(status, result) = await Request.Get <QueryResultListTest <VechicleList> >(Uri, query);

            Assert.Equal(expectedStatus, status);
            if (expectedStatus == EStatusCode.Success)
            {
                Assert.NotNull(result.Data);
                var vehicleResult = result.Data.FirstOrDefault(v => v.Id == vehicle.Id);
                Assert.NotNull(vehicleResult);
                Assert.Equal(vehicle.Year, vehicleResult.Year);
                Assert.Equal(vehicle.Model.Brand.Name, vehicleResult.BrandName);
                Assert.Equal(vehicle.Model.Name, vehicleResult.ModelName);
                Assert.NotNull(vehicleResult.ColorHex);
                Assert.NotNull(vehicleResult.ColorName);
                Assert.NotNull(vehicleResult.FuelName);
            }
        }
        public async void ListVehiclesSelect(
            EStatusCode expectedStatus,
            ListVehiclesSelect query
            )
        {
            var vehicle = EntitiesFactory.NewVehicle().Save();

            var(status, result) = await Request.Get <QueryResultListTest <VehicleSelectList> >(Uri, query);

            Assert.Equal(expectedStatus, status);
            if (expectedStatus == EStatusCode.Success)
            {
                var announcementResult = result.Data.FirstOrDefault(a => a.Id == vehicle.Id);
                Assert.NotNull(announcementResult);
            }
        }
Example #6
0
        public async void DeleteVehicle(
            EStatusCode expectedStatus,
            DeleteVehicle mutation
            )
        {
            if (expectedStatus != EStatusCode.NotFound)
            {
                EntitiesFactory.NewVehicle(id: mutation.Id).Save();
            }

            var result = await MutationsHandler.Handle(mutation);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == EStatusCode.Success)
            {
                var exists = await MutationsDbContext.Vehicles.AnyAsync(v => v.Id == mutation.Id);

                Assert.False(exists);
            }
        }
Example #7
0
        public async void ListAnnouncement(
            EStatusCode expectedStatus,
            ListAnnouncement query,
            bool?exactlyAnnouncement = false
            )
        {
            var vehicle = EntitiesFactory.NewVehicle(
                brandId: query.BrandId,
                modelId: query.ModelId,
                color: query.ColorId,
                year: query.Year
                ).Save();
            var announcement = EntitiesFactory.NewAnnouncement(
                vehicle: vehicle,
                dateSale: query.DateSale?.DateTime
                ).Save();

            var(status, result) = await Request.Get <QueryResultListTest <AnnouncementList> >(Uri, query);

            Assert.Equal(expectedStatus, status);
            if (expectedStatus == EStatusCode.Success)
            {
                Assert.True(result.TotalRows > 0);
                Assert.True(result.Data.Length <= query.Limit);
            }
            if (exactlyAnnouncement.Value)
            {
                var listAnnouncement   = result.Data.ToList();
                var announcementResult = listAnnouncement
                                         .Where(a => a.Id == announcement.Id)
                                         .FirstOrDefault();
                Assert.NotNull(announcementResult);
                Assert.Equal(announcement.PricePurchase, announcementResult.PricePurchase);
                Assert.Equal(announcement.PriceSale, announcementResult.PriceSale);
                Assert.Equal(announcement.DateSale.Value.Date, announcementResult.DateSale.Value.Date);
                Assert.Equal(announcement.Vehicle.Year, announcementResult.VehicleYear);
                Assert.Equal(announcement.Vehicle.Model.Brand.Name, announcementResult.VehicleBrandName);
                Assert.Equal(announcement.Vehicle.Model.Name, announcementResult.VehicleModelName);
            }
        }