public void ShouldFillApprenticeshipLevelIfTrainingTypeIsStandardAndApprenticeshipLevelIsUnknown()
        {
            // Arrange.
            var trainingDetailsViewModel = new TrainingDetailsViewModel
            {
                VacancyReferenceNumber = VacancyReferenceNumber,
                ApprenticeshipLevel    = ApprenticeshipLevel.Unknown,
                TrainingType           = TrainingType.Standards,
                StandardId             = 1
            };

            MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())).Returns <Vacancy>(v => v);
            MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>()))
            .Returns((Vacancy av) => new TrainingDetailsViewModel()
            {
                FrameworkCodeName = av.FrameworkCodeName, ApprenticeshipLevel = av.ApprenticeshipLevel
            });

            var provider = GetVacancyPostingProvider();

            // Act.
            var viewModel = provider.UpdateVacancy(trainingDetailsViewModel);

            // Assert.
            viewModel.ApprenticeshipLevel.Should().NotBe(ApprenticeshipLevel.Unknown);
        }
        private async Task TestCreatePOST()
        {
            // Arrange
            var id       = Guid.Empty;
            var showroom = GetShowroom();
            var car      = GetCar();
            var model    = GetCarEditViewModel(car);

            MockMapper
            .Setup(_ => _.Map <Car>(model))
            .Returns(car);

            MockShowroomData
            .Setup(_ => _.GetById(model.ShowroomId))
            .ReturnsAsync(showroom);

            // Act
            //ControllerUnderTest.ModelState.AddModelError("key", "error"); // force invalid input
            dynamic response = await ControllerUnderTest.Create(model);

            // Assert
            MockShowroomData.Verify(_ => _.GetById(model.ShowroomId), Times.Once);
            MockMapper.Verify(_ => _.Map <Car>(model), Times.Once);

            Assert.True(response.RouteValues.Values[0].Equals(car.Id));
            Assert.True(response.ActionName.Equals("Details"));
        }
        public void ShouldCreateApprenticeshipLevelIfTrainingTypeStandard(int standardId, ApprenticeshipLevel expectedApprenticeshipLevel)
        {
            // Arrange.
            var trainingDetailsViewModel = new TrainingDetailsViewModel
            {
                VacancyReferenceNumber = VacancyReferenceNumber,
                ApprenticeshipLevel    = expectedApprenticeshipLevel,
                TrainingType           = TrainingType.Standards,
                StandardId             = standardId
            };

            MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())).Returns <Vacancy>(v => v);
            MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>()))
            .Returns((Vacancy av) => new TrainingDetailsViewModel()
            {
                ApprenticeshipLevel = av.ApprenticeshipLevel
            });

            var provider = GetVacancyPostingProvider();

            // Act.
            var viewModel = provider.UpdateVacancy(trainingDetailsViewModel);

            // Assert.
            viewModel.ApprenticeshipLevel.Should().Be(expectedApprenticeshipLevel);
        }
        public void ShouldCreateNullFrameworkCodeIfTrainingTypeStandard()
        {
            // Arrange.
            var trainingDetailsViewModel = new TrainingDetailsViewModel
            {
                VacancyReferenceNumber = VacancyReferenceNumber,
                ApprenticeshipLevel    = ApprenticeshipLevel.Unknown,
                TrainingType           = TrainingType.Standards,
                StandardId             = 1,
                FrameworkCodeName      = "ShouldBeNulled"
            };

            MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())).Returns <Vacancy>(v => v);
            MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>()))
            .Returns((Vacancy av) => new TrainingDetailsViewModel()
            {
                FrameworkCodeName = av.FrameworkCodeName
            });


            var provider = GetVacancyPostingProvider();

            // Act.
            var viewModel = provider.UpdateVacancy(trainingDetailsViewModel);

            // Assert.
            viewModel.FrameworkCodeName.Should().BeNullOrEmpty();
        }
        private void TestDetailsGET()
        {
            // Arrange
            var id    = Guid.Empty;
            var car   = GetCar();
            var model = GetCarDetailsViewModel(car);

            MockCarData
            .Setup(_ => _.GetById(id))
            .ReturnsAsync(car);
            MockMapper
            .Setup(_ => _.Map <CarDetailsViewModel>(car))
            .Returns(model);

            // Act
            dynamic response = ControllerUnderTest.Details(id);

            // Assert
            MockCarData.Verify(_ => _.GetById(id), Times.Once);
            MockMapper.Verify(_ => _.Map <CarDetailsViewModel>(car), Times.Once);

            Assert.True(response.Model.Id.Equals(model.Id));
            Assert.True(response.Model.Brand.Equals(model.Brand));
            Assert.True(response.Model.Model.Equals(model.Model));
            Assert.True(response.Model.VIN.Equals(model.VIN));
        }
