Exemple #1
0
        public async Task <List <SiteNameDto> > SiteLoadAllFromRemote()
        {
            log.LogEverything("Communicator.SiteLoadAllFromRemote", "called");

            var parsedData         = JRaw.Parse(await http.SiteLoadAllFromRemote());
            List <SiteNameDto> lst = new List <SiteNameDto>();

            foreach (JToken item in parsedData)
            {
                string      name         = item["name"].ToString();
                int         microtingUid = int.Parse(item["id"].ToString());
                DateTime?   createdAt    = DateTime.Parse(item["created_at"].ToString());
                DateTime?   updatedAt    = DateTime.Parse(item["updated_at"].ToString());
                SiteNameDto temp         = new SiteNameDto(microtingUid, name, createdAt, updatedAt);
                lst.Add(temp);
            }
            return(lst);
        }
        [Test]//Using Communicatorn needs httpMock
        public async Task Core_Site_SiteUpdate_returnsTrue()
        {
            // Arrange
            // Arrange
            #region site
            string siteName         = Guid.NewGuid().ToString();
            int    siteMicrotingUid = 1; // This needs to be 1 for our tests to pass through the FakeHttp
            // TODO: Improve the test for supporting random id.

            sites site = await testHelpers.CreateSite(siteName, siteMicrotingUid);

            SiteNameDto siteName_Dto = new SiteNameDto((int)site.MicrotingUid, site.Name, site.CreatedAt, site.UpdatedAt);
            #endregion

            #region worker
            string email     = Guid.NewGuid().ToString();
            string firstName = Guid.NewGuid().ToString();
            string lastName  = Guid.NewGuid().ToString();
            //int workerMicrotingUid = await testHelpers.GetRandomInt();
            int workerMicrotingUid = 1; // This needs to be 1 for our tests to pass through the FakeHttp
            // TODO: Improve the test for supporting random id.

            workers worker = await testHelpers.CreateWorker(email, firstName, lastName, workerMicrotingUid);

            #endregion

            #region site_worker
            site_workers site_worker = await testHelpers.CreateSiteWorker(1, site, worker);

            #endregion

            #region unit
            units unit = await testHelpers.CreateUnit(1, 1, site, 1);

            #endregion


            var match = await sut.SiteUpdate((int)site.MicrotingUid, site.Name, firstName, lastName, email);

            // Assert
            Assert.True(match);
        }
Exemple #3
0
        public async Task <string> DbSetup(string token)
        {
//            try
//            {
            DbContextHelper dbContextHelper = new DbContextHelper(connectionString);

            sqlController = new SqlController(dbContextHelper);

            if (token == null)
            {
                token = await sqlController.SettingRead(Settings.token);
            }

            await sqlController.SettingUpdate(Settings.token, token);

            // configure db
            await DbSettingsReloadRemote();


            string comAddressApi = await sqlController.SettingRead(Settings.comAddressApi);

            string comAddressBasic = await sqlController.SettingRead(Settings.comAddressBasic);

            string comOrganizationId = await sqlController.SettingRead(Settings.comOrganizationId);

            string ComAddressPdfUpload = await sqlController.SettingRead(Settings.comAddressPdfUpload);

            string ComSpeechToText = await sqlController.SettingRead(Settings.comSpeechToText);

            Communicator communicator = new Communicator(token, comAddressApi, comAddressBasic, comOrganizationId, ComAddressPdfUpload, log, ComSpeechToText);

            #region add site's data to db
            if (!bool.Parse(await sqlController.SettingRead(Settings.knownSitesDone)))
            {
                foreach (var item in await communicator.SiteLoadAllFromRemote())
                {
                    SiteNameDto siteDto = await sqlController.SiteRead(item.SiteUId);

                    if (siteDto == null)
                    {
                        await sqlController.SiteCreate(item.SiteUId, item.SiteName);
                    }
                }

                foreach (var item in await communicator.WorkerLoadAllFromRemote())
                {
                    WorkerDto workerDto = await sqlController.WorkerRead(item.WorkerUId);

                    if (workerDto == null)
                    {
                        await sqlController.WorkerCreate(item.WorkerUId, item.FirstName, item.LastName, item.Email);
                    }
                }

                foreach (var item in await communicator.SiteWorkerLoadAllFromRemote())
                {
                    SiteWorkerDto siteWorkerDto = await sqlController.SiteWorkerRead(item.MicrotingUId, null, null);

                    if (siteWorkerDto == null)
                    {
                        try
                        {
                            await sqlController.SiteWorkerCreate(item.MicrotingUId, item.SiteUId, item.WorkerUId);
                        }
                        catch
                        {
                            // We do catch this because right now we a descripency at the API side.
                        }
                    }
                }

                int customerNo = communicator.OrganizationLoadAllFromRemote(token).Result.CustomerNo;

                foreach (var item in await communicator.UnitLoadAllFromRemote(customerNo))
                {
                    UnitDto unitDto = await sqlController.UnitRead(item.UnitUId);

                    if (unitDto == null)
                    {
                        try
                        {
                            await sqlController.UnitCreate(item.UnitUId, item.CustomerNo, item.OtpCode, item.SiteUId);
                        }
                        catch
                        {
                            // We do catch this because right now we a descripency at the API side.
                        }
                    }
                }

                foreach (FolderDto folderDto in await communicator.FolderLoadAllFromRemote())
                {
                    if (folderDto.MicrotingUId != null)
                    {
                        FolderDto folder = await sqlController.FolderReadByMicrotingUUID((int)folderDto.MicrotingUId);

                        if (folder == null)
                        {
                            if (folderDto.ParentId == 0)
                            {
                                await sqlController.FolderCreate(folderDto.Name, folderDto.Description, null,
                                                                 (int)folderDto.MicrotingUId);
                            }
                            else
                            {
                                if (folderDto.ParentId != null)
                                {
                                    FolderDto parenFolder =
                                        await sqlController.FolderReadByMicrotingUUID((int)folderDto.ParentId);

                                    await sqlController.FolderCreate(folderDto.Name, folderDto.Description, parenFolder.Id,
                                                                     (int)folderDto.MicrotingUId);
                                }
                            }
                        }
                    }
                }

                await sqlController.SettingUpdate(Settings.knownSitesDone, "true");
            }
            #endregion

            await sqlController.SettingUpdate(Settings.firstRunDone, "true");

            return("");
//            }
//            catch (Exception ex)
//            {
//                return t.PrintException(t.GetMethodName("AdminTools") + " failed", ex);
//            }
        }