コード例 #1
0
        public void GigController_Should_Contain_Index_Method_Which_Accepts_GigID_And_Returns_A_Gig()
        {
            MockRepository mocks = new MockRepository();

            Guid gigId = Guid.NewGuid();
            Gig gig = new Gig();
            gig.ID = gigId;

            //Mock the GigManager
            IGigManager gigManager = mocks.DynamicMock<IGigManager>();
            GigController gigController = new GigController();
            gigController.GigManager = gigManager;

            Expect.Call(gigManager.GetByID(gigId))
                .Constraints(Is.Equal(gigId))
                .Repeat.Once()
                .Return(gig);

            mocks.ReplayAll();

            ViewResult result = (ViewResult)gigController.Index(gigId);
            Gig returnedData = (Gig)(result.ViewData.Model);

            mocks.VerifyAll();

            Assert.IsNotNull(returnedData);
            Assert.AreEqual(gig.ID, returnedData.ID);
        }
コード例 #2
0
        private void TestGigControllersListMethod(DateTime expectedDate, int? year, int? month, int? day)
        {
            MockRepository mocks = new MockRepository();

            Guid siteId = new Guid("da50ad46-61a0-4ba2-96ff-7e3dddb3b761");

            IList<Gig> gigs = GigHelpers.ConstructGigs(10, expectedDate, null);

            //Mock the GigManager
            IGigManager gigManager = mocks.DynamicMock<IGigManager>();
            GigController gigController = new GigController();
            gigController.GigManager = gigManager;

            Expect.Call(gigManager.GetGigsBySiteAfterDate(siteId, expectedDate))
                .Constraints(new AbstractConstraint[] { Is.Equal(siteId), Is.Equal(expectedDate) })
                .Repeat.Once()
                .Return(gigs);

            mocks.ReplayAll();

            ViewResult result = (ViewResult)gigController.List(year, month, day);
            List<Gig> returnedData = (List<Gig>)(result.ViewData.Model);

            mocks.VerifyAll();
        }