public void CreateValid()
        {
            var controller = GetController();

            MockUpUrl(controller);
            _userService.Setup(u => u.IsEmailInUse(It.IsAny <string>())).Returns(false);
            _userService.Setup(u => u.IsNameInUse(It.IsAny <string>())).Returns(false);
            var user   = UserServiceTests.GetDummyUser("Diana", "*****@*****.**");
            var signUp = new SignupData {
                Email = "*****@*****.**", IsCoppa = true, IsDaylightSaving = true, IsSubscribed = true, IsTos = true, Name = "Diana", Password = "******", PasswordRetype = "passwerd", TimeZone = -5
            };

            _userService.Setup(u => u.CreateUser(signUp, It.IsAny <string>())).Returns(user);
            _newAccountMailer.Setup(n => n.Send(It.IsAny <User>(), It.IsAny <string>())).Returns(System.Net.Mail.SmtpStatusCode.CommandNotImplemented);
            var settings = new Settings {
                IsNewUserApproved = true
            };

            _settingsManager.Setup(s => s.Current).Returns(settings);
            var authManager = new Mock <IAuthenticationManager>();

            _owinContext.Setup(x => x.Authentication).Returns(authManager.Object);
            var authResult = Task.FromResult <ExternalAuthenticationResult>(null);

            _externalAuth.Setup(x => x.GetAuthenticationResult(It.IsAny <IAuthenticationManager>())).Returns(authResult);

            var result = controller.Create(signUp).Result;

            Assert.IsTrue(controller.ModelState.IsValid);
            Assert.AreEqual("AccountCreated", result.ViewName);
            Assert.IsTrue(result.ViewData["EmailProblem"].ToString().Contains(System.Net.Mail.SmtpStatusCode.CommandNotImplemented.ToString()));
            _userService.Verify(u => u.CreateUser(signUp, It.IsAny <string>()), Times.Once());
            _profileService.Verify(p => p.Create(user, signUp), Times.Once());
            _newAccountMailer.Verify(n => n.Send(user, It.IsAny <string>()), Times.Once());
        }
        public void CreateValidNotCallExternalAuthAssociateWithoutAuthResult()
        {
            var controller = GetController();

            MockUpUrl(controller);
            _userService.Setup(u => u.IsEmailInUse(It.IsAny <string>())).Returns(false);
            _userService.Setup(u => u.IsNameInUse(It.IsAny <string>())).Returns(false);
            var user   = UserServiceTests.GetDummyUser("Diana", "*****@*****.**");
            var signUp = new SignupData {
                Email = "*****@*****.**", IsCoppa = true, IsDaylightSaving = true, IsSubscribed = true, IsTos = true, Name = "Diana", Password = "******", PasswordRetype = "passwerd", TimeZone = -5
            };

            _userService.Setup(u => u.CreateUser(signUp, It.IsAny <string>())).Returns(user);
            _newAccountMailer.Setup(n => n.Send(It.IsAny <User>(), It.IsAny <string>())).Returns(System.Net.Mail.SmtpStatusCode.CommandNotImplemented);
            var settings = new Settings {
                IsNewUserApproved = true
            };

            _settingsManager.Setup(s => s.Current).Returns(settings);
            var authManager = new Mock <IAuthenticationManager>();

            _owinContext.Setup(x => x.Authentication).Returns(authManager.Object);
            var authResult = Task.FromResult <ExternalAuthenticationResult>(null);

            _externalAuth.Setup(x => x.GetAuthenticationResult(authManager.Object)).Returns(authResult);

            var result = controller.Create(signUp).Result;

            _userAssociationManager.Verify(x => x.Associate(user, It.IsAny <ExternalAuthenticationResult>(), It.IsAny <string>()), Times.Never);
        }
Beispiel #3
0
        public void DupeAndTimeCheckNoPreviousPost()
        {
            var postService = GetService();
            var user        = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");

            _profileRepo.Setup(p => p.GetLastPostID(user.UserID)).Returns((int?)null);
            Assert.False(postService.IsNewPostDupeOrInTimeLimit(new NewPost(), user));
        }
Beispiel #4
0
        public void DupeAndTimeCheckIsInTimeLimit()
        {
            var postService = GetService();
            var user        = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");

            _profileRepo.Setup(p => p.GetLastPostID(user.UserID)).Returns(123);
            _postRepo.Setup(p => p.Get(123)).Returns(new Post {
                PostID = 456, PostTime = DateTime.UtcNow.AddSeconds(-15)
            });
            _settings.Setup(s => s.MinimumSecondsBetweenPosts).Returns(20);
            Assert.True(postService.IsNewPostDupeOrInTimeLimit(new NewPost(), user));
        }
