Пример #1
0
        private void GenerateStubsAndController(Project currentProject)
        {
            _project = currentProject;

            _controller = new SprintsController();

            _controller.ProjectsHelper = MockRepository.GenerateStub<ProjectsHelper>();
            if (_project != null)
            {
                _controller.ProjectsHelper.Stub(x => x.GetCurrentProjectId(Arg<HttpCookieCollection>.Is.Anything)).Return(_project.Id);
            }

            HttpRequestBase request = MockRepository.GenerateStub<HttpRequestBase>();
            HttpContextBase context = MockRepository.GenerateStub<HttpContextBase>();
            context.Stub(x => x.Request).Return(request);

            _controller.ControllerContext = new ControllerContext(context, new RouteData(), _controller);

            IProjectRepository repository = MockRepository.GenerateStub<IProjectRepository>();

            if (_project != null)
            {
                repository.Stub(x => x.Get(Arg<int>.Is.Equal(_project.Id))).Return(_project);
            }

            _controller.ProjectRepository = repository;
        }
Пример #2
0
        void Test_CreateNew_Action()
        {
            FormCollection formCollection = new FormCollection
                                                {
                                                    {"name", "Name"},
                                                    {"startdate", "11-01-2009"},
                                                    {"enddate", "11-02-2009"},
                                                    {"projectId", "2"}
                                                };

            Project project = new Project
                                  {
                                      Description = "My Project",
                                      Name = "My Project",
                                      Sprints = new List<Sprint>()
                                  };

            IProjectRepository repository = MockRepository.GenerateMock<IProjectRepository>();
            repository.Expect(x => x.Get(Arg<int>.Is.Equal(2))).Return(project);

            repository.Expect(
                x =>
                x.Save(
                    Arg<Project>.Matches(
                        p =>
                        p.Sprints.First().Name == "Name" &&
                        p.Sprints.First().StartDate == new DateTime(2009, 1, 11) &&
                        p.Sprints.First().EndDate == new DateTime(2009, 2, 11)))).Return(1);

            SprintsController controller = new SprintsController {ProjectRepository = repository};

            RedirectToRouteResult result = controller.CreateNew(formCollection) as RedirectToRouteResult;

            repository.VerifyAllExpectations();

            Assert.NotNull(result);
            Assert.Equal("Index", result.Values["action"]);
        }