Ejemplo n.º 1
0
        public static void WriteTwoCalls(IFoo fake, IEnumerable <IFakeObjectCall> calls, StringOutputWriter writer)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IFoo>());

            "And an output writer"
            .x(() => writer = new StringOutputWriter());

            "And I make a call to the fake"
            .x(() => fake.VoidMethod());

            "And I make a different call to the fake"
            .x(() => fake.IntMethod());

            "And I query the fake for its calls"
            .x(() => calls = Fake.GetCalls(fake));

#pragma warning disable CS0618 // Type or member is obsolete
            "When I write the calls to the output writer"
            .x(() => calls.Write(writer));
#pragma warning restore CS0618 // Type or member is obsolete

            "Then the output lists the calls"
            .x(() => writer.ToString().Should().Be(
                   "1: FakeItEasy.Specs.ObjectCallSpecs+IFoo.VoidMethod()\r\n" +
                   "2: FakeItEasy.Specs.ObjectCallSpecs+IFoo.IntMethod()\r\n"));
        }
Ejemplo n.º 2
0
        ILoggerFactory PrepareLogger(StringBuilder logStringBuilder)
        {
            var logWriter      = new StringOutputWriter(logStringBuilder);
            var loggerProvider = new MyLabLoggerProvider(logWriter);

            var sp = new ServiceCollection()
                     .AddLogging(l => l.AddProvider(loggerProvider))
                     .BuildServiceProvider();

            return(sp.GetService <ILoggerFactory>());
        }
        void IComponent.Append(ref Dictionary <string, object> variables, IOutputWriter writer)
        {
            ClassQuery cq = new ClassQuery(_namespace, _query);
            List <IDbDataParameter> pars = new List <IDbDataParameter>();
            StringOutputWriter      swo  = new StringOutputWriter();

            foreach (string str in _parameters.Keys)
            {
                string par = "";
                foreach (IComponent ic in _parameters[str])
                {
                    swo.Clear();
                    ic.Append(ref variables, swo);
                    par += swo.ToString();
                }
                pars.Add(cq.CreateParameter(str, par));
            }
            cq.Execute(pars.ToArray());
            object var = new ArrayList();

            while (cq.Read())
            {
                Hashtable ht = new Hashtable();
                for (int x = 0; x < cq.FieldCount; x++)
                {
                    if (!cq.IsDBNull(x))
                    {
                        ht.Add(cq.GetName(x), cq[x]);
                    }
                }
                ((ArrayList)var).Add(ht);
            }
            cq.Close();
            if (((ArrayList)var).Count == 1 && ((Hashtable)((ArrayList)var)[0]).Count == 1)
            {
                Hashtable tmp = (Hashtable)((ArrayList)var)[0];
                var = tmp;
                object[] objAr = new object[1];
                ((Hashtable)var).Values.CopyTo(objAr, 0);
                var = objAr[0];
            }
            if (variables.ContainsKey(_variableName))
            {
                variables.Remove(_variableName);
            }
            variables.Add(_variableName, var);
        }
Ejemplo n.º 4
0
        void IComponent.Append(ref Dictionary <string, object> variables, IOutputWriter writer)
        {
            object var = null;

            try
            {
                Type            t  = Type.GetType(_type, true);
                ConstructorInfo ci = null;
                foreach (ConstructorInfo c in t.GetConstructors())
                {
                    if ((_pars.Count == 0) && (c.GetParameters().Length == 0))
                    {
                        ci = c;
                        break;
                    }
                    else
                    {
                        bool isOkay = c.GetParameters().Length == _pars.Count;
                        foreach (ParameterInfo pi in c.GetParameters())
                        {
                            if (!_pars.ContainsKey("@" + pi.Name))
                            {
                                isOkay = false;
                                break;
                            }
                        }
                        if (isOkay)
                        {
                            ci = c;
                            break;
                        }
                    }
                }
                if (ci != null)
                {
                    object[]           pars = new object[_pars.Count];
                    StringOutputWriter swo  = new StringOutputWriter();
                    for (int x = 0; x < pars.Length; x++)
                    {
                        ParameterInfo pi  = ci.GetParameters()[x];
                        string        tmp = "";
                        foreach (IComponent ic in _pars["@" + pi.Name])
                        {
                            swo.Clear();
                            ic.Append(ref variables, swo);
                            tmp += swo.ToString();
                        }
                        pars[x] = Convert.ChangeType(tmp, pi.ParameterType);
                    }
                    var = ci.Invoke(pars);
                }
            }
            catch (Exception e)
            {
                EventController.TriggerEvent(new ErrorOccuredEvent(e));
                Log.Error(e);
            }
            if (variables.ContainsKey(_varName))
            {
                variables.Remove(_varName);
            }
            variables.Add(_varName, var);
        }