Ejemplo n.º 6
0
 private void SetupMocksUpdate(Wallet walletToReturn)
 {
     SetupMockGetUser(fixture.UserWithWallets);
     SetupMockGetWallet(walletToReturn);
     MockUnitOfWork.Setup(x => x.WalletRepository.Update(It.IsAny <Wallet>()));
     MockMapper.Setup(x => x.Map(It.IsAny <UpdateWalletDto>(), It.IsAny <Wallet>()));
 }
Ejemplo n.º 7
0
        public void ShouldAssignLocalAuthorityCodeOnUpdatingVacancyLocationsWithMultipleAddresses()
        {
            // Arrange.
            var geopoint         = new Fixture().Create <GeoPoint>();
            var geopoint2        = new Fixture().Create <GeoPoint>();
            var addressViewModel = new Fixture().Build <AddressViewModel>().Create();
            var postalAddress    = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint).Create();
            var postalAddress2   = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint2).Create();

            MockGeocodeService.Setup(gs => gs.GetGeoPointFor(It.IsAny <PostalAddress>())).Returns(geopoint);
            var locationSearchViewModel = new LocationSearchViewModel
            {
                EmployerId     = EmployerId,
                ProviderSiteId = ProviderSiteId,
                EmployerEdsUrn = EdsUrn,
                Addresses      = new List <VacancyLocationAddressViewModel>
                {
                    new VacancyLocationAddressViewModel {
                        Address = addressViewModel
                    },
                    new VacancyLocationAddressViewModel {
                        Address = addressViewModel
                    }
                }
            };

            var vacancyLocations = new List <VacancyLocation>
            {
                new VacancyLocation {
                    Address = postalAddress
                },
                new VacancyLocation {
                    Address = postalAddress2
                }
            };

            MockMapper.Setup(m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(locationSearchViewModel.Addresses[0])).Returns(vacancyLocations[0]);
            MockMapper.Setup(m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(locationSearchViewModel.Addresses[1])).Returns(vacancyLocations[1]);

            MockVacancyPostingService.Setup(v => v.CreateVacancy(It.IsAny <Vacancy>()))
            .Returns(new Vacancy());

            var vacancy = new Fixture().Create <Vacancy>();

            MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(It.IsAny <int>()))
            .Returns(vacancy);

            MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider());

            var provider = GetVacancyPostingProvider();

            // Act.
            provider.AddLocations(locationSearchViewModel);

            // Assert.
            MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once);
            MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(It.IsAny <string>()), Times.Exactly(2));
            MockVacancyPostingService.Verify(m => m.DeleteVacancyLocationsFor(vacancy.VacancyId));
            MockVacancyPostingService.Verify(m => m.CreateVacancyLocations(It.IsAny <List <VacancyLocation> >()), Times.Once);
        }
Ejemplo n.º 8
0
 private void SetupMocksCreate(User userToReturn)
 {
     SetupMockGetUser(userToReturn);
     MockUnitOfWork.Setup(x => x.WalletRepository.Create(It.IsAny <Wallet>()));
     MockMapper.Setup(x => x.Map <Wallet>(It.IsAny <WalletDto>())).Returns(fixture.DefaultWallet);
     MockMapper.Setup(x => x.Map <WalletDto>(It.IsAny <Wallet>())).Returns(fixture.DefaultWalletDto);
 }
 private void SetupMocksCrate()
 {
     SetupMocksGeneral();
     MockUnitOfWork.Setup(x => x.CategoryRepository.Create(It.IsAny <MainCategory>()));
     MockMapper.Setup(x => x.Map <MainCategoryDto>(It.IsAny <MainCategory>()))
     .Returns(fixture.CreateCategoryDto);
     MockMapper.Setup(x => x.Map <MainCategory>(It.IsAny <MainCategoryDto>())).Returns(fixture.CreateCategory);
 }
Ejemplo n.º 10
0
 private void SetupMocksGeneral(User repositoryUser, User mapperUser, CreatePasswordDto passwordModel)
 {
     MockUnitOfWork.Setup(x =>
                          x.UserRepository.SingleOrDefaultAsync(It.IsAny <Expression <Func <User, bool> > >()))
     .ReturnsAsync(repositoryUser);
     MockUnitOfWork.Setup(x => x.CommitAsync());
     MockMapper.Setup(x => x.Map <User>(It.IsAny <UserDto>())).Returns(mapperUser);
     mockPasswordService.Setup(x => x.CreatePasswordHash(It.IsAny <string>())).Returns(passwordModel);
 }
