public async void CreateVehicle( EStatusCode expectedStatus, CreateVehicle mutation, bool?withModel = false ) { 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); } }
public async Task UpdateModel( EStatusCode expectedStatus, UpdateModel mutation, bool?withModel = false, bool?withBrand = false ) { if (withBrand.Value) { EntitiesFactory.NewBrand(id: mutation.BrandId).Save(); } if (withModel.Value) { EntitiesFactory.NewModel(id: mutation.Id, name: mutation.Name).Save(); } if (expectedStatus == EStatusCode.Conflict) { EntitiesFactory.NewModel(name: mutation.Name).Save(); } var result = await MutationsHandler.Handle(mutation); Assert.Equal(expectedStatus, result.Status); if (expectedStatus == EStatusCode.Success) { var modelDb = await MutationsDbContext.Models.FindAsync(mutation.Id); Assert.Equal(mutation.Name, modelDb.Name); Assert.Equal(mutation.BrandId, modelDb.BrandId); } }
public async void ListModels( EStatusCode expectedStatus, ListModels query ) { var model = EntitiesFactory.NewModel().Save(); var(status, result) = await Request.Get <QueryResultListTest <ModelList> >(Uri, query); Assert.Equal(expectedStatus, status); if (expectedStatus == EStatusCode.Success) { Assert.NotEmpty(result.Data); Assert.Contains(result.Data, d => d.Id == model.Id); } }
public async void ListModelsSelect( EStatusCode expectedStatus, ListModelsSelect query ) { var model = EntitiesFactory.NewModel(brandId: query.BrandId).Save(); var(status, result) = await Request.Get <QueryResultListTest <ModelSelectList> >(Uri, query); Assert.Equal(expectedStatus, status); if (expectedStatus == EStatusCode.Success) { var modelResult = result.Data.FirstOrDefault(m => m.Id == model.Id); Assert.NotNull(modelResult); Assert.Equal(model.Name, modelResult.Name); } }
private async Task CreateVehicleWithImageAsync(string id) { var image = new Bitmap(200, 200, PixelFormat.Format24bppRgb); var stream = new MemoryStream(); image.Save(stream, ImageFormat.Bmp); byte[] imageBytes = stream.ToArray(); var model = EntitiesFactory.NewModel().Save(); var createVehicle = new CreateVehicle { Id = id ?? RandomId.NewId(), FuelId = EFuel.Flex, ColorId = EColor.Black, Year = 2010, ModelId = model.Id }; createVehicle.ImageBase64 = Convert.ToBase64String(imageBytes); await MutationsHandler.Handle(createVehicle); }
public async Task DeleteModel( EStatusCode expectedStatus, DeleteModel mutation ) { if (expectedStatus != EStatusCode.NotFound) { EntitiesFactory.NewModel(id: mutation.Id).Save(); } var result = await MutationsHandler.Handle(mutation); Assert.Equal(expectedStatus, result.Status); if (expectedStatus == EStatusCode.Success) { var exists = await MutationsDbContext.Models.AnyAsync(m => m.Id == mutation.Id); Assert.False(exists); } }
public async void GetModel( EStatusCode expectedStatus, GetModel query ) { var model = null as Model; if (expectedStatus != EStatusCode.NotFound) { model = EntitiesFactory.NewModel(id: query.Id).Save(); } var(status, result) = await Request.Get <QueryResultOneTest <ModelDetail> >(new Uri($"{Uri}/{query.Id}"), query); Assert.Equal(expectedStatus, status); if (expectedStatus == EStatusCode.Success) { var modelResult = result.Data; Assert.NotNull(modelResult); Assert.Equal(model.Id, modelResult.Id); Assert.Equal(model.Name, modelResult.Name); } }
public async Task CreateModel( EStatusCode expectedStatus, CreateModel mutation ) { if (expectedStatus != EStatusCode.NotFound) { EntitiesFactory.NewBrand(id: mutation.BrandId).Save(); } if (expectedStatus == EStatusCode.Conflict) { EntitiesFactory.NewModel(name: mutation.Name).Save(); } var result = await MutationsHandler.Handle(mutation); Assert.Equal(expectedStatus, result.Status); if (expectedStatus == EStatusCode.Success) { var modelDb = await MutationsDbContext.Models.FindAsync(mutation.Id); Assert.Equal(mutation.Name, modelDb.Name); } }