public void PostSendInvalidModelReturnsViewWithModelStatErros()
        {
            // arrange
            Mock<IInvitationServiceLayer> service = new Mock<IInvitationServiceLayer>();
            service.Setup(s => s.CreateRange(It.IsAny<IEnumerable<Invitation>>())).Returns(false);
            service.SetupGet(s => s.ValidationDic).Returns(new Dictionary<string, string> { { "Duplicate", "There is already an invitation sent to this company" } });
            service.Setup(s => s.GetBidPackage(1)).Returns(new BidPackage { Id = 1, ProjectId = 1 });

            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            Mock<INotificationSender> notify = new Mock<INotificationSender>();

            InvitationController controller = new InvitationController(service.Object, security.Object, notify.Object);

            BidPackageInvitationViewModel viewModel = new BidPackageInvitationViewModel();
            viewModel.BidPackageId = 1;
            viewModel.CompanyId = new int[] { 1, 2, 3, 4, 5, 6 };

            // act
            var result = controller.SendForBidPackage(viewModel);

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsInstanceOfType(((ViewResult)result).ViewData.Model, typeof(BidPackageInvitationViewModel));
            Assert.AreEqual(1, ((BidPackageInvitationViewModel)((ViewResult)result).ViewData.Model).BidPackageId);
            Assert.AreEqual("There is already an invitation sent to this company", ((ViewResult)result).ViewData.ModelState["Duplicate"].Errors[0].ErrorMessage);
        }
Exemplo n.º 2
0
        // GET: /Project/Invitation/Send/1
        public ActionResult SendForBidPackage(int bidPackageId)
        {
            var raw = _service.GetBidPackage(bidPackageId);
            BidPackageInvitationViewModel viewModel = new BidPackageInvitationViewModel();
            viewModel.BidPackageId = bidPackageId;
            viewModel.ProjectId = raw.ProjectId;
            viewModel.ProjectName = raw.Project.Title;
            viewModel.BidPackageTitle = raw.Description;
            viewModel.BPScopeCount = _service.GetBidPackageScopesDeepestScopes(bidPackageId).Count();

            return View(viewModel);
        }
Exemplo n.º 3
0
        public ActionResult SendForBidPackage(BidPackageInvitationViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    List<Invitation> invites = new List<Invitation>();
                    foreach (var c in viewModel.CompanyId)
                    {
                        invites.Add(new Invitation { BidPackageId = viewModel.BidPackageId, SentToId = c, SentDate = DateTime.Now, InvitationType = InvitationType.SentFromCreatedBy });
                    }
                    // if successfully create invites
                    if (_service.CreateRange(invites))
                    {
                        int projectId = _service.GetBidPackage(viewModel.BidPackageId).ProjectId;

                        // send notices to all invited companies
                        for (int i = 0; i < invites.Count; i++)
                        {
                            if (!_notify.SendNotification(invites[i].SentToId, RecipientType.company, NotificationType.InvitationToBid, projectId,EntityType.Project))
                                throw new HttpException(500, "there was a problem sending notices");
                        }

                        return RedirectToRoute("Default", new { controller = "Project", action = "Details", id = projectId });
                    }
                    else
                    {
                        Util.MapValidationErrors(_service.ValidationDic, this.ModelState);
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Exception", ex.Message);
                }
            }

            return View( viewModel);
        }
        public void PostSendValidModelRedirectsToProjectDetails()
        {
            // arrange
            Mock<IInvitationServiceLayer> service = new Mock<IInvitationServiceLayer>();
            service.Setup(s => s.CreateRange(It.IsAny<IEnumerable<Invitation>>())).Returns(true);
            service.Setup(s => s.GetBidPackage(1)).Returns(new BidPackage { Id = 1, ProjectId = 1 });

            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            Mock<INotificationSender> notify = new Mock<INotificationSender>();

            InvitationController controller = new InvitationController(service.Object, security.Object, notify.Object);

            BidPackageInvitationViewModel viewModel = new BidPackageInvitationViewModel();
            viewModel.BidPackageId = 1;
            viewModel.CompanyId = new int[] { 1, 2, 3, 4, 5, 6 };

            // act
            var result = controller.SendForBidPackage(viewModel);

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual("Project", ((RedirectToRouteResult)result).RouteValues["Controller"]);
            Assert.AreEqual("Details", ((RedirectToRouteResult)result).RouteValues["Action"]);
            Assert.AreEqual(1, ((RedirectToRouteResult)result).RouteValues["id"]);
        }