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(); }
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> /// Map the fields for MasterDataInformation object /// </summary> /// <param name="reader">The SqlDataReader with the executed query result</param> /// <returns>An instance of MasterDataInformation</returns> private static MasterDataInformation MapMasterDataInformationReader(System.Data.IDataReader reader) { var masterDataInformation = new MasterDataInformation { Countries = new List<Country>(), StateProvinces = new List<StateProvince>() }; // Map Countries while (reader.Read()) { masterDataInformation.Countries.Add(CountryMapper.MapRecord(reader)); } // Map StateProvinces if (reader.NextResult()) { while (reader.Read()) { masterDataInformation.StateProvinces.Add(StateProvinceMapper.MapRecord(reader)); } } return masterDataInformation; }
/// <summary> /// Converts MasterDataInformation to Dto /// </summary> /// <param name="masterDataInformation">MasterDataInformation to convert</param> /// <returns>MasterDataInformation Dto</returns> private static MasterDataInformationDto ConvertMasterDataInformationToDto(MasterDataInformation masterDataInformation) { return new MasterDataInformationDto { Countries = masterDataInformation.Countries.ConvertAll(ConvertCountryToDto), StateProvinces = masterDataInformation.StateProvinces.ConvertAll(ConvertStateProvinceToDto) }; }