コード例 #1
0
        public async Task NoArgumentsWillWriteOutMessage()
        {
            var writer      = new MockTextWriter();
            var deliverable = new UserDeliverable(null, writer, null);

            await deliverable.Run("user", new string[0]);

            Assert.Equal(writer.Messages.Count(), 1);
        }
コード例 #2
0
        public async Task ChangeUserNameWillFailIfExpectedArgumentsAreNotProvided()
        {
            var writer      = new MockTextWriter();
            var deliverable = new UserDeliverable(null, writer, null);

            await deliverable.Run("user", new[] { "change-loginname" });

            Assert.Equal(writer.Messages.Count(), 2);
        }
コード例 #3
0
        public async Task NonNumericalUserIdWillCauseAnError()
        {
            var writer      = new MockTextWriter();
            var deliverable = new UserDeliverable(null, writer, null);

            await deliverable.Run("user", new[] { "change-password", "a", "a", "a" });

            Assert.That(writer.Messages.Count(), Is.EqualTo(1));
        }
コード例 #4
0
        public async Task ChangePasswordWillFailIfExpectedArgumentsAreNotProvided()
        {
            var writer      = new MockTextWriter();
            var deliverable = new UserDeliverable(null, writer, null);

            await deliverable.Run("user", new[] { "change-password" });

            Assert.That(writer.Messages.Count(), Is.EqualTo(2));
        }
コード例 #5
0
        public async Task UserIdForChangeUserNameNotMatchingAnyWillCauseAnError()
        {
            var writer      = new MockTextWriter();
            var userService = Substitute.For <IUserService>();

            userService.GetByUsername(Arg.Any <string>()).Returns((IUser)null);

            var deliverable = new UserDeliverable(null, writer, userService);

            await deliverable.Run("user", new[] { "change-loginname", "0", "c" });

            Assert.Equal(writer.Messages.Count(), 1);
            userService.Received(1).GetByUsername(Arg.Any <string>());
        }
コード例 #6
0
        public async Task UserIdNotMatchingAnyWillCauseAnError()
        {
            var writer   = new MockTextWriter();
            var provider = Substitute.For <UmbracoMembershipProviderBase>();

            provider.GetUser(Arg.Any <int>(), false).Returns((MembershipUser)null);

            var deliverable = new UserDeliverable(null, writer, provider);

            await deliverable.Run("user", new[] { "change-password", "0", "a", "a" });

            Assert.That(writer.Messages.Count(), Is.EqualTo(1));
            provider.Received(1).GetUser(Arg.Any <int>(), false);
        }
コード例 #7
0
        public async Task UserIdNotMatchingAnyWillCauseAnError()
        {
            var writer      = new MockTextWriter();
            var userService = Substitute.For <IUserService>();

            userService.GetByUsername(Arg.Any <string>()).Returns((IUser)null);

            var deliverable = new UserDeliverable(null, writer, userService, null);

            await deliverable.Run("user", new[] { "change-password", "0", "a" });

            Assert.Single(writer.Messages);
            userService.Received(1).GetByUsername(Arg.Any <string>());
        }
コード例 #8
0
        public async Task ValidUserWillHaveTheirPasswordUpdated()
        {
            var writer      = new MockTextWriter();
            var userService = Substitute.For <IUserService>();
            var user        = Substitute.For <IUser>();

            userService.GetByUsername(Arg.Any <string>()).Returns(user);

            var deliverable = new UserDeliverable(null, writer, userService);

            await deliverable.Run("user", new[] { "change-password", "0", "ab" });

            Assert.Equal(writer.Messages.Count(), 1);
            userService.Received(1).SavePassword(user, "ab");
        }
コード例 #9
0
        public async Task ValidUserWillHaveTheirPasswordUpdated()
        {
            var writer   = new MockTextWriter();
            var provider = Substitute.For <UmbracoMembershipProviderBase>();
            var user     = Substitute.For <MembershipUser>();

            user.ChangePassword("a", "ab").Returns(true);
            provider.GetUser(Arg.Any <int>(), false).Returns(user);

            var deliverable = new UserDeliverable(null, writer, provider);

            await deliverable.Run("user", new[] { "change-password", "0", "a", "ab" });

            Assert.That(writer.Messages.Count(), Is.EqualTo(1));
            user.Received(1).ChangePassword("a", "ab");
        }
コード例 #10
0
        public async Task ValidUserWillHaveTheirNameUpdated()
        {
            var writer      = new MockTextWriter();
            var userService = Substitute.For <IUserService>();
            var user        = Substitute.For <IUser>();

            user.Name = "a";
            userService.GetByUsername("a").Returns(user);

            var deliverable = new UserDeliverable(null, writer, userService);

            await deliverable.Run("user", new[] { "change-name", "a", "ab" });

            Assert.Equal(writer.Messages.Count(), 1);
            Assert.Equal("ab", user.Name);
            userService.Received(1).Save(user);
        }