public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ProfileImageLightModel profileImage = value as ProfileImageLightModel;

            byte[] imageData = profileImage.Content;

            if (imageData == null || imageData.Length == 0)
            {
                return(null);
            }
            var image = new BitmapImage();

            using (var mem = new MemoryStream(imageData))
            {
                mem.Position = 0;
                image.BeginInit();
                image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                image.CacheOption   = BitmapCacheOption.OnLoad;
                image.UriSource     = null;
                image.StreamSource  = mem;
                image.EndInit();
            }
            image.Freeze();
            return(image);
        }
Пример #2
0
        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());
        }
Пример #3
0
        public ProfileImage MapProfileImageLightModelToProfileImage(ProfileImageLightModel lightModel)
        {
            if (lightModel == null)
            {
                return(null);
            }

            return(new ProfileImage
            {
                Id = lightModel.Id,
                PictureFormat = lightModel.PictureFormat,
                Content = lightModel.Content
            });
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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 object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            BitmapImage bitmapImage = value as BitmapImage;

            byte[]            data;
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
            using (MemoryStream ms = new MemoryStream())
            {
                encoder.Save(ms);
                data = ms.ToArray();
            }

            var image = new ProfileImageLightModel();

            image.Id            = null;
            image.Content       = data;
            image.PictureFormat = SupportedFormatPicture.Jpg;

            return(image);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }