public void TestAdminDetailsRedirectsWhenNotSameId()
        {
            #region Arrange
            var calls = new FakeCallForProposals();
            calls.Records(3, CallForProposalRepository);
            var proposals = new List<Proposal>();
            proposals.Add(CreateValidEntities.Proposal(1));
            proposals[0].CallForProposal = CallForProposalRepository.GetNullableById(2); //different
            var fakeProposals = new FakeProposals();
            fakeProposals.Records(2, ProposalRepository, proposals);

            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "me");
            AccessService.Expect(a => a.HasAccess(null, 3, "me")).Return(true).Repeat.Any();
            AccessService.Expect(
                a =>
                a.HasSameId(Arg<Template>.Is.Anything, Arg<CallForProposal>.Is.Anything, Arg<int?>.Is.Anything,
                            Arg<int?>.Is.Anything)).Return(false).Repeat.Any();
            #endregion Arrange

            #region Act
            Controller.AdminDetails(1, 3)
                .AssertActionRedirect()
                .ToAction<HomeController>(a => a.Index());
            #endregion Act

            #region Assert
            Assert.AreEqual("You do not have access to that.", Controller.Message);
            #endregion Assert
        }
        public void TestDetailsThrowsAnExceptionIfGuidIsNotUnique()
        {
            var thisFar = false;
            try
            {
                #region Arrange
                var proposals = new List<Proposal>();
                for (int i = 0; i < 2; i++)
                {
                    proposals.Add(CreateValidEntities.Proposal(i + 1));
                    proposals[i].Guid = SpecificGuid.GetGuid(1);
                }
                var fakeProposals = new FakeProposals();
                fakeProposals.Records(3, ProposalRepository, proposals);
                thisFar = true;
                #endregion Arrange

                #region Act
                Controller.Details(SpecificGuid.GetGuid(1));
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.AreEqual("Sequence contains more than one element", ex.Message);
                throw;
            }
        }
        public void TestAdminDetailsRedirectsWhenProposalNotFound()
        {
            #region Arrange
            var calls = new FakeCallForProposals();
            calls.Records(3, CallForProposalRepository);
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "me");
            AccessService.Expect(a => a.HasAccess(null, 3, "me")).Return(true).Repeat.Any();
            AccessService.Expect(
                a =>
                a.HasSameId(Arg<Template>.Is.Anything, Arg<CallForProposal>.Is.Anything, Arg<int?>.Is.Anything,
                            Arg<int?>.Is.Anything)).Return(true).Repeat.Any();
            var proposals = new FakeProposals();
            proposals.Records(3, ProposalRepository);
            #endregion Arrange

            #region Act
            Controller.AdminDetails(4, 3)
                .AssertActionRedirect()
                .ToAction<ProposalController>(a => a.Index());
            #endregion Act

            #region Assert
            Assert.AreEqual("Proposal Not Found", Controller.Message);
            #endregion Assert
        }
        public void TestAdminDetailsReturnsView2()
        {
            #region Arrange
            var calls = new FakeCallForProposals();
            calls.Records(3, CallForProposalRepository);
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "me");
            AccessService.Expect(a => a.HasAccess(null, 3, "me")).Return(true).Repeat.Any();
            AccessService.Expect(
                a =>
                a.HasSameId(Arg<Template>.Is.Anything, Arg<CallForProposal>.Is.Anything, Arg<int?>.Is.Anything,
                            Arg<int?>.Is.Anything)).Return(true).Repeat.Any();
            var proposals = new FakeProposals();
            proposals.Records(3, ProposalRepository);

            var editors = new List<Editor>();
            editors.Add(CreateValidEntities.Editor(1));
            editors[0].CallForProposal = CallForProposalRepository.GetNullableById(3);
            editors[0].User = CreateValidEntities.User(1);
            editors[0].User.LoginId = "me";
            var fakedEditors = new FakeEditors();
            fakedEditors.Records(3, EditorRepository, editors);
            var reviewedProposals = new List<ReviewedProposal>();
            reviewedProposals.Add(CreateValidEntities.ReviewedProposal(1));
            reviewedProposals[0].Editor = EditorRepository.GetNullableById(1);
            reviewedProposals[0].Proposal = ProposalRepository.GetNullableById(2);
            reviewedProposals[0].FirstViewedDate = new DateTime(2011, 01, 01);
            var fakedReviewedProposal = new FakeReviewedProposals();
            fakedReviewedProposal.Records(0, ReviewedProposalRepository, reviewedProposals);

            #endregion Arrange

            #region Act
            var result = Controller.AdminDetails(1, 3)
                .AssertViewRendered()
                .WithViewData<ProposalAdminViewModel>();
            #endregion Act

            #region Assert
            ReviewedProposalRepository.AssertWasCalled(a => a.EnsurePersistent(Arg<ReviewedProposal>.Is.Anything));
            var args = (ReviewedProposal)ReviewedProposalRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg<ReviewedProposal>.Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(DateTime.Now.Date, args.LastViewedDate.Date);
            Assert.AreEqual(DateTime.Now.Date, args.FirstViewedDate.Date);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.CallForProposal.Id);
            Assert.AreEqual(1, result.Proposal.Id);
            #endregion Assert
        }