public void TestRainfallStationIdGroup() { Mapper.CreateMap <Rainfall, RainfallTimeAndValue>(); Mapper.CreateMap <IQueryable <Rainfall>, RainfallGroupedByStation>() .ForMember(r => r.RainfallStation, opt => opt.MapFrom(g => g.FirstOrDefault().RainfallStation)) .ForMember(r => r.RainfallTimeAndValues, opt => opt.MapFrom(g => g)); List <RainfallGroupedByStation> rainfallGroups = RainfallService.GetGroupFromSources <Rainfall, RainfallGroupedByStation>(this._rainfalls.AsQueryable(), r => r.RainfallStation.Id).ToList(); Assert.AreEqual(2, rainfallGroups.Count); Assert.AreEqual("D2020", rainfallGroups[1].RainfallStation.Id); Assert.AreEqual(new DateTime(2014, 7, 1, 17, 10, 0), rainfallGroups[1].RainfallTimeAndValues[0].CollectTime); Assert.AreEqual(1.01, rainfallGroups[1].RainfallTimeAndValues[1].Value); }
public void TestRainfallSumGroup() { Mapper.CreateMap <IQueryable <Rainfall>, SumRainfall>() .ForMember(s => s.SumValue, opt => opt.MapFrom(a => a.Sum(r => r.Value))) .ForMember(s => s.RainfallStation, opt => opt.MapFrom(g => g.FirstOrDefault().RainfallStation)); // var map=Mapper.FindTypeMapFor<IQueryable<Rainfall>, SumRainfall>(); // Mapper.DynamicMap(true, SumRainfall); List <SumRainfall> sumrainfalls = RainfallService.GetGroupFromSources <Rainfall, SumRainfall> (this._rainfalls.AsQueryable(), r => r.RainfallStation.Id).ToList(); Assert.AreEqual(2, sumrainfalls.Count); Assert.AreEqual(1, sumrainfalls[0].SumValue); Assert.AreEqual(2.02, sumrainfalls[1].SumValue); Assert.IsNotNull(sumrainfalls[0].RainfallStation); Assert.IsNotNull(sumrainfalls[1].RainfallStation); Assert.AreEqual("D1010", sumrainfalls[0].RainfallStation.Id); }