Esempio n. 1
0
        public async Task <Value <Profile_OLD> > Get(DTO.ProfileRequest dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto");
            }

            long requestedUserId = long.Parse(dto.UserId ?? throw new ArgumentNullException("dto.UserId"));

            if (requestedUserId < 0)
            {
                throw new ArgumentOutOfRangeException("requestedUserId");
            }

            Profile_OLD profile = await this.profileRepository.GetProfileAsync(requestedUserId);

            if (profile == null)
            {
                return(new Value <Profile_OLD>((int)ValueType.ProfileNotExists));
            }

            long?ownUserId = this.GetUserIdFromRequest();

            if (!ownUserId.HasValue || (ownUserId.HasValue && ownUserId.Value != requestedUserId))
            {
                RemovePrivateFieldsFrom(profile);
            }

            return(new Value <Profile_OLD>((int)ValueType.Success)
            {
                Payload = profile
            });
        }
Esempio n. 2
0
        public void SetUp()
        {
            this.ownUserId     = 1;
            this.validUserId   = 2;
            this.invalidUserId = 3;

            this.validProfileInfo   = new[] { new ProfileEntry() }.ToList();
            this.invalidProfileInfo = new[] { new ProfileEntry() }.ToList();

            this.validProfile = new Profile_OLD
            {
                ProfileInfo = new[] { new ProfileEntry() }.ToList()
            };

            this.mockProfileInfoValidator = new Mock <IProfileInfoValidator_OLD>();
            this.mockProfileInfoValidator.Setup(c => c.ValidateAsync(It.Is <List <ProfileEntry> >(v => v != this.validProfileInfo))).ReturnsAsync(false);
            this.mockProfileInfoValidator.Setup(c => c.ValidateAsync(this.validProfileInfo)).ReturnsAsync(true);

            this.mockProfileRepository = new Mock <IProfileRepository_OLD>();
            this.mockProfileRepository.Setup(c => c.GetProfileAsync(this.validUserId)).ReturnsAsync(this.validProfile);
            this.mockProfileRepository.Setup(c => c.GetProfileAsync(this.invalidUserId)).ReturnsAsync((Profile_OLD)null);
            this.mockProfileRepository.Setup(c => c.SetProfileInfoAsync(this.validUserId, this.validProfileInfo)).ReturnsAsync(true);
            this.mockProfileRepository.Setup(c => c.SetProfileInfoAsync(this.invalidUserId, this.validProfileInfo)).ReturnsAsync(false);

            this.subject = new ProfileController(this.mockProfileInfoValidator.Object, this.mockProfileRepository.Object);
        }
Esempio n. 3
0
 private static void RemovePrivateFieldsFrom(Profile_OLD profile)
 {
     profile.ProfileInfo = profile.ProfileInfo.Where(v => v.IsPublic).ToList();
 }