public When_ProviderVenueService_Is_Called_To_Get_Venue_By_Provider_Id_And_Postcode()
        {
            var config = new MapperConfiguration(c => c.AddMaps(typeof(ProviderVenueMapper).Assembly));
            var mapper = new Mapper(config);

            _providerVenueRepository = Substitute.For <IProviderVenueRepository>();
            _providerVenueRepository.GetSingleOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.ProviderVenue, bool> > >())
            .Returns(new Domain.Models.ProviderVenue
            {
                Id                   = ProviderVenueId,
                ProviderId           = ProviderId,
                Name                 = Name,
                Postcode             = Postcode,
                IsRemoved            = IsRemoved,
                IsEnabledForReferral = IsEnabledForReferral,
                Source               = DataSource
            });

            var googleMapApiClient = Substitute.For <IGoogleMapApiClient>();
            var locationService    = Substitute.For <ILocationApiClient>();

            var providerVenueService = new ProviderVenueService(mapper, _providerVenueRepository, locationService, googleMapApiClient);

            _result = providerVenueService.GetVenueAsync(ProviderId, Postcode).GetAwaiter().GetResult();
        }
        public When_ProviderVenueService_Is_Called_To_Get_Venue_With_Trimmed_Postcode()
        {
            var config = new MapperConfiguration(c => c.AddMaps(typeof(ProviderVenueMapper).Assembly));
            var mapper = new Mapper(config);

            var mockProviderVenueDbSet = new List <Domain.Models.ProviderVenue>
            {
                new Domain.Models.ProviderVenue
                {
                    Id                   = ProviderVenueId,
                    ProviderId           = ProviderId,
                    Name                 = Name,
                    Postcode             = Postcode,
                    IsRemoved            = IsRemoved,
                    IsEnabledForReferral = IsEnabledForReferral,
                    Source               = DataSource
                }
            }
            .AsQueryable()
            .BuildMockDbSet();

            _providerVenueRepository = Substitute.For <IProviderVenueRepository>();
            _providerVenueRepository.GetManyAsync(Arg.Any <Expression <Func <Domain.Models.ProviderVenue, bool> > >())
            .Returns(mockProviderVenueDbSet);

            var googleMapApiClient = Substitute.For <IGoogleMapApiClient>();
            var locationService    = Substitute.For <ILocationApiClient>();

            var providerVenueService = new ProviderVenueService(mapper, _providerVenueRepository, locationService, googleMapApiClient);

            _result = providerVenueService.GetVenueWithTrimmedPostcodeAsync(ProviderId, Postcode).GetAwaiter().GetResult();
        }
        public async Task <IActionResult> SaveProviderVenueDetailAsync(ProviderVenueDetailViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel = await Populate(viewModel.Id);

                return(View("ProviderVenueDetail", viewModel));
            }

            await _providerVenueService.UpdateVenueAsync(viewModel);

            var isSaveSection = IsSaveSection(viewModel.SubmitAction);

            if (isSaveSection)
            {
                return(RedirectToRoute("GetProviderVenueDetail", new { providerVenueId = viewModel.Id, providerId = viewModel.ProviderId }));
            }

            if (viewModel.Qualifications == null || viewModel.Qualifications.Count == 0)
            {
                return(RedirectToRoute("AddQualification", new { providerVenueId = viewModel.Id }));
            }

            return(RedirectToRoute("GetProviderDetail", new { providerId = viewModel.ProviderId }));
        }
        public async Task UpdateVenueAsync(ProviderVenueDetailViewModel viewModel)
        {
            var trackedEntity = await _providerVenueRepository.GetSingleOrDefaultAsync(v => v.Id == viewModel.Id);

            trackedEntity = _mapper.Map(viewModel, trackedEntity);

            await _providerVenueRepository.UpdateAsync(trackedEntity);
        }
        public When_ProviderVenueService_Is_Called_To_Update_Venue()
        {
            var httpContextAccessor = Substitute.For <IHttpContextAccessor>();

            httpContextAccessor.HttpContext.Returns(new DefaultHttpContext
            {
                User = new ClaimsPrincipal(new ClaimsIdentity(new[]
                {
                    new Claim(ClaimTypes.GivenName, "TestUser")
                }))
            });

            var dateTimeProvider = Substitute.For <IDateTimeProvider>();

            dateTimeProvider.UtcNow().Returns(new DateTime(2019, 1, 1));

            _locationApiClient = Substitute.For <ILocationApiClient>();
            _locationApiClient.IsValidPostcodeAsync(Arg.Any <string>(), Arg.Any <bool>())
            .Returns(callinfo => callinfo.Arg <string>() == "CV1 2WT"
                    ? (true, "CV1 2WT")
                    : (false, null));

            var config = new MapperConfiguration(c =>
            {
                c.AddMaps(typeof(ProviderVenueMapper).Assembly);
                c.ConstructServicesUsing(type =>
                                         type.Name.Contains("LoggedInUserEmailResolver") ?
                                         new LoggedInUserEmailResolver <ProviderVenueDetailViewModel, Domain.Models.ProviderVenue>(httpContextAccessor) :
                                         type.Name.Contains("LoggedInUserNameResolver") ?
                                         (object)new LoggedInUserNameResolver <ProviderVenueDetailViewModel, Domain.Models.ProviderVenue>(httpContextAccessor) :
                                         type.Name.Contains("UtcNowResolver") ?
                                         new UtcNowResolver <ProviderVenueDetailViewModel, Domain.Models.ProviderVenue>(dateTimeProvider) :
                                         type.Name.Contains("VenueNameResolver") ?
                                         (object)new VenueNameResolver(_locationApiClient) :
                                         null);
            });
            var mapper = new Mapper(config);

            _providerVenueRepository = Substitute.For <IProviderVenueRepository>();
            _providerVenueRepository.GetSingleOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.ProviderVenue, bool> > >())
            .Returns(new ValidProviderVenueBuilder().Build());

            var googleMapApiClient = Substitute.For <IGoogleMapApiClient>();
            var locationService    = Substitute.For <ILocationApiClient>();

            var providerVenueService = new ProviderVenueService(mapper, _providerVenueRepository, locationService, googleMapApiClient);

            var viewModel = new ProviderVenueDetailViewModel
            {
                Id                   = 1,
                Postcode             = "CV1 2WT",
                Name                 = "Test provider venue",
                IsEnabledForReferral = true
            };

            providerVenueService.UpdateVenueAsync(viewModel).GetAwaiter().GetResult();
        }
