public ActionResult Distribution([FromServices] InMemoryDataContext context, [FromBody] DistributionRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var useCase = new UseCase( _logger, new EmployeeAdapter(context), new CalculationInfluenceAdapter( new AreaCalculator(), new SalaryCalculator(), new AdmissionAtCalculator() ) ); var response = useCase.Execute(new Request( request.AvailableValue )); return(JsonResponse.Success((new DistributionPresenter(response)).Present())); } catch (InsufficientAvailableValueException exception) { return(JsonResponse.Error(exception.Message, 400)); } catch (System.Exception exception) { return(JsonResponse.Error(exception.Message)); } }
public void TestShoulReturnTwoParticipations() { var employee = Stubs.ValidEmployee(); var request = Stubs.ValidRequest(); _employeeGatewayMock.List().Returns(new List <Employee>() { employee, employee }); var useCase = new UseCase( _loggerGatewayMock, _employeeGatewayMock, _calculationInfluenceGateway ); var response = useCase.Execute(request); var participations = response.Distribution.Participations; Assert.Equal(36565056, response.Distribution.TotalDistributed); Assert.Same(employee, participations[0].Employee); Assert.Equal(request.AvailableValue, response.Distribution.TotalAvailable); Assert.Equal(2, participations.Count); }
public async Task ShouldSuccess() { var presenter = new Presenter(); var useCase = new UseCase( _fixture.CountryServiceFake, presenter); await useCase.Execute(new InputData("Americas")); Assert.NotEmpty(presenter.OutputData.Countries); }
public async Task ShouldReturnEmpty() { var presenter = new Presenter(); var useCase = new UseCase( _fixture.CountryServiceFake, presenter); await useCase.Execute(new InputData("SAdjlk SAdlkj ASçsad ASDk")); Assert.Empty(presenter.OutputData.Countries); }
public void TestShouldReturnFindEmployeeException() { _employeeGatewayMock.List().Returns(x => { throw new Exception(); }); var useCase = new UseCase( _loggerGatewayMock, _employeeGatewayMock, _calculationInfluenceGateway ); Assert.Throws <FindEmployeeException>(() => useCase.Execute(Stubs.ValidRequest())); }
public async Task ShouldSuccess(string name, string abbreviation) { var presenter = new Presenter(); var useCase = new UseCase( _fixture.CountryServiceFake, presenter); await useCase.Execute(new InputData(name)); Assert.Equal(abbreviation, presenter.OutputData.Abbreviation); }
public JsonResult Distribution() { try { var useCase = new UseCase(_logger); useCase.Execute(new Core.Modules.Distribution.Request()); return(JsonResponse.Success()); } catch (System.Exception exception) { return(JsonResponse.Error(exception.Message)); } }
public async Task ShouldThrowsNotFound() { var presenter = new Presenter(); var useCase = new UseCase( _fixture.CountryServiceFake, presenter); await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { await useCase.Execute(new InputData("Island")); }); }
public async Task ShouldSuccess() { var presenter = new Presenter(); var useCase = new UseCase( _fixture.CountryServiceFake, presenter); var cancellationTokenSource = new CancellationTokenSource(); await useCase.Execute(new InputData(string.Empty), cancellationTokenSource.Token); Assert.NotEmpty(presenter.OutputData.Countries); }
public async Task <ActionResult <UseCaseResult <bool> > > Delete(string fileReference) { try { return(Ok(await UseCase.Execute(new DeleteFile { FileReference = fileReference }))); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, "Delete Failed: " + e.Message)); } }
public async Task ShouldReturnOnlyOne() { var presenter = new Presenter(); var useCase = new UseCase( _fixture.CountryServiceFake, presenter); var cancellationTokenSource = new CancellationTokenSource(); await useCase.Execute(new InputData("Brazil"), cancellationTokenSource.Token); Assert.NotEmpty(presenter.OutputData.Countries); Assert.Single(presenter.OutputData.Countries); }
public void TestShouldReturnCalculationInfluenceAreaNotFoundException() { _employeeGatewayMock.List().Returns(new List <Employee>() { Stubs.EmployeeWithInvalidArea() }); var useCase = new UseCase( _loggerGatewayMock, _employeeGatewayMock, _calculationInfluenceGateway ); Assert.Throws <CalculationInfluenceAreaNotFoundException>(() => useCase.Execute(Stubs.ValidRequest())); }
public void TestShouldReturnInsufficientAvailableValueException() { _employeeGatewayMock.List().Returns(new List <Employee>() { Stubs.ValidEmployee() }); var useCase = new UseCase( _loggerGatewayMock, _employeeGatewayMock, _calculationInfluenceGateway ); Assert.Throws <InsufficientAvailableValueException>(() => useCase.Execute(new Request(50))); }
public void TestShouldReturnGenericException() { _employeeGatewayMock.List().Returns(new List <Employee>() { Stubs.ValidEmployee() }); _loggerGatewayMock.When(fake => fake.Info(Arg.Any <string>())).Do(call => { throw new Exception("Generic exception"); }); var useCase = new UseCase( _loggerGatewayMock, _employeeGatewayMock, _calculationInfluenceGateway ); Assert.Throws <Exception>(() => useCase.Execute(Stubs.ValidRequest())); }
public async Task ShouldNotContainsCountry(string regionName, string countryName) { var presenter = new Presenter(); var useCase = new UseCase( _fixture.CountryServiceFake, presenter); var cancellationTokenSource = new CancellationTokenSource(); await useCase.Execute(new InputData(regionName)); var containsCountry = presenter.OutputData.Countries.Any(country => country.Name.Equals(countryName)); Assert.NotEmpty(presenter.OutputData.Countries); Assert.False(containsCountry); }
public async Task <ActionResult> Get(string fileReference) { try { var result = await UseCase.Execute(new DownloadFile { FileReference = fileReference }); var content = result.Data.Contents; var contentType = result.Data.ContentType; //return File(new MemoryStream(content), "application/octet-stream"); // returns a FileStreamResult return(File(new MemoryStream(content), contentType ?? "application/octet-stream")); // returns a FileStreamResult } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public void TestShouldReturnGetCalculationInfluenceException() { var employee = Stubs.ValidEmployee(); _employeeGatewayMock.List().Returns(new List <Employee>() { employee }); var calculationInfluenceGatewayMock = Substitute.For <CalculationInfluenceGateway>(); calculationInfluenceGatewayMock.GetCalculationInfluence(employee).Returns(x => { throw new Exception(); }); var useCase = new UseCase( _loggerGatewayMock, _employeeGatewayMock, calculationInfluenceGatewayMock ); Assert.Throws <GetCalculationInfluenceException>(() => useCase.Execute(Stubs.ValidRequest())); }
public async Task <ActionResult <UseCaseResult <StoredFileModel> > > UploadFile(IFormFile file) { try { if (file.Length > 0) { using (var ms = new MemoryStream()) { file.CopyTo(ms); return(Ok(await UseCase.Execute(new UploadFile { FileName = file.FileName, Contents = ms.ToArray(), ContentType = file.ContentType }))); } } else { return(StatusCode(StatusCodes.Status204NoContent, "Empty file")); } } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, "Upload Failed: " + e.Message)); } }
public async Task <ActionResult <UseCaseResult <JobModel> > > Get(Guid id) { return(Ok(await UseCase.Execute(new GetJob { Id = id }))); }
public async Task <ActionResult <UseCaseResult <OvertureUser> > > Put([FromBody] UpdateUser request) { return(Ok(await UseCase.Execute(request))); }
public async Task <ActionResult <UseCaseResult <ServiceArea> > > Get([FromQuery] GetServiceAreas request) { return(Ok(await UseCase.Execute(request))); }
public async Task <ActionResult <UseCaseResult <InitializeDataModel> > > Post([FromBody] InitializeData request) { return(Ok(await UseCase.Execute(request))); }
public async Task <ActionResult <UseCaseResult <IEnumerable <BusinessServiceCategoryModel> > > > Get([FromQuery] GetBusinessServiceCategoriesList request) { return(Ok(await UseCase.Execute(request))); }
public async Task <ActionResult <UseCaseResult <ReviewModel> > > Get([FromQuery] GetReviews request) { return(Ok(await UseCase.Execute(request))); }
public async Task <ActionResult <UseCaseResult <ReviewModel> > > Post([FromBody] CreateReview request) { return(Ok(await UseCase.Execute(request))); }
public async Task ItThrowsNoAssetsException() { Assert.ThrowsAsync <NoAssetsException>(async() => await UseCase.Execute(id)); }
public async Task <ActionResult <UseCaseResult <BusinessModel> > > Put([FromBody] UpdateBusiness request) { return(Ok(await UseCase.Execute(request))); }
//public async Task<ActionResult<UseCaseResult<OvertureUser>>> Post([FromBody] AuthenticateUser request) public async Task <ActionResult> Post([FromBody] AuthenticateUser request) { return(Ok(await UseCase.Execute(request))); }
public async Task <ActionResult <UseCaseResult <IEnumerable <BusinessModel> > > > Get([FromQuery] GetBusinesses request) { return(Ok(await UseCase.Execute(request))); }
public async Task <ActionResult <UseCaseResult <OvertureUser> > > GetByEmail([FromQuery] GetUserByEmail request) { return(Ok(await UseCase.Execute(request))); }