public When_ProviderVenueQualificationService_Is_Called_To_Update_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>();

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

            providerService.GetProviderDetailByIdAsync(1)
            .Returns(new ProviderDetailViewModel
            {
                Id    = 1,
                UkPrn = 10000001,
                Name  = "Old Name",
            });

            _providerVenueService
            .GetVenueWithTrimmedPostcodeAsync(1, "CV1 2WT")
            .Returns(new ProviderVenueDetailViewModel
            {
                Id                   = 1,
                ProviderId           = 1,
                Postcode             = "CV1 2WT",
                Name                 = null,
                IsEnabledForReferral = true,
                Source               = "Import",
                Qualifications       = new List <QualificationDetailViewModel>()
            });

            _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
                                                    );

            var dtoList = new ValidProviderVenueQualificationDtoListBuilder()
                          .AddVenue()
                          .Build();

            _results = providerVenueQualificationService.UpdateAsync(dtoList).GetAwaiter().GetResult();
        }
Exemple #2
0
        private async Task <ProviderVenueDetailViewModel> CreateOrUpdateProviderVenueAsync(ProviderVenueQualificationDto providerVenueQualification, int providerId)
        {
            if (string.IsNullOrEmpty(providerVenueQualification.VenuePostcode))
            {
                return(null);
            }

            var venueViewModel = await _providerVenueService.GetVenueWithTrimmedPostcodeAsync(providerId,
                                                                                              providerVenueQualification.VenuePostcode);

            if (venueViewModel == null)
            {
                var addProviderVenue = new AddProviderVenueViewModel
                {
                    ProviderId = providerId,
                    Postcode   = providerVenueQualification.VenuePostcode,
                    Source     = Source
                };

                var venueId = await _providerVenueService.CreateVenueAsync(addProviderVenue);

                Debug.WriteLine(
                    $"Created venue with id {venueId} for provider {providerId} and postcode {providerVenueQualification.VenuePostcode}");

                venueViewModel = await _providerVenueService.GetVenueAsync(venueId);
            }

            var providerVenueValidator = ValidateProviderVenueToUpdate(venueViewModel, providerVenueQualification);

            if (providerVenueValidator.IsUpdated)
            {
                await _providerVenueService.UpdateVenueAsync(providerVenueValidator.ProviderVenueDetailViewModel);
            }

            // Provider Venue Delete
            if (venueViewModel.IsRemoved != providerVenueQualification.VenueIsRemoved)
            {
                var removeProviderVenueViewModel = new RemoveProviderVenueViewModel
                {
                    Postcode        = venueViewModel.Postcode,
                    ProviderId      = venueViewModel.ProviderId,
                    ProviderVenueId = venueViewModel.Id
                };

                if (providerVenueQualification.VenueIsRemoved)
                {
                    await _providerVenueService.UpdateVenueAsync(removeProviderVenueViewModel);
                }
                else
                {
                    await _providerVenueService.UpdateVenueToNotRemovedAsync(removeProviderVenueViewModel);
                }
            }

            return(venueViewModel);
        }
        public When_ProviderVenueQualificationService_Is_Called_With_New_Qualification()
        {
            _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()
                          .AddQualificationWithRoutes()
                          .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
            });

            _providerVenueService
            .GetVenueWithTrimmedPostcodeAsync(1, "CV1 2WT")
            .Returns(new ProviderVenueDetailViewModel
            {
                Id                   = 1,
                ProviderId           = 1,
                Postcode             = dto.VenuePostcode,
                Name                 = dto.VenueName,
                IsEnabledForReferral = dto.VenueIsEnabledForReferral,
                Qualifications       = new List <QualificationDetailViewModel>()
            });

            _qualificationService
            .GetQualificationAsync("1234567X")
            .Returns((QualificationDetailViewModel)null);

            _qualificationService
            .CreateQualificationEntityAsync(Arg.Is <MissingQualificationViewModel>(
                                                p => p.LarId == "1234567X"))
            .Returns(10);         //Qualification id

            _providerQualificationService
            .GetProviderQualificationAsync(Arg.Any <int>(), Arg.Any <int>())
            .Returns((ProviderQualificationDto)null);

            _routePathService
            .GetRouteSummaryByNameAsync("Agriculture, environmental and animal care")
            .Returns(new RouteSummaryViewModel
            {
                Id   = 1,
                Name = "Agriculture, environmental and animal care"
            });
            _routePathService
            .GetRouteSummaryByNameAsync("Digital")
            .Returns(new RouteSummaryViewModel
            {
                Id   = 3,
                Name = "Digital"
            });

            _qualificationRouteMappingService
            .GetQualificationRouteMappingAsync(Arg.Any <int>(), Arg.Any <int>())
            .Returns((QualificationRouteMappingViewModel)null);

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

            _results = providerVenueQualificationService.UpdateAsync(dtoList).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();
        }
        public When_ProviderVenueQualificationService_Is_Called_To_Remove_Provider_Qualification()
        {
            _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()
                          .AddQualificationWithRoutes(false) // Qualification not offerred
                          .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
            });

            _providerVenueService
            .GetVenueWithTrimmedPostcodeAsync(1, "CV1 2WT")
            .Returns(new ProviderVenueDetailViewModel
            {
                Id                   = 1,
                ProviderId           = 1,
                Postcode             = dto.VenuePostcode,
                Name                 = dto.VenueName,
                IsEnabledForReferral = dto.VenueIsEnabledForReferral,
                Qualifications       = new List <QualificationDetailViewModel>()
            });

            _qualificationService
            .GetQualificationAsync("1234567X")
            .Returns(new QualificationDetailViewModel
            {
                Id         = 10,
                LarId      = "1234567X",
                Title      = "Full qualification title",
                ShortTitle = "Short qualification title"
            });

            _providerQualificationService
            .GetProviderQualificationAsync(Arg.Any <int>(), Arg.Any <int>())
            .Returns(new ProviderQualificationDto
            {
                ProviderVenueId = 1,
                QualificationId = 10
            });

            _routePathService
            .GetRouteSummaryByNameAsync("Agriculture, environmental and animal care")
            .Returns(new RouteSummaryViewModel
            {
                Id   = 1,
                Name = "Agriculture, environmental and animal care"
            });
            _routePathService
            .GetRouteSummaryByNameAsync("Digital")
            .Returns(new RouteSummaryViewModel
            {
                Id   = 3,
                Name = "Digital"
            });

            _qualificationRouteMappingService
            .GetQualificationRouteMappingAsync(1, 10)
            .Returns(new QualificationRouteMappingViewModel
            {
                QualificationId = 10,
                RouteId         = 1,
                Source          = "Test"
            });
            _qualificationRouteMappingService
            .GetQualificationRouteMappingAsync(3, 10)
            .Returns(new QualificationRouteMappingViewModel
            {
                QualificationId = 10,
                RouteId         = 3,
                Source          = "Test"
            });

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

            _results = providerVenueQualificationService.UpdateAsync(dtoList).GetAwaiter().GetResult();
        }