public async Task ThenRedirectsToConfirmProvider(
            SelectProviderViewModel viewModel,
            long providerId,
            ValidationResult validationResult,
            [Frozen] Mock <IValidator <SelectProviderViewModel> > mockValidator,
            [Frozen] Mock <ICommitmentsApiClient> mockApiClient,
            [Frozen] Mock <IModelMapper> mockMapper,
            GetProviderResponse apiResponse,
            ConfirmProviderRequest confirmProviderRequest,
            [Greedy] CohortController controller)
        {
            var actionName = "ConfirmProvider";

            viewModel.ProviderId = providerId.ToString();
            mockValidator
            .Setup(x => x.Validate(viewModel))
            .Returns(validationResult);
            mockApiClient
            .Setup(x => x.GetProvider(long.Parse(viewModel.ProviderId), CancellationToken.None))
            .ReturnsAsync(apiResponse);
            mockMapper
            .Setup(x => x.Map <ConfirmProviderRequest>(viewModel))
            .ReturnsAsync(confirmProviderRequest);

            var result = await controller.SelectProvider(viewModel) as RedirectToActionResult;

            Assert.NotNull(result);
            Assert.AreEqual(actionName, result.ActionName);
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Return Affected Row Or Error If Exist
            /// </summary>
            /// <param name="request">Provider Information</param>
            /// <returns>Affected Row Or Error If Exist</returns>
            public static GetProviderResponse Provider(GetProviderResponse request)
            {
                GetProviderResponse response = new GetProviderResponse();

                try
                {
                    tblProvider provider = new tblProvider()
                    {
                        id          = request.Provider.id,
                        companyName = request.Provider.companyName,
                        detail      = request.Provider.detail,
                        createDate  = request.Provider.createDate,
                        upDateDate  = DateTime.Now,
                        deleteDate  = null,
                        state       = "Active"
                    };

                    var result = ProviderData.Update.Provider(provider);
                    if (result.Item1.Error)
                    {
                        response.Error.InfoError(result.Item1);
                    }
                    else
                    {
                        response.Message = result.Item2;
                    }
                }
                catch (Exception ex)
                {
                    response.Error.InfoError(ex);
                }

                return(response);
            }
Ejemplo n.º 3
0
            /// <summary>
            /// Return Provider Information
            /// </summary>
            /// <param name="request">Provider ID</param>
            /// <returns>Provider Information</returns>
            public static GetProviderResponse GetProvider(GetProviderRequest request)
            {
                GetProviderResponse response = new GetProviderResponse();

                response.Error    = new Handler.ErrorObject();
                response.Provider = new Provider();
                try
                {
                    var provider = ProviderData.Select.GetProvider(request.ProviderID);
                    if (!provider.Item1.Error)
                    {
                        response.Provider = new Provider()
                        {
                            id          = provider.Item2.id,
                            companyName = provider.Item2.companyName,
                            detail      = provider.Item2.detail,
                            createDate  = provider.Item2.createDate,
                            upDateDate  = provider.Item2.upDateDate,
                            deleteDate  = provider.Item2.deleteDate,
                            state       = provider.Item2.state
                        };
                    }
                    else
                    {
                        response.Error.InfoError(provider.Item1);
                    }
                }
                catch (Exception ex)
                {
                    response.Error.InfoError(ex);
                }

                return(response);
            }
Ejemplo n.º 4
0
        public void Arrange()
        {
            _getProviderResponse = MockGetProvider();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _mockCommitmentsApiClient.Setup(m => m.GetProvider(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getProviderResponse);

            _mapper = new WhoWillEnterTheDetailsViewModelMapper(_mockCommitmentsApiClient.Object);
        }
Ejemplo n.º 5
0
        public void ProviderUseCaseEqualTest()
        {
            GetProviderRequest getProviderRequest = new GetProviderRequest();

            IRepositoryFactory  repositoryFactory   = new RepositoryFactory(new DBContext());
            IActivityFactory    activityFactory     = new ActivityFactory(repositoryFactory, new ValidationRuleFactory());
            IUseCaseFactory     useCaseFactory      = new UseCaseFactory(activityFactory);
            GetProviderResponse getProviderResponse = useCaseFactory.Create <IUseCase <GetProviderRequest, GetProviderResponse> >().Execute(getProviderRequest);

            Assert.IsTrue(getProviderResponse.Providers.Count > 0);
        }
        public async Task Then_Maps_ProviderName(
            ConfirmProviderRequest request,
            [Frozen] Mock <ICommitmentsApiClient> commitmentsApiClient,
            GetProviderResponse provider,
            ConfirmProviderViewModelMapper mapper)
        {
            commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny <long>(), It.IsAny <CancellationToken>())).ReturnsAsync(provider);
            var viewModel = await mapper.Map(request);

            viewModel.ProviderName.Should().Be(provider.Name);
        }
