public void TestEditGetReturnsView()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            AccessService.Expect(a => a.HasAccess(null, 1, "Me")).Return(true).Repeat.Any();
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(1, CallForProposalRepository);
            #endregion Arrange

            #region Act
            var result = Controller.Edit(1)
                .AssertViewRendered()
                .WithViewData<CallForProposalViewModel>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Name1", result.CallForProposal.Name);
            Assert.AreEqual(1, result.CallForProposalId);
            Assert.IsNull(result.TemplateId);
            Assert.IsTrue(result.IsCallForProposal);
            Assert.IsFalse(result.IsTemplate);

            AccessService.AssertWasCalled(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything));
            var args = AccessService.GetArgumentsForCallsMadeOn(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything))[0];
            Assert.AreEqual(null, args[0]);
            Assert.AreEqual(1, args[1]);
            Assert.AreEqual("Me", args[2]);
            #endregion Assert
        }
        public void TestSendCallGetWHereNoAccessRegirectsToHome()
        {
            #region Arrange
            var fakeCall = new FakeCallForProposals();
            fakeCall.Records(3, CallForProposalRepository);
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            AccessService.Expect(a => a.HasAccess(null, 3, "Me")).Return(false).Repeat.Any();
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual("You do not have access to that.", Controller.Message);

            AccessService.AssertWasCalled(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything));
            var args = AccessService.GetArgumentsForCallsMadeOn(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything))[0];
            Assert.AreEqual(null, args[0]);
            Assert.AreEqual(3, args[1]);
            Assert.AreEqual("Me", args[2]);
            #endregion Assert
        }
        public void TestSendCallGetWHereCallNotFoundRegirectsToIndex()
        {
            #region Arrange
            var fakeCall = new FakeCallForProposals();
            fakeCall.Records(3, CallForProposalRepository);
            #endregion Arrange

            #region Act
            var result = Controller.SendCall(4)
                .AssertActionRedirect()
                .ToAction<CallForProposalController>(a => a.Index(null, null, null));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("filterActive", result.RouteValues.ElementAt(2).Key);
            Assert.AreEqual(null, result.RouteValues.ElementAt(2).Value);

            Assert.AreEqual("filterStartCreate", result.RouteValues.ElementAt(3).Key);
            Assert.AreEqual(null, result.RouteValues.ElementAt(3).Value);

            Assert.AreEqual("filterEndCreate", result.RouteValues.ElementAt(4).Key);
            Assert.AreEqual(null, result.RouteValues.ElementAt(4).Value);
            #endregion Assert
        }
        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 TestReviewerIndexRedirectsInNoAccess2()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(1, new[] { "" }, "*****@*****.**");
            var editors = new List<Editor>();
            editors.Add(CreateValidEntities.Editor(1));
            editors.Add(CreateValidEntities.Editor(2));
            editors.Add(CreateValidEntities.Editor(3));
            editors[1].ReviewerEmail = "*****@*****.**";
            var calls = new List<CallForProposal>();
            calls.Add(CreateValidEntities.CallForProposal(1));
            calls[0].Editors = editors;
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(2, CallForProposalRepository, calls);
            #endregion Arrange

            #region Act
            Controller.ReviewerIndex(1, null, "*****@*****.**")
                .AssertActionRedirect()
                .ToAction<ProposalController>(a => a.Home());
            #endregion Act

            #region Assert
            Assert.AreEqual("You do not have access to that.", Controller.Message);
            #endregion Assert
        }
        public void TestDetailsRedirectsToHomeIndexIfIdDifferent()
        {
            #region Arrange
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.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(false).Repeat.Any();

            var fakeEmail = new List<EmailQueue>();
            for (int i = 0; i < 3; i++)
            {
                fakeEmail.Add(CreateValidEntities.EmailQueue(i + 1));
                fakeEmail[i].CallForProposal = CallForProposalRepository.GetNullableById(3);
            }
            fakeEmail[0].CallForProposal = CallForProposalRepository.GetNullableById(1);
            var fakeEmails = new FakeEmailQueues();
            fakeEmails.Records(0, EmailQueueRepository, fakeEmail);

            #endregion Arrange

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

            #region Assert
            Assert.AreEqual("You do not have access to that.", Controller.Message);
            AccessService.AssertWasCalled(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything));
            var args = AccessService.GetArgumentsForCallsMadeOn(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything))[0];
            Assert.IsNull(args[0]);
            Assert.AreEqual(3, args[1]);
            Assert.AreEqual("Me", args[2]);

            AccessService.AssertWasCalled(a => a.HasSameId(Arg<Template>.Is.Anything,
                Arg<CallForProposal>.Is.Anything,
                Arg<int?>.Is.Anything,
                Arg<int?>.Is.Anything));
            var args2 = AccessService.GetArgumentsForCallsMadeOn(a => a.HasSameId(Arg<Template>.Is.Anything, Arg<CallForProposal>.Is.Anything, Arg<int?>.Is.Anything, Arg<int?>.Is.Anything))[0];
            Assert.AreEqual(null, args2[0]);
            Assert.AreEqual(3, ((CallForProposal)args2[1]).Id);
            Assert.AreEqual(null, args2[2]);
            Assert.AreEqual(1, args2[3]);
            #endregion Assert
        }
        public void TestExportExcellRedirectsWhenCallNotFound()
        {
            #region Arrange
            var fakeCall = new FakeCallForProposals();
            fakeCall.Records(3, CallForProposalRepository);
            #endregion Arrange

            #region Act
            Controller.ExportExcell(1, 4)
                .AssertActionRedirect()
                .ToAction<CallForProposalController>(a => a.Index(null, null, null));
            #endregion Act

            #region Assert
            #endregion Assert
        }
        public void TestDetailsRedirectsToCallForProposalIndexIfCallNotFound()
        {
            #region Arrange
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(3, CallForProposalRepository);
            #endregion Arrange

            #region Act
            Controller.Details(4, 5)
                .AssertActionRedirect()
                .ToAction<CallForProposalController>(a => a.Index(null, null, null));
            #endregion Act

            #region Assert
            #endregion Assert
        }
        public void TestEditGetRedirectsToIndexIfCallNotFound()
        {
            #region Arrange
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(1, CallForProposalRepository);
            #endregion Arrange

            #region Act
            Controller.Edit(2)
                .AssertActionRedirect()
                .ToAction<CallForProposalController>(a => a.Index(null, null, null));
            #endregion Act

            #region Assert
            Assert.IsNull(Controller.Message);
            #endregion Assert
        }
        public void TestAdminDetailsRedirectsWhenNoAccess()
        {
            #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(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 TestAdminDetailsRedirectsWhenCallForProposalNotFound()
        {
            #region Arrange
            var calls = new FakeCallForProposals();
            calls.Records(3, CallForProposalRepository);
            #endregion Arrange

            #region Act
            var result = Controller.AdminDetails(1, 4)
                .AssertActionRedirect()
                .ToAction<CallForProposalController>(a => a.Index(null, null, null));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.IsNull(result.RouteValues.ElementAt(2).Value);
            Assert.IsNull(result.RouteValues.ElementAt(3).Value);
            Assert.IsNull(result.RouteValues.ElementAt(4).Value);
            #endregion Assert
        }
        public void TestExportExcellRedirectsWhenNoAccess()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "*****@*****.**");
            var fakeCall = new FakeCallForProposals();
            fakeCall.Records(3, CallForProposalRepository);
            AccessService.Expect(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything)).Return(false);
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual("You do not have access to that.", Controller.Message);
            AccessService.AssertWasCalled(a => a.HasAccess(null, 3, "*****@*****.**"));
            #endregion Assert
        }
        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 TestSendCallPostReturnsViewWhenValid()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            AccessService.Expect(a => a.HasAccess(null, 1, "Me")).Return(true).Repeat.Any();
            var calls = new List<CallForProposal>();
            calls.Add(CreateValidEntities.CallForProposal(1));
            calls[0].IsActive = true;
            calls[0].EndDate = DateTime.Now.AddDays(1);
            calls[0].EmailTemplates.Add(CreateValidEntities.EmailTemplate(1));
            calls[0].EmailTemplates[0].TemplateType = EmailTemplateType.InitialCall;
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(0, CallForProposalRepository, calls);

            var emailsForCall = new List<EmailsForCall>();
            for (int i = 0; i < 5; i++)
            {
                emailsForCall.Add(CreateValidEntities.EmailsForCall(i + 1));
                emailsForCall[i].CallForProposal = CallForProposalRepository.GetNullableById(1);
                emailsForCall[i].HasBeenEmailed = true;
            }
            emailsForCall[1].HasBeenEmailed = false;
            emailsForCall[3].HasBeenEmailed = false;
            var fakeEmails = new FakeEmailsForCall();
            fakeEmails.Records(0, EmailsForCallRepository, emailsForCall);

            #endregion Arrange

            #region Act
            var result = Controller.SendCall(1, false)
                .AssertViewRendered()
                .WithViewData<EmailsForCallSendViewModel>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(5, result.EmailsForCallList.Count());
            Assert.AreEqual(1, result.CallForProposal.Id);
            Assert.IsFalse(result.Immediate);

            Assert.AreEqual("2 Emails Generated", Controller.Message);

            AccessService.AssertWasCalled(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything));
            var args = AccessService.GetArgumentsForCallsMadeOn(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything))[0];
            Assert.AreEqual(null, args[0]);
            Assert.AreEqual(1, args[1]);
            Assert.AreEqual("Me", args[2]);

            EmailService.AssertWasCalled(a => a.SendEmail(Arg<HttpRequestBase>.Is.Anything, Arg<UrlHelper>.Is.Anything, Arg<CallForProposal>.Is.Anything, Arg<EmailTemplate>.Is.Anything, Arg<string>.Is.Anything, Arg<bool>.Is.Anything, Arg<string>.Is.Anything), x=> x.Repeat.Times(2));
            EmailsForCallRepository.AssertWasCalled(a => a.EnsurePersistent(Arg<EmailsForCall>.Is.Anything), x=> x.Repeat.Times(2));
            CallForProposalRepository.AssertWasCalled(a => a.EnsurePersistent(Arg<CallForProposal>.Is.Anything));

            var args1 =
                EmailService.GetArgumentsForCallsMadeOn(
                    a =>
                    a.SendEmail(Arg<HttpRequestBase>.Is.Anything, Arg<UrlHelper>.Is.Anything,
                                Arg<CallForProposal>.Is.Anything, Arg<EmailTemplate>.Is.Anything,
                                Arg<string>.Is.Anything, Arg<bool>.Is.Anything, Arg<string>.Is.Anything));
            Assert.AreEqual(1, ((CallForProposal)args1[0][2]).Id);
            Assert.AreEqual(EmailTemplateType.InitialCall, ((EmailTemplate)args1[0][3]).TemplateType);
            Assert.AreEqual("*****@*****.**", args1[0][4]);
            Assert.IsFalse(((bool)args1[0][5]));
            Assert.IsNull(args1[0][6]);

            Assert.AreEqual(1, ((CallForProposal)args1[1][2]).Id);
            Assert.AreEqual(EmailTemplateType.InitialCall, ((EmailTemplate)args1[1][3]).TemplateType);
            Assert.AreEqual("*****@*****.**", args1[1][4]);
            Assert.IsFalse(((bool)args1[1][5]));
            Assert.IsNull(args1[1][6]);

            var args2 =
                EmailsForCallRepository.GetArgumentsForCallsMadeOn(
                    a => a.EnsurePersistent(Arg<EmailsForCall>.Is.Anything));
            Assert.IsNotNull(((EmailsForCall)args2[0][0]).EmailedOnDate);
            Assert.AreEqual(DateTime.Now.Date, ((EmailsForCall)args2[0][0]).EmailedOnDate.Value.Date);
            Assert.AreEqual(true, ((EmailsForCall)args2[0][0]).HasBeenEmailed);

            Assert.IsNotNull(((EmailsForCall)args2[1][0]).EmailedOnDate);
            Assert.AreEqual(DateTime.Now.Date, ((EmailsForCall)args2[1][0]).EmailedOnDate.Value.Date);
            Assert.AreEqual(true, ((EmailsForCall)args2[1][0]).HasBeenEmailed);

            var args3 =
                CallForProposalRepository.GetArgumentsForCallsMadeOn(
                    a => a.EnsurePersistent(Arg<CallForProposal>.Is.Anything))[0][0];
            Assert.IsNotNull(((CallForProposal)args3).CallsSentDate);
            Assert.AreEqual(DateTime.Now.Date, ((CallForProposal)args3).CallsSentDate.Value.Date);

            #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
        }
        public void TestSendCallPostReturnsViewIfCallNotActive()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            AccessService.Expect(a => a.HasAccess(null, 1, "Me")).Return(true).Repeat.Any();
            var calls = new List<CallForProposal>();
            calls.Add(CreateValidEntities.CallForProposal(1));
            calls[0].IsActive = false;
            calls[0].EndDate = DateTime.Now.AddDays(1);
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(0, CallForProposalRepository, calls);

            var emailsForCall = new List<EmailsForCall>();
            for (int i = 0; i < 5; i++)
            {
                emailsForCall.Add(CreateValidEntities.EmailsForCall(i+1));
                emailsForCall[i].CallForProposal = CallForProposalRepository.GetNullableById(1);
            }
            emailsForCall[1].HasBeenEmailed = true;
            var fakeEmails = new FakeEmailsForCall();
            fakeEmails.Records(0, EmailsForCallRepository, emailsForCall);

            #endregion Arrange

            #region Act
            var result = Controller.SendCall(1, false)
                .AssertViewRendered()
                .WithViewData<EmailsForCallSendViewModel>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(5, result.EmailsForCallList.Count());
            Assert.AreEqual(1, result.CallForProposal.Id);
            Assert.IsFalse(result.Immediate);

            Assert.AreEqual("Is not active or end date is passed", Controller.Message);

            AccessService.AssertWasCalled(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything));
            var args = AccessService.GetArgumentsForCallsMadeOn(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything))[0];
            Assert.AreEqual(null, args[0]);
            Assert.AreEqual(1, args[1]);
            Assert.AreEqual("Me", args[2]);

            EmailService.AssertWasNotCalled(a => a.SendEmail(Arg<HttpRequestBase>.Is.Anything, Arg<UrlHelper>.Is.Anything, Arg<CallForProposal>.Is.Anything, Arg<EmailTemplate>.Is.Anything, Arg<string>.Is.Anything, Arg<bool>.Is.Anything, Arg<string>.Is.Anything));
            EmailsForCallRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg<EmailsForCall>.Is.Anything));
            #endregion Assert
        }
        public void TestDetailsRedirectsToIndexIfEmailNotFound()
        {
            #region Arrange
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(3, CallForProposalRepository);
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            AccessService.Expect(a => a.HasAccess(null, 3, "Me")).Return(true).Repeat.Any();
            var fakeEmails = new FakeEmailQueues();
            fakeEmails.Records(3, EmailQueueRepository);

            #endregion Arrange

            #region Act
            var result = Controller.Details(4, 3)
                .AssertActionRedirect()
                .ToAction<EmailQueueController>(a => a.Index(3));
            #endregion Act

            #region Assert
            Assert.AreEqual("Email not found.", Controller.Message);
            AccessService.AssertWasCalled(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything));
            var args = AccessService.GetArgumentsForCallsMadeOn(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything))[0];
            Assert.IsNull(args[0]);
            Assert.AreEqual(3, args[1]);
            Assert.AreEqual("Me", args[2]);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.RouteValues.ElementAt(2).Value);

            #endregion Assert
        }
        public void TestReviewerIndexRedirectsToProposalHomeIfCallNotFound1()
        {
            #region Arrange
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(3, CallForProposalRepository);
            #endregion Arrange

            #region Act
            Controller.ReviewerIndex(4, null, null)
                .AssertActionRedirect()
                .ToAction<ProposalController>(a => a.Home());
            #endregion Act

            #region Assert
            #endregion Assert
        }
        public void TestIndexReturnsViewWithExpectedValuesIfHasAccess()
        {
            #region Arrange
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(3, CallForProposalRepository);
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            AccessService.Expect(a => a.HasAccess(null, 2, "Me")).Return(true).Repeat.Any();

            var fakeEmails = new List<EmailQueue>();
            for (int i = 0; i < 4; i++)
            {
                fakeEmails.Add(CreateValidEntities.EmailQueue(i + 1));
                fakeEmails[i].CallForProposal = CallForProposalRepository.GetNullableById(2);
            }
            fakeEmails[1].CallForProposal = CallForProposalRepository.GetNullableById(1);
            var fakeEmailQueue = new FakeEmailQueues();
            fakeEmailQueue.Records(0, EmailQueueRepository, fakeEmails);
            #endregion Arrange

            #region Act
            var result = Controller.Index(2)
                .AssertViewRendered()
                .WithViewData<EmailQueueListViewModel>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.EmailQueues.Count());
            #endregion Assert
        }
        public void TestDetailsReturnsViewWithExpectedResults()
        {
            #region Arrange
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.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 fakeEmail = new List<EmailQueue>();
            for (int i = 0; i < 3; i++)
            {
                fakeEmail.Add(CreateValidEntities.EmailQueue(i + 1));
                fakeEmail[i].CallForProposal = CallForProposalRepository.GetNullableById(3);
            }
            fakeEmail[0].CallForProposal = CallForProposalRepository.GetNullableById(1);
            var fakeEmails = new FakeEmailQueues();
            fakeEmails.Records(0, EmailQueueRepository, fakeEmail);
            #endregion Arrange

            #region Act
            var result = Controller.Details(2, 3)
                .AssertViewRendered()
                .WithViewData<EmailQueueViewModel>();
            #endregion Act

            #region Assert
            AccessService.AssertWasCalled(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything));
            var args = AccessService.GetArgumentsForCallsMadeOn(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything))[0];
            Assert.IsNull(args[0]);
            Assert.AreEqual(3, args[1]);
            Assert.AreEqual("Me", args[2]);

            AccessService.AssertWasCalled(a => a.HasSameId(Arg<Template>.Is.Anything,
                Arg<CallForProposal>.Is.Anything,
                Arg<int?>.Is.Anything,
                Arg<int?>.Is.Anything));
            var args2 = AccessService.GetArgumentsForCallsMadeOn(a => a.HasSameId(Arg<Template>.Is.Anything, Arg<CallForProposal>.Is.Anything, Arg<int?>.Is.Anything, Arg<int?>.Is.Anything))[0];
            Assert.AreEqual(null, args2[0]);
            Assert.AreEqual(3, ((CallForProposal)args2[1]).Id);
            Assert.AreEqual(null, args2[2]);
            Assert.AreEqual(3, args2[3]);

            Assert.IsNotNull(result);
            Assert.AreEqual("Subject2", result.EmailQueue.Subject);
            Assert.AreEqual(3, result.CallForProposal.Id);
            #endregion Assert
        }
        public void TestReviewerIndexRedirectsToProposalHomeIfCallNotFound3()
        {
            #region Arrange
            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(3, CallForProposalRepository);
            #endregion Arrange

            #region Act
            Controller.ReviewerIndex(4, StaticValues.RB_Decission_NotDecided, "*****@*****.**")
                .AssertActionRedirect()
                .ToAction<ProposalController>(a => a.Home());
            #endregion Act

            #region Assert
            #endregion Assert
        }
        public void TestEditPostChecksProposalMaximum()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            AccessService.Expect(a => a.HasAccess(null, 1, "Me")).Return(true).Repeat.Any();

            var calls = new List<CallForProposal>();
            calls.Add(CreateValidEntities.CallForProposal(1));
            calls[0].AddEditor(CreateValidEntities.Editor(1));
            calls[0].Editors[0].User = CreateValidEntities.User(1);
            calls[0].Editors[0].IsOwner = true;
            calls[0].SetIdTo(1);

            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(0, CallForProposalRepository, calls);
            var editcall = CreateValidEntities.CallForProposal(9);
            editcall.ProposalMaximum = 0m;
            editcall.Description = "Desc";
            #endregion Arrange

            #region Act
            var result = Controller.Edit(1, editcall)
                .AssertViewRendered()
                .WithViewData<CallForProposalViewModel>();
            #endregion Act

            #region Assert
            Controller.ModelState.AssertErrorsAre("You need to specify a Proposal Maximum of at least a cent");
            Assert.IsNotNull(result);
            Assert.AreEqual("Name9", result.CallForProposal.Name);
            Assert.AreEqual("Desc", result.CallForProposal.Description);
            Assert.AreEqual(1, result.CallForProposalId);
            Assert.IsNull(result.TemplateId);
            Assert.IsTrue(result.IsCallForProposal);
            Assert.IsFalse(result.IsTemplate);

            AccessService.AssertWasCalled(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything));
            var args = AccessService.GetArgumentsForCallsMadeOn(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything))[0];
            Assert.AreEqual(null, args[0]);
            Assert.AreEqual(1, args[1]);
            Assert.AreEqual("Me", args[2]);
            #endregion Assert
        }
