示例#1
0
        public async Task ChangeUserValuesWithNullUser_ShouldReturnStatusInvalidUser()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            var user1 = await this.CreateUserAsync("*****@*****.**", "Pesho", "Peshev", repository);

            var user2 = await this.CreateUserAsync("*****@*****.**", "Vank", "Vanko", repository);

            var getUser = await repository.All().Where(x => x.Id == user1).FirstOrDefaultAsync();

            var valueExample  = 20;
            var statusInvalid = "Invalid user";

            var changeUserAge = await service.ChangeUserAge(null, valueExample);

            var userCurrentHipsSizeSecondCheck  = getUser.ModelInformation.Hips;
            var userCurrentWaistSizeSecondCheck = getUser.ModelInformation.Waist;

            Assert.Equal(statusInvalid, changeUserAge);

            // Checked only with two properties no need for more.
            Assert.Equal(14, userCurrentHipsSizeSecondCheck);
            Assert.Equal(16, userCurrentWaistSizeSecondCheck);
        }
示例#2
0
        public async Task ChangeUserEthnicityWithNullUser_ShouldReturnStatusInvalidUser()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            var user1 = await this.CreateUserAsync("*****@*****.**", "Pesho", "Peshev", repository);

            var user2 = await this.CreateUserAsync("*****@*****.**", "Vank", "Vanko", repository);

            var getUser = await repository.All().Where(x => x.Id == user1).FirstOrDefaultAsync();

            var changeTo      = Ethnicity.Japanese;
            var statusInvalid = "Invalid user";

            var changeUserEthnicity = await service.ChangeUserEthnicity(null, changeTo);

            var userCurrentEthnicitySecondCheck = getUser.ModelInformation.Ethnicity;

            Assert.Equal(statusInvalid, changeUserEthnicity);
            Assert.Equal(Ethnicity.Chinese, userCurrentEthnicitySecondCheck);
        }
示例#3
0
        public async Task ChangeUserLastNameWithNullUser_ShouldReturnStatusInvalidUser()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            var user1 = await this.CreateUserAsync("*****@*****.**", "Pesho", "Peshev", repository);

            var user2 = await this.CreateUserAsync("*****@*****.**", "Vank", "Vanko", repository);

            var getUser = await repository.All().Where(x => x.Id == user1).FirstOrDefaultAsync();

            var nameChangeExample = "Sanchev";
            var statusInvalid     = "Invalid user";

            var changeUserLastName = await service.ChangeUserFirstName(null, nameChangeExample);

            var userCurrentNameSecondCheck = getUser.LastName;

            Assert.Equal(statusInvalid, changeUserLastName);
            Assert.Equal("Peshev", userCurrentNameSecondCheck);
        }
示例#4
0
        public async Task ChangeUserGender_ShouldChangeUsersGenderWithStatusSuccess()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            var user1 = await this.CreateUserAsync("*****@*****.**", "Pesho", "Peshev", repository);

            var user2 = await this.CreateUserAsync("*****@*****.**", "Vank", "Vanko", repository);

            var getUser = await repository.All().Where(x => x.Id == user1).FirstOrDefaultAsync();

            var changeTo = Gender.Female;
            var status   = "Success";

            var changeUserGender = await service.ChangeUserGender(getUser, changeTo);

            var userCurrentGenderSecondCheck = getUser.ModelInformation.Gender;

            Assert.Equal(status, changeUserGender);
            Assert.Equal(changeTo, userCurrentGenderSecondCheck);
        }
示例#5
0
        public async Task ChangeUserStringValuesCountry_ShouldChangeUserValuesWithStatusSuccess()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            var user1 = await this.CreateUserAsync("*****@*****.**", "Pesho", "Peshev", repository);

            var user2 = await this.CreateUserAsync("*****@*****.**", "Vank", "Vanko", repository);

            var getUser = await repository.All().Where(x => x.Id == user1).FirstOrDefaultAsync();

            var valueInput   = "country";
            var valueExample = "Norway";
            var status       = "Success";

            var changeUserValues = await service.ChangeUserStringValues(getUser, valueExample, valueInput);

            var userCurrentValueSecondCheck = getUser.ModelInformation.Country;

            Assert.Equal(status, changeUserValues);
            Assert.Equal(valueExample, userCurrentValueSecondCheck);
        }
示例#6
0
        public async Task TakeAllModels_ShouldReturnListOfModelsDependingOnPerPage()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            for (int i = 0; i < 12; i++)
            {
                await this.CreateUserAsync($"pesho{i}@abv.bg", "Pesho", "Peshev", repository);
            }

            var perPage    = 6;
            var pagesCount = await service.GetPagesCount(perPage);

            var takeModels = await service.TakeAllModels <ModelProfileView>(1, perPage);

            var takeModelsPage2 = await service.TakeAllModels <ModelProfileView>(2, perPage);

            var modelReturned      = takeModels.Count();
            var modelReturnedPage2 = takeModelsPage2.Count();

            // Page one should return 6 and page 2 should return 6 for overall 12 users in the db;
            Assert.Equal(6, modelReturned);
            Assert.Equal(6, modelReturnedPage2);
            Assert.Equal(2, pagesCount);
        }
示例#7
0
        public async Task GetPageCount_NoUsersShouldReturnZero()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);
            var perPage = 6;

            var pagesCount = await service.GetPagesCount(perPage);

            Assert.Equal(0, pagesCount);
        }
示例#8
0
        public async Task UploadAlbum_WithNoUrls_ShouldRetunNoUpdates()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));
            var imageRepo  = new EfDeletableEntityRepository <UserImage>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, imageRepo, null);

            var user1 = await this.CreateUserAsync($"*****@*****.**", "Pesho", "Peshev", repository);

            var listUrls = new List <string>
            {
            };
            var count = await service.UploadAlbum(listUrls, user1);

            Assert.Equal(0, count);
        }
