Пример #1
0
        public async Task Should_Create_New_Account()
        {
            SignUpCommand command = new SignUpCommand
            {
                Email    = "*****@*****.**",
                Name     = "Jubileu antunes",
                Password = "******",
                Picture  = null
            };

            _userReadOnlyRepository
            .Setup(x => x.Any(command.Email))
            .ReturnsAsync(false);

            _accountWriteOnlyRepository
            .Setup(x => x.Create(It.IsAny <Account>()));

            _userWriteOnlyRepository
            .Setup(x => x.Create(It.IsAny <User>()));

            SignUpResult result = await signUpUseCase.Execute(command);

            Assert.NotNull(result);
            Assert.NotEqual(Guid.Empty, result.UserId);
            Assert.NotEqual(Guid.Empty, result.AccountId);
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] SignUpRequest request)
        {
            Picture picture = null;

            if (request.Picture != null)
            {
                picture = Picture.Create(
                    request.Picture.Bytes,
                    request.Picture.Size,
                    request.Picture.Type,
                    request.Picture.Name
                    );
            }
            SignUpCommand command = new SignUpCommand
            {
                Picture  = picture,
                Name     = request.Name,
                Email    = request.Email,
                Password = request.Password
            };

            SignUpResult result = await _useCase.Execute(command);

            return(Created(Request.Path, result));
        }
Пример #3
0
        public void UserManagerTestSignUpResultFalse()
        {
            var result = new SignUpResult(new User {
                Name = "test"
            }, false, new SignUpResultError());

            Assert.IsFalse(result.Success);
        }
Пример #4
0
        public void UserManagerTestSignUpResult()
        {
            var result = new SignUpResult(new User {
                Name = "test"
            });

            Assert.AreEqual("test", result.User.Name);
        }
Пример #5
0
        public string SignUp(string Name, string UserName, string Password)
        {
            SignUpResult result = authenticationService.SignUp(new SignUpRequest()
            {
                UserName = UserName, Password = Password, Deposit = 100
            });

            if (!result.Success.HasValue || !result.Success.Value)
            {
                return(null);
            }
            return(result.UserName);
        }
Пример #6
0
            public async Task Returns_CreatedUser_When_SignUpSuccessful()
            {
                var signUpResult = new SignUpResult {
                    CognitoId = "test-id"
                };

                _cognitoUserManagerMock.Setup(m => m.RegisterAsync(It.IsAny <NewUser>(), It.IsAny <CancellationToken>())).ReturnsAsync(signUpResult);

                var createdUser = await _sut.CreateAsync(new NewUser("test", "test"), CancellationToken.None);

                Assert.NotNull(createdUser.User);
                Assert.Null(createdUser.ErrorMessage);

                _cognitoUserManagerMock.Verify(m => m.RegisterAsync(It.IsAny <NewUser>(), It.IsAny <CancellationToken>()), Times.Once);
            }
Пример #7
0
            public async Task Returns_ErrorCreatedUser_When_SignupResult_HasFailureReason()
            {
                var failedSignUpResult = new SignUpResult {
                    ErrorMessage = "Failed to signup user"
                };

                _cognitoUserManagerMock.Setup(m => m.RegisterAsync(It.IsAny <NewUser>(), It.IsAny <CancellationToken>())).ReturnsAsync(failedSignUpResult);

                var createdUser = await _sut.CreateAsync(new NewUser("test", "test"), CancellationToken.None);

                Assert.Null(createdUser.User);
                Assert.NotNull(createdUser.ErrorMessage);

                _cognitoUserManagerMock.Verify(m => m.RegisterAsync(It.IsAny <NewUser>(), It.IsAny <CancellationToken>()), Times.Once);
            }
