public void GetAll_WithExistingProfileImage_DoesNotThrow() { var profileImage1Model = new ProfileImageModel { Id = 11, PictureFormat = SupportedFormatPicture.Png }; var profileImage2Model = new ProfileImageModel { Id = 12, PictureFormat = SupportedFormatPicture.Jpg }; var returnedProfileImage1 = RepositorySUT.Add(profileImage1Model); var returnedProfileImage2 = RepositorySUT.Add(profileImage2Model); var allProfileImages = RepositorySUT.GetAll(); Assert.NotNull(returnedProfileImage1); Assert.NotNull(returnedProfileImage2); Assert.NotEmpty(allProfileImages); RepositorySUT.Remove(returnedProfileImage1.Id); RepositorySUT.Remove(returnedProfileImage2.Id); }
internal object AddProfileImage(ProfileImageModel model) { try { User user = _dbContext.Users.Find(model.UserId); if (user != null) { user.UserImage = ParseImage(model.userImage); _dbContext.Entry(user).State = EntityState.Modified; _dbContext.SaveChanges(); ImageUploadResponse imageResponse = new ImageUploadResponse { Success = true, ImageUrl = user.UserImage }; return(imageResponse); } else { ImageUploadResponse imageResponse = new ImageUploadResponse { Success = false, ImageUrl = null }; return(imageResponse); } } catch (Exception ex) { return("{success:" + ex.Message + "}"); } }
public void UpdatePicture_ToExistingUser_PictureChanged() { ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 650, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; imageToUserJames = FacadeSUT.Create(imageToUserJames) as ProfileImageModel; var lightPic = new ProfileImageLightModel { Id = imageToUserJames.Id }; UserModel james = new UserModel { Id = 651, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = lightPic, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; james = FacadeSUT.Create(james) as UserModel; var lightJames = new UserLightModel { Id = james.Id }; var user = FacadeSUT.GetDetail(lightJames) as UserModel; //Act var newPicture = new ProfileImageLightModel { Id = 650, Content = new byte[20], PictureFormat = SupportedFormatPicture.Jpg }; user.ProfilePicture = newPicture; FacadeSUT.Update(user.ProfilePicture); //Assert var returnedUser = FacadeSUT.GetDetail(user) as UserModel; Assert.Equal(newPicture.Content.ToString(), returnedUser.ProfilePicture.Content.ToString()); }
public async Task SaveImage() { try { CheckConnectivity(); IsSaving = true; CanUpload = false; // var profileimage = new ProfileImageModel //{ // ImageByte = Convert.ToBase64String(ImageStream.ToArray()), // NUBAN = GlobalStaticFields.Customer.ListOfAllAccounts.FirstOrDefault().nuban, // ReferenceID = Utilities.GenerateReferenceId(), // RequestType = "928" //}; var profileimage = new ProfileImageModel { Base64Image = Convert.ToBase64String(ImageStream.ToArray()), Email = GlobalStaticFields.Customer.Email, FileType = "jpg" }; var apirequest = new ApiRequest(); string msg = ""; string content = ""; var request = await apirequest.Post <ProfileImageModel>(profileimage, "", URLConstants.SwitchApiLiveBaseUrl, "Switch/SaveImage", "ProfilePageViewModel"); if (request.IsSuccessStatusCode) { content = await request.Content.ReadAsStringAsync(); ProfileImageSource = ImageSource.FromUri(new Uri($"{URLConstants.SwitchUrl}upload/{GlobalStaticFields.Customer.UserID}.jpg")); } else { content = await request.Content.ReadAsStringAsync(); } if (!string.IsNullOrWhiteSpace(content)) { content = content.JsonCleanUp(); Utilities.ShowToast(content); } } catch (Exception ex) { } finally { IsSaving = false; CanUpload = true; } }
public void Create_NonExisting_DoesNotThrow() { var profileImageModel = new ProfileImageModel { Id = 10, PictureFormat = SupportedFormatPicture.Png }; var returnedProfileImage = RepositorySUT.Add(profileImageModel); Assert.NotNull(returnedProfileImage); RepositorySUT.Remove(returnedProfileImage.Id); }
public void Remove_WithExistingProfileImage_DoesNotThrow() { var profileImageModel = new ProfileImageModel { Id = 15, PictureFormat = SupportedFormatPicture.Png }; RepositorySUT.Add(profileImageModel); RepositorySUT.Remove(profileImageModel.Id); var returnedProfileImage = RepositorySUT.GetById(profileImageModel.Id); Assert.Null(returnedProfileImage); }
public ProfileImage MapProfileImageModelToProfileImage(ProfileImageModel model) { if (model == null) { return(null); } return(new ProfileImage { Id = model.Id, FileName = model.FileName, Content = model.Content, PictureFormat = model.PictureFormat }); }
public void DeleteUser_AddedUser_UserDeleted() { ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 605, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; var lightPic = new ProfileImageLightModel { Id = 605 }; FacadeSUT.Create(imageToUserJames); UserModel james = new UserModel { Id = 606, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = lightPic, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; FacadeSUT.Create(james); //Arrange var lightUser = new UserLightModel { Id = 606 }; //Act FacadeSUT.Delete(lightUser); var returned = FacadeSUT.GetDetail(lightUser); //Assert Assert.Null(returned); }
public void GetById_WithExistingProfileImage_DoesNotThrow() { var profileImageModel = new ProfileImageModel { Id = 13, PictureFormat = SupportedFormatPicture.Png }; var returnedProfileImage = RepositorySUT.Add(profileImageModel); var foundProfileImage = RepositorySUT.GetById(returnedProfileImage.Id); Assert.NotNull(foundProfileImage); Assert.Equal(profileImageModel.Id, foundProfileImage.Id); RepositorySUT.Remove(returnedProfileImage.Id); }
public async Task <IActionResult> Index() { var user = await _userManager.GetUserAsync(User); var userId = user.Id; ApplicationUser applicationUser = await _db.ApplicationUser .Include(x => x.Images) .FirstOrDefaultAsync(x => x.Id == userId); if (applicationUser == null) { return(NotFound()); } var auth = new FirebaseAuthProvider(new FirebaseConfig(FirebaseKeys.apiKey)); var a = await auth.SignInWithEmailAndPasswordAsync(FirebaseKeys.AuthEmail, FirebaseKeys.AuthPassword); List <Tuple <Guid, string, string> > firebaseImagesUrl = new List <Tuple <Guid, string, string> >(); foreach (var item in applicationUser.Images) { var Url = new FirebaseStorage( FirebaseKeys.Bucket, new FirebaseStorageOptions { AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken), ThrowOnCancel = true }) .Child("images") .Child($"{item.ImageFirebaseTitle}") .GetDownloadUrlAsync().Result; firebaseImagesUrl.Add(new Tuple <Guid, string, string>(item.ID, Url, item.ImageFirebaseTitle)); } ProfileImageModel profileImageModel = new ProfileImageModel() { ApplicationUser = user, FirebaseImageURL = firebaseImagesUrl }; return(View(profileImageModel)); }
public void FindUserByEmail_ExistingUsersEmail_DoesNotThrow() { //Arrange ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 625, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; var lightPic = new ProfileImageLightModel { Id = 625 }; imageToUserJames = FacadeSUT.Create(imageToUserJames) as ProfileImageModel; UserModel userModel = new UserModel { Id = 626, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = new ProfileImageLightModel { Id = imageToUserJames.Id }, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; userModel = FacadeSUT.Create(userModel) as UserModel; //Act var userModels = FacadeSUT.FindUserByEmail("*****@*****.**"); //Assert Assert.NotNull(userModels); }
public static Photo ConvertDataToPhoto(PhotoDao photo, UserDao user, UserImageUrlDao imgUrls, PhotoUrlDao urls) { var photoData = new Photo(); photoData.Id = photo.Id; photoData.Create = photo.CreateDate; photoData.Update = photo.UpdateDate; photoData.LikedByUser = photo.LikedByUser; photoData.Likes = photo.Likes; photoData.Description = photo.Description; if (user != null) { var userData = new User(); userData.Id = user.Id; userData.Name = user.Name; if (imgUrls != null) { var profileImgData = new ProfileImageModel(); profileImgData.Large = imgUrls.Large; profileImgData.Medium = imgUrls.Medium; profileImgData.Small = imgUrls.Small; userData.ProfileImages = profileImgData; } photoData.User = userData; } if (urls != null) { var photoUrlData = new Url(); photoUrlData.Raw = urls.Raw; photoUrlData.Regular = urls.Regular; photoUrlData.Small = urls.Small; photoUrlData.Thumb = urls.Thumb; photoData.Urls = photoUrlData; } return(photoData); }
public void Create_NonExistingUser_IsCreated() { ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 7, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; var lightPic = new ProfileImageLightModel { Id = 7 }; FacadeSUT.Create(imageToUserJames); UserModel james = new UserModel { Id = 10, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = new ProfileImageLightModel { Id = 7 }, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; james = FacadeSUT.Create(james) as UserModel; var receivedUser = FacadeSUT.GetDetail(james) as UserModel; Assert.NotNull(receivedUser); FacadeSUT.Delete(receivedUser); }
public void ChangeFormat_WithExistingProfileImage_DoesNotThrow() { var profileImageModel = new ProfileImageModel { Id = 14, PictureFormat = SupportedFormatPicture.Png }; var addedProfileImage = RepositorySUT.Add(profileImageModel); addedProfileImage.PictureFormat = SupportedFormatPicture.Gif; RepositorySUT.Update(addedProfileImage); var updatedProfileImage = RepositorySUT.GetById(addedProfileImage.Id); Assert.NotNull(updatedProfileImage); Assert.Equal(SupportedFormatPicture.Gif, updatedProfileImage.PictureFormat); RepositorySUT.Remove(updatedProfileImage.Id); }
public IActionResult AddProfileImage(ProfileImageModel model) { return(Ok(register.AddProfileImage(model))); }
public void getAllPostsInIFJTeam_twoPosts_notThrow() { //Arrange var imageToUserLucas = new ProfileImageModel { Id = 810, Content = new byte[10], FileName = "Profile Lucas Picture", PictureFormat = SupportedFormatPicture.Png }; imageToUserLucas = FacadeSUT.Create(imageToUserLucas) as ProfileImageModel; var imageToUserLucasLight = new ProfileImageLightModel { Id = imageToUserLucas.Id }; var lucas = new UserModel { Id = 811, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "Lucas", LastName = "Collins", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = imageToUserLucasLight, UserDescription = "Lucas school account", UserTeams = new List <UserTeamMemberModel>() }; lucas = FacadeSUT.Create(lucas) as UserModel; var lucasLight = new UserLightModel { Id = lucas.Id }; var teamIFJ = new TeamModel { Id = 812, Admin = lucasLight, Description = "Team for formal language and compilators (IFJ) project.", Name = "IFJ team", Posts = new List <PostLightModel>(), Members = new List <UserTeamMemberModel>() }; teamIFJ = FacadeSUT.Create(teamIFJ) as TeamModel; var teamLight = new TeamLightModel { Id = teamIFJ.Id }; FacadeSUT.JoinUserToTeam(lucasLight, teamLight); var lucasPostInIFJ = new PostModel { Id = 813, AssociatedFiles = new List <ContributionFileLightModel>(), Author = lucasLight, Comments = new List <CommentModel>(), Content = "Download documentation on private web.", ContributionUserTags = new List <ContributionUserTagModel>(), CorrespondingTeam = teamLight, Date = new DateTime(2019, 2, 1), Title = "Project has been released!" }; lucasPostInIFJ = FacadeSUT.Create(lucasPostInIFJ) as PostModel; teamIFJ = FacadeSUT.GetDetail(teamLight) as TeamModel; //Act var allPosts = FacadeSUT.GetAllPostsInTeam(teamIFJ).ToList(); //Assert Assert.Contains(allPosts, model => model.Id == lucasPostInIFJ.Id); }
public void findAllNonMemebrs_UserIsNotMember_UserIsInNonmembersList() { //Arrange ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 670, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; var lightPic = new ProfileImageLightModel { Id = imageToUserJames.Id }; imageToUserJames = FacadeSUT.Create(imageToUserJames) as ProfileImageModel; UserModel userModel = new UserModel { Id = 671, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = new ProfileImageLightModel { Id = imageToUserJames.Id }, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; userModel = FacadeSUT.Create(userModel) as UserModel; var userLight = new UserLightModel { Id = userModel.Id }; var teamModel = new TeamModel { Id = 672, Name = "Team1", Description = "First team", Admin = new UserLightModel(), Members = new List <UserTeamMemberModel>(), Posts = new List <PostLightModel>() }; teamModel = FacadeSUT.Create(teamModel) as TeamModel; var teamLight = new TeamLightModel { Id = teamModel.Id }; //Act var allNonUsers = FacadeSUT.GetAllNonMembers(teamLight); //Assert Assert.Contains(allNonUsers, model => model.Id == userModel.Id); }
public void JoinUserToTeam_UserAndTeamExist_UserIsTeamMember() { ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 620, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; var lightPic = new ProfileImageLightModel { Id = 620 }; imageToUserJames = FacadeSUT.Create(imageToUserJames) as ProfileImageModel; UserModel userModel = new UserModel { Id = 621, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = new ProfileImageLightModel { Id = imageToUserJames.Id }, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; userModel = FacadeSUT.Create(userModel) as UserModel; var userLight = new UserLightModel { Id = userModel.Id }; var teamModel = new TeamModel { Id = 622, Name = "Team1", Description = "First team", Admin = new UserLightModel(), Members = new List <UserTeamMemberModel>(), Posts = new List <PostLightModel>() }; teamModel = FacadeSUT.Create(teamModel) as TeamModel; var teamLight = new TeamLightModel { Id = teamModel.Id }; //Act FacadeSUT.JoinUserToTeam(userLight, teamLight); //Assert var teamsMembers = FacadeSUT.GetAllMembers(teamLight).ToList(); Assert.Contains(teamsMembers, member => member.Id == userLight.Id); FacadeSUT.DeleteUserFromTeam(userLight, teamLight); }
public void FindMyTeam_UserInTeams_IsInTeams() { //Arrange ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 660, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; imageToUserJames = FacadeSUT.Create(imageToUserJames) as ProfileImageModel; var lightPic = new ProfileImageLightModel { Id = imageToUserJames.Id }; UserModel userModel = new UserModel { Id = 661, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = new ProfileImageLightModel { Id = imageToUserJames.Id }, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; userModel = FacadeSUT.Create(userModel) as UserModel; var userLight = new UserLightModel { Id = userModel.Id }; var teamModel = new TeamModel { Id = 662, Name = "Team1", Description = "First team", Admin = new UserLightModel(), Members = new List <UserTeamMemberModel>(), Posts = new List <PostLightModel>() }; teamModel = FacadeSUT.Create(teamModel) as TeamModel; var teamLight = new TeamLightModel { Id = teamModel.Id }; //Act FacadeSUT.JoinUserToTeam(userLight, teamLight); //Act var teams = FacadeSUT.FindMyTeams(userLight).ToList(); //Assert var teamsCount = teams.Count; Assert.Equal(1, teamsCount); }