示例#1
0
        public async Task Post_ForgotPassword_Should_Return_Ok_TokenModel()
        {
            //Arrange
            var forgotPasswordUser = new ForgotPasswordUserModel
            {
                Email    = "*****@*****.**",
                Id       = "1",
                Password = "******"
            };

            var message = new IdentityMessage
            {
                Body        = "Reset pasword at test.com",
                Destination = "*****@*****.**",
                Subject     = "Password reset"
            };

            //Action
            GenerateData("1", new[] { "NoRoles" });
            RegisterController registerController = new RegisterController(userService.Object,
                                                                           tokenValidation.Object,
                                                                           incUserMapper.Object,
                                                                           mesService.Object);
            var    tokenModel  = new TokenModel();
            string locationUrl = "http://location/";

            urlHelper.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>()))
            .Returns(locationUrl);
            registerController.Url = urlHelper.Object;

            mesService
            .Setup(x => x.SendAsync(message))
            .Returns(Task.FromResult(0));

            userService.Setup(x => x.CheckUserEmail(forgotPasswordUser))
            .Returns(true);

            tokenValidation.Setup(x => x.GetHashSha256("asdf"))
            .Returns("fdsa");

            var actual = await registerController.ForgotPassword(forgotPasswordUser) as OkNegotiatedContentResult <TokenModel>;

            var contentResult = actual as OkNegotiatedContentResult <TokenModel>;

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.Content.GetType(), tokenModel.GetType());
        }