示例#1
0
        public async Task <List <OperatorItem> > LoadOperators(CountryItem selected)
        {
            Operators operD = await communication.GetOperators(config.DefaultOperatorUri(selected.CountryCodeLong, selected.LanguageCode, "XONE"));

            Operators operO = await communication.GetOperators(config.ListOperatorsUri(selected.CountryCodeShort, selected.LanguageCode, "XONE"));

            List <OperatorItem> result = operD.Items;

            result.AddRange(operO.Items);
            return(result);
        }
示例#2
0
        public void Instance_Is_ICountry()
        {
            //Arrange
            var type = typeof(ICountry);

            //Act
            var region = new CountryItem();

            //Assert
            Assert.IsInstanceOf(type, region);
        }
示例#3
0
        public void RetrieveAdditionalInformationTest_withInvalidID(string value)
        {
            // Arrange
            CountryItem item = new CountryItem("_aa1", "Country");

            item.BaseTableName = value;

            // Act
            int count = item.RetrieveAdditionalInformation();

            // Assert
            Assert.AreEqual(0, count);
        }
示例#4
0
        public MainViewModel(IConfigService config, ISettingsService settings, ICommunicationService communication)
        {
            this.config        = config;
            this.settings      = settings;
            this.communication = communication;

            if (!settings.NationalDomain.IsNullOrWhiteSpace())
            {
                CurrentlySelectedCountry = Static.Static.CountriesList.First(c => c.NationalDomain == settings.NationalDomain);
            }

            RegisterOrLoadCurrentDevice();
        }
示例#5
0
        public void Code()
        {
            //Arrange
            const string code    = "CZ";
            var          country = new CountryItem()
            {
                Code = code
            };

            //Act
            var result = country.Code;

            //Assert
            Assert.IsTrue(code == result);
        }
示例#6
0
        public void Name()
        {
            //Arrange
            const string name    = "Czech Republic";
            var          country = new CountryItem
            {
                Name = name
            };

            //Act
            var result = country.Name;

            //Assert
            Assert.IsTrue(name == result);
        }
示例#7
0
        public void CountryItemTest_withID()
        {
            // Arrange
            CountryItem item = new CountryItem("_xx1", "Country");

            // Act
            // Assert
            Assert.IsNotNull(item);
            Assert.IsNotNull(item.Reader);
            Assert.AreEqual("", item.BaseTableName);
            Assert.AreEqual("Country", item.TargetTableName);

            Assert.AreEqual("_xx1", item.ID);
            Assert.IsNull(item.Country);
            Assert.IsNull(item.Details);
            Assert.IsNull(item.Status);
            Assert.IsNull(item.LastUpdated);
        }
示例#8
0
        public void RetrieveBasicInformationTest_withValidID_AdditionalInfo(string value)
        {
            // Arrange
            CountryItem item = new CountryItem("_xx1", "Country");

            item.BaseTableName = value;

            // Act
            int count = item.RetrieveBasicInformation(false);

            // Assert
            Assert.AreEqual(1, count);

            Assert.AreEqual("_xx1", item.ID);
            Assert.AreEqual("_xxx", item.Country.ID);
            Assert.AreEqual($"{value} Country Details X1", item.Details);
            Assert.AreEqual("_xxx", item.Status.ID);
            Assert.AreEqual($"{value} Country LastUpdated X1", item.LastUpdated);
        }
示例#9
0
        public void RetrieveTest_withInvalidID_AdditionalInfo(string value)
        {
            // Arrange
            CountryItem item = new CountryItem("_aa1", "Country");

            item.BaseTableName = value;

            // Act
            int count = item.Retrieve(false);

            // Assert
            Assert.AreEqual(0, count);

            Assert.AreEqual("_aa1", item.ID);
            Assert.IsNull(item.Country);
            Assert.IsNull(item.Details);
            Assert.IsNull(item.Status);
            Assert.IsNull(item.LastUpdated);
        }