Beispiel #5
0
        public async Task GetProfile()
        {
            var service = GetService();
            var profile = new Profile {
                UserID = 123, Location = "Cleveland"
            };
            var user = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");

            _profileRepo.Setup(p => p.GetProfile(user.UserID)).ReturnsAsync(profile);
            var result = await service.GetProfile(user);

            Assert.Equal(profile, result);
            _profileRepo.Verify(p => p.GetProfile(user.UserID), Times.Once());
        }
Beispiel #6
0
        public void DupeAndTimeCheckIsNotInTimeLimitOrDupeText()
        {
            var postService = GetService();
            var user        = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");

            _profileRepo.Setup(p => p.GetLastPostID(user.UserID)).Returns(123);
            _postRepo.Setup(p => p.Get(123)).Returns(new Post(456)
            {
                FullText = "one thing", PostTime = DateTime.UtcNow.AddSeconds(-30)
            });
            _settings.Setup(s => s.MinimumSecondsBetweenPosts).Returns(20);
            Assert.False(postService.IsNewPostDupeOrInTimeLimit(new NewPost {
                FullText = "another"
            }, user));
        }
Beispiel #7
0
        public void GetProfile()
        {
            var service = GetService();
            var profile = new Profile(123)
            {
                Aim = "blah", Location = "Cleveland"
            };
            var user = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");

            _profileRepo.Setup(p => p.GetProfile(user.UserID)).Returns(profile);
            var result = service.GetProfile(user);

            Assert.Equal(profile, result);
            _profileRepo.Verify(p => p.GetProfile(user.UserID), Times.Once());
        }
Beispiel #8
0
        public async Task GetProfileForEditParsesSig()
        {
            var service = GetService();
            var profile = new Profile {
                UserID = 123, Location = "Cleveland", Signature = "blah"
            };
            var user = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");

            _profileRepo.Setup(p => p.GetProfile(user.UserID)).ReturnsAsync(profile);
            _textParsingService.Setup(t => t.ClientHtmlToForumCode("blah")).Returns("parsed");
            var result = await service.GetProfileForEdit(user);

            Assert.Equal("parsed", result.Signature);
            _profileRepo.Verify(p => p.GetProfile(user.UserID), Times.Once());
        }
Beispiel #9
0
        public void DupeAndTimeCheckIsDupeTextRichText()
        {
            var          postService = GetService();
            var          user        = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");
            const string dupeText    = "whatever";

            _profileRepo.Setup(p => p.GetLastPostID(user.UserID)).Returns(123);
            _postRepo.Setup(p => p.Get(123)).Returns(new Post {
                PostID = 456, FullText = dupeText
            });
            _textParsingService.Setup(x => x.ClientHtmlToHtml(dupeText)).Returns(dupeText);
            Assert.True(postService.IsNewPostDupeOrInTimeLimit(new NewPost {
                FullText = dupeText, IsPlainText = false
            }, user));
        }
Beispiel #10
0
        public async Task GetProfileForEditParsesSigGuardForNull()
        {
            var service = GetService();
            var profile = new Profile {
                UserID = 123, Location = "Cleveland", Signature = null
            };
            var user = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");

            _profileRepo.Setup(p => p.GetProfile(user.UserID)).ReturnsAsync(profile);

            var result = await service.GetProfileForEdit(user);

            _textParsingService.Verify(x => x.ClientHtmlToForumCode(It.IsAny <string>()), Times.Never);
            Assert.Equal(string.Empty, result.Signature);
            _profileRepo.Verify(p => p.GetProfile(user.UserID), Times.Once());
        }
Beispiel #11
0
        public void CreateFromUserAndSignupData()
        {
            var service    = GetService();
            var user       = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");
            var signupData = new SignupData {
                TimeZone = -5, IsSubscribed = true, IsTos = true, IsDaylightSaving = true
            };

            _profileRepo.Setup(r => r.Create(It.Is <Profile>(p =>
                                                             p.UserID == user.UserID &&
                                                             p.TimeZone == signupData.TimeZone &&
                                                             p.IsSubscribed == signupData.IsSubscribed &&
                                                             p.IsTos == signupData.IsTos &&
                                                             p.IsDaylightSaving == signupData.IsDaylightSaving))).Verifiable();
            var result = service.Create(user, signupData);

            Assert.Equal(user.UserID, result.UserID);
            Assert.Equal(signupData.IsDaylightSaving, result.IsDaylightSaving);
            Assert.Equal(signupData.IsSubscribed, result.IsSubscribed);
            Assert.Equal(signupData.IsTos, result.IsTos);
            Assert.Equal(signupData.TimeZone, result.TimeZone);
        }