Example #23
0
        public void SetupData()
        {
            var users = new List<User>();
            var editors = new List<Editor>();
            for (int i = 0; i < 3; i++)
            {
                users.Add(CreateValidEntities.User(i+1));
                editors.Add(CreateValidEntities.Editor(i+1));
                editors[i].User = users[i];
            }

            var templates = new List<Template>();
            for (int i = 0; i < 3; i++)
            {
                templates.Add( CreateValidEntities.Template(i+1));
            }
            templates[1].Editors = editors;

            var fakeTemplates = new FakeTemplates();
            fakeTemplates.Records(0, TemplateRepository, templates);

            var calls = new List<CallForProposal>();
            for(int i = 0; i < 3; i++)
            {
                calls.Add(CreateValidEntities.CallForProposal(i + 1));
            }
            calls[1].Editors = editors;

            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(0, CallForProposalRepository, calls);
        }
        public void TestEditPostRedirectsToEditGetWhenValid()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            AccessService.Expect(a => a.HasAccess(null, 1, "Me")).Return(true).Repeat.Any();

            var calls = new List<CallForProposal>();
            calls.Add(CreateValidEntities.CallForProposal(1));
            calls[0].AddEditor(CreateValidEntities.Editor(1));
            calls[0].Editors[0].User = CreateValidEntities.User(1);
            calls[0].Editors[0].IsOwner = true;
            calls[0].SetIdTo(1);

            var fakeCalls = new FakeCallForProposals();
            fakeCalls.Records(0, CallForProposalRepository, calls);
            var editcall = CreateValidEntities.CallForProposal(9);
            editcall.IsActive = true;
            editcall.Description = "Updated";
            editcall.ProposalMaximum = 12.97m;
            editcall.EndDate = new DateTime(2009, 12, 23).Date;
            editcall.Name = "UName";
            #endregion Arrange

            #region Act
            var result = Controller.Edit(1, editcall)
                .AssertActionRedirect()
                .ToAction<CallForProposalController>(a => a.Edit(1));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            //Assert.AreEqual(1, result.RouteValues.ElementAt(2));
            Assert.AreEqual("Call For Proposal Edited Successfully.", Controller.Message);

            AccessService.AssertWasCalled(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything));
            var args = AccessService.GetArgumentsForCallsMadeOn(a => a.HasAccess(Arg<int?>.Is.Anything, Arg<int?>.Is.Anything, Arg<string>.Is.Anything))[0];
            Assert.AreEqual(null, args[0]);
            Assert.AreEqual(1, args[1]);
            Assert.AreEqual("Me", args[2]);

            CallForProposalRepository.AssertWasCalled(a => a.EnsurePersistent(Arg<CallForProposal>.Is.Anything));
            var args2 = (CallForProposal) CallForProposalRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg<CallForProposal>.Is.Anything))[0][0];
            Assert.IsNotNull(args2);
            Assert.AreEqual("UName", args2.Name);
            Assert.AreEqual("Updated", args2.Description);
            Assert.AreEqual(12.97m, args2.ProposalMaximum);
            Assert.AreEqual(new DateTime(2009, 12, 23).Date, args2.EndDate.Date);
            #endregion Assert
        }