示例#10
0
        /// <summary>
        /// Returns all of the country codes.
        /// </summary>
        /// <returns></returns>
        public IList <CountryItem> GetCountries()
        {
            List <CountryItem> countries = new List <CountryItem>();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();

                string     sql = "SELECT code, name FROM country;";
                SqlCommand cmd = new SqlCommand(sql, conn);

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    CountryItem item = new CountryItem();
                    item.Code = Convert.ToString(reader["code"]);
                    item.Name = Convert.ToString(reader["name"]);
                    countries.Add(item);
                }
            }

            return(countries);
        }
示例#11
0
        private void LoadCountry()
        {
            ArrayList     arr  = Country.GetData();
            CountryItem   item = null;
            StringBuilder sb   = new StringBuilder();

            sb.Append("[");
            for (int i = 0; i < arr.Count; i++)
            {
                item = (CountryItem)arr[i];
                if (i != arr.Count - 1)
                {
                    sb.AppendFormat("{0}Key:'{1}',Val:'{2}'{3},", "{", item.Id, item.Name, "}");
                }
                else
                {
                    sb.AppendFormat("{0}Key:'{1}',Val:'{2}'{3}", "{", item.Id, item.Name, "}");
                }
            }

            sb.Append("]");

            zCountry = sb.ToString();
        }
        public void TryTransactionScope()
        {
            int count;

            TryDeleteAllTestData();

            var countryItems = GetCountryItems();

            var documentItems = new List <DocumentItem>
            {
                GetDocumentItem(ContactTestFixtureData.Keys.Document[1]),
                GetDocumentItem(ContactTestFixtureData.Keys.Document[2]),
                GetDocumentItem(ContactTestFixtureData.Keys.Document[3])
            };

            var addressItems = new List <AddressItem>
            {
                GetAddressItem(ContactTestFixtureData.Keys.Address[1]),
                GetAddressItem(ContactTestFixtureData.Keys.Address[2]),
                new AddressItem()
            };

            try
            {
                var countryItemsSaved = new List <CountryItem>(countryItems.Count);

                count = countryItems.Count;
                for (var i = 0; i < count; i++)
                {
                    CountryItem countryItemSaved = ContactAgentFactory
                                                   .CreateCountryAgent()
                                                   .SaveCountryItem(countryItems[i]);
                    Debug.WriteLineIf(countryItemSaved.HasErrors, "Error saving countryitem " + (i + 1) + " / " + count + "\n\t" + countryItemSaved.Errors);
                    countryItemsSaved.Add(countryItemSaved);
                }

                using (var scope = new TransactionScope())
                {
                    var addressItemsSaved  = new List <AddressItem>(addressItems.Count);
                    var documentItemsSaved = new List <DocumentItem>(documentItems.Count);

                    count = documentItems.Count;
                    for (var i = 0; i < count; i++)
                    {
                        DocumentItem documentItemSaved = ContactAgentFactory
                                                         .CreateDocumentAgent()
                                                         .SaveDocumentItem(documentItems[i]);
                        documentItemsSaved.Add(documentItemSaved);
                    }

                    count = addressItems.Count;
                    for (var i = 0; i < count; i++)
                    {
                        AddressItem addressItemSaved = ContactAgentFactory
                                                       .CreateAddressAgent()
                                                       .SaveAddressItem(addressItems[i]);
                        Debug.WriteLineIf(addressItemSaved.HasErrors, "Error saving AddressItem " + (i + 1) + " / " + count + "\n\tError = " + GetErrorString(addressItemSaved.Errors));
                        addressItemsSaved.Add(addressItemSaved);
                    }

                    bool succes = !(from i in documentItemsSaved where i.HasErrors select i).Any() & !(from i in addressItemsSaved where i.HasErrors select i).Any();

                    if (succes)
                    {
                        scope.Complete();
                        Debug.WriteLine("OK");
                    }
                    else
                    {
                        throw new ApplicationException(GetErrorString(addressItemsSaved.ToArray()) + GetErrorString(documentItemsSaved.ToArray()));
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error(s) occured.\n" + ex.Message);
            }
        }
        public void TryGetRelationAddresses()
        {
            IContactAgent agent = ContactAgentFactory.CreateContactAgent();

            List <DocumentItem>         documentItemsSaved;
            List <AddressItem>          addressItemsSaved;
            RelationItem                relationItemSaved;
            List <RelationAddressItem>  relationAddressItemsSaved;
            List <RelationDocumentItem> relationDocumentItemsSaved;
            List <CountryItem>          countryItemsSaved;

            AddressItem[] addressItems;
            int           count = 0;

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    Debug.WriteLine("Creating all objects on " + DateTime.Now);
                    List <AddressItem>          addressItemsNew          = GetAddressItems(2);
                    List <CountryItem>          countryItemsNew          = GetCountryItems(2);
                    List <DocumentItem>         documentItemsNew         = GetDocumentItems(2);
                    RelationItem                relationItemNew          = GetRelationItem();
                    List <RelationAddressItem>  relationAddressItemsNew  = GetRelationAddressItems(2);
                    List <RelationDocumentItem> relationDocumentItemsNew = GetRelationDocumentItems(2);

                    Debug.WriteLine("All objects in memory on {0}", DateTime.Now);

                    Debug.WriteLine("Saving all objects");

                    count             = countryItemsNew.Count;
                    countryItemsSaved = new List <CountryItem>(count);
                    Debug.WriteLine("Saving countries objects");
                    for (int i = 0; i < count; i++)
                    {
                        CountryItem countryItemSaved = agent.SaveCountryItem(countryItemsNew[i]);
                        Debug.WriteLine("CountryItem {0} / {1} saved {2}on {3}", (i + 1), count, (countryItemSaved.HasErrors ? "with errors " : ""), DateTime.Now);
                        countryItemsSaved.Add(countryItemSaved);
                    }

                    count = documentItemsNew.Count;
                    documentItemsSaved = new List <DocumentItem>(count);
                    Debug.WriteLine("Saving documents objects");
                    for (int i = 0; i < count; i++)
                    {
                        DocumentItem documentItemSaved = agent.SaveDocumentItem(documentItemsNew[i]);
                        Debug.WriteLine("DocumentItem {0} / {1} saved {2}on {3}", (i + 1), count, (documentItemSaved.HasErrors ? "with errors " : ""), DateTime.Now);
                        documentItemsSaved.Add(documentItemSaved);
                    }

                    relationItemSaved = agent.SaveRelationItem(relationItemNew);
                    Debug.WriteLine("AddressItem saved {0}on {1}", (relationItemSaved.HasErrors ? "with errors " : ""), DateTime.Now);

                    count             = addressItemsNew.Count;
                    addressItemsSaved = new List <AddressItem>(count);
                    Debug.WriteLine("Saving addresses objects");
                    for (int i = 0; i < count; i++)
                    {
                        AddressItem addressItemSaved = agent.SaveAddressItem(addressItemsNew[i]);
                        Debug.WriteLine("CountryItem {0} / {1} saved {2}on {3}", (i + 1), count, (addressItemSaved.HasErrors ? "with errors " : ""), DateTime.Now);
                        addressItemsSaved.Add(addressItemSaved);
                    }

                    count = relationAddressItemsNew.Count;
                    relationAddressItemsSaved = new List <RelationAddressItem>(count);
                    Debug.WriteLine("Saving RelationAddress objects");
                    for (int i = 0; i < count; i++)
                    {
                        RelationAddressItem relationAddressItemSaved = agent.SaveRelationAddressItem(relationAddressItemsNew[i]);
                        Debug.WriteLine("RelationAddressItem {0} / {1} saved {2}on {3}", (i + 1), count, (relationAddressItemSaved.HasErrors ? "with errors " : ""), DateTime.Now);
                        relationAddressItemsSaved.Add(relationAddressItemSaved);
                    }

                    count = relationDocumentItemsNew.Count;
                    relationDocumentItemsSaved = new List <RelationDocumentItem>(count);
                    Debug.WriteLine("Saving RelationDocument objects");
                    for (int i = 0; i < count; i++)
                    {
                        RelationDocumentItem relationDocumentItemSaved = agent.SaveRelationDocumentItem(relationDocumentItemsNew[i]);
                        Debug.WriteLine("RelationDocumentItem {0} / {1} saved {2}on {3}", (i + 1), count, (relationDocumentItemSaved.HasErrors ? "with errors " : ""), DateTime.Now);
                        relationDocumentItemsSaved.Add(relationDocumentItemSaved);
                    }

                    Debug.WriteLine("All objects saved");

                    Debug.WriteLine("Before commiting transaction");
                    scope.Complete();
                    Debug.WriteLine("Commit transaction completed");
                }
                addressItems = agent.GetAddressItemsForRelation(ContactTestFixtureData.Keys.Relation[1]);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error(s) occured\n" + e.Message);
            }
        }
