public void PasswordModelBinderShouldReturnValuesForSpecifiedQueryStrings() { var viewContext = new ViewContext(); viewContext.HttpContext = MockHttpContext.FakeHttpContext(); var appraisalCompanyAdminManagement = Substitute.For<IAppraiserManagement>(); var appraisalCompanyWizardService = Substitute.For<IAppraisalCompanyService>(); var controller = new AppraisalCompanyFeesController(appraisalCompanyWizardService, appraisalCompanyAdminManagement); controller.SetFakeControllerContext(viewContext.HttpContext); NameValueCollection queryString = new NameValueCollection(); controller.HttpContext.Request.QueryString.Returns(queryString); PasswordModelBinder target = new PasswordModelBinder(); var testCases = new[] { new {QueryStringParameterName="UserChangePasswordViewModel.NewPassword",Value="17"}, new {QueryStringParameterName="CreateUserGeneralInfoViewModel.Password",Value="42"}, new {QueryStringParameterName="Password",Value="2"}, new {QueryStringParameterName="NewPassword",Value="33"}, new {QueryStringParameterName="AppraisalCompanyAdmin.Password",Value="asd"}, new {QueryStringParameterName="GeneralInfo.Password",Value="sssssssssss"}, }; //act foreach (var testCase in testCases) { queryString.Add(testCase.QueryStringParameterName, testCase.Value); string result = (string)target.BindModel(controller.ControllerContext, new ModelBindingContext()); result.Should().BeEquivalentTo(testCase.Value); queryString.Remove(testCase.QueryStringParameterName); } }
public void FeeAdd_should_add_editable_fee_to_model() { var controller = new AppraisalCompanyFeesController(Substitute.For<IAppraisalCompanyService>(), Substitute.For<IAppraiserManagement>()); var result = new List<RefFeeProductType>(); result.Add(new RefFeeProductType() { DisplayName = "Test", Id = 1 }); _refRepository.GetFeeProductTypes().Returns(result); var model = new AppraisalCompanyFeesViewModel(); var actionResult = controller.FeeAdd(model); actionResult.Should().NotBeNull().And.BeOfType<PartialViewResult>(); ((PartialViewResult)actionResult).ViewName.Should().Be("Tables/AppraisalCompanyFees"); model.Fees.FeesItems.Count.Should().Be(1); model.Fees.FeesItems[0].IsEditable.Should().BeTrue(); }
public void FeeAdd_should_not_add_fee_if_fees_for_all_products_are_specified() { var controller = new AppraisalCompanyFeesController(Substitute.For<IAppraisalCompanyService>(), Substitute.For<IAppraiserManagement>()); var model = new AppraisalCompanyFeesViewModel(); foreach (var product in Singletones.ReferenceManager.GetReference(ReferenceType.FeeProducts, false)) { var fee = new FeeItemViewModel(); fee.ProductType = product.Key; model.Fees.FeesItems.Add(fee); } var actionResult = controller.FeeAdd(model); actionResult.Should().NotBeNull().And.BeOfType<PartialViewResult>(); ((PartialViewResult)actionResult).ViewName.Should().Be("Tables/AppraisalCompanyFees"); ((string)((PartialViewResult)actionResult).ViewBag.NotificationMessage).Should().BeEquivalentTo("You have already specified Fee for each available Product Type."); model.Fees.FeesItems.Count.Should().Be(model.Fees.FeesItems.Count); }
public void FeeAdd_should_save_editable_fee() { var viewContext = new ViewContext(); viewContext.HttpContext = MockHttpContext.FakeHttpContext(); IPrincipal user = new GenericPrincipal(new GenericIdentity("someUser"), null); viewContext.HttpContext.User.ReturnsForAnyArgs<IPrincipal>(user); var appraisalCompanyAdminManagement = Substitute.For<IAppraiserManagement>(); var appraisalCompanyWizardService = Substitute.For<IAppraisalCompanyService>(); appraisalCompanyAdminManagement.GetByEmail(Arg.Any<string>()).Returns(new AppraiserUser() { Company = new AppraisalCompanyDetail() { Id = 0 } }); appraisalCompanyWizardService.GetAppraisalCompanyFees(Arg.Any<int>()).Returns(new AppraisalCompanyFeesViewModel()); var controller = new AppraisalCompanyFeesController(appraisalCompanyWizardService, appraisalCompanyAdminManagement); controller.SetFakeControllerContext(viewContext.HttpContext); var model = new AppraisalCompanyFeesViewModel(); var feesList = new List<FeeItemViewModel>(); feesList.Add(new FeeItemViewModel() { Id = "1", IsEditable = true }); model.Fees.FeesItems = feesList; var actionResult = controller.FeeAdd(model); actionResult.Should().NotBeNull().And.BeOfType<PartialViewResult>(); ((PartialViewResult)actionResult).ViewName.Should().Be("Tables/AppraisalCompanyFees"); model.Fees.FeesItems.Count.Should().Be(2); model.Fees.FeesItems[0].IsEditable.Should().BeFalse(); model.Fees.FeesItems[1].IsEditable.Should().BeTrue(); }
public void FeeDel_should_throw_exception_if_trying_to_delete_nonexistent_fee() { var target = new AppraisalCompanyFeesController(Substitute.For<IAppraisalCompanyService>(), Substitute.For<IAppraiserManagement>()); var model = new AppraisalCompanyFeesViewModel(); var feesList = new List<FeeItemViewModel>(); feesList.Add(new FeeItemViewModel() { Id = "1" }); model.Fees.FeesItems = feesList; target.Invoking(t => t.FeeDel(model, "false id")).ShouldThrow<ApplicationException>().And.Message.Should().Contain("not found"); }