Beispiel #1
0
		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_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();
		}