Exemplo n.º 1
0
        public void Test_AwbRepository_GetAggregate()
        {
            var data11 = CreateApplicationData(TestConstants.TestClientId1);
            var data12 = CreateApplicationData(TestConstants.TestClientId1);
            var data21 = CreateApplicationData(TestConstants.TestClientId1);
            var data22 = CreateApplicationData(TestConstants.TestClientId1);

            var awbId1 = _awbs.Add(CreateAirWaybillData(), TestConstants.DefaultStateId, TestConstants.TestAdminUserId);
            var awbId2 = _awbs.Add(CreateAirWaybillData(), TestConstants.DefaultStateId, TestConstants.TestAdminUserId);

            var applications = _applicationEditor;
            var app11        = applications.Add(data11);
            var app12        = applications.Add(data12);
            var app21        = applications.Add(data21);
            var app22        = applications.Add(data22);

            applications.SetAirWaybill(app11, awbId1);
            applications.SetAirWaybill(app12, awbId1);
            applications.SetAirWaybill(app21, awbId2);
            applications.SetAirWaybill(app22, awbId2);

            var aggregates = _awbs.GetAggregate(new[] { awbId1, awbId2 });

            aggregates.Count().ShouldBeEquivalentTo(2);

            var aggregate1 = aggregates.First(x => x.AirWaybillId == awbId1);

            aggregate1.TotalCount.ShouldBeEquivalentTo(data11.Count + data12.Count);
            aggregate1.TotalWeight.ShouldBeEquivalentTo(data11.Weight + data12.Weight);
            aggregate1.TotalVolume.ShouldBeEquivalentTo(data11.Volume + data12.Volume);
            aggregate1.TotalValue.ShouldBeEquivalentTo(data11.Value + data12.Value);

            var aggregate2 = aggregates.First(x => x.AirWaybillId == awbId2);

            aggregate2.TotalCount.ShouldBeEquivalentTo(data21.Count + data22.Count);
            aggregate2.TotalWeight.ShouldBeEquivalentTo(data21.Weight + data22.Weight);
            aggregate2.TotalVolume.ShouldBeEquivalentTo(data21.Volume + data22.Volume);
            aggregate2.TotalValue.ShouldBeEquivalentTo(data21.Value + data22.Value);
        }
Exemplo n.º 2
0
        public long Create(long?applicationId, AirWaybillEditData data, long creatorUserId)
        {
            if (data.GTD != null)
            {
                throw new InvalidLogicException("GTD data should be defined by update");
            }

            var id = _awbs.Add(data, _stateConfig.CargoIsFlewStateId, creatorUserId);

            if (applicationId.HasValue)
            {
                _applicationAwbManager.SetAwb(applicationId.Value, id);
            }

            if (data.BrokerId.HasValue)
            {
                _events.Add(id, EventType.SetBroker, EventState.Emailing);
            }

            _events.Add(id, EventType.AwbCreated, EventState.Emailing, data);

            return(id);
        }