コード例 #1
0
        public void GetCreateReturnsViewModelWithProjectIdAndTemplateId()
        {
            // arrange
            Mock<IBidPackageServiceLayer> service = new Mock<IBidPackageServiceLayer>();
            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            Mock<INotificationSender> notice = new Mock<INotificationSender>();

            BidPackageController controller = new BidPackageController(service.Object, security.Object, notice.Object);

            // act
            var result = controller.Create(1, 1);

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsInstanceOfType(((ViewResult)result).ViewData.Model, typeof(EditBidPackageViewModel));
            Assert.AreEqual(1, ((EditBidPackageViewModel)((ViewResult)result).ViewData.Model).ProjectId);
            Assert.AreEqual(1, ((EditBidPackageViewModel)((ViewResult)result).ViewData.Model).TemplateId);
        }
コード例 #2
0
        public void PostCreateBidPackageExceptionReturnsModelStateErrors()
        {
            // arrange
            Mock<IBidPackageServiceLayer> service = new Mock<IBidPackageServiceLayer>();
            service.Setup(s => s.Create(It.IsAny<BidPackage>())).Throws(new Exception("my spoon is too big"));
            service.SetupGet(s => s.ValidationDic).Returns(new Dictionary<string, string> { { "Description", "You already have a bid package with this description" } });

            service.Setup(s => s.GetUser(It.IsAny<int>())).Returns(new UserProfile { CompanyId = 1, UserId = 1 });
            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            security.Setup(s => s.GetUserId("*****@*****.**")).Returns(1);

            Mock<INotificationSender> notice = new Mock<INotificationSender>();

            BidPackageController controller = new BidPackageController(service.Object, security.Object, notice.Object);

            Mock<IPrincipal> principal = new Mock<IPrincipal>();
            principal.Setup(p => p.Identity.Name).Returns("*****@*****.**");

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.SetupGet(c => c.HttpContext.User.Identity.Name).Returns("*****@*****.**");
            context.SetupGet(c => c.HttpContext.Request.IsAuthenticated).Returns(true);

            controller.ControllerContext = context.Object;

            EditBidPackageViewModel viewModel = new EditBidPackageViewModel
            {
                ProjectId = 1,
                TemplateId = 1,
                SelectedScope = new int[] { 1, 2, 3 },
                BidDateTime = new DateTime(2014, 2, 2, 17, 0, 0),
                Description = "booga booga"
            };

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

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsTrue(((ViewResult)result).ViewData.ModelState.ContainsKey("Exception"));
            Assert.AreEqual("my spoon is too big", ((ViewResult)result).ViewData.ModelState["Exception"].Errors[0].ErrorMessage.ToString());
        }
コード例 #3
0
        public void PostCreateValidBidPackageRedirectsToDetails()
        {
            // arrange
            Mock<IBidPackageServiceLayer> service = new Mock<IBidPackageServiceLayer>();
            service.Setup(s => s.Create(It.IsAny<BidPackage>())).Returns(true);
            service.Setup(s => s.GetUser(It.IsAny<int>())).Returns(new UserProfile { CompanyId = 1, UserId = 1 });
            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            security.Setup(s => s.GetUserId("*****@*****.**")).Returns(1);
            Mock<INotificationSender> notice = new Mock<INotificationSender>();

            BidPackageController controller = new BidPackageController(service.Object, security.Object, notice.Object);

            Mock<IPrincipal> principal = new Mock<IPrincipal>();
            principal.Setup(p => p.Identity.Name).Returns("*****@*****.**");

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.SetupGet(c => c.HttpContext.User.Identity.Name).Returns("*****@*****.**");
            context.SetupGet(c => c.HttpContext.Request.IsAuthenticated).Returns(true);

            controller.ControllerContext = context.Object;

            EditBidPackageViewModel viewModel = new EditBidPackageViewModel
            {
                ProjectId = 1,
                TemplateId = 1,
                SelectedScope = new int[] { 1, 2, 3 },
                BidDateTime = new DateTime(2014, 2, 2, 17, 0, 0),
                Description = "booga booga"
            };

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

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual("BidPackage", ((RedirectToRouteResult)result).RouteValues["controller"].ToString());
            Assert.AreEqual("Details", ((RedirectToRouteResult)result).RouteValues["action"].ToString());
        }