public void Test_WillGetPreviousMonthOfCurrentMonth()
        {
            int expected = DateTimeCalculator.GetPreviousMonth(DateTime.Now.Month);

            int actual = DateTimeCalculator.PreviousMonth;

            Assert.Equal(expected, actual);
        }
        public void Test_WillGetDecemberIfIsJenuary()
        {
            int expected = 12;

            int actual = DateTimeCalculator.GetPreviousMonth(1);

            Assert.Equal(expected, actual);
        }
示例#3
0
        public int[] GetVisitTimes()
        {
            SqlDataAccess      sql    = new SqlDataAccess();
            List <VisitModel>  visits = sql.LoadData <VisitModel, dynamic>("dbo.spVisitTimesList", new { }, "MeatAndMoreData");
            DateTimeCalculator calc   = new DateTimeCalculator();

            return(calc.CalculateHourDifference(visits));
        }
示例#4
0
        public void AgeTests(string creatingDateTimeStr, string nowDateTimeStr, string ageExpectedDateTimeStr, string expectedAgeDescription)
        {
            var creatingParts = creatingDateTimeStr
                                .Split('.')
                                .Select(int.Parse)
                                .ToList();
            var nowParts = nowDateTimeStr
                           .Split('.')
                           .Select(int.Parse)
                           .ToList();
            var creatingDateTime = new DateTime(creatingParts[0], creatingParts[1], creatingParts[2], creatingParts[3], creatingParts[4], 0);
            var nowDateDime      = new DateTime(nowParts[0], nowParts[1], nowParts[2], nowParts[3], nowParts[4], 0);
            var age = DateTimeCalculator.CalculateAge(creatingDateTime, nowDateDime);
            var ageExpectedParts = ageExpectedDateTimeStr
                                   .Split('.')
                                   .Select(int.Parse)
                                   .ToList();
            var ageDescription = DateTimeCalculator.GetAgeDescription(creatingDateTime, nowDateDime);

            Assert.AreEqual(new TimeSpan(ageExpectedParts[0], ageExpectedParts[1], ageExpectedParts[2], 0), age);
            Assert.AreEqual(expectedAgeDescription, ageDescription);
        }
示例#5
0
        public static Action <IMapperConfigurationExpression> CreateMappingExpression()
        {
            return(opt =>
            {
                opt.CreateMap <LocalRegisterUserDto, User>()
                .ForMember(dest => dest.UserName, opts => opts.MapFrom(src => src.Email))
                .ForMember(dest => dest.RegisteredWith, opts => opts.MapFrom(_ => LoginProvider.Local));

                opt.CreateMap <ExternalRegisterUserDto, User>()
                .ForMember(dest => dest.UserName, opts => opts.MapFrom(src => src.Email));

                opt.CreateMap <FacebookUserDto, ExternalRegisterUserDto>()
                .ForMember(dest => dest.PictureSrc, opts => opts.MapFrom(src => src.Picture.PictureDataDto.Url));

                opt.CreateMap <User, UserDto>()
                .ForMember(dest => dest.HasLocalAccount, opts => opts.MapFrom(src => src.HasLocalAccount()))
                .AfterMap((src, dest) =>
                {
                    if (dest.PictureSrc == null)
                    {
                        dest.PictureSrc = $"{Profile.GravatarUrl}{src.Email.ToMdHashed()}{Profile.GravatarSize}";
                    }
                });

                opt.CreateMap <UserWallet, WalletParticipantDto>();

                opt.CreateMap <AddWalletDto, Wallet>()
                .ForMember(dest => dest.Category,
                           opts => opts.MapFrom(src => src.Category.ToEnumValue <WalletCategory>()))
                .ForMember(dest => dest.DefaultCurrency,
                           opts => opts.MapFrom(src => src.Category.ToEnumValue <SupportedCurrencies>()));

                opt.CreateMap <UserWallet, BaseWalletDto>()
                .ForMember(dest => dest.Id,
                           opts => opts.MapFrom(src => src.WalletId.ToObfuscated()))
                .ForMember(dest => dest.Category,
                           opts => opts.MapFrom(src => src.Wallet.Category.GetStringValue()))
                .ForMember(dest => dest.Role,
                           opts => opts.MapFrom(src => src.Role.GetStringValue()))
                .ForMember(dest => dest.DefaultCurrency,
                           opts => opts.MapFrom(src => src.Wallet.DefaultCurrency.GetStringValue()))
                .ForMember(dest => dest.Name,
                           opts => opts.MapFrom(src => src.Wallet.Name));


                opt.CreateMap <UserWallet, ExtendedWalletDto>()
                .IncludeBase <UserWallet, BaseWalletDto>()
                .ForMember(dest => dest.Participants,
                           opts => opts.MapFrom(src =>
                                                src.Wallet.UserWallets.Where(x => x.UserId != src.UserId)));

                opt.CreateMap <BaseModifyExpenseDto, Expense>()
                .ForMember(dest => dest.WalletId,
                           opts => opts.MapFrom(src => src.WalletId.ToDeobfuscated()));

                opt.CreateMap <BaseModifyExpenseDto, CyclicExpense>()
                .ForMember(dest => dest.WalletId,
                           opts => opts.MapFrom(src => src.WalletId.ToDeobfuscated()));


                opt.CreateMap <ModifyExpenseDto, Expense>()
                .IncludeBase <BaseModifyExpenseDto, Expense>();

                opt.CreateMap <AddCyclicExpenseDto, CyclicExpense>()
                .IncludeBase <BaseModifyExpenseDto, CyclicExpense>();


                opt.CreateMap <ExpenseSearchResult, ExpenseDto>()
                .ForMember(dest => dest.Category,
                           opts => opts.MapFrom(src => src.Category.GetStringValue()))
                .ForMember(dest => dest.Type,
                           opts => opts.MapFrom(src => src.Type.GetStringValue()));

                opt.CreateMap <Expense, ExpenseDto>()
                .ForMember(dest => dest.Category,
                           opts => opts.MapFrom(src => src.Category.GetStringValue()))
                .ForMember(dest => dest.Type,
                           opts => opts.MapFrom(src => src.Type.GetStringValue()));

                opt.CreateMap <CyclicExpense, Expense>()
                .ForMember(dest => dest.CyclicExpenseId,
                           opts => opts.MapFrom(src => src.Id));

                opt.CreateMap <CyclicExpense, CyclicExpenseDto>()
                .ForMember(dest => dest.Category,
                           opts => opts.MapFrom(src => src.Category.GetStringValue()))
                .ForMember(dest => dest.Type,
                           opts => opts.MapFrom(src => src.Type.GetStringValue()))
                .ForMember(dest => dest.PeriodType,
                           opts => opts.MapFrom(src => src.PeriodType.GetStringValue()))
                .ForMember(dest => dest.NextApplyingDate, opts => opts.MapFrom(src =>
                                                                               src.StartingFrom.Date >= DateTime.UtcNow.Date || src.LastApplied == default
                            ? src.StartingFrom
                            : DateTimeCalculator.GetNextApplyingDate(src.LastApplied, src.PeriodType)
                                                                               ));
            });
        }
 private DateTime GetNextAplyingDate(CyclicExpensePeriodType period, DateTime date)
 {
     return(DateTimeCalculator.GetNextApplyingDate(date, period));
 }
        public void Test_WillGetPreviousMonth(int month, int expected)
        {
            int actual = DateTimeCalculator.GetPreviousMonth(month);

            Assert.Equal(expected, actual);
        }