예제 #1
0
        /// <summary>
        /// 发送忘记密码验证码
        /// </summary>
        /// <param name="mail"></param>
        /// <returns></returns>
        public Result SendForgetVerificationCode(string mail)
        {
            Result result = new Result()
            {
                Status     = true,
                Message    = "发送邮件成功",
                StatusCode = "SR000"
            };

            try
            {
                //生成code码加入缓存 设置时效日期
                if (!string.IsNullOrEmpty(mail))
                {
                    string code = VerificationUtils.GetVefication();

                    CookieUtils.SetCookie(string.Format("forget{0}", mail), code, DateTime.Now.AddMinutes(30));


                    SendMailInfo sendinfo = new SendMailInfo();

                    using (StreamReader sr = File.OpenText(AppDomain.CurrentDomain.BaseDirectory + "ForgetVerificationMail.html"))
                    {
                        sendinfo.Content = sr.ReadToEnd();
                    }
                    sendinfo.Title = string.Format("你此次重置密码的验证码是:{0}", code);
                    if (!string.IsNullOrEmpty(sendinfo.Content))
                    {
                        sendinfo.Content = sendinfo.Content.Replace("(手机)", mail);
                        sendinfo.Content = sendinfo.Content.Replace("(验证码)", code);
                    }

                    VerifiedMail.Sender.AddSend(sendinfo, new List <string>()
                    {
                        "*****@*****.**"
                    });
                }
            }
            catch (Exception ex)
            {
                result.Status     = false;
                result.Message    = string.Format("忘记密码邮件验证出错 /r/n{0}", ex.Message);
                result.StatusCode = "EX000";
                LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:SendForgetVerificationCode() .AccountService"), LogType.ErrorLog);
            }

            return(result);
        }
예제 #2
0
 private static void VerifySyntaxTreesAreEqualImpl(SyntacticTree expected, SyntacticTree actual, AssertionHandler assert)
 {
     VerifyStringsAreEqual(expected.Path, actual.Path, assert);
     VerifyQueryTokensAreEqual(expected.Filter, actual.Filter, assert);
     if (expected.OrderByTokens != null && actual.OrderByTokens != null)
     {
         VerifyQueryTokensAreEqual(expected.OrderByTokens.Cast <QueryToken>(), actual.OrderByTokens.Cast <QueryToken>(), assert);
     }
     else if ((expected.OrderByTokens != null && actual.OrderByTokens == null) || (expected.OrderByTokens == null && actual.OrderByTokens != null))
     {
         assert.Fail("Query tokens are different");
     }
     assert.AreEqual(expected.Skip, actual.Skip, "Skip values are different.");
     VerificationUtils.VerifyEnumerationsAreEqual(
         expected.QueryOptions,
         actual.QueryOptions,
         VerifyCustomQueryOptionQueryTokensAreEqual,
         (item) => item.ToDebugString(),
         assert);
 }
