Ejemplo n.º 1
0
        private Mock <IUserManager> GetMockUserManager()
        {
            Mock <IUserManager> mock = new Mock <IUserManager>();

            mock.Setup(e => e.GetUserByEmail(It.IsAny <string>()))
            .ReturnsAsync((string target) =>
            {
                User user = null;
                if (target == "*****@*****.**")
                {
                    user = new User()
                    {
                        Name     = "test user",
                        Email    = "*****@*****.**",
                        Password = UserExtension.GetEncryptedPassword("abcd"),
                    };
                }
                return(user);
            });

            mock.Setup(e => e.InsertUser(It.IsAny <User>()))
            .ReturnsAsync((User target) =>
            {
                if (target.Email == "*****@*****.**")
                {
                    return(true);
                }
                return(false);
            });

            mock.Setup(e => e.GetUser(It.IsAny <string>()))
            .ReturnsAsync((string target) =>
            {
                if (target == "1")
                {
                    return(new User()
                    {
                        Id = "1",
                        Email = "test",
                        Name = "test user",
                    });
                }

                if (target == "0")
                {
                    return(new User()
                    {
                        Id = "0",
                        Email = "test",
                        Name = "test user",
                    });
                }

                return(null);
            });
            mock.Setup(e => e.UpdateUser(It.IsAny <string>(), It.IsAny <User>()))
            .ReturnsAsync((string targetId, User target) =>
            {
                if (targetId == "1")
                {
                    return(true);
                }

                return(false);
            });

            return(mock);
        }