public void RemoveAll() { var keyCreator = new KeyCreator(_config); var people = new List <Person> { new Person { Id = 1, Name = "person 1" }, new Person { Id = 2, Name = "person 2" }, new Person { Id = 3, Name = "person 3" }, new Person { Id = 4, Name = "person 4" } }; foreach (var person in people) { var key = keyCreator.CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(10)); } _cache.RemoveAll <Person>(); foreach (var person in people) { Assert.IsFalse(_internalCache.Contains(keyCreator.CreateKey(person))); } }
public void GetAll() { var keyCreator = new KeyCreator(_config); var people = new List <Person> { new Person { Id = 1, Name = "person 1" }, new Person { Id = 2, Name = "person 2" }, new Person { Id = 3, Name = "person 3" } }; foreach (var person in people) { var key = keyCreator.CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(10)); } var retrivedPeople = _cache.GetAll <Person>().ToList(); Assert.Contains(people[0], retrivedPeople); Assert.Contains(people[1], retrivedPeople); Assert.Contains(people[2], retrivedPeople); }
internal String CreateCode(Goal item) { // creates public and unique ID return(KeyCreator.RequestKey(String.Format("", item.Name, item.StartDate), CODE_LENGHT, excludeInvalidChars: true, date: DateTimeOffset.Now.DateTime)); }
public void RequestKey_SendValueWithNowDate_Success(bool exluceChars, int limit = -1) { var fixture = CompositionRoot.FixtureInstance; var code = KeyCreator.RequestKey(fixture.Create <int>() + "", limit, DateTimeOffset.Now.DateTime, exluceChars); Assert.IsNotNull(code); Assert.AreEqual(limit, code.Length, "Longitudes no pueden ser diferentes de las ordenadas."); }
public void CreatePartialKey() { _config = new CacheConfiguration(new MemoryCache("KeyCreatorTests"), new MalformedConvention()); _keyCreator = new KeyCreator(_config); var person = new Person { Id = 1, Name = "Maria" }; var createdKey = _keyCreator.CreateKey(person); }
public void RequestKey_SendInvalidValue_Fail() { var fixture = CompositionRoot.FixtureInstance; var code = KeyCreator.RequestKey(Guid.NewGuid().ToString(), -1); Assert.IsNotNull(code); var regex = new Regex(KeyCreator.INVALID_CHARS_REGEX); Assert.IsTrue(regex.IsMatch(code), "There could be matches."); }
public void RequestKey_SendFiniteValuesWithTime_Success() { var test1 = KeyCreator.RequestKey(1 + "", 4, DateTimeOffset.Now.DateTime, true); var test2 = KeyCreator.RequestKey(2 + "", 8, DateTimeOffset.Now.DateTime, true); var test3 = KeyCreator.RequestKey(3 + "", 15, DateTimeOffset.Now.DateTime, true); var test4 = KeyCreator.RequestKey(4 + "", 30, DateTimeOffset.Now.DateTime, true); Assert.IsFalse(test1.Equals(test2), "The contain must not be the same."); Assert.IsFalse(test3.Equals(test4), "The contain must not be the same."); Assert.IsFalse(test1.Equals(test4), "The contain must not be the same."); }
private void SetKeyValue(Type type, object entity) { var propes = type.GetProperties(); var prope = propes.Where(a => a.GetCustomAttribute(typeof(KeyAttribute)) != null).FirstOrDefault(); var value = (long)prope.GetValue(entity); if (value == 0) { value = KeyCreator.CreateKey(); prope.SetValue(entity, value); } }
public void RequestKey_SendValueAndLimitWithNowDate_Success(bool excludeChars, int limit) { var fixture = CompositionRoot.FixtureInstance; var code = KeyCreator.RequestKey(fixture.Create <int>() + "", limit, DateTimeOffset.Now.DateTime, excludeChars); Assert.IsNotNull(code); var regex = new Regex(KeyCreator.INVALID_CHARS_REGEX); Assert.IsFalse(regex.IsMatch(code), "There could not be matches."); Assert.AreEqual(limit, code.Length, "Longitudes no pueden ser diferentes de las ordenadas."); }
public void CreateKey() { _config = new CacheConfiguration(new MemoryCache("KeyCreatorTests")); _keyCreator = new KeyCreator(_config); var person = new Person { Id = 2, Name = "person" }; var key = CreateKey(person, person.Id.ToString()); var createdKey = _keyCreator.CreateKey(person); Assert.AreEqual(key, createdKey); }
public void RequestKey_Success() { var codes = new Dictionary <int, string>(); for (int i = 0; i < 2500; i++) { var value = KeyCreator.RequestKey(i + "", 4); // assert Assert.IsFalse(codes.ContainsValue(value), "El índice {0} es un duplicado de '{1}'.", i, value); // continue... codes.Add(i, value); } }
public void GetItem() { var person = new Person { Id = 1, Name = "person" }; var key = new KeyCreator(_config).CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(1)); var retrivedPerson = _cache.Get <Person>(p => p.Id == person.Id); Assert.AreSame(person, retrivedPerson); }
/// <summary> /// Renders from the cache or adds the result to the cache. /// </summary> /// <param name="helper">The helper.</param> /// <param name="partialRequest">The partial request.</param> /// <param name="content">The content.</param> /// <param name="templateModel">The template model.</param> /// <param name="settings">The settings.</param> protected virtual void RenderFromOrAddToCache(HtmlHelper helper, PartialRequest partialRequest, IContent content, TemplateModel templateModel, ICacheableSettings settings) { string cacheKey = KeyCreator.GenerateCacheKey(settings, helper, content); if (Cache.TryGet(cacheKey, ReadStrategy.Immediate, out string cachedHtml)) { helper.ViewContext.Writer.Write(cachedHtml); } else { RenderAndAddToCache(helper, partialRequest, content, templateModel, settings, cacheKey); } }
public void RequestKey_SendInfiniteValuesWithTime_Success() { //KeyCreator.RequestKey(String.Format("{0}", i), x, DateTimeOffset.Now.DateTime, true); var codes = new Dictionary <int, string>(); for (int i = 0; i < 4500; i++) { var value = KeyCreator.RequestKey(i + "", 5, DateTimeOffset.Now.DateTime, true); // assert Assert.IsFalse(codes.ContainsValue(value), "El índice {0} es un duplicado de '{1}'.", i, value); // continue... codes.Add(i, value); } }
public void RemoveItem() { var person = new Person { Id = 1, Name = "jamir" }; var keyCreator = new KeyCreator(_config); var key = keyCreator.CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(10)); _cache.Remove <Person>(p => p.Id == person.Id); Assert.IsFalse(_internalCache.Contains(key)); }
public void Clear() { var keyCreator = new KeyCreator(_config); var items = new List <object> { new Person { Id = 1, Name = "person 1" }, new Person { Id = 2, Name = "person 2" }, new Person { Id = 3, Name = "person 3" }, new Book { Id = 1, Title = "book 1" }, new Book { Id = 2, Title = "book 2" }, new Book { Id = 3, Title = "book 3" } }; foreach (var item in items) { var key = keyCreator.CreateKey(item); _internalCache.Add(key, item, DateTime.Now + TimeSpan.FromMinutes(10)); } _cache.Clear(); foreach (var item in items) { Assert.IsFalse(_internalCache.Contains(keyCreator.CreateKey(item))); } }
/// <summary> /// Indexes this instance. /// </summary> /// <param name="value">Name of Country/City/Name you want to display.</param> /// <param name="key">Group Of the Display Name.</param> /// <returns> /// view for home /// </returns> public async Task <IActionResult> Index(string value, string key) { if (value != null) { this.ViewBag.Display = value; this.ViewBag.Group = key; } try { var searchKey = KeyCreator.Create(DateTime.Now.ToString("dd/MM/yyyy")); var homepageConfigRs = await this.tableCacheHandler.GetFromCacheAsync( searchKey, () => this.homePageBusiness.GetHomePageConfiguration(), SearchExpiryInSeconds); var result = homepageConfigRs.Result; this.ViewBag.PageType = result.PageType; this.ViewBag.TravelStyle = result.TravelStyle; this.ViewBag.BannersList = result.BannersList; this.ViewBag.PopularDestinations = result.PopularDestinations; this.ViewBag.CurationBanner = result.CurationBanner; this.ViewBag.BlogPosts = result.BlogPosts; this.ViewBag.FlashDeals = result.FlashDeals; this.ViewBag.DealOfMonth = result.DealOfMonth; this.ViewBag.LocationBasedCuration = result.LocationBasedCuration; } catch (Exception ex) { var msg = ex.ToString(); } return(this.View()); }
/// <summary> /// Initializes a new instance of <see cref="WeakSingleValueContainer{T}"/> class. /// </summary> /// <remarks> /// The optional <paramref name="keyCreator"/> is used to /// create an immutable key when adding new items to the container. The creator /// should return a key based on the added value (or the value itself, it the value is immutable). /// The returned key must be equal to the value and have the same hash code. /// </remarks> /// <param name="comparer">An IEqualityComparer`1{T} that is used for equality tests and hash codes.</param> /// <param name="keyCreator">Optional key creator.</param> public WeakSingleValueContainer(IEqualityComparer <T> comparer, KeyCreator <T> keyCreator = null) : base(comparer, keyCreator) { }
/// <summary> /// Initializes a new instance of <see cref="WeakSingleValueContainer{T}"/> class. /// </summary> /// <remarks> /// The optional <paramref name="keyCreator"/> is used to /// create an immutable key when adding new items to the container. The creator /// should return a key based on the added value (or the value itself, it the value is immutable). /// The returned key must be equal to the value and have the same hash code. /// </remarks> /// <param name="keyCreator">Optional key creator.</param> public WeakSingleValueContainer(KeyCreator <T> keyCreator = null) : base(EqualityComparer <T> .Default, keyCreator) { }
/// <summary> /// Initializes a new instance of <see cref="WeakSingleValueContainer{T}"/> class. /// </summary> /// <remarks> /// The optional <paramref name="keyCreator"/> is used to /// create an immutable key when adding new items to the container. The creator /// should return a key based on the added value (or the value itself, it the value is immutable). /// The return key must be equal to the value and have the same hash code. /// </remarks> /// <param name="comparer">An IEqualityComparer`1{T} that is used for equality tests and hash codes.</param> /// <param name="keyCreator">Optional key creator.</param> protected SingleValueContainerBase(IEqualityComparer <T> comparer, KeyCreator <T> keyCreator) { this.comparer = comparer ?? EqualityComparer <T> .Default; this.keyCreator = keyCreator; }
public void RemoveItem() { var person = new Person { Id = 1, Name = "jamir" }; var keyCreator = new KeyCreator(_config); var key = keyCreator.CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(10)); _cache.Remove<Person>(p => p.Id == person.Id); Assert.IsFalse(_internalCache.Contains(key)); }
public void RemoveAll_WithPredicate() { var keyCreator = new KeyCreator(_config); var people = new List<Person> { new Person { Id = 1, Name = "person 1" }, new Person { Id = 2, Name = "person 2" }, new Person { Id = 3, Name = "person 3" }, new Person { Id = 4, Name = "person 4" } }; foreach (var person in people) { var key = keyCreator.CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(10)); } _cache.RemoveAll<Person>(p => p.Name.StartsWith("person")); foreach (var person in people) Assert.IsFalse(_internalCache.Contains(keyCreator.CreateKey(person))); }
public void GetItems() { var keyCreator = new KeyCreator(_config); var people = new List<Person> { new Person { Id = 1, Name = "person 1" }, new Person { Id = 2, Name = "person 2" }, new Person { Id = 3, Name = "person 3" } }; foreach (var person in people) { var key = keyCreator.CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(10)); } var retrivedPeople = _cache.GetAll<Person>(p => p.Name.StartsWith("person")).ToList(); Assert.Contains(people[0], retrivedPeople); Assert.Contains(people[1], retrivedPeople); Assert.Contains(people[2], retrivedPeople); }
public void GetItem() { var person = new Person { Id = 1, Name = "person" }; var key = new KeyCreator(_config).CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(1)); var retrivedPerson = _cache.Get<Person>(p => p.Id == person.Id); Assert.AreSame(person, retrivedPerson); }
public void Clear() { var keyCreator = new KeyCreator(_config); var items = new List<object> { new Person { Id = 1, Name = "person 1" }, new Person { Id = 2, Name = "person 2" }, new Person { Id = 3, Name = "person 3" }, new Book { Id = 1, Title = "book 1" }, new Book { Id = 2, Title = "book 2" }, new Book { Id = 3, Title = "book 3" } }; foreach (var item in items) { var key = keyCreator.CreateKey(item); _internalCache.Add(key, item, DateTime.Now + TimeSpan.FromMinutes(10)); } _cache.Clear(); foreach (var item in items) Assert.IsFalse(_internalCache.Contains(keyCreator.CreateKey(item))); }
/// <summary> /// Initializes a new instance of <see cref="SingleValueContainer{T}"/> class. /// </summary> /// <remarks> /// The optional <paramref name="keyCreator"/> is used to /// create an immutable key when adding new items to the container. The creator /// should return a key based on the added value (or the value itself, if it is immutable). /// The return key must be equal to the value and have the same hash code. /// </remarks> /// <param name="keyCreator">Optional key creator.</param> public SingleValueContainer(KeyCreator <T> keyCreator = null) : base(null, keyCreator) { }
public async Task <IActionResult> SearchOneLevel( bool showSearchTerm, int searchType, int value, string searchTerm, int adults = 1, int kids = 0, int infants = 0, int rooms = 1, string kidsage = null, string startDate = null, string endDate = null) { Tuple <int, int, bool> valueSearchType; if (searchTerm.ToLower() == "flash-deal") { valueSearchType = new Tuple <int, int, bool>(0, (int)Enums.SearchType.FlashDeal, false); } else if (searchTerm.ToLower() == "deals-of-the-month") { valueSearchType = new Tuple <int, int, bool>(0, (int)Enums.SearchType.DealOfTheMonth, false); } else { valueSearchType = await this.listingService.GetValueListTypeOfSearchCountryTravelStyleAsync(searchTerm); } this.ViewBag.startDate = startDate; this.ViewBag.endDate = endDate; this.ViewBag.adults = adults; this.ViewBag.kids = kids; this.ViewBag.infants = infants; this.ViewBag.rooms = rooms; this.ViewBag.searchTerm = searchTerm.Replace("-", " "); this.ViewBag.showSearchTerm = valueSearchType.Item3; ListingViewModel listingModel = new ListingViewModel(); listingModel.SearchTermViewModel = new SearchTermViewModel { Adults = adults, EndDate = endDate, SearchType = valueSearchType.Item2, StartDate = startDate, Kids = kids, Infants = infants, Rooms = rooms, SearchTerm = searchTerm.Replace("-", " "), ShowSearchTerm = valueSearchType.Item3, Value = valueSearchType.Item1, KidsAge = kidsage, StartDateVar = !string.IsNullOrEmpty(startDate) ? DateTime.ParseExact(startDate, "dd-MM-yyyy", null) : DateTime.Now.Date, EndDateVar = !string.IsNullOrEmpty(endDate) ? DateTime.ParseExact(endDate, "dd-MM-yyyy", null) : DateTime.Now.Date.AddYears(1), }; if (!string.IsNullOrEmpty(startDate)) { this.TempData["StartDate"] = listingModel.SearchTermViewModel.StartDateVar; } else { this.TempData["StartDate"] = null; } if (!string.IsNullOrEmpty(endDate)) { this.TempData["EndDate"] = listingModel.SearchTermViewModel.EndDateVar; } else { this.TempData["EndDate"] = null; } if (searchType == (int)Enums.SearchType.Product) { DealsPackageModel dealsPackageModel = await this.homePageService.GetDealPackageByIdAsync(listingModel.SearchTermViewModel.Value); if (dealsPackageModel.Type == 1) ////Hotel { return(this.RedirectToAction("Hotel", "Deal", new { url = dealsPackageModel.Url })); } else { return(this.RedirectToAction("Tour", "Deal", new { url = dealsPackageModel.Url })); } } ListingViewModel result = new ListingViewModel(); try { var searchkey = KeyCreator.Create(listingModel); var productRs = await this.tableCacheHandler.GetFromCacheAsync( searchkey, () => this.homePageBusiness.GetSearchResults(listingModel), SearchExpiryInSeconds); result = productRs.Result; } catch (Exception ex) { result = this.listingService.GetSearchResults(listingModel); string msg = ex.ToString(); } this.ViewBag.FilterActivated = false; if (result.ResultViewModels.Count == 0) { result.TrendingDeals = this.listingService.GetTop6TrendingDeals(); } return(this.View("Search", result)); }
public async Task <IActionResult> SearchHolidayProduct( bool showSearchTerm, int searchType, int value, string searchTerm, string subSearchTerm, int adults = 1, int kids = 0, int infants = 0, int rooms = 1, string kidsage = null, string startDate = null, string endDate = null) { Tuple <int, int, bool, string> valueSearchType; valueSearchType = await this.listingService.GetProductUrlAsync(searchTerm); if (valueSearchType.Item2 == (int)Enums.SearchType.Product) { return(this.RedirectToAction("Holiday", "Deal", new { url = valueSearchType.Item4 })); } this.ViewBag.startDate = startDate; this.ViewBag.endDate = endDate; this.ViewBag.adults = adults; this.ViewBag.kids = kids; this.ViewBag.infants = infants; this.ViewBag.rooms = rooms; this.ViewBag.searchTerm = searchTerm; this.ViewBag.showSearchTerm = valueSearchType.Item3; ListingViewModel listingModel = new ListingViewModel(); listingModel.SearchTermViewModel = new SearchTermViewModel { Adults = adults, EndDate = endDate, SearchType = valueSearchType.Item2, StartDate = startDate, Kids = kids, Infants = infants, Rooms = rooms, SearchTerm = searchTerm, ShowSearchTerm = valueSearchType.Item3, Value = valueSearchType.Item1, KidsAge = kidsage, StartDateVar = !string.IsNullOrEmpty(startDate) ? DateTime.ParseExact(startDate, "dd-MM-yyyy", null) : DateTime.Now.Date, EndDateVar = !string.IsNullOrEmpty(endDate) ? DateTime.ParseExact(endDate, "dd-MM-yyyy", null) : DateTime.Now.Date.AddYears(1), }; if (!string.IsNullOrEmpty(startDate)) { this.TempData["StartDate"] = listingModel.SearchTermViewModel.StartDateVar; } else { this.TempData["StartDate"] = null; } if (!string.IsNullOrEmpty(endDate)) { this.TempData["EndDate"] = listingModel.SearchTermViewModel.EndDateVar; } else { this.TempData["EndDate"] = null; } ListingViewModel result = new ListingViewModel(); try { var searchkey = KeyCreator.Create(listingModel); var productRs = await this.tableCacheHandler.GetFromCacheAsync( searchkey, () => this.homePageBusiness.GetSearchResults(listingModel), SearchExpiryInSeconds); result = productRs.Result; } catch (Exception ex) { result = this.listingService.GetSearchResults(listingModel); string msg = ex.ToString(); } this.ViewBag.FilterActivated = false; if (result.ResultViewModels.Count == 0) { result.TrendingDeals = this.listingService.GetTop6TrendingDeals(); } return(this.View("Search", result)); }