Example #1
0
		public void FillFees(ICollection<AppraiserFee> fees, FeesViewModel feesViewModel)
		{
			if (fees == null)
			{
				throw new ArgumentNullException("fees");
			}
			if (feesViewModel == null)
			{
				throw new ArgumentNullException("fees view model");
			}
			var feesArray = fees.ToArray();
			foreach (var fee in feesArray)
			{
				if (!feesViewModel.FeesItems.Any(f => f.Id == fee.Id.ToString()))
				{
					fees.Remove(fee);
				}
			}
			foreach (var item in feesViewModel.FeesItems)
			{
				if (string.IsNullOrEmpty(_refManager.GetProductNameById(item.ProductType)))
				{
					throw new ArgumentException("product id");
				}
				var fee = fees.SingleOrDefault(e => e.Id.ToString() == item.Id);
				if (fee == null)
				{
					fee = new AppraiserFee();
					fees.Add(fee);
				}
				fee.Amount = item.Fee.Value;
				fee.ProductId = item.ProductType;
			}
		}
Example #2
0
		public void FillFees_should_throw_exeption_if_any_argument_is_null()
		{
			var feesViewModel = new FeesViewModel();
			List<AppraiserFee> fees = new List<AppraiserFee>();
			var refManager = Substitute.For<IReferenceManagement>();
			var feeManager = new FeeManager(refManager);
			feeManager.Invoking(fm => fm.FillFees(null, feesViewModel)).ShouldThrow<ArgumentNullException>().And.ParamName.Should().Contain("fees");
			feeManager.Invoking(fm => fm.FillFees(fees, null)).ShouldThrow<ArgumentNullException>().And.ParamName.Should().Contain("fees view model");
		}
Example #3
0
		public FeesViewModel GetFeesViewModel(ICollection<AppraiserFee> fees)
		{
			var feesViewModel = new FeesViewModel();
			feesViewModel.FeesItems = new List<FeeItemViewModel>();

			foreach (var fee in fees)
			{
				var feeItemViewModel = new FeeItemViewModel();
				feeItemViewModel.Id = fee.Id.ToString();
				feeItemViewModel.ProductType = fee.ProductId;
				feeItemViewModel.Fee = fee.Amount;
				feeItemViewModel.ProductName = _refManager.GetProductNameById(fee.ProductId);
				feesViewModel.FeesItems.Add(feeItemViewModel);
			}
			return feesViewModel;
		}
Example #4
0
		public void FillFees_should_fill_in_properties_correctly()
		{
			var refManager = Substitute.For<IReferenceManagement>();
			refManager.GetProductNameById(3).Returns("name1");
			refManager.GetProductNameById(4).Returns("name2");
			var feeManager = new FeeManager(refManager);
			List<AppraiserFee> actual = new List<AppraiserFee>();
			actual.Add(new AppraiserFee(){Id = 1, ProductId = 1, Amount = 1.1 });
			actual.Add(new AppraiserFee(){Id = 2, ProductId = 2, Amount = 10.1 });
			var feesViewModel = new FeesViewModel();
			feesViewModel.FeesItems.Add(new FeeItemViewModel() { Id = "2", ProductType = 3, Fee = 20 });
			feesViewModel.FeesItems.Add(new FeeItemViewModel() { Id = Guid.NewGuid().ToString(), ProductType = 4, Fee = 200 });
			feeManager.FillFees(actual, feesViewModel);
			for (int i = 0; i < actual.Count; i++)
			{
				actual[i].Id.ToString().Should().BeEquivalentTo(actual[i].Id == 0 ? "0" : feesViewModel.FeesItems[i].Id);
				actual[i].Amount.Should().BeGreaterOrEqualTo(feesViewModel.FeesItems[i].Fee.Value).And.BeLessOrEqualTo(feesViewModel.FeesItems[i].Fee.Value);
				actual[i].ProductId.Should().Be(feesViewModel.FeesItems[i].ProductType);
			}
		}
Example #5
0
		public void FillFees_should_throw_exeption_if_passed_invalid_product_type()
		{
			var refManager = Substitute.For<IReferenceManagement>();
			refManager.GetProductNameById(1).Returns("name1");
			var feeManager = new FeeManager(refManager);
			List<AppraiserFee> model = new List<AppraiserFee>();
			var feesViewModel = new FeesViewModel();
			feesViewModel.FeesItems.Add(new FeeItemViewModel() { Id = "2", ProductType = 200, Fee = 20 });
			feeManager.Invoking(m => m.FillFees(model, feesViewModel)).ShouldThrow<ArgumentException>().And.Message.Should().Contain("product id"); ;
		}