Ejemplo n.º 1
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>()));
 }
        public void ShouldReturnOkIfThereIsntAnyValidationError()
        {
            var vacancyReferenceNumber = 1;

            var closingDate = DateTime.Now;

            var apprenticeshipVacancy = new Vacancy
            {
                VacancyReferenceNumber = vacancyReferenceNumber,
                Wage = new Wage(WageType.NationalMinimum, null, null, null, null, WageUnit.Weekly, 30, null)
            };

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel(),
                VacancyReferenceNumber = vacancyReferenceNumber,
                VacancyDatesViewModel  = new VacancyDatesViewModel
                {
                    ClosingDate = new DateViewModel(closingDate)
                },
            };

            MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(vacancyReferenceNumber))
            .Returns(apprenticeshipVacancy);
            MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>()))
            .Returns(apprenticeshipVacancy);
            MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(apprenticeshipVacancy))
            .Returns(viewModel);

            var provider = GetVacancyPostingProvider();

            provider.CloseVacancy(viewModel);
            MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>(v => v.Status == VacancyStatus.Closed)));
        }
        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();
        }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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);
        }
        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 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));
        }
        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);
        }
        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"));
        }
 private void VerifyMocksCreate(Times methodCalls)
 {
     VerifyMocksGeneral(methodCalls);
     MockUnitOfWork.Verify(x => x.CategoryRepository.Create(fixture.CreateCategory), methodCalls);
     MockMapper.Verify(x => x.Map <MainCategoryDto>(fixture.CreateCategory), methodCalls);
     MockMapper.Verify(x => x.Map <MainCategory>(fixture.CreateCategoryDto), methodCalls);
 }
Ejemplo n.º 11
0
        public void ShouldUpdateWage()
        {
            //Arrange.
            const int vacancyReferenceNumber = 1;
            var       closingDate            = DateTime.Today.AddDays(20);
            var       possibleStartDate      = DateTime.Today.AddDays(30);

            var wageViewModel = new WageViewModel()
            {
                Type             = WageType.Custom,
                CustomType       = CustomWageType.Fixed,
                Amount           = 450,
                AmountLowerBound = null,
                AmountUpperBound = null,
                Text             = null,
                Unit             = WageUnit.Monthly,
                HoursPerWeek     = 37.5m
            };
            var wage = new Wage(WageType.Custom, 450, null, null, null, WageUnit.Monthly, 37.5m, null);

            var updatedViewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(closingDate),
                    PossibleStartDate = new DateViewModel(possibleStartDate)
                },
                VacancyReferenceNumber = vacancyReferenceNumber,
                Wage = wageViewModel
            };

            var dbApprenticeshipVacancy = new Vacancy
            {
                VacancyReferenceNumber = vacancyReferenceNumber,
                Wage = new Wage(WageType.NationalMinimum, null, null, null, "Legacy text", WageUnit.Weekly, 30, null)
            };

            MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(vacancyReferenceNumber))
            .Returns(dbApprenticeshipVacancy);
            MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>()))
            .Returns(dbApprenticeshipVacancy);
            MockMapper.Setup(m => m.Map <WageViewModel, Wage>(It.IsAny <WageViewModel>())).Returns(wage);
            MockMapper.Setup(m => m.Map <Wage, WageViewModel>(It.IsAny <Wage>())).Returns(wageViewModel); //this line kind of invalidates this test.
            MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(dbApprenticeshipVacancy))
            .Returns(updatedViewModel);

            var provider = GetVacancyPostingProvider();

            //Act.
            provider.UpdateVacancyDates(updatedViewModel);

            //Assert.
            MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>(
                                                                      v => v.PossibleStartDate == possibleStartDate &&
                                                                      v.Wage.Type == updatedViewModel.Wage.Type &&
                                                                      v.Wage.Amount == updatedViewModel.Wage.Amount &&
                                                                      v.Wage.Text == dbApprenticeshipVacancy.Wage.Text &&
                                                                      v.Wage.Unit == updatedViewModel.Wage.Unit &&
                                                                      v.Wage.HoursPerWeek == dbApprenticeshipVacancy.Wage.HoursPerWeek)));
        }