Exemplo n.º 6
0
        public When_ProviderVenue_Detail_Save_Has_No_Qualifications()
        {
            _providerVenueService = Substitute.For <IProviderVenueService>();
            _providerVenueService.IsValidPostcodeAsync("CV1 2WT").Returns((true, "CV1 2WT"));
            var providerVenueController = new ProviderVenueController(_providerVenueService);
            var controllerWithClaims    = new ClaimsBuilder <ProviderVenueController>(providerVenueController)
                                          .AddUserName("username")
                                          .AddEmail("*****@*****.**")
                                          .Build();

            var viewModel = new ProviderVenueDetailViewModel
            {
                Id       = 1,
                Postcode = "CV1 2WT"
            };

            _result = controllerWithClaims.SaveProviderVenueDetailAsync(viewModel).GetAwaiter().GetResult();
        }
Exemplo n.º 7
0
        public When_ProviderVenue_Detail_Save_Submitted_Successfully()
        {
            _providerVenueService = Substitute.For <IProviderVenueService>();

            var providerVenueController = new ProviderVenueController(_providerVenueService);

            var viewModel = new ProviderVenueDetailViewModel
            {
                Id             = 1,
                ProviderId     = 2,
                Postcode       = "CV1 2WT",
                Qualifications = new List <QualificationDetailViewModel>
                {
                    new QualificationDetailViewModel
                    {
                        LarId = "123"
                    }
                }
            };

            _result = providerVenueController.SaveProviderVenueDetailAsync(viewModel).GetAwaiter().GetResult();
        }
        public When_ProviderVenueRepository_GetVenueWithQualifications_Is_Called()
        {
            var logger = Substitute.For <ILogger <ProviderVenueRepository> >();

            using var dbContext = InMemoryDbContext.Create();
            dbContext.Add(new Domain.Models.ProviderVenue
            {
                Id                   = Id,
                Name                 = VenueName,
                Postcode             = Postcode,
                IsEnabledForReferral = IsEnabledForReferral,
                IsRemoved            = IsRemoved,
                Provider             = new Domain.Models.Provider
                {
                    Id            = ProviderId,
                    Name          = ProviderName,
                    IsCdfProvider = IsCdfProvider
                },
                ProviderQualification = new List <Domain.Models.ProviderQualification>
                {
                    new Domain.Models.ProviderQualification
                    {
                        Qualification = new Domain.Models.Qualification
                        {
                            Id         = QualificationId,
                            LarId      = LarId,
                            Title      = Title,
                            ShortTitle = ShortTitle
                        }
                    }
                }
            });
            dbContext.SaveChanges();

            var repository = new ProviderVenueRepository(logger, dbContext);

            _result = repository.GetVenueWithQualificationsAsync(Id)
                      .GetAwaiter().GetResult();
        }
        public When_ProviderVenueQualificationService_Is_Called_To_Unremove_ProviderVenue()
        {
            var providerService = Substitute.For <IProviderService>();

            _providerVenueService             = Substitute.For <IProviderVenueService>();
            _providerQualificationService     = Substitute.For <IProviderQualificationService>();
            _qualificationRouteMappingService = Substitute.For <IQualificationRouteMappingService>();
            _qualificationService             = Substitute.For <IQualificationService>();
            _routePathService = Substitute.For <IRoutePathService>();

            var dtoList = new ValidProviderVenueQualificationDtoListBuilder()
                          .AddVenue(isRemoved: false)
                          .Build();
            var dto = dtoList.First();

            providerService.SearchAsync(10000001)
            .Returns(new ProviderSearchResultDto
            {
                Id    = 1,
                UkPrn = dto.UkPrn,
                Name  = dto.ProviderName
            });

            providerService.GetProviderDetailByIdAsync(1)
            .Returns(new ProviderDetailViewModel
            {
                UkPrn                 = dto.UkPrn,
                Name                  = dto.ProviderName,
                DisplayName           = dto.DisplayName,
                IsCdfProvider         = dto.IsCdfProvider,
                IsEnabledForReferral  = dto.IsEnabledForReferral,
                PrimaryContact        = dto.PrimaryContact,
                PrimaryContactEmail   = dto.PrimaryContactEmail,
                PrimaryContactPhone   = dto.PrimaryContactPhone,
                SecondaryContact      = dto.SecondaryContact,
                SecondaryContactEmail = dto.SecondaryContactEmail,
                SecondaryContactPhone = dto.SecondaryContactPhone
            });

            var providerVenueDetailViewModel = new ProviderVenueDetailViewModel
            {
                Id                   = 1,
                ProviderId           = 1,
                Postcode             = dto.VenuePostcode,
                Name                 = dto.VenueName,
                IsEnabledForReferral = dto.VenueIsEnabledForReferral,
                IsRemoved            = true,
                Qualifications       = new List <QualificationDetailViewModel>()
            };

            _providerVenueService
            .GetVenueWithTrimmedPostcodeAsync(1, "CV1 2WT")
            .Returns(providerVenueDetailViewModel);

            _qualificationService.GetQualificationAsync(Arg.Any <string>()).Returns((QualificationDetailViewModel)null);
            _providerQualificationService.GetProviderQualificationAsync(Arg.Any <int>(), Arg.Any <int>()).Returns((ProviderQualificationDto)null);
            _routePathService.GetRouteSummaryByNameAsync(Arg.Any <string>()).Returns((RouteSummaryViewModel)null);

            var providerVenueQualificationService = new ProviderVenueQualificationService
                                                    (
                providerService,
                _providerVenueService,
                _providerQualificationService,
                _qualificationService,
                _routePathService,
                _qualificationRouteMappingService
                                                    );

            _results = providerVenueQualificationService.UpdateAsync(dtoList).GetAwaiter().GetResult();
        }
Exemplo n.º 10
0
        private static (bool IsUpdated, ProviderVenueDetailViewModel ProviderVenueDetailViewModel) ValidateProviderVenueToUpdate(ProviderVenueDetailViewModel providerVenueDetailViewModel, ProviderVenueQualificationDto providerVenueQualification)
        {
            var isUpdated = false;

            if (ValidateToUpdate(providerVenueDetailViewModel.Name, providerVenueQualification.VenueName))
            {
                providerVenueDetailViewModel.Name = providerVenueQualification.VenueName;
                isUpdated = true;
            }

            if (providerVenueDetailViewModel.IsEnabledForReferral != providerVenueQualification.VenueIsEnabledForReferral)
            {
                providerVenueDetailViewModel.IsEnabledForReferral = providerVenueQualification.VenueIsEnabledForReferral;
                isUpdated = true;
            }

            return(isUpdated, providerVenueDetailViewModel);
        }