Ejemplo n.º 1
0
        /// <summary>
        /// Map the fields for RegionalizedInformation object
        /// </summary>
        /// <param name="reader">The SqlDataReader with the executed query result</param>
        /// <param name="prefix">A prefix used to identify fields for the RegionalizedInformation model in the resultset if required</param>
        /// <returns>An instance of RegionalizedInformation</returns>
        private static RegionalizedInformation MapRegionalizedInformationReader(IDataReader reader, string prefix = "")
        {
            var regionalizedInformation = new RegionalizedInformation
            {
                Titles = new List<Title>()
            };

            while (reader.Read())
            {
                // Map Region information
                MapCultureInformation(reader, regionalizedInformation);
            }

            // Map Titles
            if (reader.NextResult())
            {
                while (reader.Read())
                {
                    regionalizedInformation.Titles.Add(TitleMapper.MapRecord(reader));
                }
            }

            return regionalizedInformation;
        }
Ejemplo n.º 2
0
            public void GetInitialDataSetupValidBusinessGetsPopulatedObject()
            {
                // Arrange
                const long BUSINESS_ID = 1;

                var stubInitialDataSetupManager = MockRepository.GenerateStub<IInitialDataSetupManager>();

                // Stub the BusinessCache to be used by our service method
                CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID);

                // invalidate the cache so we make sure our business is loaded into the cache
                Cache.Business.Invalidate();

                // Regionalized Information
                var regionalizedInformation = new RegionalizedInformation
                {
                    CurrentCulture = "en-GB",
                    SupportEmail = "*****@*****.**",
                    SupportNumber = "01122334455",
                    Titles = new List<Title>
                    {
                        new Title { Id = 1, Name = "Mr" },
                        new Title { Id = 2, Name = "Mrs" }
                    }

                };

                // MasterDataInformation
                var masterDataInformation = new MasterDataInformation
                {
                    Countries = new List<Country>
                    { 
                        new Country { Id = 1, Name = "Country1", IsoCode = 1 },
                        new Country { Id = 2, Name = "Country2", IsoCode = 2 }
                    },
                    StateProvinces = new List<StateProvince>
                    {
                        new StateProvince { Id = 1, Name = "StateProvince1", Country = new Country{Id = 1, Name = "Country1", IsoCode = 1 } },
                        new StateProvince { Id = 2, Name = "StateProvince2", Country = new Country{Id = 2, Name = "Country2", IsoCode = 2 } }
                    }
                };

                stubInitialDataSetupManager.Stub(r => r.GetInitialDataSetup(BUSINESS_ID)).Return(new InitialDataSetup
                                                                                                    {
                                                                                                        RegionalizedInformation = regionalizedInformation,
                                                                                                        MasterDataInformation = masterDataInformation
                                                                                                    });
                limitedMobileService.InitialDataSetupManager = stubInitialDataSetupManager;

                // Act
                InitialDataSetupDto initialDataSetupDto = limitedMobileService.GetInitialDataSetup(BUSINESS_ID);

                // Assert
                Assert.IsNotNull(initialDataSetupDto, "InitialDataSetup is Null");
                Assert.IsNotNull(initialDataSetupDto.RegionalizedInformation, "RegionalizedInformation is Null");
                Assert.IsNotNull(initialDataSetupDto.MasterDataInformation, "MasterDataInformation is Null");
                Assert.AreEqual("en-GB", initialDataSetupDto.RegionalizedInformation.CurrentCulture, "CurrentCulture attribute retrieved is incorrect.");
                Assert.AreEqual("*****@*****.**", initialDataSetupDto.RegionalizedInformation.SupportEmail, "SupportEmail attribute retrieved is incorrect.");
                Assert.AreEqual("01122334455", initialDataSetupDto.RegionalizedInformation.SupportNumber, "SupportNumber attribute retrieved is incorrect.");

                Assert.IsNotNull(initialDataSetupDto.RegionalizedInformation.Titles, "Titles are not retrieved.");
                Assert.AreEqual(2, initialDataSetupDto.RegionalizedInformation.Titles.Count, "Total number of titles retrieved is incorrect.");
                Assert.AreEqual("Mr", initialDataSetupDto.RegionalizedInformation.Titles.Find(t => t.Id == 1).Description, "Translated Description is not retrieved.");
                Assert.AreEqual("Mrs", initialDataSetupDto.RegionalizedInformation.Titles.Find(t => t.Id == 2).Description, "Translated Description is not retrieved.");

                Assert.IsNotNull(initialDataSetupDto.MasterDataInformation.Countries, "Countries are not retrieved.");
                Assert.AreEqual(2, initialDataSetupDto.MasterDataInformation.Countries.Count, "Total number of Countries retrieved is incorrect.");
                Assert.AreEqual("Country1", initialDataSetupDto.MasterDataInformation.Countries.Find(c => c.Id == 1).Description, "Translated Description is not retrieved.");
                Assert.AreEqual("Country2", initialDataSetupDto.MasterDataInformation.Countries.Find(c => c.Id == 2).Description, "Translated Description is not retrieved.");

                Assert.IsNotNull(initialDataSetupDto.MasterDataInformation.StateProvinces, "StateProvinces are not retrieved.");
                Assert.AreEqual(2, initialDataSetupDto.MasterDataInformation.StateProvinces.Count, "Total number of StateProvinces retrieved is incorrect.");
                Assert.AreEqual("StateProvince1", initialDataSetupDto.MasterDataInformation.StateProvinces.Find(s => s.Id == 1).Description, "StateProvinces Description is not retrieved.");
                Assert.AreEqual("StateProvince2", initialDataSetupDto.MasterDataInformation.StateProvinces.Find(s => s.Id == 2).Description, "StateProvinces Description is not retrieved.");
                Assert.AreEqual("Country1", initialDataSetupDto.MasterDataInformation.StateProvinces.Find(s => s.Id == 1).Country.Description, "Country Description is not retrieved.");
                Assert.AreEqual("Country2", initialDataSetupDto.MasterDataInformation.StateProvinces.Find(s => s.Id == 2).Country.Description, "Country Description is not retrieved.");

                // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
