public async Task <ActionResult <ProductTypeCreated> > Post(Commands.Create request) { try { request.Id = new ProductTypeId(SequentialGuid.NewSequentialGuid()); await RequestHandler.HandleCommand(request, service.Handle); // HACK: Future me, do something clever instead... if (!string.IsNullOrEmpty(request.Name)) { return(new ProductTypeCreated { Id = (Guid)request.Id, Name = request.Name }); } return(new BadRequestObjectResult( new { error = "ProductType was not in valid state! Name should not be empty." } )); } catch (Exception e) { Log.Logger.Error(e, "Somehow something happened while creating a new product type =-O"); throw; } }
public async Task <ActionResult <SizeCreated> > Post(Commands.Create request) { try { request.Id = new SizeId(SequentialGuid.NewSequentialGuid()); await RequestHandler.HandleCommand(request, _service.Handle); // HACK: Future me, do something clever instead... if (!string.IsNullOrEmpty(request.Amount)) { if (request.Id != null) { return new SizeCreated { Id = (Guid)request.Id, Amount = request.Amount } } ; } return(new BadRequestObjectResult( new { error = "Size was not in valid state! Amount should not be empty." } )); } catch (Exception e) { Log.Logger.Error(e, "Somehow something happened while creating a new size =-O"); throw; } }
public async Task <ActionResult <Created> > Post(Commands.Create request) { try { await RequestHandler.HandleCommand(request, _service.Handle); // HACK: Future me, do something clever instead... if (!string.IsNullOrEmpty(request.Name)) { if (request.Id != null) { return new Created { Id = (Guid)request.Id, Name = request.Name } } ; } return(new BadRequestObjectResult( new { error = "Language was not in valid state! Name should not be empty." } )); } catch (Exception e) { Log.Logger.Error(e, "Somehow something happened while creating a new language =-O"); throw; } }
public async Task <ActionResult <LocationCreated> > Post(Commands.Create request) { if (request.CityId == default || request.CountryId == default) { return(new BadRequestObjectResult( new { error = "Location was not in valid state! Name should not be empty." } )); } try { request.Id = new LocationId(SequentialGuid.NewSequentialGuid()); await RequestHandler.HandleCommand(request, service.Handle); return(new LocationCreated { Id = (Guid)request.Id }); } catch (Exception e) { Log.Logger.Error(e, "Somehow something happened while creating a new location =-O"); throw; } }
public static async Task <dynamic> CreateInvalidBrand() { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new BrandRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new BrandService(repository, unitOfWork); var command = new Commands.Create { Id = null }; var brandController = new BrandController(service); return(await brandController.Post(command)); }
public static async Task <Brand> CreateValidBrand() { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new BrandRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new BrandService(repository, unitOfWork); var command = new Commands.Create { Name = "Levi's", Id = null }; var brandController = new BrandController(service); var brand = await brandController.Post(command); return(await repository.GetAsync(brand.Value.Id)); }
public static async Task <ProductType> CreateValidProductType() { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new ProductTypeRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new ProductTypeService(repository, unitOfWork); var command = new Commands.Create { Name = "trousers", Id = null }; var productTypeController = new ProductTypeController(service); var productType = await productTypeController.Post(command); return(await repository.GetAsync(productType.Value.Id)); }
public static async Task <Country> CreateValidCountry() { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new CountryRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new CountryService(repository, unitOfWork); var command = new Commands.Create { Name = "Rapture", Id = null }; var countryController = new CountryController(service); var country = await countryController.Post(command); return(await repository.GetAsync(country.Value.Id)); }
public async Task <ActionResult <PurchaseTransactionCreated> > Post(Commands.Create request) { try { request.Id = new PurchaseTransactionId(SequentialGuid.NewSequentialGuid()); await RequestHandler.HandleCommand(request, service.Handle); return(new PurchaseTransactionCreated { Id = (Guid)request.Id }); } catch (Exception e) { Log.Logger.Error(e, "Somehow something happened =-O"); return(new BadRequestResult()); throw; } }
public async Task New_Language_Fails() { var mockService = new Mock <ISimpleDomainService <Language, LanguageId> >(); var lookupServiceMock = new Mock <ILanguageLookupDataService>(); var cmd = new Commands.Create { Id = null }; mockService.Setup(s => s.Handle(cmd)) .Returns(() => Task.FromException(new Exception())); var languageController = new LanguageController(mockService.Object, lookupServiceMock.Object); Func <Task> action = async() => await languageController.Post(cmd); action.Should().Throw <Exception>(); mockService.Verify(x => x.Handle(cmd), Times.Once()); }
public async Task Create_New_Language() { var mockService = new Mock <ISimpleDomainService <Language, LanguageId> >(); var lookupServiceMock = new Mock <ILanguageLookupDataService>(); var cmd = new Commands.Create { Id = Guid.NewGuid(), Name = "Gibberish" }; var created = new Events.Created { Id = (Guid)cmd.Id, Name = cmd.Name }; mockService.Setup(s => s.Handle(cmd)) .Returns(() => Task.FromResult(created)); var languageController = new LanguageController(mockService.Object, lookupServiceMock.Object); var result = await languageController.Post(cmd); mockService.Verify(x => x.Handle(cmd), Times.Once()); result.Value.Id.Should().Be(cmd.Id.ToString()); result.Value.Name.Should().Be(cmd.Name); }