Пример #8
0
        public void SetUp()
        {
            var user   = new User();
            var result = new SignUpResult
            {
                TokenCode = Test,
                User      = user
            };
            var emailTemplate = new EmailTemplate
            {
                TemplateName      = Test,
                Subject           = Test,
                Content           = Test,
                AllowedParameters = new[] { "{{username}}", "{{callbackUrl}}" }
            };

            request = new SignUpRequest();

            authService            = new Mock <IAuthService>();
            serialService          = new Mock <ISerialService>();
            userService            = new Mock <IReadOnlyUserService>();
            emailSender            = new Mock <IEmailSender>();
            cryptoService          = new Mock <ICryptoService>();
            emailTemplateGenerator = new Mock <IEmailTemplateGenerator>();
            authValidationService  = new Mock <IAuthValidationService>();
            captchaService         = new Mock <ICaptchaService>();
            mapper        = new Mock <IMapper>();
            configuration = new Mock <IConfiguration>();

            authService.Setup(a => a.SignUp(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(),
                                            It.IsAny <string>(), It.IsAny <int>())).ReturnsAsync(result);
            captchaService.Setup(c => c.VerifyCaptcha(It.IsAny <string>())).ReturnsAsync(true);
            authValidationService.Setup(a => a.UsernameExists(It.IsAny <string>())).ReturnsAsync(false);
            authValidationService.Setup(a => a.EmailExists(It.IsAny <string>())).ReturnsAsync(false);
            serialService.Setup(s => s.SerialExists(It.IsAny <string>(), It.IsAny <int>())).ReturnsAsync(false);
            userService.Setup(u => u.FindUserByUsername(It.IsAny <string>())).ReturnsAsync(user);
            cryptoService.Setup(c => c.Encrypt(It.IsAny <string>())).Returns(Test);
            emailTemplateGenerator.Setup(etg => etg.FindEmailTemplate(It.IsAny <string>()))
            .ReturnsAsync(emailTemplate);
            emailSender.Setup(es => es.Send(It.IsAny <EmailMessage>()))
            .ReturnsAsync(true);
            configuration.Setup(c => c.GetSection(It.IsAny <string>()))
            .Returns(new Mock <IConfigurationSection>().Object);

            signUpCommand = new SignUpCommand(authService.Object, serialService.Object, userService.Object,
                                              emailSender.Object, cryptoService.Object, emailTemplateGenerator.Object, authValidationService.Object,
                                              captchaService.Object, configuration.Object, mapper.Object);
        }
        public HttpResponseMessage SignUp(SignUpRequest request)
        {
            var result = new SignUpResult();

            try
            {
                result = service.SignUp(request);
            }
            catch (Exception e)
            {
                result.ErrorMessage = e.Message;
                result.Success      = false;
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, result));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Пример #10
0
        public SignUpResult SignUp(SignUpRequest request)
        {
            var result = new SignUpResult();

            try
            {
                User user = UserManager.AddUser(request.UserName, request.Password, request.Deposit);
                result.UserName = user.UserName;
                Users.Add(user.UserName, user);
                result.Success = true;
            }
            catch (PokerException e)
            {
                result.Success      = false;
                result.ErrorMessage = e.Message;
                Logger.Error(e, this);
            }
            return(result);
        }
Пример #11
0
        public static Task <SignUpResult> Show(Window parent)
        {
            var title  = "Create Account";
            var msgbox = new SignUpWindow
            {
                Title = title
            };
            var buttonPanel = msgbox.FindControl <StackPanel>("Buttons");

            SignUpResult res = new SignUpResult();

            void AddButton(string caption)
            {
                var btn = new Button {
                    Content = caption
                };

                btn.Click += (_, __) =>
                {
                    var nickName     = msgbox.FindControl <TextBox>("tbNickName").Text;
                    var passwordHash = msgbox.FindControl <TextBox>("tbPassword").Text;
                    var email        = msgbox.FindControl <TextBox>("tbEmail").Text;
                    var firstName    = msgbox.FindControl <TextBox>("tbFirstName").Text;
                    var lastName     = msgbox.FindControl <TextBox>("tbLastName").Text;
                    if (string.IsNullOrWhiteSpace(nickName))
                    {
                        ShowError("Incorrect Nick name");
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(passwordHash) || passwordHash.Length < 6)
                    {
                        ShowError("Incorrect Password");
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(firstName))
                    {
                        ShowError("Incorrect First name");
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(lastName))
                    {
                        ShowError("Incorrect Last name");
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(email) || !email.Contains('@') || !email.Contains('.'))
                    {
                        ShowError("Incorrect Email");
                        return;
                    }

                    PasswordHasher hasher = new PasswordHasher();
                    passwordHash = hasher.GenerateIdentityV3Hash(passwordHash);

                    res = new SignUpResult
                    {
                        Email        = email,
                        PasswordHash = passwordHash,
                        Id           = 1,
                        Time         = DateTime.Now.ToString()
                    };

                    var path = AppDomain.CurrentDomain.BaseDirectory + "user_info";
                    if (File.Exists(path))
                    {
                        ShowInfo("You already signed up. Please log in.");
                        msgbox.Close();
                        return;
                    }

                    res.IsSignIn = true;

                    File.AppendAllText(
                        path,
                        JsonConvert.SerializeObject(res));
                    msgbox.Close();
                };
                buttonPanel.Children.Add(btn);
            }

            AddButton("Sign Up");
            var tcs = new TaskCompletionSource <SignUpResult>();

            msgbox.Closed += delegate { tcs.TrySetResult(res); };
            if (parent != null)
            {
                msgbox.ShowDialog(parent);
            }
            else
            {
                msgbox.Show();
            }
            return(tcs.Task);
        }
Пример #12
0
        public void UserManagerTestSignUpResultError()
        {
            var result = new SignUpResult(null, false, new SignUpResultError());

            Assert.AreEqual(new SignUpResultError(), result.Error);
        }
Пример #13
0
        public async Task <SignUpResult> SingUp(SignUpModel signUpModel)
        {
            SignUpResult result = await signUpService.SignUp(ModelConverter.ToUserModel(signUpModel));

            return(result);
        }