Ejemplo n.º 12
0
 private void VerifyMocksCreate(int userIdToReturn, Times mapperCalls)
 {
     VerifyMockGetUser(userIdToReturn, Times.Once());
     VerifyMockCommit(mapperCalls);
     MockUnitOfWork.Verify(x => x.WalletRepository.Create(fixture.DefaultWallet), mapperCalls);
     MockMapper.Verify(x => x.Map <Wallet>(fixture.DefaultWalletDto), mapperCalls);
     MockMapper.Verify(x => x.Map <WalletDto>(fixture.DefaultWallet), mapperCalls);
 }
Ejemplo n.º 13
0
 private void VerifyMocksGeneral(UserDto mappedUser, Times methodCalls)
 {
     MockUnitOfWork.Verify(x =>
                           x.UserRepository.SingleOrDefaultAsync(It.IsAny <Expression <Func <User, bool> > >()), Times.Once());
     MockUnitOfWork.Verify(x => x.CommitAsync(), methodCalls);
     MockMapper.Verify(x => x.Map <User>(mappedUser), methodCalls);
     mockPasswordService.Verify(x => x.CreatePasswordHash(fixture.Password), methodCalls);
 }
 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.º 15
0
 private void VerifyMocksUpdate(int userId, int walletId, Wallet walletToUpdate, Times times)
 {
     VerifyMockGetWallet(walletId, Times.Once());
     VerifyMockGetUser(userId, times);
     VerifyMockCommit(times);
     MockUnitOfWork.Verify(x => x.WalletRepository.Update(walletToUpdate), times);
     MockMapper.Verify(x => x.Map(fixture.UpdateWalletDto, walletToUpdate), times);
 }
Ejemplo n.º 16
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.º 17
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.º 18
0
 private void VerifyMocks(Wallet userWallet, int userId, Operation createOperation,
                          OperationDto createOperationDto, Times methodCalls)
 {
     MockUnitOfWork.Verify(x => x.UserRepository.GetAsync(userId));
     MockUnitOfWork.Verify(x => x.OperationRepository.Create(createOperation), methodCalls);
     MockUnitOfWork.Verify(x => x.WalletRepository.Update(userWallet), methodCalls);
     MockUnitOfWork.Verify(x => x.CommitAsync(), methodCalls);
     MockMapper.Verify(x => x.Map <Operation>(createOperationDto), methodCalls);
     MockMapper.Verify(x => x.Map <OperationDto>(createOperation), methodCalls);
 }
Ejemplo n.º 19
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);
 }
Ejemplo n.º 20
0
        public async Task GetWalletAsync_GetWallet_WalletReturned()
        {
            SetupMocksGet <Wallet, WalletDto>(fixture.DefaultUser, fixture.DefaultWalletDto, fixture.DefaultWallet);

            var wallet = await service.GetWalletAsync(fixture.DefaultUser.UserId, fixture.DefaultWalletDto.WalletId);

            Assert.Equal(wallet, fixture.DefaultWalletDto);
            VerifyMockGetWallet(fixture.DefaultWalletDto.WalletId, Times.Once());
            MockMapper.Verify(x => x.Map <WalletDto>(fixture.DefaultWallet), Times.Once);
        }
