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));
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 7
0
 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"));
            });
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 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));
     }
 }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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()));
        }
Esempio n. 13
0
        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)));
        }
Esempio n. 14
0
        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()));
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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));
            }
        }
Esempio n. 17
0
        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()));
        }
Esempio n. 18
0
 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));
     }
 }
Esempio n. 19
0
 public async Task <ActionResult <UseCaseResult <JobModel> > > Get(Guid id)
 {
     return(Ok(await UseCase.Execute(new GetJob {
         Id = id
     })));
 }
Esempio n. 20
0
 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)));
 }
Esempio n. 22
0
 public async Task <ActionResult <UseCaseResult <InitializeDataModel> > > Post([FromBody] InitializeData request)
 {
     return(Ok(await UseCase.Execute(request)));
 }
Esempio n. 23
0
 public async Task <ActionResult <UseCaseResult <IEnumerable <BusinessServiceCategoryModel> > > > Get([FromQuery] GetBusinessServiceCategoriesList request)
 {
     return(Ok(await UseCase.Execute(request)));
 }
Esempio n. 24
0
 public async Task <ActionResult <UseCaseResult <ReviewModel> > > Get([FromQuery] GetReviews request)
 {
     return(Ok(await UseCase.Execute(request)));
 }
Esempio n. 25
0
 public async Task <ActionResult <UseCaseResult <ReviewModel> > > Post([FromBody] CreateReview request)
 {
     return(Ok(await UseCase.Execute(request)));
 }
Esempio n. 26
0
 public async Task ItThrowsNoAssetsException()
 {
     Assert.ThrowsAsync <NoAssetsException>(async() => await UseCase.Execute(id));
 }
Esempio n. 27
0
 public async Task <ActionResult <UseCaseResult <BusinessModel> > > Put([FromBody] UpdateBusiness request)
 {
     return(Ok(await UseCase.Execute(request)));
 }
Esempio n. 28
0
 //public async Task<ActionResult<UseCaseResult<OvertureUser>>> Post([FromBody] AuthenticateUser request)
 public async Task <ActionResult> Post([FromBody] AuthenticateUser request)
 {
     return(Ok(await UseCase.Execute(request)));
 }
Esempio n. 29
0
 public async Task <ActionResult <UseCaseResult <IEnumerable <BusinessModel> > > > Get([FromQuery] GetBusinesses request)
 {
     return(Ok(await UseCase.Execute(request)));
 }
Esempio n. 30
0
 public async Task <ActionResult <UseCaseResult <OvertureUser> > > GetByEmail([FromQuery] GetUserByEmail request)
 {
     return(Ok(await UseCase.Execute(request)));
 }