public async Task NewAsyncShouldThrowArgumentNullExceptionOnNullProviderId() { // arrange var providerBoatTowRepository = new ProviderBoatTowRepository(_mongoDatabase); var providerBoatTow = new ProviderBoatTow(); // act (deferred) var testCode = (Func <Task>)(async() => await providerBoatTowRepository.NewAsync(null, providerBoatTow)); // assert await Assert.ThrowsAsync <ArgumentNullException>(testCode); }
private static ProviderBoatTowViewModel MapToProviderBoatTowViewModel(ProviderBoatTow providerBoatTow) => providerBoatTow != null ? new ProviderBoatTowViewModel { Id = providerBoatTow.Id, RegistrationNumber = providerBoatTow.RegistrationNumber, Name = providerBoatTow.Name, BoatModel = providerBoatTow.BoatModel, EngineType = providerBoatTow.EngineType, FuelCostPerKm = providerBoatTow.FuelCostPerKm } : null;
public async Task <IActionResult> NewProviderBoatTow(string providerId, [FromBody] ProviderBoatTowBindingModel providerBoatTowBindingModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrors())); } var providerBoatTow = new ProviderBoatTow { BoatModel = providerBoatTowBindingModel.BoatModel, EngineType = providerBoatTowBindingModel.EngineType, Name = providerBoatTowBindingModel.Name, RegistrationNumber = providerBoatTowBindingModel.RegistrationNumber, FuelCostPerKm = providerBoatTowBindingModel.FuelCostPerKm }; var(providerBoatTowResult, outcomeAction, error) = await _providerBoatTowRepository.NewAsync(providerId, providerBoatTow); return(this.FromRepositoryOutcome(outcomeAction, error, MapToProviderBoatTowViewModel(providerBoatTowResult), Url.BuildGetProviderBoatTowUrl(providerId, providerBoatTowResult.Id))); }
public async Task <IActionResult> UpdateProviderBoatTow(string providerId, string id, [FromBody] ProviderBoatTowBindingModel boatTow) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrors())); } var providerBoatTow = new ProviderBoatTow { Id = id, BoatModel = boatTow.BoatModel, EngineType = boatTow.EngineType, Name = boatTow.Name, RegistrationNumber = boatTow.RegistrationNumber, FuelCostPerKm = boatTow.FuelCostPerKm }; var(providerBoatTowResult, outcomeAction, error) = await _providerBoatTowRepository.UpdateAsync(providerId, providerBoatTow); return(this.FromRepositoryOutcome(outcomeAction, error, MapToProviderBoatTowViewModel(providerBoatTowResult))); }
public void EnsureProviderBoatTow(ProviderBoatTow providerBoatTow) { _mongoDatabase.BoatTows().InsertOne(providerBoatTow); }
public async Task <(ProviderBoatTow boatTow, RepositoryOutcomeAction outcomeAction, object error)> UpdateAsync(string providerId, ProviderBoatTow boatTow, CancellationToken cancellationToken = default(CancellationToken)) { if (providerId == null) { throw new ArgumentNullException(nameof(providerId)); } if (boatTow == null) { throw new ArgumentNullException(nameof(boatTow)); } var providerExists = await(await _mongoDatabase.Providers().FindAsync(_ => _.Id == providerId, cancellationToken: cancellationToken)).AnyAsync(cancellationToken); if (!providerExists) { return(null, RepositoryOutcomeAction.ValidationErrorNone, new { cause = "Missing Provider", data = providerId }); } boatTow.ProviderId = providerId; var result = await _mongoDatabase .BoatTows() .ReplaceOneAsync(_ => _.Id == boatTow.Id, boatTow, cancellationToken: cancellationToken); return (result.MatchedCount == 1 && result.MatchedCount == result.ModifiedCount ? (boatTow, RepositoryOutcomeAction.OkUpdated, null) : ((ProviderBoatTow)null, RepositoryOutcomeAction.NotFoundNone, (object)null)); }
public async Task <(ProviderBoatTow boatTow, RepositoryOutcomeAction outcomeAction, object error)> NewAsync(string providerId, ProviderBoatTow boatTow, CancellationToken cancellationToken = default(CancellationToken)) { if (providerId == null) { throw new ArgumentNullException(nameof(providerId)); } if (boatTow == null) { throw new ArgumentNullException(nameof(boatTow)); } var providerExists = await(await _mongoDatabase.Providers().FindAsync(_ => _.Id == providerId, cancellationToken: cancellationToken)).AnyAsync(cancellationToken); if (!providerExists) { return(null, RepositoryOutcomeAction.ValidationErrorNone, new { cause = "Missing Provider", data = providerId }); } boatTow.Id = Guid.NewGuid().ToString("n"); boatTow.ProviderId = providerId; await _mongoDatabase .BoatTows() .InsertOneAsync(boatTow, cancellationToken: cancellationToken); return(boatTow, RepositoryOutcomeAction.OkCreated, null); }