Example #1
0
        /// <summary>
        ///     Setup our DTO mapping profile.
        /// </summary>
        internal static void SetupProfile(IMapperConfigurationExpression mapper)
        {
            if (mapper is null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            mapper.CreateMap <FollowRequest, FollowRequestDto>()
            .ForMember(dest => dest.ReceiverId, o => o.MapFrom(src => src.Id.ReceiverId))
            .ForMember(dest => dest.RequesterId, o => o.MapFrom(src => src.Id.RequesterId));
            mapper.CreateMap <Reaction, ReactionDto>().ReverseMap();
            mapper.CreateMap <ReactionWrapper, ReactionWrapperDto>();
            mapper.CreateMap <TokenWrapper, TokenWrapperDto>();
            mapper.CreateMap <UploadWrapper, UploadWrapperDto>();
            mapper.CreateMap <User, UserDto>();
            mapper.CreateMap <User, UserCompleteDto>();
            mapper.CreateMap <UserWithStats, UserWithStatsDto>();
            mapper.CreateMap <UserWithRelationWrapper, UserWithRelationWrapperDto>();
            mapper.CreateMap <Vlog, VlogDto>().ReverseMap();
            mapper.CreateMap <VlogWrapper, VlogWrapperDto>();
            mapper.CreateMap <VlogLike, VlogLikeDto>()
            .ForMember(dest => dest.UserId, o => o.MapFrom(src => src.Id.UserId))
            .ForMember(dest => dest.VlogId, o => o.MapFrom(src => src.Id.VlogId));
            mapper.CreateMap <VlogLikeSummary, VlogLikeSummaryDto>();
            mapper.CreateMap <VlogLikingUserWrapper, VlogLikingUserWrapperDto>();

            // Create custom mapping for time zone types
            mapper.CreateMap <TimeZoneInfo, string>().ConvertUsing(tz => tz == null
                ? null
                : TimeZoneInfoHelper.MapTimeZoneToStringOrNull(tz));
            mapper.CreateMap <string, TimeZoneInfo>().ConvertUsing(s => string.IsNullOrEmpty(s)
                ? null
                : TimeZoneInfoHelper.MapStringToTimeZone(s));
        }
        public void NullTimeZoneMapsToNull()
        {
            // Act.
            var result = TimeZoneInfoHelper.MapTimeZoneToStringOrNull(null);

            // Assert.
            Assert.Null(result);
        }
        public void MappedTimeZoneInfoMatchesRegex()
        {
            // Arrange.
            var timeZoneInfo = TimeZoneInfo.Utc;

            // Act.
            var result = TimeZoneInfoHelper.MapTimeZoneToStringOrNull(timeZoneInfo);

            // Assert.
            Assert.Matches(RegexConstants.TimeZoneRegex, result);
        }
Example #4
0
 /// <summary>
 ///     Maps a swabbr user entity onto a writer.
 /// </summary>
 /// <param name="context">The context to add parameters to.</param>
 /// <param name="user">The user object.</param>
 private static void MapToWriter(DatabaseContext context, User user)
 {
     context.AddParameterWithValue("birth_date", user.BirthDate);
     context.AddParameterWithValue("country", user.Country);
     context.AddParameterWithValue("daily_vlog_request_limit", (int)user.DailyVlogRequestLimit);
     context.AddParameterWithValue("first_name", user.FirstName);
     context.AddParameterWithValue("follow_mode", user.FollowMode);
     context.AddParameterWithValue("gender", user.Gender);
     context.AddParameterWithValue("has_profile_image", user.HasProfileImage);
     context.AddParameterWithValue("is_private", user.IsPrivate);
     context.AddParameterWithValue("last_name", user.LastName);
     context.AddParameterWithValue("latitude", user.Latitude);
     context.AddParameterWithValue("longitude", user.Longitude);
     context.AddParameterWithValue("nickname", user.Nickname);
     context.AddParameterWithValue("timezone", TimeZoneInfoHelper.MapTimeZoneToStringOrNull(user.TimeZone));
 }