예제 #3
0
        private static void RunHeaderTest(
            Func <IEnumerable <KeyValuePair <string, string> > > getHeadersFunc,
            bool writing,
            Func <string, string> getHeaderFunc,
            Action <string, string> setHeaderAction,
            AssertionHandler assert,
            IExceptionVerifier exceptionVerifier)
        {
            assert.IsNotNull(getHeadersFunc(), "Non-null headers expected.");
            assert.AreEqual(0, getHeadersFunc().Count(), "Empty header collection expected.");
            assert.IsNull(getHeaderFunc("a"), "Unexpectedly found header.");

            ExpectedException expectedException = writing ? null : ODataExpectedExceptions.ODataException("ODataMessage_MustNotModifyMessage");

            TestExceptionUtils.ExpectedException(
                assert,
                () =>
            {
                setHeaderAction("a", "b");

                assert.AreEqual(1, getHeadersFunc().Count(), "One header expected.");
                assert.AreEqual("b", getHeaderFunc("a"), "Header not found or invalid header value.");
                List <KeyValuePair <string, string> > expectedHeaders = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("a", "b")
                };
                VerificationUtils.VerifyEnumerationsAreEqual(
                    expectedHeaders,
                    getHeadersFunc(),
                    (first, second, assert2) => assert2.AreEqual(first, second, "Items differ."),
                    (item) => item.Key + " = " + item.Value,
                    assert);

                setHeaderAction("a", "c");

                assert.AreEqual(1, getHeadersFunc().Count(), "One header expected.");
                assert.AreEqual("c", getHeaderFunc("a"), "Header not found or invalid header value.");
                expectedHeaders[0] = new KeyValuePair <string, string>("a", "c");
                VerificationUtils.VerifyEnumerationsAreEqual(
                    expectedHeaders,
                    getHeadersFunc(),
                    (first, second, assert2) => assert2.AreEqual(first, second, "Items differ."),
                    (item) => item.Key + " = " + item.Value,
                    assert);

                setHeaderAction("d", "e");

                assert.AreEqual(2, getHeadersFunc().Count(), "Two headers expected.");
                assert.AreEqual("c", getHeaderFunc("a"), "Header not found or invalid header value.");
                assert.AreEqual("e", getHeaderFunc("d"), "Header not found or invalid header value.");
                expectedHeaders.Add(new KeyValuePair <string, string>("d", "e"));
                VerificationUtils.VerifyEnumerationsAreEqual(
                    expectedHeaders,
                    getHeadersFunc(),
                    (first, second, assert2) => assert2.AreEqual(first, second, "Items differ."),
                    (item) => item.Key + " = " + item.Value,
                    assert);

                setHeaderAction("d", null);
                setHeaderAction("a", null);

                assert.AreEqual(0, getHeadersFunc().Count(), "Empty header collection expected.");
                assert.IsNull(getHeaderFunc("a"), "Unexpectedly found header.");
            },
                expectedException,
                exceptionVerifier);
        }
        public void ColumnCombinationsTest()
        {
            int[] rowOneToFour     = new int[] { 1, 2, 3, 4 };
            int[] rowFiveToSeven   = new int[] { 5, 6, 7 };
            int[] rowEightToNine   = new int[] { 8, 9 };
            int[] rowTenToFourteen = new int[] { 10, 11, 12, 13, 14 };

            var testCases = new[]
            {
                new
                {
                    Items = new int[0][],
                    ExpectedCombinations = new int[][]
                    {
                        new int[] { },
                    }
                },
                new
                {
                    Items = new int[][]
                    {
                        rowOneToFour,
                        rowFiveToSeven
                    },
                    ExpectedCombinations = new int[][]
                    {
                        new int[] { },
                        new int[] { 1 },
                        new int[] { 5 },
                        new int[] { 1, 5 },
                        new int[] { 2 },
                        new int[] { 6 },
                        new int[] { 2, 6 },
                        new int[] { 3 },
                        new int[] { 7 },
                        new int[] { 3, 7 },
                        new int[] { 4 },
                    }
                },
                new
                {
                    Items = new int[][]
                    {
                        rowOneToFour,
                        rowFiveToSeven,
                        rowEightToNine,
                        rowTenToFourteen
                    },
                    ExpectedCombinations = new int[][]
                    {
                        new int[] { },
                        new int[] { 1 },
                        new int[] { 5 },
                        new int[] { 8 },
                        new int[] { 10 },
                        new int[] { 1, 5 },
                        new int[] { 1, 8 },
                        new int[] { 1, 10 },
                        new int[] { 5, 8 },
                        new int[] { 5, 10 },
                        new int[] { 8, 10 },
                        new int[] { 1, 5, 8 },
                        new int[] { 1, 5, 10 },
                        new int[] { 1, 8, 10 },
                        new int[] { 5, 8, 10 },
                        new int[] { 1, 5, 8, 10 },
                        new int[] { 2 },
                        new int[] { 6 },
                        new int[] { 9 },
                        new int[] { 11 },
                        new int[] { 2, 6 },
                        new int[] { 2, 9 },
                        new int[] { 2, 11 },
                        new int[] { 6, 9 },
                        new int[] { 6, 11 },
                        new int[] { 9, 11 },
                        new int[] { 2, 6, 9 },
                        new int[] { 2, 6, 11 },
                        new int[] { 2, 9, 11 },
                        new int[] { 6, 9, 11 },
                        new int[] { 2, 6, 9, 11 },
                        new int[] { 3 },
                        new int[] { 7 },
                        new int[] { 12 },
                        new int[] { 3, 7 },
                        new int[] { 3, 12 },
                        new int[] { 7, 12 },
                        new int[] { 3, 7, 12 },
                        new int[] { 4 },
                        new int[] { 13 },
                        new int[] { 4, 13 },
                        new int[] { 14 },
                    }
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
            {
                int[][] results = testCase.Items.ColumnCombinations().ToArray();

                this.Assert.IsNotNull(results, "results != null");
                this.Assert.AreEqual(testCase.ExpectedCombinations.Length, results.Length, "Did not find expected number of column combinations.");

                for (int i = 0; i < results.Length; ++i)
                {
                    VerificationUtils.VerifyEnumerationsAreEqual(testCase.ExpectedCombinations[i], results[i], this.Assert);
                }
            });
        }
        public void VariationsTest()
        {
            int[] items = new int[] { 1, 2, 3, 4 };

            var testCases = new[]
            {
                new
                {
                    Items   = items,
                    Lengths = new int[] { 0 },
                    ExpectedCombinations = new int[][]
                    {
                        new int[0],
                    }
                },
                new
                {
                    Items   = items,
                    Lengths = new int[] { 1 },
                    ExpectedCombinations = new int[][]
                    {
                        new int[] { 1 },
                        new int[] { 2 },
                        new int[] { 3 },
                        new int[] { 4 },
                    }
                },
                new
                {
                    Items   = items,
                    Lengths = new int[] { 3 },
                    ExpectedCombinations = new int[][]
                    {
                        new int[] { 1, 2, 3 },
                        new int[] { 1, 2, 4 },
                        new int[] { 1, 3, 2 },
                        new int[] { 1, 3, 4 },
                        new int[] { 1, 4, 2 },
                        new int[] { 1, 4, 3 },
                        new int[] { 2, 1, 3 },
                        new int[] { 2, 1, 4 },
                        new int[] { 2, 3, 1 },
                        new int[] { 2, 3, 4 },
                        new int[] { 2, 4, 1 },
                        new int[] { 2, 4, 3 },
                        new int[] { 3, 1, 2 },
                        new int[] { 3, 1, 4 },
                        new int[] { 3, 2, 1 },
                        new int[] { 3, 2, 4 },
                        new int[] { 3, 4, 1 },
                        new int[] { 3, 4, 2 },
                        new int[] { 4, 1, 2 },
                        new int[] { 4, 1, 3 },
                        new int[] { 4, 2, 1 },
                        new int[] { 4, 2, 3 },
                        new int[] { 4, 3, 1 },
                        new int[] { 4, 3, 2 },
                    }
                },
                new
                {
                    Items   = items,
                    Lengths = new int[] { 0, 1, 3 },
                    ExpectedCombinations = new int[][]
                    {
                        new int[0],
                        new int[] { 1 },
                        new int[] { 2 },
                        new int[] { 3 },
                        new int[] { 4 },
                        new int[] { 1, 2, 3 },
                        new int[] { 1, 2, 4 },
                        new int[] { 1, 3, 2 },
                        new int[] { 1, 3, 4 },
                        new int[] { 1, 4, 2 },
                        new int[] { 1, 4, 3 },
                        new int[] { 2, 1, 3 },
                        new int[] { 2, 1, 4 },
                        new int[] { 2, 3, 1 },
                        new int[] { 2, 3, 4 },
                        new int[] { 2, 4, 1 },
                        new int[] { 2, 4, 3 },
                        new int[] { 3, 1, 2 },
                        new int[] { 3, 1, 4 },
                        new int[] { 3, 2, 1 },
                        new int[] { 3, 2, 4 },
                        new int[] { 3, 4, 1 },
                        new int[] { 3, 4, 2 },
                        new int[] { 4, 1, 2 },
                        new int[] { 4, 1, 3 },
                        new int[] { 4, 2, 1 },
                        new int[] { 4, 2, 3 },
                        new int[] { 4, 3, 1 },
                        new int[] { 4, 3, 2 },
                    }
                },
                new
                {
                    Items   = items,
                    Lengths = new int[] { 4 },
                    ExpectedCombinations = new int[][]
                    {
                        new int[] { 1, 2, 3, 4 },
                        new int[] { 1, 2, 4, 3 },
                        new int[] { 1, 3, 2, 4 },
                        new int[] { 1, 3, 4, 2 },
                        new int[] { 1, 4, 2, 3 },
                        new int[] { 1, 4, 3, 2 },
                        new int[] { 2, 1, 3, 4 },
                        new int[] { 2, 1, 4, 3 },
                        new int[] { 2, 3, 1, 4 },
                        new int[] { 2, 3, 4, 1 },
                        new int[] { 2, 4, 1, 3 },
                        new int[] { 2, 4, 3, 1 },
                        new int[] { 3, 1, 2, 4 },
                        new int[] { 3, 1, 4, 2 },
                        new int[] { 3, 2, 1, 4 },
                        new int[] { 3, 2, 4, 1 },
                        new int[] { 3, 4, 1, 2 },
                        new int[] { 3, 4, 2, 1 },
                        new int[] { 4, 1, 2, 3 },
                        new int[] { 4, 1, 3, 2 },
                        new int[] { 4, 2, 1, 3 },
                        new int[] { 4, 2, 3, 1 },
                        new int[] { 4, 3, 1, 2 },
                        new int[] { 4, 3, 2, 1 },
                    }
                },
                new
                {
                    Items   = items,
                    Lengths = new int[] { 0, 4 },
                    ExpectedCombinations = new int[][]
                    {
                        new int[0],
                        new int[] { 1, 2, 3, 4 },
                        new int[] { 1, 2, 4, 3 },
                        new int[] { 1, 3, 2, 4 },
                        new int[] { 1, 3, 4, 2 },
                        new int[] { 1, 4, 2, 3 },
                        new int[] { 1, 4, 3, 2 },
                        new int[] { 2, 1, 3, 4 },
                        new int[] { 2, 1, 4, 3 },
                        new int[] { 2, 3, 1, 4 },
                        new int[] { 2, 3, 4, 1 },
                        new int[] { 2, 4, 1, 3 },
                        new int[] { 2, 4, 3, 1 },
                        new int[] { 3, 1, 2, 4 },
                        new int[] { 3, 1, 4, 2 },
                        new int[] { 3, 2, 1, 4 },
                        new int[] { 3, 2, 4, 1 },
                        new int[] { 3, 4, 1, 2 },
                        new int[] { 3, 4, 2, 1 },
                        new int[] { 4, 1, 2, 3 },
                        new int[] { 4, 1, 3, 2 },
                        new int[] { 4, 2, 1, 3 },
                        new int[] { 4, 2, 3, 1 },
                        new int[] { 4, 3, 1, 2 },
                        new int[] { 4, 3, 2, 1 },
                    }
                },
                new
                {
                    Items   = items,
                    Lengths = new int[0],
                    ExpectedCombinations = new int[][]
                    {
                        new int[0],
                        new int[] { 1 },
                        new int[] { 2 },
                        new int[] { 3 },
                        new int[] { 4 },
                        new int[] { 1, 2 },
                        new int[] { 1, 3 },
                        new int[] { 1, 4 },
                        new int[] { 2, 1 },
                        new int[] { 2, 3 },
                        new int[] { 2, 4 },
                        new int[] { 3, 1 },
                        new int[] { 3, 2 },
                        new int[] { 3, 4 },
                        new int[] { 4, 1 },
                        new int[] { 4, 2 },
                        new int[] { 4, 3 },
                        new int[] { 1, 2, 3 },
                        new int[] { 1, 2, 4 },
                        new int[] { 1, 3, 2 },
                        new int[] { 1, 3, 4 },
                        new int[] { 1, 4, 2 },
                        new int[] { 1, 4, 3 },
                        new int[] { 2, 1, 3 },
                        new int[] { 2, 1, 4 },
                        new int[] { 2, 3, 1 },
                        new int[] { 2, 3, 4 },
                        new int[] { 2, 4, 1 },
                        new int[] { 2, 4, 3 },
                        new int[] { 3, 1, 2 },
                        new int[] { 3, 1, 4 },
                        new int[] { 3, 2, 1 },
                        new int[] { 3, 2, 4 },
                        new int[] { 3, 4, 1 },
                        new int[] { 3, 4, 2 },
                        new int[] { 4, 1, 2 },
                        new int[] { 4, 1, 3 },
                        new int[] { 4, 2, 1 },
                        new int[] { 4, 2, 3 },
                        new int[] { 4, 3, 1 },
                        new int[] { 4, 3, 2 },
                        new int[] { 1, 2, 3, 4 },
                        new int[] { 1, 2, 4, 3 },
                        new int[] { 1, 3, 2, 4 },
                        new int[] { 1, 3, 4, 2 },
                        new int[] { 1, 4, 2, 3 },
                        new int[] { 1, 4, 3, 2 },
                        new int[] { 2, 1, 3, 4 },
                        new int[] { 2, 1, 4, 3 },
                        new int[] { 2, 3, 1, 4 },
                        new int[] { 2, 3, 4, 1 },
                        new int[] { 2, 4, 1, 3 },
                        new int[] { 2, 4, 3, 1 },
                        new int[] { 3, 1, 2, 4 },
                        new int[] { 3, 1, 4, 2 },
                        new int[] { 3, 2, 1, 4 },
                        new int[] { 3, 2, 4, 1 },
                        new int[] { 3, 4, 1, 2 },
                        new int[] { 3, 4, 2, 1 },
                        new int[] { 4, 1, 2, 3 },
                        new int[] { 4, 1, 3, 2 },
                        new int[] { 4, 2, 1, 3 },
                        new int[] { 4, 2, 3, 1 },
                        new int[] { 4, 3, 1, 2 },
                        new int[] { 4, 3, 2, 1 },
                    }
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
            {
                int[][] results = testCase.Items.Variations(testCase.Lengths).ToArray();

                this.Assert.IsNotNull(results, "results != null");
                this.Assert.AreEqual(testCase.ExpectedCombinations.Length, results.Length, "Did not find expected number of combinations.");

                for (int i = 0; i < results.Length; ++i)
                {
                    VerificationUtils.VerifyEnumerationsAreEqual(testCase.ExpectedCombinations[i], results[i], this.Assert);
                }
            });
        }