Example #1
0
        public async Task ShouldCreateUser()
        {
            CreateUserRequestModel model = new CreateUserRequestModel()
            {
                Email = "*****@*****.**", Name = "user name", Password = "******"
            };

            _userRepositoryMock.GetByEmail(Arg.Any <string>()).Returns(null as User);
            _fileUploadUtilsMock.GetDefaultUserProfileImage().Returns(new MemoryStream());
            _fileUploadUtilsMock.UploadImage(Arg.Any <Stream>()).Returns(new FileDTO()
            {
                FileName = "FILENAME", FilePath = "FILEPATH"
            });

            Exception exception = await Record.ExceptionAsync(() => _userService.Create(model));

            Assert.Null(exception);

            _randomCodeUtils.Received(1).GenerateRandomCode();
            _hashUtilsMock.Received(1).GenerateHash(Arg.Is <string>(text => text == model.Password));
            await _fileUploadUtilsMock.Received(1).UploadImage(Arg.Any <Stream>());

            await _userRepositoryMock.Received(1).Create(Arg.Is <User>(user => user.Email == model.Email));

            await _userRepositoryMock.Received(1).Save();

            await _emailUtilsMock.Received(1).SendEmail(Arg.Is <string>(email => email == model.Email), Arg.Any <string>(), Arg.Any <string>());
        }
Example #2
0
        public async Task Create(CreateUserRequestModel model)
        {
            await new CreateUserValidator().ValidateRequestModelAndThrow(model);

            User user = new User(model.Name, model.Email, model.Password);

            await ThrowIfUserNameAlreadyExists(user.Name);
            await ThrowIfUserEmailAlreadyExists(user.Email);


            user.UpdateConfirmationCode(_randomCodeUtils.GenerateRandomCode());
            user.UpdatePassword(_hashUtils.GenerateHash(user.Password));

            Stream  userDefaultProfileImage = _fileUploadUtils.GetDefaultUserProfileImage();
            FileDTO uploadedProfileImage    = await _fileUploadUtils.UploadImage(userDefaultProfileImage);

            ProfileImage image = new ProfileImage(uploadedProfileImage.FileName, uploadedProfileImage.FilePath);

            user.AddProfileImage(image);
            await _userRepository.Create(user);

            await _userRepository.Save();

            await _emailUtils.SendEmail(user.Email, "Confirmation", $"Please confirm your account using this code {user.ConfirmationCode}");
        }
Example #3
0
        public async Task ShouldCreateReview()
        {
            CreateOrUpdateReviewRequestModel model = new CreateOrUpdateReviewRequestModel()
            {
                Image = new MemoryStream(),
                Text  = "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ",
                Title = "TITLE",
                Stars = 1
            };

            _fileUploadUtilsMock.UploadImage(Arg.Any <Stream>()).Returns(new FileDTO()
            {
                FileName = "FILENAME", FilePath = "FILEPATH"
            });

            Exception exception = await Record.ExceptionAsync(() => _reviewService.Create(Guid.NewGuid().ToString(), model));

            Assert.Null(exception);
            await _reviewRepositoryMock.Received(1).Create(Arg.Any <Review>());

            await _reviewRepositoryMock.Received(1).Save();
        }
Example #4
0
        private async Task <ReviewImage> UploadImage(Stream image)
        {
            FileDTO uploadedImage = await _fileUploadUtils.UploadImage(image);

            return(new ReviewImage(uploadedImage.FileName, uploadedImage.FilePath));
        }