예제 #1
0
        public void Create_Should_ThrowException_When_Movie_AlreadyExists()
        {
            InMemoryCache cache      = new InMemoryCache();
            Movie         FakeMovie1 = new Movie()
            {
                MovieId = 1,
                Title   = "New Movie"
            };

            cache.Create(FakeMovie1);

            Movie FakeMovie2 = new Movie()
            {
                MovieId = 1,
                Title   = "New Movie"
            };

            cache.Create(FakeMovie2);
        }
예제 #2
0
        public void Create_Should_AddNewMovie_Without_Exceptions()
        {
            InMemoryCache cache     = new InMemoryCache();
            Movie         FakeMovie = new Movie()
            {
                MovieId = 1,
                Title   = "New Movie"
            };

            cache.Create(FakeMovie);
            Assert.IsTrue(true);
        }
예제 #3
0
        public void INvalidate_Clears_Cache()
        {
            InMemoryCache cache = new InMemoryCache();

            cache.Create(new Movie()
            {
                MovieId = 1, Title = "New Movie"
            });

            cache.Invalidate();
            List <Movie> movies = cache.SearchMovies(new SearchObject("MovieId", "=", "1"));

            Assert.AreEqual(movies.Count, 0);
        }
예제 #4
0
        public async Task <List <RestaurantDto> > GetRestaurants()
        {
            var restaurants = _restaurantCache.Get <List <RestaurantDto> >(DateTime.UtcNow.AddHours(9).ToString("yyyy-MM-dd"));

            if (restaurants == null || restaurants.Count <= 0)
            {
                restaurants = _mySqlRestaurantDataService.GetRestaurants();

                if (restaurants.Count <= 0 || restaurants == null)
                {
                    throw new RestaurantNotFoundException($"can not find any restaurants.");
                }

                bool isCreated = await _restaurantCache.Create(restaurants.FirstOrDefault().date.ToString("yyyy-MM-dd"), restaurants);

                if (!isCreated)
                {
                    throw new CreateCacheException($"failed to create cache.");
                }
            }

            return(restaurants);
        }