Beispiel #1
0
        public async Task DownloadAsyncReturnsCorrectFile()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();

            await context.Documents.AddRangeAsync(this.SeedTestData());

            await context.SaveChangesAsync();

            var repository       = new EfDeletableEntityRepository <Document>(context);
            var mockFileDownload = new Mock <IFileDownloadService>();

            mockFileDownload.Setup(m => m.DownloadFileAsync(It.IsAny <string>())).Returns(Task.FromResult(new byte[7]));
            var documentsService = this.GetMockedService(repository, mockFileDownload.Object, null);

            var result = await documentsService.DownloadAsync("11");

            Assert.Equal(7, result.Length);
        }
        public async Task GetDetailsReturnsCorrectInformation()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.JobSectors.AddRangeAsync(this.SeedData());

            await context.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <JobSector>(context);

            var service = new JobSectorsService(repository);

            var result = service.GetDetails <EditViewModel>(1);

            Assert.NotNull(result);
            Assert.Equal(1, result.Id);
            Assert.Equal("First", result.Name);
            Assert.False(result.IsDeleted);
        }
        public async Task CreateSuccessfullyAddsNewCategory()
        {
            AutoMapperInitializer.InitializeMapper();
            var context    = InMemoryDbContextInitializer.InitializeContext();
            var repository = new EfDeletableEntityRepository <JobSector>(context);

            var service = new JobSectorsService(repository);

            var model = new CreateViewModel
            {
                Name      = "New Sector",
                IsDeleted = true,
            };

            int id = await service.CreateAsync(model);

            Assert.NotEqual(-1, id);
            Assert.Equal(1, context.JobSectors.IgnoreQueryFilters().Count());
        }
Beispiel #4
0
        public async Task DeleteMarksRecordAsDeletedButPreservesTheDbEntry()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();

            await context.Documents.AddRangeAsync(this.SeedTestData());

            await context.SaveChangesAsync();

            var repository       = new EfDeletableEntityRepository <Document>(context);
            var documentsService = this.GetMockedService(repository, null, null);
            var result           = await documentsService.DeleteAsync("11");

            Assert.True(result);
            var dbRecord = await context.Documents.FindAsync("11");

            Assert.True(dbRecord.IsDeleted);
            Assert.NotNull(dbRecord.DeletedOn);
            Assert.Equal(1, context.Documents.Count());
        }
Beispiel #5
0
        public async Task UploadAsyncSavesFileSuccessfully()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();

            var repository       = new EfDeletableEntityRepository <Document>(context);
            var cloudinary       = new Cloudinary(new Account(CloudinaryConfig.CloudName, CloudinaryConfig.ApiKey, CloudinaryConfig.ApiSecret));
            var documentsService = this.GetMockedService(repository, null, cloudinary);

            var model = new UploadInputModel
            {
                DocumentCategoryId = 123,
                File = this.PrepareFile(),
            };

            var result = await documentsService.UploadAsync(model, "1");

            Assert.NotNull(result);
            Assert.Equal(1, context.Documents.Count());
        }
        public async Task CreateProfileAsyncSavesInfoCorrectly()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();

            var candidatesRepository = new EfDeletableEntityRepository <Candidate>(context);
            var languagesRepository  = new EfDeletableEntityRepository <CandidateLanguage>(context);
            var skillsRepository     = new EfDeletableEntityRepository <CandidateSkill>(context);

            var candidatesService = this.GetMockedService(candidatesRepository, languagesRepository, skillsRepository, null);

            var model = new CreateCandidateProfileInputModel
            {
                AboutMe           = "some info",
                ApplicationUserId = "11",
                ContactAddress    = "address",
                FirstName         = "Georgi",
                LastName          = "Georgiev",
                LanguagesIds      = new List <int> {
                    1, 2, 3
                },
                SkillsIds = new List <int> {
                    4, 5, 6
                },
            };

            var candidateId = await candidatesService.CreateProfileAsync(model);

            Assert.NotNull(candidateId);

            var record = await context.Candidates.Include(c => c.Languages).Include(c => c.Skills).Where(c => c.Id == candidateId).FirstOrDefaultAsync();

            Assert.Equal(model.AboutMe, record.AboutMe);
            Assert.Equal(model.ApplicationUserId, record.ApplicationUserId);
            Assert.Equal(model.ContactAddress, record.ContactAddress);
            Assert.Null(record.Education);
            Assert.Null(record.PhoneNumber);
            Assert.Null(record.ProfilePictureUrl);
            Assert.Equal(3, record.Languages.Count());
            Assert.Equal(3, record.Skills.Count());
        }
        public async Task DeleteMarksRecordAsDeleted()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.Skills.AddAsync(new Skill { Id = 1, Name = "Skill", IsDeleted = false });

            await context.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Skill>(context);

            var service = new SkillsService(repository);

            var result = await service.DeleteAsync(1);

            var dbRecord = await context.Skills.FindAsync(1);

            Assert.True(result);
            Assert.True(dbRecord.IsDeleted);
            Assert.NotNull(dbRecord.DeletedOn);
            Assert.Equal(1, context.Skills.IgnoreQueryFilters().Count());
        }
        public async Task GetAllValidFilteredOffersAsyncReturnsCorrectDetailsWhenSalaryFilterIsActive()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.JobOffers.AddRangeAsync(this.SeedTestData());

            await context.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <JobOffer>(context);
            var service    = this.GetMockedService(repository);

            var filterModel = new FilterModel
            {
                SalaryFrom = 990,
                SalaryTo   = 2000,
            };

            var result = await service.GetAllValidFilteredOffersAsync <IndexJobOffersModel>(filterModel);

            Assert.Equal(2, result.Count());
        }
        public async Task GetAllValidFilteredOffersAsyncReturnsCorrectDetailsWhenJobSectorFilterIsActive()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.JobOffers.AddRangeAsync(this.SeedTestData());

            await context.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <JobOffer>(context);
            var service    = this.GetMockedService(repository);

            var filterModel = new FilterModel
            {
                SectorsIds = new List <int> {
                    2
                },
            };

            var result = await service.GetAllValidFilteredOffersAsync <IndexJobOffersModel>(filterModel);

            Assert.Single(result);
        }