Ejemplo n.º 3
0
 /// <summary>
 /// Attaches Region and Culture information to RegionalizedInformation object
 /// </summary>
 /// <param name="record">DataRecord</param>
 /// <param name="regionalizedInformation">Regionalized Information</param>
 private static void MapCultureInformation(System.Data.IDataRecord record, RegionalizedInformation regionalizedInformation)
 {
     regionalizedInformation.CurrentCulture = DbHelper.ConvertValue<string>(record[Parameters.DefaultCultureCode.ToString()]);
 }
Ejemplo n.º 4
0
            public void GetInitialDataSetupValidBusinessGetsPopulatedObject()
            {
                // Arrange
                int businessId = 1;
                var stubInitialDataSetupDao = MockRepository.GenerateStub<IInitialDataSetupDao>();

                // Regionalized Information
                RegionalizedInformation regionalizedInformation = new RegionalizedInformation()
                                                                      {
                                                                          CurrentCulture = "en-GB",
                                                                          SupportEmail = "*****@*****.**",
                                                                          SupportNumber = "01122334455",
                                                                          Titles = new List<Title>()
                                                                                       {
                                                                                           new Title() {Id = 1, Name = "Mr"},
                                                                                           new Title() {Id = 2, Name = "Mrs"}
                                                                                       }

                                                                      };

                // MasterDataInformation
                Country country1 = new Country() { Id = 1, Name = "Country1", IsoCode = 1 };
                Country country2 = new Country() { Id = 2, Name = "Country2", IsoCode = 2 };
                MasterDataInformation masterDataInformation = new MasterDataInformation()
                                                                  {
                                                                      Countries = new List<Country>()
                                                                                      {
                                                                                          country1,
                                                                                          country2
                                                                                      },
                                                                      StateProvinces = new List<StateProvince>()
                                                                                      {
                                                                                          new StateProvince() {Id = 1, Name = "StateProvince1", Country = country1},
                                                                                          new StateProvince() {Id = 2, Name = "StateProvince2", Country = country2}
                                                                                      }
                                                                  };
                stubInitialDataSetupDao.Stub(r => r.GetByBusiness(businessId)).Return(new InitialDataSetup()
                                                                                                      { 
                                                                                                          RegionalizedInformation = regionalizedInformation,
                                                                                                          MasterDataInformation = masterDataInformation
                                                                                                      });
                initialDataSetupManager.InitialDataSetupDao = stubInitialDataSetupDao;
                
                // Act
                InitialDataSetup initialDataSetup = initialDataSetupManager.GetInitialDataSetup(businessId);

                // Assert
                Assert.IsNotNull(initialDataSetup, "initialDataSetup retrieved is null.");
                Assert.IsNotNull(initialDataSetup.RegionalizedInformation, "RegionalizedInformation retrieved is null.");
                Assert.IsNotNull(initialDataSetup.MasterDataInformation, "MasterDataInformation retrieved is null.");
                Assert.AreEqual("en-GB", initialDataSetup.RegionalizedInformation.CurrentCulture, "CurrentCulture attribute retrieved is incorrect.");
                Assert.AreEqual("*****@*****.**", initialDataSetup.RegionalizedInformation.SupportEmail, "SupportEmail attribute retrieved is incorrect.");
                Assert.AreEqual("01122334455", initialDataSetup.RegionalizedInformation.SupportNumber, "SupportNumber attribute retrieved is incorrect.");
                
                Assert.IsNotNull(initialDataSetup.RegionalizedInformation.Titles, "Titles are not retrieved.");
                Assert.AreEqual(2, initialDataSetup.RegionalizedInformation.Titles.Count, "Total number of titles retrieved is incorrect.");
                Assert.AreEqual("Mr", initialDataSetup.RegionalizedInformation.Titles.Find(t => t.Id == 1).Name, "Translated Name is not retrieved.");
                Assert.AreEqual("Mrs", initialDataSetup.RegionalizedInformation.Titles.Find(t => t.Id == 2).Name, "Translated Name is not retrieved.");

                Assert.IsNotNull(initialDataSetup.MasterDataInformation.Countries, "Countries are not retrieved.");
                Assert.AreEqual(2, initialDataSetup.MasterDataInformation.Countries.Count, "Total number of Countries retrieved is incorrect.");
                Assert.AreEqual("Country1", initialDataSetup.MasterDataInformation.Countries.Find(c => c.Id == 1).Name, "Translated Name is not retrieved.");
                Assert.AreEqual("Country2", initialDataSetup.MasterDataInformation.Countries.Find(c => c.Id == 2).Name, "Translated Name is not retrieved.");

                Assert.IsNotNull(initialDataSetup.MasterDataInformation.StateProvinces, "StateProvinces are not retrieved.");
                Assert.AreEqual(2, initialDataSetup.MasterDataInformation.StateProvinces.Count, "Total number of StateProvinces retrieved is incorrect.");
                Assert.AreEqual("StateProvince1", initialDataSetup.MasterDataInformation.StateProvinces.Find(s => s.Id == 1).Name, "Translated Name is not retrieved.");
                Assert.AreEqual("StateProvince2", initialDataSetup.MasterDataInformation.StateProvinces.Find(s => s.Id == 2).Name, "Translated Name is not retrieved.");

                Assert.IsNotNull(initialDataSetup.MasterDataInformation.StateProvinces.Find(c => c.Id == 1).Country, "Country for StateProvince id 1 is not retrieved.");
                Assert.IsNotNull(initialDataSetup.MasterDataInformation.StateProvinces.Find(c => c.Id == 2).Country, "Country for StateProvince id 2 is not retrieved.");
                Assert.AreEqual("Country1", initialDataSetup.MasterDataInformation.StateProvinces.Find(c => c.Id == 1).Country.Name, "Translated Description of the Country is not retrieved.");
                Assert.AreEqual("Country2", initialDataSetup.MasterDataInformation.StateProvinces.Find(c => c.Id == 2).Country.Name, "Translated Description of the Country is not retrieved.");
                Assert.AreEqual(1, initialDataSetup.MasterDataInformation.StateProvinces.Find(c => c.Id == 1).Country.IsoCode, "IsoCode of the country is not retrieved.");
                Assert.AreEqual(2, initialDataSetup.MasterDataInformation.StateProvinces.Find(c => c.Id == 2).Country.IsoCode, "IsoCode of the country is not retrieved.");
            }
 /// <summary>
 /// Converts RegionalizedInformation to Dto
 /// </summary>
 /// <param name="regionalizedInformation">RegionalizedInformation to convert</param>
 /// <returns>RegionalizedInformation Dto</returns>
 private static RegionalizedInformationDto ConvertRegionalizedInformationToDto(RegionalizedInformation regionalizedInformation)
 {
     return new RegionalizedInformationDto
     {
         CurrentCulture = regionalizedInformation.CurrentCulture,
         SupportEmail = regionalizedInformation.SupportEmail,
         SupportNumber = regionalizedInformation.SupportNumber,
         Titles = regionalizedInformation.Titles.ConvertAll(ConvertTitleToDto)
     };
 }