Пример #1
0
        public async Task Should_Create_ANewOfficePerCompany()
        {
            // arrange: delete the office if exists
            IOfficeDataServices officeDataServices = _dataServices.GetOfficeDataServices();
            IHelperDataServices helperData         = _dataServices.GetHelperDataServices();
            var asyncOffice = await _officeDataLoader.LoadAsyncAll();

            var id  = officeDataServices.GetNewId();
            var dto = officeDataServices.GetNewOfficeDo(id);

            if (dto != null)
            {
                var holiday = new List <HolidayViewObject> {
                    Craft_Holiday_Date(dto.Value.Codigo)
                };
                // act: now we act to receive an office.
                dto.Value.HolidayDates = holiday;
                var value = await _officeDataSaver.SaveAsync(dto.Value);

                // assert: now we assert to get correctly and office.
                var currentOffice = await officeDataServices.GetAsyncOfficeDo(dto.Value.Codigo);

                var dates      = currentOffice.Value.HolidayDates;
                var singleDate = dates.FirstOrDefault();
                Assert.Greater(dates.Count(), 0);
                Assert.IsTrue(value);
                Assert.AreEqual(singleDate.FESTIVO.ToLongDateString(), new DateTime(2018, 12, 24).ToLongDateString());
            }
            else
            {
                Assert.Fail();
            }
        }
Пример #2
0
        protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad)
        {
            Contract.Requires(payLoad != null, "The payload at company data shall be not null");
            Contract.Requires(payLoad.DataObject != null, "Payload shall have data object");
            if (payLoad.DataObject is OfficeViewObject dto)
            {
                IOfficeData data = _officeDataServices.GetNewOfficeDo(dto.Codigo);
                data.Value = dto;
                bool result = false;
                try
                {
                    result = await _officeDataServices.SaveAsync(data).ConfigureAwait(false);
                }
                catch (DataLayerException e)
                {
                    throw new DataLayerException("Error during saving", e);
                }


                // FIXME: where it is used current payload. shall enforce dry.
                if (result)
                {
                    payLoad.Sender      = ToolBarModule.NAME;
                    payLoad.PayloadType = DataPayLoad.Type.UpdateView;
                    // see if currentPayload make sense.
                    CurrentPayload = new DataPayLoad
                    {
                        PayloadType   = DataPayLoad.Type.UpdateView,
                        Sender        = ToolBarModule.NAME,
                        HasDataObject = true,
                        Subsystem     = payLoad.Subsystem,
                        DataObject    = data
                    };
                }
            }

            Contract.Ensures(payLoad != null);
            return(payLoad);
        }