Beispiel #10
0
        public async Task UpdateProfileCorrectlyUpdatesProfilePictureUrlWhenItIsNotNull()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.Employers.AddRangeAsync(this.SeedTestData());

            await context.SaveChangesAsync();

            var repository       = new EfDeletableEntityRepository <Employer>(context);
            var cloudinary       = new Cloudinary(new Account(CloudinaryConfig.CloudName, CloudinaryConfig.ApiKey, CloudinaryConfig.ApiSecret));
            var employersService = this.GetMockedService(repository, cloudinary);

            var logo = this.PrepareImage();

            var employerId = await employersService.UpdateProfileAsync("Second", new UpdateEmployerProfileViewModel { Logo = logo });

            Assert.NotNull(employerId);

            var logoUrl = context.Employers.Find(employerId).LogoUrl;

            Assert.NotEqual("someUrl", logoUrl);
        }
        public async Task IfPictureIsInvalidCreateProfileReturnsNull()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();

            var candidatesRepository = new EfDeletableEntityRepository <Candidate>(context);
            var cloudinary           = new Cloudinary(new Account(CloudinaryConfig.CloudName, CloudinaryConfig.ApiKey, CloudinaryConfig.ApiSecret));
            var candidatesService    = this.GetMockedService(candidatesRepository, null, null, cloudinary);

            var profilePicture = this.PrepareInvalidImage();
            var model          = new CreateCandidateProfileInputModel
            {
                FirstName         = "Ivan",
                LastName          = "Ivanov",
                ApplicationUserId = "1",
                ProfilePicture    = profilePicture,
            };

            var candidateId = await candidatesService.CreateProfileAsync(model);

            Assert.Null(candidateId);
        }
Beispiel #12
0
        public async Task CreateProfileAsyncSavesInfoCorrectly()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();

            var repository = new EfDeletableEntityRepository <Employer>(context);

            var employersService = this.GetMockedService(repository, null);

            var model = new CreateEmployerProfileInputModel
            {
                ApplicationUserId = "11",
                Address           = "address",
                Name = "Recruit Me",
                ContactPersonNames       = "Ivan Ivanov",
                ContactPersonEmail       = "*****@*****.**",
                JobSectorId              = 4,
                UniqueIdentificationCode = "204558718",
            };

            var employerId = await employersService.CreateProfileAsync(model);

            Assert.NotNull(employerId);

            var record = await context.Employers.Where(c => c.Id == employerId).FirstOrDefaultAsync();

            Assert.Equal(model.Name, record.Name);
            Assert.Equal(model.ApplicationUserId, record.ApplicationUserId);
            Assert.Equal(model.Address, record.Address);
            Assert.Null(record.WebsiteAddress);
            Assert.Null(record.PhoneNumber);
            Assert.Null(record.LogoUrl);
            Assert.Equal(4, record.JobSectorId);
            Assert.NotNull(record.ContactPersonNames);
            Assert.NotNull(record.ContactPersonEmail);
            Assert.NotNull(record.UniqueIdentificationCode);
        }
