public void When() { // Arange dbContext.Add(new Brand { Name = "Renault", Id = 100 }); dbContext.Add(new Brand { Name = "Mercedes", Id = 101 }); dbContext.Add(new Brand { Name = "BMW", Id = 123 }); dbContext.SaveChanges(); BrandFinder brandFinder = new BrandFinder(dbContext); // Act List <string> brandNames = brandFinder.GetBrandNames(); // Assert Assert.That(brandNames, Has.Count.EqualTo(3)); Assert.That(brandNames[0], Is.EqualTo("Renault")); Assert.That(brandNames[1], Is.EqualTo("Mercedes")); Assert.That(brandNames[2], Is.EqualTo("BMW")); }
private static void LoadBrands(ServiceProvider serviceProvider) { ExistingBrands existingBrands = serviceProvider.GetService <ExistingBrands>(); BrandFinder brandFinder = serviceProvider.GetService <BrandFinder>(); existingBrands.Load(brandFinder.GetBrandNames()); }
private static void Validate(Brand entity, BinaryFile file, BinaryFile watermarkImage) { ErrorList errors = new ErrorList(); if (StringUtils.IsBlank(entity.Name)) { errors.Add("Name is required"); } if (StringUtils.IsBlank(entity.ShortName)) { errors.Add("Short Name is required"); } if (StringUtils.IsBlank(entity.ApplicationName)) { errors.Add("Application Name is required"); } if (StringUtils.IsBlank(entity.OrganisationName)) { errors.Add("Organisation Name is required"); } if (StringUtils.IsBlank(entity.WebsiteUrl)) { errors.Add("Website URL is required"); } else if (!entity.WebsiteUrl.ToLower().StartsWith("http://")) { errors.Add("Website URL must start with http://"); } if (StringUtils.IsBlank(entity.EmailFrom)) { errors.Add("Email From is required"); } else if (!StringUtils.IsEmail(entity.EmailFrom)) { errors.Add("Email From must be a valid email address"); } if (StringUtils.IsBlank(entity.LoginPageUpperCopy)) { errors.Add("Login page upper copy is required"); } if (StringUtils.IsBlank(entity.LoginPageLowerCopy)) { errors.Add("Login page lower copy is required"); } if (StringUtils.IsBlank(entity.DefaultUsageRestrictionsCopy)) { errors.Add("Default Usage Restrictions notice is required"); } if (StringUtils.IsBlank(entity.MyAccountCopy)) { errors.Add("My Account copy is required"); } if (StringUtils.IsBlank(entity.AdminCopy)) { errors.Add("Admin copy is required"); } if (StringUtils.IsBlank(entity.TermsConditionsCopy)) { errors.Add("Terms and Conditions copy is required"); } if (StringUtils.IsBlank(entity.PrivacyPolicyCopy)) { errors.Add("Privacy Policy copy is required"); } if (entity.IsMasterBrand) { BrandFinder finder = new BrandFinder { IsMasterBrand = true }; List <Brand> masterBrandList = Brand.FindMany(finder); if (masterBrandList.Count > 1) { errors.Add("Only one master brand is allowed"); } if (masterBrandList.Count == 1 && entity.IsNew) { errors.Add("Only one master brand is allowed. Current master brand is: " + masterBrandList[0].Name); } if (masterBrandList.Count == 1 && !entity.IsNew && !masterBrandList[0].BrandId.Equals(entity.BrandId)) { errors.Add("Only one master brand is allowed. Current master brand is: " + masterBrandList[0].Name); } } if (!file.IsEmpty && file.FileExtension != "zip") { errors.Add("UI file pack must be a zip file"); } if (!watermarkImage.IsEmpty && !GeneralUtils.ValueIsInList(watermarkImage.FileExtension, "gif", "jpg", "png")) { errors.Add("Watermark must be a GIF, JPG or PNG image"); } if (errors.Count > 0) { throw new InvalidBrandException(errors, entity); } }
public void When_DataIsCorrect() { // Arange dbContext.Add(new Source { Id = 1, Name = "cars.bg" }); dbContext.Add(new Source { Id = 2, Name = "mobile.bg" }); dbContext.SaveChanges(); Brand renault = new Brand { Id = 100, Name = "Renault", }; BrandKey renaultBrandKey = new BrandKey { SourceId = 1, BrandId = 100, Key = "renault_key" }; renault.BrandKeys.Add(renaultBrandKey); Brand mercedes = new Brand { Id = 101, Name = "Mercedes", }; BrandKey mercedesBrandKey = new BrandKey { SourceId = 1, BrandId = 101, Key = "mercedes_key" }; mercedes.BrandKeys.Add(mercedesBrandKey); Brand bmw = new Brand { Id = 102, Name = "BMW", }; BrandKey bmwBrandKeyCarsBg = new BrandKey { SourceId = 1, BrandId = 102, Key = "bmw_key_cars_bg" }; BrandKey bmwBrandKeyMobileBg = new BrandKey { SourceId = 2, BrandId = 102, Key = "bmw_key_mobile_bg" }; bmw.BrandKeys.Add(bmwBrandKeyCarsBg); bmw.BrandKeys.Add(bmwBrandKeyMobileBg); dbContext.Brands.Add(renault); dbContext.Brands.Add(mercedes); dbContext.Brands.Add(bmw); dbContext.SaveChanges(); BrandFinder brandFinder = new BrandFinder(dbContext); // Act List <BrandSearchDto> brands = brandFinder.GetBrandSearchDtos(SourceEnum.CarsBg); // Assert Assert.That(brands, Has.Count.EqualTo(3)); Assert.That(brands[0].Id, Is.EqualTo(100)); Assert.That(brands[0].BrandKey, Is.EqualTo("renault_key")); Assert.That(brands[1].Id, Is.EqualTo(101)); Assert.That(brands[1].BrandKey, Is.EqualTo("mercedes_key")); Assert.That(brands[2].Id, Is.EqualTo(102)); Assert.That(brands[2].BrandKey, Is.EqualTo("bmw_key_cars_bg")); }
public void When_BrandMissesKeyForSource() { // Arange dbContext.Add(new Source { Id = 1, Name = "cars.bg" }); dbContext.Add(new Source { Id = 2, Name = "mobile.bg" }); dbContext.SaveChanges(); Brand renault = new Brand { Id = 100, Name = "Renault", }; BrandKey renaultBrandKey = new BrandKey { SourceId = 1, BrandId = 100, Key = "renault_key" }; renault.BrandKeys.Add(renaultBrandKey); Brand mercedes = new Brand { Id = 101, Name = "Mercedes", }; BrandKey mercedesBrandKey = new BrandKey { SourceId = 1, BrandId = 101, Key = "mercedes_key" }; mercedes.BrandKeys.Add(mercedesBrandKey); Brand bmw = new Brand { Id = 102, Name = "BMW", }; BrandKey bmwBrandKeyMobileBg = new BrandKey { SourceId = 2, BrandId = 102, Key = "bmw_key_mobile_bg" }; bmw.BrandKeys.Add(bmwBrandKeyMobileBg); dbContext.Brands.Add(renault); dbContext.Brands.Add(mercedes); dbContext.Brands.Add(bmw); dbContext.SaveChanges(); BrandFinder brandFinder = new BrandFinder(dbContext); // Act Assert.Throws <InvalidOperationException>(() => brandFinder.GetBrandSearchDtos(SourceEnum.CarsBg)); }
public void CallInvalidateUrl() { try { m_Logger.DebugFormat("Invalidating cache for section: {0}", m_Section); // Get list of brands BrandFinder finder = new BrandFinder(); IList <Brand> brandList = Brand.FindMany(finder); m_Logger.DebugFormat("Found {0} brands where the cache needs to be invalidated", brandList.Count); // List of URL's that have been processed // This is in case brand share URL's, in which case // we don't want to invalidate the same cache twice. List <string> processUrlList = new List <string>(); foreach (Brand brand in brandList) { // Get the website URL, ensure ends with / string websiteUrl = brand.WebsiteUrl.EnsureEndsWith("/"); // Skip duplicate URL's if (processUrlList.Contains(websiteUrl)) { m_Logger.DebugFormat("Skipping {0}. Duplicate Url: {1}", brand.Name, websiteUrl); continue; } // Not a duplicate, add it to the list processUrlList.Add(websiteUrl); // Construct the URL to the invalidate request string url = string.Concat(websiteUrl, "InvalidateCache.ashx?section=", m_Section); m_Logger.DebugFormat("Sending cache invalidation request to '{0}' (BrandId: {1}) - URL: {2}", brand.Name, brand.BrandId, url); try { // Send the request HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.KeepAlive = false; request.GetResponse().Close(); m_Logger.DebugFormat("Cache invalidation request done. Waiting {0}s before sending next request.", WAIT_BETWEEN_REQUESTS); } catch (Exception e) { m_Logger.WarnFormat("Error sending invalidation request to: {0}. Error: {1}", url, e.Message); } // Wait a few seconds before sending the next request Thread.Sleep(WAIT_BETWEEN_REQUESTS * 1000); } m_Logger.Debug("Done sending invalidation requests."); } catch (Exception e) { m_Logger.Warn(string.Format("Error invalidating cache: {0}", e.Message), e); } }