public void CreateMappings(IProfileExpression configuration) { configuration.CreateMap <StudentResponseModel, StudentResponseViewModel>() .ForMember(x => x.CreatedOn, opt => opt.MapFrom(x => DateTimeMapper.Map(x.CreatedOn))) .ForMember(x => x.ModifiedOn, opt => opt.MapFrom(x => DateTimeMapper.Map(x.ModifiedOn))) .ForMember(x => x.DateOfBirth, opt => opt.MapFrom(x => DateTimeMapper.Map(x.DateOfBirth))); }
public void Ctor_Default() { var item = new DateTimeMapper(); Assert.Equal(new string[] { "G" }, item.Formats); Assert.Null(item.Provider); Assert.Equal(DateTimeStyles.None, item.Style); }
public void CreateMappings(IProfileExpression configuration) { configuration.CreateMap <SemesterResponseModel, SemesterResponseViewModel>() .ForMember(x => x.CreatedOn, opt => opt.MapFrom(x => DateTimeMapper.Map(x.CreatedOn))) .ForMember(x => x.ModifiedOn, opt => opt.MapFrom(x => DateTimeMapper.Map(x.ModifiedOn))) .ForMember(x => x.StartDate, opt => opt.MapFrom(x => DateTimeMapper.Map(x.StartDate))) .ForMember(x => x.EndDate, opt => opt.MapFrom(x => DateTimeMapper.Map(x.EndDate))); }
public static async Task <ICollection <LogMessage> > GetLoggingAsync(string loglevel, string from, string through) { var fromUnixMs = DateTimeMapper.ToUnixMs(from); var throughUnixMs = DateTimeMapper.ToUnixMs(through); var result = await Repository.GetLogging(loglevel, fromUnixMs, throughUnixMs); return(result.Select(l => new LogMessage(l)).ToList()); }
public void Styles_Set_GetReturnsExpected(DateTimeStyles style) { var item = new DateTimeMapper { Style = style }; Assert.Equal(style, item.Style); }
public LogMessage(LogEntry l) { DateTime = DateTimeMapper.ToString(l.Timestamp); Level = l.LogLevel; CallSite = l.CallSite ?? string.Empty; Message = l.Message ?? string.Empty; Exception = l.Exception; }
public void Formats_SetValid_GetReturnsExpected() { var formats = new string[] { null, "", "abc" }; var item = new DateTimeMapper { Formats = formats }; Assert.Same(formats, item.Formats); }
public void Provider_Set_GetReturnsExpected() { IFormatProvider provider = CultureInfo.CurrentCulture; var item = new DateTimeMapper { Provider = provider }; Assert.Same(provider, item.Provider); }
public GpsMeasurement(GpsEntry g) { //TODO JV RadioID = g.RadioId ?? 0; Timestamp = DateTimeMapper.ToString(g.Timestamp); Latitude = g.Latitude; Longitude = g.Longitude; Rssi = g.Rssi; }
public void WithDateFormats_NullableAutoMappedIEnumerableString_Success(IEnumerable <string> formats) { SingleExcelPropertyMap <DateTime?> propertyMap = Map(t => t.NullableDateValue); Assert.Same(propertyMap, propertyMap.WithDateFormats(formats)); DateTimeMapper item = propertyMap.CellValueMappers.OfType <DateTimeMapper>().Single(); Assert.Equal(formats, item.Formats); }
public void WithDateFormats_AutoMappedIEnumerableString_Success(IEnumerable <string> formats) { OneToOneMap <DateTime> propertyMap = Map(t => t.DateValue); Assert.Same(propertyMap, propertyMap.WithDateFormats(formats)); DateTimeMapper item = propertyMap.Pipeline.CellValueMappers.OfType <DateTimeMapper>().Single(); Assert.Equal(formats, item.Formats); }
public void GetProperty_InvalidStringValue_ReturnsInvalid(string stringValue) { var item = new DateTimeMapper(); object value = 1; PropertyMapperResultType result = item.MapCellValue(new ReadCellValueResult(-1, stringValue), ref value); Assert.Equal(PropertyMapperResultType.Invalid, result); Assert.Equal(1, value); }
public void WithDateFormats_NullableAutoMappedStringArray_Success(IEnumerable <string> formats) { var formatsArray = formats.ToArray(); SingleExcelPropertyMap <DateTime?> propertyMap = Map(t => t.NullableDateValue); Assert.Same(propertyMap, propertyMap.WithDateFormats(formatsArray)); DateTimeMapper item = propertyMap.CellValueMappers.OfType <DateTimeMapper>().Single(); Assert.Same(formatsArray, item.Formats); }
public void WithDateFormats_AutoMappedStringArray_Success(IEnumerable <string> formats) { var formatsArray = formats.ToArray(); OneToOneMap <DateTime> propertyMap = Map(t => t.DateValue); Assert.Same(propertyMap, propertyMap.WithDateFormats(formatsArray)); DateTimeMapper item = propertyMap.Pipeline.CellValueMappers.OfType <DateTimeMapper>().Single(); Assert.Same(formatsArray, item.Formats); }
public void GetProperty_ValidStringValue_ReturnsSuccess(string stringValue, string[] formats, DateTimeStyles style, DateTime expected) { var item = new DateTimeMapper { Formats = formats, Style = style }; object value = null; PropertyMapperResultType result = item.MapCellValue(new ReadCellValueResult(-1, stringValue), ref value); Assert.Equal(PropertyMapperResultType.Success, result); Assert.Equal(expected, value); }
public Task <ICollection <GpsMeasurement> > GetGpsHistory([FromUri] IEnumerable <int> id, [FromUri] string from, [FromUri] string through) { var f = DateTimeMapper.ToDateTime(from); var t = DateTimeMapper.ToDateTime(through); if (f.HasValue && t.HasValue && f > t) { var message = "From need to be before through"; throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message)); } return(TrboPortalHelper.GetGpsMeasurementsAsync(id, f, t)); }
private static void AddFormats(this ISinglePropertyMap propertyMap, string[] formats) { if (formats == null) { throw new ArgumentNullException(nameof(formats)); } if (formats.Length == 0) { throw new ArgumentException("Formats cannot be empty.", nameof(formats)); } var dateTimeItem = (DateTimeMapper)propertyMap.CellValueMappers.FirstOrDefault(item => item is DateTimeMapper); if (dateTimeItem == null) { dateTimeItem = new DateTimeMapper(); propertyMap.AddCellValueMapper(dateTimeItem); } dateTimeItem.Formats = formats; }
public void CreateMappings(IProfileExpression configuration) { configuration.CreateMap <DisciplineResponseModel, DisciplineResponseViewModel>() .ForMember(x => x.CreatedOn, opt => opt.MapFrom(x => DateTimeMapper.Map(x.CreatedOn))) .ForMember(x => x.ModifiedOn, opt => opt.MapFrom(x => DateTimeMapper.Map(x.ModifiedOn))); }
public override string ToString() => $"{DateTimeMapper.ToString(Timestamp)} {LogLevel} {CallSite} {Message} {Exception}";
public void Formats_SetEmpty_ThrowsArgumentException() { var item = new DateTimeMapper(); Assert.Throws <ArgumentException>("value", () => item.Formats = new string[0]); }
public void Formats_SetNull_ThrowsArgumentNullException() { var item = new DateTimeMapper(); Assert.Throws <ArgumentNullException>("value", () => item.Formats = null); }
private static bool AutoMap(this Type memberType, FallbackStrategy emptyValueStrategy, out ICellValueMapper mapper, out IFallbackItem emptyFallback, out IFallbackItem invalidFallback) { Type type = memberType.GetNullableTypeOrThis(out bool isNullable); Type[] interfaces = type.GetTypeInfo().ImplementedInterfaces.ToArray(); IFallbackItem ReconcileFallback(FallbackStrategy strategyToPursue, bool empty) { // Empty nullable values should be set to null. if (empty && isNullable) { return(new FixedValueFallback(null)); } else if (strategyToPursue == FallbackStrategy.SetToDefaultValue || emptyValueStrategy == FallbackStrategy.SetToDefaultValue) { return(new FixedValueFallback(type.DefaultValue())); } else { Debug.Assert(emptyValueStrategy == FallbackStrategy.ThrowIfPrimitive); // The user specified that we should set to the default value if it was empty. return(new ThrowFallback()); } } if (type == typeof(DateTime)) { mapper = new DateTimeMapper(); emptyFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, empty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, empty: false); } else if (type == typeof(bool)) { mapper = new BoolMapper(); emptyFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, empty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, empty: false); } else if (type.GetTypeInfo().IsEnum) { mapper = new EnumMapper(type); emptyFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, empty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, empty: false); } else if (type == typeof(string) || type == typeof(object) || type == typeof(IConvertible)) { mapper = new StringMapper(); emptyFallback = ReconcileFallback(FallbackStrategy.SetToDefaultValue, empty: true); invalidFallback = ReconcileFallback(FallbackStrategy.SetToDefaultValue, empty: false); } else if (type == typeof(Uri)) { mapper = new UriMapper(); emptyFallback = ReconcileFallback(FallbackStrategy.SetToDefaultValue, empty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, empty: false); } else if (interfaces.Any(t => t == typeof(IConvertible))) { mapper = new ChangeTypeMapper(type); emptyFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, empty: true); invalidFallback = ReconcileFallback(FallbackStrategy.ThrowIfPrimitive, empty: false); } else { mapper = null; emptyFallback = null; invalidFallback = null; return(false); } return(true); }