Ejemplo n.º 21
0
        public void MapperBase_WhenBinaryResourceInDataSourceIsNull_ExpectException()
        {
            var dataSource = new MockDataSource();
            //{
            //    BinaryResource = null
            //};
            var sut = new MockMapper();

            sut.ImportEntityFromDataSource(dataSource, new MockEntity(), new MockLocator());
        }
        public void SetUp()
        {
            _validNewVacancyViewModelWithReferenceNumber = new NewVacancyViewModel()
            {
                VacancyReferenceNumber   = 1,
                OfflineVacancy           = false,
                VacancyOwnerRelationship = new VacancyOwnerRelationshipViewModel()
            };

            MockVacancyPostingService.Setup(mock => mock.GetVacancyByReferenceNumber(_validNewVacancyViewModelWithReferenceNumber.VacancyReferenceNumber.Value))
            .Returns(_existingVacancy);
            MockVacancyPostingService.Setup(mock => mock.CreateVacancy(It.IsAny <Vacancy>()))
            .Returns <Vacancy>(v => v);
            MockReferenceDataService.Setup(mock => mock.GetSectors())
            .Returns(new List <Sector>
            {
                new Sector
                {
                    Id        = 1,
                    Standards =
                        new List <Standard>
                    {
                        new Standard {
                            Id = 1, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Intermediate
                        },
                        new Standard {
                            Id = 2, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Advanced
                        },
                        new Standard {
                            Id = 3, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Higher
                        },
                        new Standard {
                            Id = 4, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.FoundationDegree
                        },
                        new Standard {
                            Id = 5, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Degree
                        },
                        new Standard {
                            Id = 6, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Masters
                        }
                    }
                }
            });
            MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(ProviderSiteId, EdsUrn))
            .Returns(_vacancyOwnerRelationship);
            MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true))
            .Returns(_vacancyOwnerRelationship);
            MockProviderService.Setup(s => s.GetProvider(Ukprn, true))
            .Returns(new Provider());
            MockEmployerService.Setup(s => s.GetEmployer(EmployerId, It.IsAny <bool>())).Returns(new Fixture().Build <Employer>().Create());

            MockMapper.Setup(m => m.Map <Vacancy, NewVacancyViewModel>(It.IsAny <Vacancy>()))
            .Returns(new NewVacancyViewModel());
        }
Ejemplo n.º 23
0
        public async Task GetAllWalletsAsync_GetWallets_AllWalletsReturned()
        {
            SetupMocksGet <IEnumerable <Wallet>, IEnumerable <WalletDto> >(fixture.UserWithWallets,
                                                                           fixture.UserWalletsDtos);

            var wallets = await service.GetAllWalletsAsync(fixture.UserWithWallets.UserId, fixture.PaginationFilter);

            Assert.Equal(wallets, fixture.UserWalletsDtos);
            VerifyMockGetUser(fixture.UserWithWallets.UserId, Times.Once());
            MockMapper.Verify(x => x.Map <IEnumerable <WalletDto> >(fixture.UserWithWallets.Wallets), Times.Once);
        }
        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);
        }
Ejemplo n.º 25
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);
            }
        }
Ejemplo n.º 26
0
        public void ShouldSetVacancyApplicationStateAfterUpdate(int applicationCount, VacancyApplicationsState expectedState)
        {
            // Arrange.
            const int vacancyId = 1;
            const int vacancyReferenceNumber = 2;

            var closingDate       = DateTime.Today.AddDays(20);
            var possibleStartDate = DateTime.Today.AddDays(30);

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel(),
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(closingDate),
                    PossibleStartDate = new DateViewModel(possibleStartDate)
                },
                VacancyReferenceNumber = vacancyReferenceNumber
            };

            var vacancy = new Vacancy
            {
                VacancyId = vacancyId,
                VacancyReferenceNumber = vacancyReferenceNumber,
                Wage = new Wage(WageType.NationalMinimum, null, null, null, null, WageUnit.Weekly, 30, null)
            };

            MockVacancyPostingService.Setup(mock => mock
                                            .GetVacancyByReferenceNumber(vacancyReferenceNumber))
            .Returns(vacancy);

            MockVacancyPostingService.Setup(mock => mock
                                            .UpdateVacancy(It.IsAny <Vacancy>()))
            .Returns(vacancy);

            MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(vacancy))
            .Returns(viewModel);

            MockApprenticeshipApplicationService.Setup(mock => mock.
                                                       GetApplicationCount(vacancyId))
            .Returns(applicationCount);

            var provider = GetVacancyPostingProvider();

            // Act.
            var result = provider.UpdateVacancyDates(viewModel);

            // Assert.
            result.VacancyApplicationsState.Should().Be(expectedState);
        }
        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();
        }
        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);
        }
        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))));
        }
        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));
        }