public void ShouldRegisterUserIfNonExistingEmailAddress()
        {
            user newUser = new user();

            newUser.Email    = "*****@*****.**";
            newUser.Password = "******";
            newUser.Name     = "name";

            EmailAddress = newUser.Email;
            Password     = newUser.Password;
            Name         = newUser.Name;

            user existingUser = new user();

            existingUser.Name     = "myFakeName";
            existingUser.Password = "******";
            existingUser.Email    = "*****@*****.**";

            List <user> listOfUsers = new List <user>();

            listOfUsers.Add(existingUser);

            serviceClient.Setup(s => s.GetExistingUsers()).Returns(listOfUsers.ToArray());
            serviceClient.Setup(s => s.SaveUser(newUser)).Returns(1);
            serviceClient.Setup(s => s.SaveUserRole(It.IsAny <userrole>())).Verifiable();

            viewModel.ExecuteRegisterUserCommand();

            serviceClient.Verify(s => s.GetExistingUsers(), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUser(newUser), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserRole(It.IsAny <userrole>()), Times.Exactly(1));
        }
        public void ShouldRegisterUserIfNonExistingEmailAddress()
        {
            #region Setup
            user newUser = new user();
            newUser.Email    = "*****@*****.**";
            newUser.Password = "******";
            newUser.Name     = "name";

            EmailAddress = newUser.Email;
            Password     = newUser.Password;
            Name         = newUser.Name;

            user existingUser = new user();
            existingUser.Name     = "myFakeName";
            existingUser.Password = "******";
            existingUser.Email    = "*****@*****.**";

            List <user> listOfUsers = new List <user>();
            listOfUsers.Add(existingUser);

            List <companydetail> listOfCompanies = new List <companydetail>();

            companydetail fakeCompany = new companydetail();
            fakeCompany.CompanyName     = "Fake company";
            fakeCompany.CompanyPassword = "******";
            fakeCompany.UserId          = 1;
            fakeCompany.CompanyId       = 1;

            listOfCompanies.Add(fakeCompany);

            CompanyName     = "Company Name";
            CompanyPassword = fakeCompany.CompanyPassword;

            securityquestion question = new securityquestion();
            question.SecurityQuestionId = 1;
            CurrentSecurityQuestion     = question;
            SecurityAnswer = "answer";

            long id = 1;
            #endregion

            serviceClient.Setup(s => s.GetExistingUsersAsync()).Returns(Task.FromResult(listOfUsers.ToArray()));
            serviceClient.Setup(s => s.SaveUserAsync(It.IsAny <user>())).Returns(Task.FromResult(id));
            serviceClient.Setup(s => s.saveCompanyAsync(It.IsAny <companydetail>())).Returns(Task.FromResult(""));
            serviceClient.Setup(s => s.SaveUserRoleAsync(It.IsAny <userrole>())).Returns(Task.FromResult(""));
            serviceClient.Setup(s => s.getExistingCompaniesAsync()).Returns(Task.FromResult(listOfCompanies.ToArray()));
            serviceClient.Setup(s => s.SaveUserSecurityQuestionAsync(It.IsAny <usersecurityquestion>())).Returns(Task.FromResult(""));

            viewModel.ExecuteRegisterUserCommand();

            serviceClient.Verify(s => s.GetExistingUsersAsync(), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserRoleAsync(It.IsAny <userrole>()), Times.Exactly(1));
            serviceClient.Verify(s => s.getExistingCompaniesAsync(), Times.Exactly(1));
            serviceClient.Verify(s => s.saveCompanyAsync(It.IsAny <companydetail>()), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserSecurityQuestionAsync(It.IsAny <usersecurityquestion>()), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserAsync(It.IsAny <user>()), Times.Exactly(1));
        }