Ejemplo n.º 11
0
        public void ShouldAssignLocalAuthorityCodeOnUpdatingVacancyLocationsWithSingleAddressDifferentToEmployer()
        {
            // Arrange.
            const string localAuthorityCode = "ABCD";
            var          geopoint           = new Fixture().Create <GeoPoint>();
            var          addressViewModel   = new Fixture().Build <AddressViewModel>().Create();
            var          postalAddress      = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint).Create();

            MockGeocodeService.Setup(gs => gs.GetGeoPointFor(It.IsAny <PostalAddress>())).Returns(geopoint);
            var locationSearchViewModel = new LocationSearchViewModel
            {
                EmployerId     = EmployerId,
                ProviderSiteId = ProviderSiteId,
                EmployerEdsUrn = EdsUrn,
                Addresses      = new List <VacancyLocationAddressViewModel>()
                {
                    new VacancyLocationAddressViewModel()
                    {
                        Address = addressViewModel
                    }
                }
            };

            MockMapper.Setup(
                m =>
                m.Map <VacancyLocationAddressViewModel, VacancyLocation>(It.IsAny <VacancyLocationAddressViewModel>()))
            .Returns(new VacancyLocation
            {
                Address = postalAddress
            });

            MockMapper.Setup(m => m.Map <AddressViewModel, PostalAddress>(addressViewModel)).Returns(postalAddress);
            var geoPointViewModel = new Fixture().Create <GeoPointViewModel>();

            MockMapper.Setup(m => m.Map <GeoPoint, GeoPointViewModel>(geopoint))
            .Returns(geoPointViewModel);
            MockMapper.Setup(m => m.Map <GeoPointViewModel, GeoPoint>(geoPointViewModel)).Returns(geopoint);
            MockLocalAuthorityLookupService.Setup(m => m.GetLocalAuthorityCode(It.IsAny <string>()))
            .Returns(localAuthorityCode);
            var vacancy = new Fixture().Create <Vacancy>();

            MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(It.IsAny <int>()))
            .Returns(vacancy);

            MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider());

            var provider = GetVacancyPostingProvider();

            // Act.
            provider.AddLocations(locationSearchViewModel);

            // Assert.
            MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(It.IsAny <string>()), Times.Once);
            MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.Is <Vacancy>(av => av.LocalAuthorityCode == localAuthorityCode)));
            MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once);
        }
Ejemplo n.º 12
0
 private void SetupMocks(Operation createOperation, OperationDto createOperationDto, User user)
 {
     MockUnitOfWork.Setup(x => x.UserRepository.GetAsync(It.IsAny <int>()))
     .ReturnsAsync(user);
     MockUnitOfWork.Setup(x => x.OperationRepository.Create(It.IsAny <Operation>()));
     MockUnitOfWork.Setup(x => x.WalletRepository.Update(It.IsAny <Wallet>()));
     MockUnitOfWork.Setup(x => x.CommitAsync());
     MockMapper.Setup(x => x.Map <Operation>(It.IsAny <OperationDto>())).Returns(createOperation);
     MockMapper.Setup(x => x.Map <OperationDto>(It.IsAny <Operation>())).Returns(createOperationDto);
 }
        public void ShouldDefaultApprenticeshipLevel()
        {
            // Arrange.
            MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>())).Returns(new TrainingDetailsViewModel());
            var provider = GetVacancyPostingProvider();

            // Act.
            var viewModel = provider.GetTrainingDetailsViewModel(VacancyReferenceNumber);

            // Assert.
            viewModel.Should().NotBeNull();
            viewModel.ApprenticeshipLevel.Should().Be(ApprenticeshipLevel.Unknown);
        }
        public void ShouldGetSectorsAndFrameworks()
        {
            // Arrange.
            MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>())).Returns(new TrainingDetailsViewModel());
            var provider = GetVacancyPostingProvider();

            // Act.
            var viewModel = provider.GetTrainingDetailsViewModel(VacancyReferenceNumber);

            // Assert.
            viewModel.Should().NotBeNull();
            viewModel.SectorsAndFrameworks.Should().NotBeNull();
            viewModel.SectorsAndFrameworks.Count.Should().BePositive();
        }
