Exemple #1
0
        public void GetTagContent_WhenTagAndContentExists_ReturnContent()
        {
            var tagContent = "sampleContent";
            var result     = _xmlProcessor.GetTagContent("test", $"this is a <test>{tagContent}</test> xml");

            Assert.AreEqual(result, tagContent);
        }
Exemple #2
0
 public static IRuleBuilderOptions <T, string> IsValidDateFormat <T>(this IRuleBuilder <T, string> ruleBuilder, IXmlProcessor xmlProcessor, string tagName)
 {
     return(ruleBuilder.Must((rootObject, value, context) =>
     {
         context.MessageFormatter.AppendArgument("TagName", tagName);
         var tagContent = xmlProcessor.GetTagContent(tagName, value);
         if (string.IsNullOrEmpty(tagContent))
         {
             return true;
         }
         return DateTime.TryParse(tagContent, out _);
     })
            .WithMessage("'{PropertyName}' has '{TagName}' content which is an invalid date format."));
 }
        public async Task <ExpenseClaimResponseDto> Handle(CreateExpenseClaimCommand request, CancellationToken cancellationToken)
        {
            var expenseClaim = new ExpenseClaim();

            PropertyInfo[] properties = typeof(ExpenseClaim).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if (property.CustomAttributes.Count() > 0)
                {
                    var xmlTag = property.CustomAttributes.First().ConstructorArguments.First().Value.ToString();
                    property.SetValue(expenseClaim, _xmlProcessor.GetTagContent(xmlTag, request.Message));
                }
            }
            return(_mapper.Map <ExpenseClaimResponseDto>(expenseClaim));
        }
        public async Task <ReservationResponseDto> Handle(CreateReservationCommand request, CancellationToken cancellationToken)
        {
            var reservation = new Reservation();

            PropertyInfo[] properties = typeof(Reservation).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if (property.CustomAttributes.Count() > 0)
                {
                    var xmlTag = property.CustomAttributes.First().ConstructorArguments.First().Value.ToString();
                    property.SetValue(reservation, _xmlProcessor.GetTagContent(xmlTag, request.Message));
                }
            }
            return(_mapper.Map <ReservationResponseDto>(reservation));
        }