Exemple #1
0
        public void GetCurrentMode_can_be_injected_outside_if_condition_is_single()
        {
            RegistryModeFactory.ClearConditions();
            RegistryModeFactory.AddCondition(() => RegistryMode.Release);

            var mode = RegistryModeFactory.GetCurrentMode();

            Assert.Equal(RegistryMode.Release, mode);
        }
        public void GetCurrentMode_can_be_injected_outside_if_condition_are_multiple()
        {
            RegistryModeFactory.ClearConditions();
            RegistryModeFactory.AddCondition(() => RegistryMode.Release);
            RegistryModeFactory.AddCondition(() => RegistryMode.Live);

            var mode = RegistryModeFactory.GetCurrentMode();

            Console.WriteLine(mode);
            Assert.Equal(RegistryMode.Release | RegistryMode.Live, mode);
        }
        private void WriteDebugLog(IRequestRepository request, MobileParam mobileParam, string controllerName, string actionName)
        {
            var mode = RegistryModeFactory.GetCurrentMode();

            if (mode == RegistryMode.Debug || mode == RegistryMode.Release)
            {
                LogHelper.WriteInfo(string.Format("/{0}/{1}:URL: {2}", controllerName, actionName, request.RawUrl));

                if (request.Header != null && request.Header.Count > 0)
                {
                    var sb = new StringBuilder();
                    foreach (var item in request.Header.AllKeys)
                    {
                        sb.AppendFormat("{0}={1}", item, request.Header[item]);
                    }
                    LogHelper.WriteInfo(string.Format("/{0}/{1}:HeaderInfo: {2}", controllerName, actionName, sb.ToString()));
                }

                //LogHelper.WriteInfo(string.Format("/{0}/{1}:MobileParam: {2}", controllerName, actionName, mobileParam.ToString(true)));
            }
        }
        public void GetCurrentMode_should_return_correct_mode()
        {
            RegistryModeFactory.ClearConditions();
            var mode = RegistryModeFactory.GetCurrentMode();

            Console.WriteLine(mode);

            if (ProjectConfigHelper.IsInDebugMode())
            {
                Assert.Equal(mode, RegistryMode.Debug);
            }

            if (ProjectConfigHelper.IsInReleaseMode())
            {
                Assert.Equal(mode, RegistryMode.Release);
            }

            if (ProjectConfigHelper.IsInLiveMode())
            {
                Assert.Equal(mode, RegistryMode.Live);
            }
        }
Exemple #5
0
        public override MethodResult Execute(object testClass)
        {
            try
            {
                var currentMode = RegistryModeFactory.GetCurrentMode();

                var shouldProcess = true;

                if (LiveOnly && currentMode != RegistryMode.Live)
                {
                    shouldProcess = false;
                }

                if (shouldProcess)
                {
                    var observer = ObjectFactory.GetInstance <IObserver>();
                    if (observer != null)
                    {
                        observer.PopAll();

                        var ret = testMethod.MethodInfo.Invoke(testClass, null);

                        var specItem = ret as SpecItem;
                        if (specItem == null)
                        {
                            throw new InvalidOperationException("The function has no return type or the type is not SpecItem!");
                        }

                        specItem.ToWatchItem().RunTest(true);

                        if (observer.HasItem)
                        {
                            // send email
                            #region SendEmail
                            var notify = new MailNotify()
                            {
                                SMTP     = "smtp.exmail.qq.com",
                                UserName = "******",
                                Password = "******",
                                Subject  = "【自动化测试】接口测试异常报警",
                                MailTo   = new string[] { "*****@*****.**" },
                                MailFrom = "*****@*****.**"
                            };

                            var mailContent = new StringBuilder();
                            while (observer.HasItem)
                            {
                                var item = observer.Pop().Display();

                                mailContent.AppendLine(item);
                            }

                            notify.SendMail(mailContent.ToString());

                            #endregion

                            return(new FailedResult(testMethod, new Exception(mailContent.ToString()), DisplayName));
                        }
                    }
                }
            }
            catch (ParameterCountMismatchException)
            {
                throw new InvalidOperationException("Fact method " + TypeName + "." + MethodName + " cannot have parameters");
            }

            return(new PassedResult(testMethod, DisplayName));
        }