public async Task GetAllContinentsAsync_ContinentsNotInCache_SaveInCache()
        {
            #region Arrange
            var continents = new List <Continent>
            {
                new Continent
                {
                    code = "AF",
                    name = "Africa"
                },
                new Continent
                {
                    code = "AN",
                    name = "Antarctica"
                }
            };
            Mock <ICacheContinentRepository> cacheRepositoryMock = GenerateCacheRepositoryMock();
            Mock <IGraphQLRepository>        graphQLMock         = GenerateGraphQLMock(continents);
            var continentRepository = new ContinentRepository(_logger, cacheRepositoryMock.Object, graphQLMock.Object);
            #endregion


            #region Act
            var result = await continentRepository.GetAllContinentsAsync();

            #endregion


            #region Assert
            cacheRepositoryMock.Verify(c => c.SaveAllContinentsAsync(It.IsAny <ICollection <Continent> >()));
            #endregion
        }
        public async Task GetAllContinentsAsync_ContinentsNotInCache_ReturnContinentsCollectionFromGraphQL()
        {
            #region Arrange
            var continents = new List <Continent>
            {
                new Continent
                {
                    code = "AF",
                    name = "Africa"
                },
                new Continent
                {
                    code = "AN",
                    name = "Antarctica"
                }
            };
            Mock <ICacheContinentRepository> cacheRepositoryMock = GenerateCacheRepositoryMock();
            Mock <IGraphQLRepository>        graphQLMock         = GenerateGraphQLMock(continents);
            var continentRepository = new ContinentRepository(_logger, cacheRepositoryMock.Object, graphQLMock.Object);
            #endregion


            #region Act
            var result = await continentRepository.GetAllContinentsAsync();

            #endregion


            #region Assert
            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(continents);
            #endregion
        }
        public async Task GetAllContinentsAsync_NotExistInRedis_GraphQLThrowException_LogErrorAndThrowException()
        {
            #region Arrange
            var continents = new List <Continent>
            {
                new Continent
                {
                    code = "AF",
                    name = "Africa"
                },
                new Continent
                {
                    code = "AN",
                    name = "Antarctica"
                }
            };
            Mock <ICacheContinentRepository> cacheRepositoryMock = GenerateCacheRepositoryMock();
            Mock <IGraphQLRepository>        graphQLMock         = new Mock <IGraphQLRepository>();
            graphQLMock.Setup(g => g.GetAllContinentsAsync())
            .ThrowsAsync(new Exception("test exception"));
            var continentRepository = new ContinentRepository(_logger, cacheRepositoryMock.Object, graphQLMock.Object);
            #endregion

            #region Act
            bool isExceptionThrow          = false;
            ICollection <Continent> result = null;
            try
            {
                result = await continentRepository.GetAllContinentsAsync();
            }
            catch (Exception e)
            {
                isExceptionThrow = e.Message == ContinentRepository.GetDataFromGraphQLError;
            }
            #endregion


            #region Assert
            result.Should().BeNull();
            isExceptionThrow.Should().BeTrue();
            InMemorySink.Instance.Should().HaveMessage(ContinentRepository.GetDataFromGraphQLError)
            .WithLevel(Serilog.Events.LogEventLevel.Error);
            #endregion
        }
        public async Task GetAllContinentsAsync_CacheThrowException_LogErrorAndReturnContinentsCollectionFromGraphQL()
        {
            #region Arrange
            var continents = new List <Continent>
            {
                new Continent
                {
                    code = "AF",
                    name = "Africa"
                },
                new Continent
                {
                    code = "AN",
                    name = "Antarctica"
                }
            };
            Mock <ICacheContinentRepository> cacheRepositoryMock = new Mock <ICacheContinentRepository>();
            cacheRepositoryMock.Setup(c => c.GetAllContinentsAsync())
            .ThrowsAsync(new Exception("some exceptio on get"));
            cacheRepositoryMock.Setup(c => c.SaveAllContinentsAsync(It.IsAny <ICollection <Continent> >()))
            .ThrowsAsync(new Exception("some exceptio on save"));
            Mock <IGraphQLRepository> graphQLMock = GenerateGraphQLMock(continents);
            var continentRepository = new ContinentRepository(_logger, cacheRepositoryMock.Object, graphQLMock.Object);
            #endregion


            #region Act
            var result = await continentRepository.GetAllContinentsAsync();

            #endregion


            #region Assert
            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(continents);
            InMemorySink.Instance.Should().HaveMessage(ContinentRepository.GetDataFromCacheError)
            .WithLevel(Serilog.Events.LogEventLevel.Error);
            InMemorySink.Instance.Should().HaveMessage(ContinentRepository.SaveDataInCacheError)
            .WithLevel(Serilog.Events.LogEventLevel.Error);
            #endregion
        }