示例#9
0
        public async Task TakeAllModels_WithNoUsersShouldReturnZero()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            var perPage    = 6;
            var pagesCount = await service.GetPagesCount(perPage);

            var takeModels = await service.TakeAllModels <ModelProfileView>(1, perPage);

            var modelReturned = takeModels.Count();

            Assert.Equal(0, modelReturned);
            Assert.Equal(0, pagesCount);
        }
示例#10
0
        public async Task InsertModelInformation_ShouldAddFillTablesWithDefaultInformation()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var userRepository      = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));
            var modelInfoRepository = new EfDeletableEntityRepository <ModelInformation>(new ApplicationDbContext(options));
            var service             = new ModelService.ModelService(userRepository, null, null, modelInfoRepository);

            var user1 = await this.CreateUserWithNoInformationAsync("*****@*****.**", "Pesho", "Peshev", userRepository);

            var user2 = await this.CreateUserWithNoInformationAsync("*****@*****.**", "Vank", "Vanko", userRepository);

            await service.InsertModelInformation(user1);

            var check = await modelInfoRepository.All().Where(x => x.UserId == user1).FirstOrDefaultAsync();

            Assert.NotNull(check);
        }
示例#11
0
        public async Task GetModelById_WithWrongDataShouldReturnNothing()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            var user1 = await this.CreateUserAsync("*****@*****.**", "Pesho", "Peshev", repository);

            var user2 = await this.CreateUserAsync("*****@*****.**", "Vank", "Vanko", repository);

            var user3 = await this.CreateUserAsync("*****@*****.**", "Ri", "Ro", repository);

            var getModel = await service.GetModelById <ProfileViewModel>("TESTID123");

            Assert.Null(getModel);
        }
示例#12
0
        public async Task GetModelCount_ShouldReturnZero_IfUserHasNoPictureOrInformation()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            var user1 = await this.CreateUserWithNoInformationAsync("*****@*****.**", "Pesho", "Peshev", repository);

            var user2 = await this.CreateUserWithNoInformationAsync("*****@*****.**", "Vank", "Vanko", repository);

            var user3 = await this.CreateUserWithNoInformationAsync("*****@*****.**", "Ri", "Ro", repository);

            var count = await service.GetModelCount();

            Assert.Equal(0, count);
        }
示例#13
0
        public async Task TakeSixModels_WithLessThanSixUsers_ShouldReturnLessThanSix()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            for (int i = 0; i < 4; i++)
            {
                await this.CreateUserAsync($"pesho{i}@abv.bg", "Pesho", "Peshev", repository);
            }

            var takeSixUsers = await service.TakeSixModels <ModelProfileView>();

            var countUsers = takeSixUsers.Count();

            Assert.Equal(4, countUsers);
        }
示例#14
0
        public async Task TakeAllPictures_ShouldReturnAllPicturesFromUser()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository      = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));
            var imageRepository = new EfDeletableEntityRepository <UserImage>(new ApplicationDbContext(options));
            var service         = new ModelService.ModelService(repository, null, imageRepository, null);

            var user1 = await this.CreateUserWithImage("*****@*****.**", "Pesho", "Peshev", repository);

            var takeImages = await service.TakeAllPictures <AlbumViewModel>(user1);

            var count = 0;

            foreach (var image in takeImages)
            {
                count = image.UserImages.Count();
            }

            Assert.Equal(3, count);
        }
示例#15
0
        public async Task GetPageCount_ShouldRetunPageCountDependingOnPerPage()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            for (int i = 0; i < 12; i++)
            {
                await this.CreateUserAsync($"pesho{i}@abv.bg", "Pesho", "Peshev", repository);
            }

            var perPage    = 6;
            var pagesCount = await service.GetPagesCount(perPage);

            var pageCountPlus1 = pagesCount + 1;

            Assert.Equal(2, pagesCount);
            Assert.Equal(3, pageCountPlus1);
        }
示例#16
0
        public async Task ChangeUserStringValuesWithNullUser_ShouldReturnStatusInvalidUser()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));

            var service = new ModelService.ModelService(repository, null, null, null);

            var user1 = await this.CreateUserAsync("*****@*****.**", "Pesho", "Peshev", repository);

            var user2 = await this.CreateUserAsync("*****@*****.**", "Vank", "Vanko", repository);

            var getUser = await repository.All().Where(x => x.Id == user1).FirstOrDefaultAsync();

            var valueInput    = "country";
            var valueExample  = "Norway";
            var statusInvalid = "Invalid user";

            var changeUserAge = await service.ChangeUserStringValues(null, valueExample, valueInput);

            Assert.Equal(statusInvalid, changeUserAge);
        }
示例#17
0
        public async Task InsertModelInformation_CallingTheMethodTwiceShouldReturnRightStatusMassages()
        {
            string infoUpdate  = "User Information Updated";
            string infoCreated = "User Information was created";

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var userRepository      = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));
            var modelInfoRepository = new EfDeletableEntityRepository <ModelInformation>(new ApplicationDbContext(options));
            var service             = new ModelService.ModelService(userRepository, null, null, modelInfoRepository);

            var user1 = await this.CreateUserWithNoInformationAsync("*****@*****.**", "Pesho", "Peshev", userRepository);

            var user2 = await this.CreateUserWithNoInformationAsync("*****@*****.**", "Vank", "Vanko", userRepository);

            var response = await service.InsertModelInformation(user1);

            var response2 = await service.InsertModelInformation(user1);

            Assert.Equal(infoCreated, response);
            Assert.Equal(infoUpdate, response2);
        }