Ejemplo n.º 7
0
        public CreateCohortWithDraftApprenticeshipControllerTestFixtures WithTrainingProvider()
        {
            var response = new GetProviderResponse {
                Name = "Name", ProviderId = 1
            };

            CommitmentsApiClientMock.Setup(p => p.GetProvider(1, CancellationToken.None))
            .ReturnsAsync(response);

            return(this);
        }
        public void Arrange()
        {
            _getProviderResponse = new GetProviderResponse {
                Name = "Test Provider"
            };
            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _mockCommitmentsApiClient.Setup(c => c.GetProvider(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getProviderResponse);

            _mapper = new EnterNewTrainingProviderToChangeOfProviderRequestMapper(_mockCommitmentsApiClient.Object);
        }
        public async Task ThenCallsApi(
            SelectProviderViewModel viewModel,
            long providerId,
            [Frozen] Mock <ICommitmentsApiClient> mockApiClient,
            GetProviderResponse apiResponse,
            [Greedy] CohortController controller)
        {
            viewModel.ProviderId = providerId.ToString();

            await controller.SelectProvider(viewModel);

            mockApiClient.Verify(x => x.GetProvider(providerId, CancellationToken.None), Times.Once);
        }
        public async Task Then_Gets_Provider_From_Courses_Api(
            GetProviderQuery query,
            GetProviderResponse apiResponse,
            [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient,
            GetProviderQueryHandler handler)
        {
            mockApiClient
            .Setup(client => client.Get <GetProviderResponse>(It.Is <GetProviderRequest>(request => request.Ukprn == query.Ukprn)))
            .ReturnsAsync(apiResponse);

            var result = await handler.Handle(query, CancellationToken.None);

            result.Provider.Should().BeEquivalentTo(apiResponse);
        }
Ejemplo n.º 11
0
        public async Task Then_The_View_Is_Returned(
            int providerId,
            ConfirmProviderRequest confirmProviderRequest,
            GetProviderResponse getProviderResponse,
            [Frozen] Mock <ICommitmentsApiClient> mockApiClient,
            [Greedy] CohortController controller)
        {
            confirmProviderRequest.ProviderId = providerId;
            mockApiClient
            .Setup(x => x.GetProvider(providerId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(getProviderResponse);

            var result = await controller.ConfirmProvider(confirmProviderRequest) as ViewResult;

            result.ViewName.Should().BeNull();
        }
        public async Task GetProvider()
        {
            var request             = new TestRequest(new Uri(ExpectedApiBaseUrl + $"api/provider/{ProviderId}"), string.Empty);
            var getProviderResponse = new GetProviderResponse
            {
                Provider = new ProviderResponse()
            };
            var content = JsonConvert.SerializeObject(
                getProviderResponse);

            _fakeHandler.AddFakeResponse(request, new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK, Content = new StringContent(content)
            });

            var response = (await _apiclient.GetProvider(ProviderId));

            response.ShouldBeEquivalentTo(getProviderResponse);
        }
Ejemplo n.º 13
0
        public async Task Arrange()
        {
            var autoFixture = new Fixture();

            _course                     = autoFixture.Create <TrainingProgramme>();
            _courseStandard             = autoFixture.Create <TrainingProgramme>();
            _providerResponse           = autoFixture.Create <GetProviderResponse>();
            _accountLegalEntityResponse = autoFixture.Build <AccountLegalEntityResponse>().With(x => x.LevyStatus, ApprenticeshipEmployerType.Levy).Create();
            _source                     = autoFixture.Create <ApprenticeRequest>();
            _source.StartMonthYear      = "062020";
            _source.TransferSenderId    = string.Empty;
            _source.AccountId           = 12345;

            _commitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_providerResponse);
            _commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_accountLegalEntityResponse);
            _standardTrainingProgrammes = new List <TrainingProgramme> {
                _courseStandard
            };
            _commitmentsApiClient
            .Setup(x => x.GetAllTrainingProgrammeStandards(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new GetAllTrainingProgrammeStandardsResponse
            {
                TrainingProgrammes = _standardTrainingProgrammes
            });
            _allTrainingProgrammes = new List <TrainingProgramme> {
                _courseStandard, _course
            };
            _commitmentsApiClient
            .Setup(x => x.GetAllTrainingProgrammes(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new GetAllTrainingProgrammesResponse
            {
                TrainingProgrammes = _allTrainingProgrammes
            });


            _mapper = new ApprenticeViewModelMapper(
                _commitmentsApiClient.Object);

            _result = await _mapper.Map(TestHelper.Clone(_source));
        }
Ejemplo n.º 14
0
        public async Task Arrange()
        {
            var autoFixture = new Fixture();

            _source = autoFixture.Create <MessageRequest>();
            _source.StartMonthYear = "062020";

            _providerResponse = autoFixture.Create <GetProviderResponse>();

            _commitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny <long>(),
                                                           It.IsAny <CancellationToken>()))
            .ReturnsAsync(_providerResponse);


            _mapper = new MessageViewModelMapper(_commitmentsApiClient.Object);

            _result = await _mapper.Map(TestHelper.Clone(_source));
        }
        public async Task AndUnexpectedExceptionThrown_ThenReturnsErrorView(
            SelectProviderViewModel viewModel,
            long providerId,
            [Frozen] Mock <ICommitmentsApiClient> mockApiClient,
            GetProviderResponse apiResponse,
            HttpResponseMessage error,
            [Greedy] CohortController controller)
        {
            error.StatusCode     = HttpStatusCode.NetworkAuthenticationRequired;
            viewModel.ProviderId = providerId.ToString();
            mockApiClient
            .Setup(x => x.GetProvider(providerId, CancellationToken.None))
            .ThrowsAsync(new RestHttpClientException(error, error.ReasonPhrase));

            var result = await controller.SelectProvider(viewModel) as RedirectToActionResult;

            Assert.NotNull(result);
            Assert.AreEqual("Error", result.ActionName);
            Assert.AreEqual("Error", result.ControllerName);
        }
        public void Arrange()
        {
            var autoFixture = new Fixture();

            _apprenticeshipResponse = autoFixture.Build <GetApprenticeshipResponse>()
                                      .Create();
            _providerResponse = autoFixture.Build <GetProviderResponse>()
                                .Create();
            _request = autoFixture.Build <SendNewTrainingProviderRequest>()
                       .Create();


            _commitmentApiClient = new Mock <ICommitmentsApiClient>();
            _commitmentApiClient.Setup(a => a.GetApprenticeship(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_apprenticeshipResponse);

            _commitmentApiClient.Setup(a => a.GetProvider(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_providerResponse);

            _sut = new SendNewTrainingProviderViewModelMapper(_commitmentApiClient.Object, Mock.Of <ILogger <SendNewTrainingProviderViewModelMapper> >());
        }
        public void Arrange()
        {
            _autoFixture = new Fixture();

            _changeOfPartyResponse = _autoFixture.Build <GetChangeOfPartyRequestsResponse>()
                                     .With(r => r.ChangeOfPartyRequests, GetChangeOfPartyRequestsMock())
                                     .Create();
            _apprenticeshipResponse = _autoFixture.Build <GetApprenticeshipResponse>()
                                      .Create();
            _priceEpisodesResponse = _autoFixture.Build <GetPriceEpisodesResponse>()
                                     .With(p => p.PriceEpisodes, GetPriceEpisodesMock())
                                     .Create();
            _providerResponse = _autoFixture.Build <GetProviderResponse>()
                                .Create();
            _request = _autoFixture.Build <ViewChangesRequest>()
                       .Create();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            _mockCommitmentsApiClient.Setup(c => c.GetChangeOfPartyRequests(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_changeOfPartyResponse);

            _mockCommitmentsApiClient.Setup(c => c.GetApprenticeship(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_apprenticeshipResponse);

            _mockCommitmentsApiClient.Setup(c => c.GetPriceEpisodes(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_priceEpisodesResponse);

            _mockCommitmentsApiClient.Setup(c => c.GetProvider(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_providerResponse);

            _mockEncodingService = new Mock <IEncodingService>();
            _mockEncodingService.Setup(c => c.Encode(It.IsAny <long>(), EncodingType.CohortReference))
            .Returns(_cohortReference);

            _mockCommitmentsApiClient.Setup(c => c.GetCohort(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(GetCohortResponseMock());

            _mapper = new ViewChangesViewModelMapper(_mockCommitmentsApiClient.Object, _mockEncodingService.Object);
        }
        public void Arrange()
        {
            var autoFixture = new Fixture();

            _apprenticeshipResponse = autoFixture.Build <GetApprenticeshipResponse>()
                                      .With(a => a.FirstName, "FirstName")
                                      .With(a => a.LastName, "LastName")
                                      .Create();

            _providerResponse = autoFixture.Build <GetProviderResponse>()
                                .With(p => p.Name, "Test Provider")
                                .Create();

            _mockCommitmentsApi = new Mock <ICommitmentsApiClient>();

            _mockCommitmentsApi.Setup(c => c.GetApprenticeship(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_apprenticeshipResponse);
            _mockCommitmentsApi.Setup(c => c.GetProvider(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_providerResponse);

            _mapper = new ChangeProviderRequestedConfirmationViewModelMapper(_mockCommitmentsApi.Object);
        }
        public async Task ThenMapsConfirmProviderRequest(
            SelectProviderViewModel viewModel,
            long providerId,
            ValidationResult validationResult,
            [Frozen] Mock <IValidator <SelectProviderViewModel> > mockValidator,
            [Frozen] Mock <ICommitmentsApiClient> mockApiClient,
            [Frozen] Mock <IModelMapper> mockMapper,
            GetProviderResponse apiResponse,
            [Greedy] CohortController controller)
        {
            viewModel.ProviderId = providerId.ToString();
            mockValidator
            .Setup(x => x.Validate(viewModel))
            .Returns(validationResult);
            mockApiClient
            .Setup(x => x.GetProvider(long.Parse(viewModel.ProviderId), CancellationToken.None))
            .ReturnsAsync(apiResponse);

            await controller.SelectProvider(viewModel);

            mockMapper.Verify(x => x.Map <ConfirmProviderRequest>(viewModel), Times.Once);
        }
Ejemplo n.º 20
0
            /// <summary>
            /// Return Affected Row Or Error If Exist
            /// </summary>
            /// <param name="ProviderID">ProviderID</param>
            /// <param name="state">State</param>
            /// <returns>Affected Row Or Error If Exist</returns>
            public static GetProviderResponse ProviderDisable(int ProviderID, string state)
            {
                GetProviderResponse response = new GetProviderResponse();

                try
                {
                    var result = ProviderData.Delete.ProviderDisable(ProviderID, state);
                    if (result.Item1.Error)
                    {
                        response.Error.InfoError(result.Item1);
                    }
                    else
                    {
                        response.Message = result.Item2;
                    }
                }
                catch (Exception ex)
                {
                    response.Error.InfoError(ex);
                }
                return(response);
            }
Ejemplo n.º 21
0
            /// <summary>
            /// Return Provider List
            /// </summary>
            /// <returns>Provider List</returns>
            public static GetProviderResponse GetProviderList()
            {
                GetProviderResponse response = new GetProviderResponse();

                response.ProviderList = new List <Provider>();
                response.Error        = new Handler.ErrorObject();

                try
                {
                    var provider = ProviderData.Select.GetProviderList();
                    if (!provider.Item1.Error)
                    {
                        foreach (var item in provider.Item2)
                        {
                            response.ProviderList.Add(new Provider()
                            {
                                id          = item.id,
                                companyName = item.companyName,
                                detail      = item.detail,
                                createDate  = item.createDate,
                                upDateDate  = item.upDateDate,
                                deleteDate  = item.deleteDate,
                                state       = item.state
                            });
                        }
                    }
                    else
                    {
                        response.Error.InfoError(provider.Item1);
                    }
                }
                catch (Exception ex)
                {
                    response.Error.InfoError(ex);
                }
                return(response);
            }
Ejemplo n.º 22
0
        public async Task <OperationStatusInfo> ShowProviders()
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);
                GetProviderRequest getProviderRequest = new GetProviderRequest();

                try
                {
                    GetProviderResponse getProviderResponse = hubEnvironment.UseCaseFactory
                                                              .Create <IUseCase <GetProviderRequest, GetProviderResponse> >()
                                                              .Execute(getProviderRequest);
                    operationStatusInfo.AttachedObject = getProviderResponse.Providers;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }