public void СalculationPeriodTest_NotIndecationOnStart_Should_ThrowExcaption() { //arrange var begDate = randomizer.Create <DateTime>().Date; var endDate = begDate.AddMonths(1); var aggregate = new MeterScaleAggregate( randomizer.Create <long>(), randomizer.Create <long>(), randomizer.Create <string>(), randomizer.Create <Const.ZoneOfDay>(), 5, begDate, endDate, false, false ); var endIndication = new IndicationDocumentAggregate(randomizer.Create <long>(), endDate, 9000, false); var endIndicationDouble = new IndicationDocumentAggregate(randomizer.Create <long>(), endDate, 9100, false); //act aggregate.AddIndication(endIndication); aggregate.AddIndication(endIndicationDouble); Action act = () => aggregate.СalculationPeriod(begDate, begDate, endDate); //assert act.Should().Throw <ArgumentException>().WithMessage("Error not find indication date"); }
public void СalculationPeriodTest_Indecation_NotOverDimenshion() { //arrange var begDate = randomizer.Create <DateTime>().Date; var endDate = begDate.AddMonths(1); var aggregate = new MeterScaleAggregate( randomizer.Create <long>(), randomizer.Create <long>(), randomizer.Create <string>(), randomizer.Create <Const.ZoneOfDay>(), 5, begDate, endDate, false, false ); var begIndication = new IndicationDocumentAggregate(randomizer.Create <long>(), begDate, 9000, false); var endIndication = new IndicationDocumentAggregate(randomizer.Create <long>(), endDate, 9100, false); //act aggregate.AddIndication(begIndication); aggregate.AddIndication(endIndication); var act = aggregate.СalculationPeriod(begDate, begDate, endDate); //assert act.Should().Be(100.0); }
public void Update(MeterScaleAggregate item) { context.ExecuteInTransaction(() => { var existed = context.MeterScaleDTOs.SingleOrDefault(x => x.Id == item.Id); if (existed != null) { Mapper.Map(item, existed); var link = context.LinkObjectsDTOs.Single(l => l.Owner.Id == item.OwnerId && l.Childen.Id == item.Id); Mapper.Map(item, link); } else { Create(item, true); } }); }
public MeterScaleAggregate Get(long id) { var item = context.MeterScaleDTOs .Join(context.LinkObjectsDTOs, t => t.Id, l => l.Childen.Id, (t, l) => new { scale = t, link = l }) .Where(l => !l.link.IsTransit) .FirstOrDefault(v => v.scale.Id == id); if (item == null) { throw new ArgumentException($"MeterScale id = {id} not found"); } var result = new MeterScaleAggregate(item.scale.Id, item.link.Owner.Id, item.scale.Name, (ZoneOfDay)item.scale.ZoneOfDayId, item.scale.Dimension, item.link.BeginDate, item.link.EndDate, item.link.IsTransit, item.scale.Deleted && item.link.Deleded); return(result); }
private void Create(MeterScaleAggregate item, bool notCheck) { context.ExecuteInTransaction(() => { if (!notCheck && (item.Id != -1 || context.MeterScaleDTOs.SingleOrDefault(x => x.Id == item.Id) != null)) { throw new ArgumentException($"MeterScale id = {item.Id} found"); } var newItem = Mapper.Map <MeterScaleDTO>(item); context.MeterScaleDTOs.Add(newItem); var link = new LinkObjectsDTO() { Owner = context.ObjectDTOs.Single(o => o.Id == item.OwnerId), Childen = newItem, BeginDate = item.BeginDate, EndDate = item.EndDate, IsTransit = false, }; context.LinkObjectsDTOs.Add(link); }); }
public IEnumerable <IndicationDocumentAggregate> GetAllByMeterScale(MeterScaleAggregate meterScale) { var items = context.IndicationDocumentDTOs.Where(d => d.Scale.Id == meterScale.Id && !d.Deleted).ToList(); return(items.Select(item => new IndicationDocumentAggregate(item.Id, item.ReceiptDate, item.Indication, item.Deleted))); }
public void Create(MeterScaleAggregate item) { Create(item, false); }