Beispiel #13
0
        public async Task UpdateProfileShouldUpdateProfileWhenValidIdIsPassed()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.Employers.AddRangeAsync(this.SeedTestData());

            await context.SaveChangesAsync();

            var repository       = new EfDeletableEntityRepository <Employer>(context);
            var cloudinary       = new Cloudinary(new Account(CloudinaryConfig.CloudName, CloudinaryConfig.ApiKey, CloudinaryConfig.ApiSecret));
            var employersService = this.GetMockedService(repository, cloudinary);

            var logo = this.PrepareImage();

            var model = new UpdateEmployerProfileViewModel
            {
                Name = "New Name",
                ContactPersonNames       = "Georgi Georgiev",
                ContactPersonEmail       = "*****@*****.**",
                UniqueIdentificationCode = "0009039460577",
                JobSectorId = 3,
                Logo        = logo,
            };
            var employerId = await employersService.UpdateProfileAsync("First", model);

            Assert.NotNull(employerId);

            var record = await context.Employers.FirstOrDefaultAsync(c => c.Id == "First");

            Assert.Equal(model.Name, record.Name);
            Assert.Equal(model.ContactPersonNames, record.ContactPersonNames);
            Assert.Equal(model.ContactPersonEmail, record.ContactPersonEmail);
            Assert.NotNull(record.LogoUrl);
            Assert.Equal(3, record.JobSectorId);
            Assert.Equal(model.UniqueIdentificationCode, record.UniqueIdentificationCode);
        }
        public async Task UpdateProfileCorrectlyUpdatesProfilePictureUrlWhenItIsNotNull()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.Candidates.AddRangeAsync(this.SeedTestData());

            await context.SaveChangesAsync();

            var candidatesRepository = new EfDeletableEntityRepository <Candidate>(context);
            var languagesRepository  = new EfDeletableEntityRepository <CandidateLanguage>(context);
            var skillsRepository     = new EfDeletableEntityRepository <CandidateSkill>(context);
            var cloudinary           = new Cloudinary(new Account(CloudinaryConfig.CloudName, CloudinaryConfig.ApiKey, CloudinaryConfig.ApiSecret));
            var candidatesService    = this.GetMockedService(candidatesRepository, languagesRepository, skillsRepository, cloudinary);

            var profilePicture = this.PrepareImage();

            var candidateId = await candidatesService.UpdateProfileAsync("Second", new UpdateCandidateProfileViewModel { ProfilePicture = profilePicture });

            Assert.NotNull(candidateId);

            var profilePictureUrl = context.Candidates.Find(candidateId).ProfilePictureUrl;

            Assert.NotEqual("someUrl", profilePictureUrl);
        }
        public async Task UpdateAsyncCorrectlyUpdatesRecord()
        {
            AutoMapperInitializer.InitializeMapper();
            var context             = InMemoryDbContextInitializer.InitializeContext();
            var repository          = new EfDeletableEntityRepository <JobOffer>(context);
            var languagesRepository = new EfDeletableEntityRepository <JobOfferLanguage>(context);
            var skillsRepository    = new EfDeletableEntityRepository <JobOfferSkill>(context);
            var typesRepository     = new EfDeletableEntityRepository <JobOfferJobType>(context);
            var service             = this.GetMockedService(repository, languagesRepository, skillsRepository, typesRepository);

            var offer = new PostViewModel
            {
                LanguagesIds = new List <int> {
                    1, 2, 3
                },
                SkillsIds = new List <int> {
                    4, 5,
                },
                JobTypesIds = new List <int> {
                    6
                },
                JobLevelId  = 1,
                ValidFrom   = DateTime.UtcNow,
                ValidUntil  = DateTime.UtcNow.AddDays(30),
                JobSectorId = 1,
                City        = "Sofia",
                Position    = "Tech Lead",
            };
            var id = await service.AddAsync(offer, "1");

            var model = new EditViewModel
            {
                JobOfferDetails = new EditJobOfferDetailsModel
                {
                    Id           = id,
                    LanguagesIds = new List <int> {
                        4, 5,
                    },
                    SkillsIds = new List <int> {
                        6, 7
                    },
                    JobTypesIds = new List <int> {
                        8, 9, 1
                    },
                    JobLevelId  = 2,
                    JobSectorId = 3,
                    City        = "New York",
                    Position    = "CEO",
                },
            };

            var result = await service.UpdateAsync(model, "1");

            Assert.NotNull(result);

            var offerLanguagesCount = await context.JobOffers.Include(jo => jo.Languages).Where(jo => jo.Id == result).Select(jo => jo.Languages.Count).FirstOrDefaultAsync();

            var offerSkillsCount = await context.JobOffers.Include(jo => jo.Skills).Where(jo => jo.Id == result).Select(jo => jo.Skills.Count).FirstOrDefaultAsync();

            var offerTypesCount = await context.JobOffers.Include(jo => jo.JobTypes).Where(jo => jo.Id == result).Select(jo => jo.JobTypes.Count).FirstOrDefaultAsync();

            Assert.Equal(1, context.JobOffers.Count());
            Assert.Equal(2, offerLanguagesCount);
            Assert.Equal(2, offerSkillsCount);
            Assert.Equal(3, offerTypesCount);
        }