Ejemplo n.º 15
0
        private void SetupMocksGet <TSource, TDestination>(User userToReturn, TDestination mappedInstance,
                                                           Wallet walletToReturn = null)
        {
            MockUnitOfWork.Setup(x => x.UserRepository.GetAsync(It.IsAny <int>()))
            .ReturnsAsync(userToReturn);
            MockMapper.Setup(x => x.Map <TDestination>(It.IsAny <TSource>()))
            .Returns(mappedInstance);

            if (walletToReturn != null)
            {
                MockUnitOfWork.Setup(x => x.WalletRepository.GetAsync(fixture.DefaultWalletDto.WalletId))
                .ReturnsAsync(walletToReturn);
            }
        }
        public void ShouldNotGetBlacklistedSectorsAndFrameworks()
        {
            // Arrange.
            MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>())).Returns(new TrainingDetailsViewModel());
            var provider       = GetVacancyPostingProvider();
            var blackListCodes = _webConfiguration.BlacklistedCategoryCodes.Split(',').Select(each => each.Trim()).ToArray();

            // Act.
            var viewModel = provider.GetTrainingDetailsViewModel(VacancyReferenceNumber);

            // Assert.
            viewModel.Should().NotBeNull();
            viewModel.SectorsAndFrameworks.Should().NotBeNull();

            Assert.That(!viewModel.SectorsAndFrameworks.Any(sector => blackListCodes.Any(bc => sector.Value != string.Empty && bc.StartsWith(sector.Value))));
        }
        public void ShouldSetTrainingTypeIfTraineeship()
        {
            // Arrange.
            MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>())).Returns(new TrainingDetailsViewModel
            {
                VacancyType = VacancyType.Traineeship
            });
            var provider = GetVacancyPostingProvider();

            // Act.
            var viewModel = provider.GetTrainingDetailsViewModel(VacancyReferenceNumber);

            // Assert.
            viewModel.Should().NotBeNull();
            viewModel.TrainingType.Should().Be(TrainingType.Sectors);
        }
        private async Task TestEditPOST()
        {
            // Arrange
            var id    = Guid.Empty;
            var car   = GetCar();
            var model = GetCarEditViewModel(car);

            MockCarData
            .Setup(_ => _.GetById(id))
            .ReturnsAsync(car);
            MockMapper
            .Setup(_ => _.Map <Car>(model))
            .Returns(car);

            // Act
            dynamic response = await ControllerUnderTest.Edit(model);

            // Assert
            MockCarData.Verify(_ => _.GetById(model.Id), Times.Once);
            MockCarData.Verify(_ => _.Update(car), Times.Once);
            Assert.True(response.RouteValues.Values[0].Equals(car.Id));
        }
Ejemplo n.º 19
0
        public void ShouldAssignLocalAuthorityCodeToVacancyWithSameAddressAsEmployer()
        {
            // Arrange.
            const string localAuthorityCode = "ABCD";
            var          vvm = new Fixture().Build <NewVacancyViewModel>().Create();
            var          employerWithGeocode = new Fixture().Create <Employer>();

            MockMapper.Setup(m => m.Map <Vacancy, NewVacancyViewModel>(It.IsAny <Vacancy>())).Returns(vvm);
            MockEmployerService.Setup(m => m.GetEmployer(It.IsAny <int>(), It.IsAny <bool>())).Returns(employerWithGeocode);
            MockLocalAuthorityLookupService.Setup(m => m.GetLocalAuthorityCode(employerWithGeocode.Address.Postcode)).Returns(localAuthorityCode);
            MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider());
            MockVacancyPostingService.Setup(s => s.GetVacancy(It.IsAny <Guid>())).Returns(new Fixture().Create <Vacancy>());

            var provider = GetVacancyPostingProvider();

            // Act.
            provider.UpdateVacancy(_validVacancyMinimumDataSansReferenceNumber);

            // Assert.
            MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(employerWithGeocode.Address.Postcode), Times.Once);
            MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>(v => v.LocalAuthorityCode == localAuthorityCode)), Times.Once);
        }
        private async Task TestEditGET()
        {
            // Arrange
            var id    = Guid.Empty;
            var car   = GetCar();
            var model = GetCarEditViewModel(car);

            MockCarData
            .Setup(_ => _.GetById(id))
            .ReturnsAsync(car);
            MockMapper
            .Setup(_ => _.Map <CarEditViewModel>(car))
            .Returns(model);
            MockShowroomData
            .Setup(_ => _.GetAllActive())
            .ReturnsAsync(new List <Showroom>().AsEnumerable());

            // Act
            dynamic response = await ControllerUnderTest.Edit(id);

            // Assert
            MockCarData.Verify(_ => _.GetById(id), Times.Once);
            Assert.True(response.Model.Brand.Equals(model.Brand));
        }
 private void SetupMocksUpdate()
 {
     SetupMocksGeneral();
     MockUnitOfWork.Setup(x => x.CategoryRepository.Update(It.IsAny <MainCategory>()));
     MockMapper.Setup(x => x.Map(It.IsAny <UpdateCategoryDto>(), It.IsAny <MainCategory>()));
 }