示例#1
0
 /// <summary>
 /// Configures any call to the fake object.
 /// </summary>
 /// <returns>A configuration object.</returns>
 public IVoidConfiguration <T> AnyCall()
 {
     return(Fake.Configure(this.FakedObject).AnyCall());
 }
示例#2
0
 /// <summary>
 /// Configures calls to the specified member.
 /// </summary>
 /// <param name="callSpecification">An expression specifying the call to configure.</param>
 /// <returns>A configuration object.</returns>
 public IVoidConfiguration <T> CallsTo(Expression <Action <T> > callSpecification)
 {
     return(Fake.Configure(this.FakedObject).CallsTo(callSpecification));
 }
示例#3
0
 /// <summary>
 /// Configures calls to the specified member.
 /// </summary>
 /// <typeparam name="TMember">The type of value the member returns.</typeparam>
 /// <param name="callSpecification">An expression specifying the call to configure.</param>
 /// <returns>A configuration object.</returns>
 public IReturnValueConfiguration <T, TMember> CallsTo <TMember>(Expression <Func <T, TMember> > callSpecification)
 {
     return(Fake.Configure(this.FakedObject).CallsTo(callSpecification));
 }
示例#4
0
        public void Test()
        {
            var foo = A.Fake <Foo>();



            Fake.Configure(foo).AnyCall().Throws(new ArgumentNullException());

            Fake.Configure(foo)
            .CallsTo(x => x.Bar())
            .Returns("1");

            Fake.Configure(foo)
            .CallsTo(x => x.Bar())
            .Returns("foo");

            Fake.Configure(foo)
            .CallsTo(x => x.Baz())
            .Throws(new Exception());

            Fake.Configure(foo)
            .CallsTo(x => x.Bar())
            .Returns("test")
            .Twice();


            Fake.Configure(foo)
            .CallsTo(x => x.Baz())
            .Throws(new ArgumentNullException("test"));


            Fake.Configure(foo)
            .CallsTo(x => x.Bar())
            .Returns(() => "test");

            //Fake.Configure(foo).CallsTo(x => x.Baz()).RemoveCallConfigurations();
            //Fake.Configure(foo).RemoveFakeObjectConfigurations();

            //// Expectations
            Fake.Configure(foo)
            .CallsTo(x => x.Bar())
            .Returns("test")
            .Once();

            Fake.Configure(foo)
            .CallsTo(x => x.Baz())
            .Throws(new ArgumentNullException())
            .Twice();



            Fake.Configure(foo).CallsTo(x => x.Bar()).Throws(new ArgumentException()).NumberOfTimes(2);

            Fake.Configure(foo)
            .CallsTo(x => x.Bar(Argument.Is.Any <string>(), Argument.Is.Matching <int>(p => p > 10)))
            .Returns("foo");


            foo = A.Fake <Foo>();
            //Fake.Configure(foo).Event(x => x.SomethingHappened += null)
            //foo.SomethingHappened += new EventHandler(foo_SomethingHappened);
            //Fake.VerifySetExpectations(foo);

            //Fake.Configure(foo).Event(x => x.SomethingHappened += null).Throws(new ArgumentNullException());
            //Fake.Configure(foo).Event(x => x.SomethingHappened += null).Raise(sender, EventArgs.Empty);

            //var t = foo.SomethingHappened;
            //foo.SomethingHappened += new EventManager<EventArgs>().Raise;
            //var raiser = Raise.With(foo, EventArgs.Empty);
            //foo.SomethingHappened += raiser.Now;
            //var f = foo.SomethingHappened;
            //foo.SomethingHappened += Raise.With(foo, EventArgs.Empty).Now;
            //foo.SomethingHappened += Raise.With(EventArgs.Empty).Now;
        }