public void ToDynamicTest()
 {
     var obj1 = new { Name = "GMF" };
     Assert.True(obj1.ToDynamic().Name == "GMF");
     var obj2 = new { Name = "GMF", Value = new { IsLocked = true } };
     Assert.True(obj2.ToDynamic().Value.IsLocked);
 }
Example #2
0
        public void Can_create_with_arrays()
        {
            // Arrange
            var input = new[] {1, 2, 3};

            // Act
            var sut = input.ToDynamic();

            // Assert
            Assert.IsInstanceOf<IEnumerable<dynamic>>(sut);
            Assert.AreEqual(3, sut.Count);
            Assert.AreEqual(1, sut[0]);
        }
Example #3
0
        public void Can_create_with_anonymous_objects_containing_arrays()
        {
            // Arrange
            var input = new
                {
                    Property = "test",
                    Array = new[]
                        {
                            new {Property = 1},
                            new {Property = 2},
                            new {Property = 3},
                        }
                };

            // Act
            var sut = input.ToDynamic();

            // Assert
            Assert.IsInstanceOf<ExpandoObject>(sut);
            Assert.IsInstanceOf<IEnumerable<dynamic>>(sut.Array);
            Assert.AreEqual(3, sut.Array.Count);
            Assert.AreEqual(1, sut.Array[0].Property);
        }
        /// <summary>
        /// tranform invoice object into Invoice email template
        /// </summary>
        /// <param name="user"></param>
        /// <param name="invoice"></param>
        /// <param name="unit">months, minutes, hours,...</param>
        /// <returns></returns>
        public string TranformToInvoiceTemplate(UserDto user, InvoiceDto invoice, string unit, string mailTemplateKey, List<InvoiceDto> listConsultationInvoiceForWalvedFee)
        {
            try
            {
                LocationDto location = user.Locations.First();
                bool hasDisplayMinimum = true;
                decimal originAmount = invoice.Amount - invoice.GST;
                decimal invoiceTotal = invoice.Amount;
                decimal walvedFee = 0;
                decimal subTotal = 0;
                int duration = invoice.Duration;
                decimal GST = invoice.GST;
                decimal ratePerMinute = GST > 0 ? invoice.RatePerMinute - SubtractGSTCalculator(invoice.RatePerMinute) : invoice.RatePerMinute;
                if (InvoiceType.OrderTranscript.Equals(invoice.Type) || InvoiceType.Prepayment.Equals(invoice.Type))
                {
                    hasDisplayMinimum = false;
                }
                else if (InvoiceType.WaiveFee.Equals(invoice.Type) && listConsultationInvoiceForWalvedFee != null)
                {
                    var customerInvoice = listConsultationInvoiceForWalvedFee.First(x => x.Booking.Customer.Id == x.User.Id && x.Type == InvoiceType.Consultation);
                    var specialistInvoice = listConsultationInvoiceForWalvedFee.First(x => x.Booking.Specialist.Id == x.User.Id && x.Type == InvoiceType.Consultation);
                    duration = customerInvoice.Duration;
                    originAmount = customerInvoice.Amount - customerInvoice.GST;
                    walvedFee = specialistInvoice.Amount - specialistInvoice.GST;
                    subTotal = originAmount - walvedFee;
                    GST = customerInvoice.GST > 0 ? SubtractGSTCalculator(customerInvoice.Amount - specialistInvoice.Amount) : 0;
                    ratePerMinute = GST > 0 ? customerInvoice.RatePerMinute - SubtractGSTCalculator(customerInvoice.RatePerMinute) : customerInvoice.RatePerMinute;
                    invoiceTotal = subTotal + GST;
                }

                object transformWith = new
                {
                    BaseUrl = baseUrl,
                    //- XXXXXXXX-X
                    InvoiceNumber = invoice.InvoiceNumber,
                    //- 27/02/2015
                    CreatedDate = invoice.CreatedDate.ToString(Infrastructure.Core.Const.SystemConfig.GlobalDateFormat),

                    Name = user.Name,
                    Street = string.Format("{0} {1}", location.StreetNumber, location.Street),
                    Country = string.Format("{0} {1} {2}", location.Country, location.Suburb, location.Postcode),
                    MobileNumber = user.MobileCountryCode + user.MobilePhone,
                    //- AUD USD VND ...
                    Currency = invoice.Currency,
                    Description = invoice.Description,
                    //- 1 (minutes) or 12 (months)
                    Duration = invoice.Type != InvoiceType.Subscription ? TimeSpan.FromSeconds(duration).ToString() : duration.ToString(),
                    Unit = unit,
                    //- $XX
                    Cost = invoice.Type == InvoiceType.Subscription ?
                            (originAmount - GST).ToString("C", new CultureInfo("en-Us"))
                            : ratePerMinute.ToString("C", new CultureInfo("en-Us")),
                    Amount = originAmount.ToString("C", new CultureInfo("en-Us")),
                    Total = invoiceTotal.ToString("C", new CultureInfo("en-Us")),
                    //WaivedFeeDescription = string.IsNullOrWhiteSpace(waiveFeeDescription) ? null : "*" + waiveFeeDescription,
                    IsWavedFee = InvoiceType.WaiveFee.Equals(invoice.Type) ? string.Empty : "display:none;",
                    WaivedFee = walvedFee.ToString("C", new CultureInfo("en-Us")),
                    Subtotal = subTotal.ToString("C", new CultureInfo("en-Us")),
                    IsGST = GST > 0 ? string.Empty : "display:none;",
                    GST = GST.ToString("C", new CultureInfo("en-Us")),
                    Minimum = (hasDisplayMinimum && invoice.Booking != null) ? string.Format(InvoiceConst.InvoiceMinimumDescription, invoice.Booking.CustomerMinCharge.ToString("C", new CultureInfo("en-Us"))) : string.Empty
                };

                var mailTemplate = ConfigurationManager.AppSettings[mailTemplateKey];

                var transformWithDynamic = transformWith.ToDynamic();
                //- Generate mail content from mail template and object transformWith (invoice information)
                string mailContent = StringExtend.TransformWithDynamic(File.ReadAllText(HostingEnvironment.MapPath(mailTemplate)), transformWithDynamic);

                return mailContent;
            }
            catch (Exception e)
            {
                Log.Error("Tranform to invoice template", e);
                return null;
            }
        }
        public string GetEmailContentOfInvoice(InvoiceDto invoice)
        {
            string result = string.Empty;
            string FirstFullName = invoice.User.Name;
            string SecondFullName = string.Empty;
            if (invoice.Booking != null)
            {
                SecondFullName = Role.Customer.Equals(invoice.User.Role) ? invoice.Booking.Specialist.Name : invoice.Booking.Customer.Name;
            }

            string ammount = invoice.Amount.ToString("C", new CultureInfo("en-Us"));
            switch (invoice.Type)
            {
                case InvoiceType.WaiveFee:
                case InvoiceType.Consultation:
                    result = string.Format(InvoiceEmailContent.ConsultationInvoices, FirstFullName, ammount, SecondFullName);
                    if (ConsultationType.MinimumCharge.Equals(invoice.ConsultationType))
                    {
                        result = string.Format(InvoiceEmailContent.CancelInvoices, FirstFullName, ammount, SecondFullName);
                    }
                    break;

                case InvoiceType.Subscription:
                    string subscriptionEndDate = Role.Specialist.Equals(invoice.User.Role) && invoice.User.Profile != null ? invoice.User.Profile.SubscriptionEndDate.ToString("dd/MM/yyyy") : string.Empty;
                    result = string.Format(InvoiceEmailContent.SubscriptionInvoices, FirstFullName, ammount, subscriptionEndDate);
                    break;

                case InvoiceType.Prepayment:
                    result = string.Format(InvoiceEmailContent.TopupInvoices, FirstFullName, ammount);
                    break;

                case InvoiceType.OrderTranscript:
                    result = string.Format(InvoiceEmailContent.OrderTranscriptInvoices, FirstFullName, ammount, SecondFullName);
                    break;

                default:
                    break;
            }

            if (!string.IsNullOrWhiteSpace(result))
            {
                object transformWith = new
                {
                    BaseUrl = AppSettings.BaseUrl,
                    content = result.Replace("\n", "<br/>")
                };
                var transformWithDynamic = transformWith.ToDynamic();
                result = StringExtend.TransformWithDynamic(File.ReadAllText(HostingEnvironment.MapPath(ConfigurationData.GeneralEmailTemplate())), transformWithDynamic);
            }

            return result;
        }
        public void GetPropOfAnonymousType_by_Dynamic()
        {
            object obj = new
            {
                Person = new
                {
                    Gender = Gender.Male,
                    Birthday = DateTime.Parse("1970/01/15"),
                    ProgramingLangs = new[] { "C#", "F#" }
                },
                Count = 1
            };

            Gender gender = obj.ToDynamic().Person.Gender;
            DateTime birthday = obj.ToDynamic().Person.Birthday;
            int birthdayYear = obj.ToDynamic().Person.Birthday.Year;
            string birthdayMonth = obj.ToDynamic().Person.Birthday.ToLocalTime().Month.ToString();
            string[] programingLangs = obj.ToDynamic().Person.ProgramingLangs;
            int count = obj.ToDynamic().Count;

            gender.Is(Gender.Male);
            birthday.Is(DateTime.Parse("1970/01/15"));
            birthdayYear.Is(1970);
            birthdayMonth.Is("1");
            programingLangs.Is("C#", "F#");
            count.Is(1);
        }