示例#14
0
 public async Task <LoginResponse> TryLogin(string login, string password, Guid operatorId, CountryItem selected)
 {
     return(await communication.Login(config.HboAccountLoginUri(selected.CountryCodeLong, selected.LanguageCode, "XONE"), login, password, operatorId, CurrentDevice));
 }
示例#15
0
        public async void InitCountry()
        {
            var idLogin = await BlobCache.LocalMachine.GetObject <string>("loginCookie");

            string      countryId   = null;
            CountryItem countryList = null;

            //Set the cookiee manually (propertie 'UseCookies = false')
            //Or use cookieContainer
            using (var client = new HttpClient(new HttpClientHandler {
                UseCookies = false
            }))
            {
                client.DefaultRequestHeaders.Add("Cookie", idLogin);
                var dashboardUrl = new Uri("http://app.casterstats.com/dashboard");
                var resp         = await client.GetAsync(dashboardUrl);

                string content = await resp.Content.ReadAsStringAsync();


                List <Dashboard> dashboards = JsonConvert.DeserializeObject <List <Dashboard> >(content);
                foreach (var dashboard in dashboards)
                {
                    countryId = dashboard.DashboardComponents.FirstOrDefault(x => x.Name.Equals("Countries")).Id;
                }

                if (countryId != null)
                {
                    dashboardUrl = new Uri("http://app.casterstats.com/dashboard/component/userscity/" + countryId + "");
                    resp         = await client.GetAsync(dashboardUrl);

                    content = await resp.Content.ReadAsStringAsync();



                    countryList = JsonConvert.DeserializeObject <CountryItem>(content);
                }
            }
            //Display the content
            SfDataGrid dataGrid = new SfDataGrid();

            CountryDataRepository countryData = new CountryDataRepository();

            if (countryList != null)
            {
                countryData.ListCountry = countryList.CountryData;

                dataGrid.AutoGenerateColumns = false;

                GridImageColumn countryIcon = new GridImageColumn();
                countryIcon.MappingName = "Flag";
                countryIcon.HeaderText  = "Flag";
                GridTextColumn countryName = new GridTextColumn();
                countryName.MappingName = "Country";
                countryName.HeaderText  = "Country";
                GridTextColumn nbUsers = new GridTextColumn();
                nbUsers.MappingName = "Count";
                nbUsers.HeaderText  = "Users";



                dataGrid.Columns.Add(countryIcon);
                dataGrid.Columns.Add(countryName);
                dataGrid.Columns.Add(nbUsers);


                dataGrid.ColumnSizer = ColumnSizer.Auto;

                dataGrid.ItemsSource  = countryData.GetCountryInfo();
                dataGrid.AllowSorting = true;
            }


            Content = dataGrid; //page content = stacklayout
        }