Exemplo n.º 1
0
        public void SetupResultWithNestedOrdering()
        {
            MockRepository mocks      = new MockRepository();
            ISongBird      maleBird   = (ISongBird)mocks.StrictMock(typeof(ISongBird)),
                           femaleBird = (ISongBird)mocks.StrictMock(typeof(ISongBird));

            SetupResult.On(maleBird).Call(maleBird.Sing()).Return("");
            using (mocks.Ordered())
            {
                using (mocks.Unordered())
                {
                    maleBird.Eat("seeds", 250);
                    femaleBird.Eat("seeds", 250);
                }

                using (mocks.Unordered())
                {
                    maleBird.Mate(femaleBird);
                    femaleBird.Mate(maleBird);
                }
            }
            mocks.ReplayAll();

            maleBird.Sing();
            femaleBird.Eat("seeds", 250);
            maleBird.Sing();
            maleBird.Eat("seeds", 250);

            maleBird.Sing();
            femaleBird.Mate(maleBird);
            maleBird.Sing();
            maleBird.Mate(femaleBird);
            maleBird.Sing();
            mocks.VerifyAll();
        }
Exemplo n.º 2
0
        public void Add_WithNotUniqueEmail_ThrowsException()
        {
            var customerSet = new FakeObjectSet <Customer>();

            objectContext = mocks.Stub <IObjectContext>();
            SetupResult.On(objectContext)
            .Call(objectContext.CreateObjectSet <Customer>())
            .Return(customerSet);

            mocks.ReplayAll();

            Customer c = new Customer();

            c.CompanyId = 3;
            c.Email     = "*****@*****.**";
            customerSet.AddObject(c);

            CustomerRepository repo = new CustomerRepository(this.objectContext);

            repo.Add(new Customer {
                Email = c.Email
            });

            Assert.Fail();
        }
Exemplo n.º 3
0
 public void SetupResultUsingOn()
 {
     SetupResult.On(demo).Call(demo.Prop).Return("Ayende");
     mocks.ReplayAll();
     for (int i = 0; i < 30; i++)
     {
         Assert.Equal("Ayende", demo.Prop);
     }
     mocks.VerifyAll();
 }
Exemplo n.º 4
0
        public void SetUp()
        {
            mocks         = new MockRepository();
            objectContext = mocks.Stub <IObjectContext>();
            objectSet     = mocks.DynamicMock <IObjectSet <Customer> >();

            SetupResult.On(objectContext)
            .Call(objectContext.CreateObjectSet <Customer>())
            .Return(objectSet);
        }
Exemplo n.º 5
0
        public void StubCheckDeliveryStatus_WhenOrderIsDelivered_ReturnsDelivered()
        {
            SetupResult.On(trackingServiceStub)
            .Call(trackingServiceStub.GetTracking(null))
            .Return("delivered")
            .IgnoreArguments();
            mocks.ReplayAll();

            var order = new Order();

            DeliveryStatus result = order.CheckDeliveryStatus(trackingServiceStub);

            Assert.AreEqual(DeliveryStatus.Delivered, result);
        }
Exemplo n.º 6
0
 public void SetupResultUsingOrdered()
 {
     SetupResult.On(demo).Call(demo.Prop).Return("Ayende");
     using (mocks.Ordered())
     {
         demo.VoidNoArgs();
         LastCall.On(demo).Repeat.Twice();
     }
     mocks.ReplayAll();
     demo.VoidNoArgs();
     for (int i = 0; i < 30; i++)
     {
         Assert.Equal("Ayende", demo.Prop);
     }
     demo.VoidNoArgs();
     mocks.VerifyAll();
 }
Exemplo n.º 7
0
 public void SetupResultForTheSameMethodTwiceCauseExcetion()
 {
     SetupResult.On(demo).Call(demo.Prop).Return("Ayende");
     Assert.Throws <InvalidOperationException>("The result for IDemo.get_Prop(); has already been setup.", () => SetupResult.On(demo).Call(demo.Prop).Return("Ayende"));
 }