Exemplo n.º 1
0
        public void ContinentRepositoryFunction_AddContinent_FunctionalityTest()
        {
            GeographyContextTest context = new GeographyContextTest(false);
            ContinentRepository  repo    = new ContinentRepository(context);

            Continent continent  = new Continent("Continent");
            Continent continent2 = new Continent("Continent2");

            Continent continent3 = new Continent("Continent4");

            continent3.AddCountry(new Country(12, "Country1", 20.0f, continent3));

            repo.AddContinent(continent);
            context.SaveChanges();

            repo.AddContinent(continent2);
            context.SaveChanges();

            repo.AddContinent(continent3);
            context.SaveChanges();


            repo.GetContinent(1).Name.Should().Be(continent.Name);
            repo.GetContinent(2).Name.Should().Be(continent2.Name);

            var continentWithCountries = repo.GetContinent(3);

            continentWithCountries.Name.Should().Be(continent3.Name);

            continentWithCountries.Countries.Count.Should().Be(1);
            continentWithCountries.Countries[0].Name.Should().Be("Country1");
            continentWithCountries.Countries[0].Population.Should().Be(12);
            continentWithCountries.Countries[0].Surface.Should().Be(20.0f);
        }
Exemplo n.º 2
0
 /// <summary>Creates an instance for the given language.</summary>
 /// <param name="culture">The culture.</param>
 /// <returns>A repository.</returns>
 public IContinentRepository ForCulture(CultureInfo culture)
 {
     Contract.Ensures(Contract.Result<IContinentRepository>() != null);
     IContinentRepository repository = new ContinentRepository(this.serviceClient);
     repository.Culture = culture;
     return repository;
 }
        public void CountryRepositoryFunction_AddCountry_FunctionalityTest()
        {
            GeographyContextTest context       = new GeographyContextTest(true);
            CountryRepository    countryRepo   = new CountryRepository(context);
            ContinentRepository  continentRepo = new ContinentRepository(context);

            Continent continent = new Continent("Continent60");

            context.SaveChanges();

            continentRepo.AddContinent(continent);
            context.SaveChanges();

            countryRepo.AddCountry(4, "Country60", 20, 30.0f);
            context.SaveChanges();

            var countryFromRepo = countryRepo.GetCountry(4, 2);

            continentRepo.HasCountries(4).Should().BeTrue();

            countryFromRepo.Name.Should().Be("Country60");
            countryFromRepo.Population.Should().Be(20);
            countryFromRepo.Surface.Should().Be(30.0f);
            countryFromRepo.Continent.Name.Should().Be("Continent60");
        }
        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 GetContinentAsync_ContinentExistInCache_ReturnContinentFromCache()
        {
            #region Arrange
            var expectedContinent = new Continent
            {
                code      = "AF",
                name      = "Africa",
                countries = new List <Country> {
                    new Country
                    {
                        code = "test",
                    }
                }
            };
            Mock <ICacheContinentRepository> cacheRepositoryMock = GenerateCacheRepositoryMock(continent: expectedContinent, isContinentInCache: true);
            Mock <IGraphQLRepository>        graphQLMock         = GenerateGraphQLMock(continent: expectedContinent);
            var continentRepository = new ContinentRepository(_logger, cacheRepositoryMock.Object, graphQLMock.Object);
            #endregion


            #region Act
            var result = await continentRepository.GetContinentByCodeAsync(expectedContinent.code);

            #endregion


            #region Assert
            cacheRepositoryMock.Verify(c => c.GetContinentByCodeAsync(It.Is <string>(s => s == expectedContinent.code)));
            cacheRepositoryMock.Verify(c => c.SaveContinentByCodeAsync(It.Is <string>(s => s == expectedContinent.code), It.IsAny <Continent>()));
            graphQLMock.VerifyNoOtherCalls();
            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(expectedContinent);
            #endregion
        }
 //Return All
 public List <ContinentViewModel> ReturnAllContinents(string searchCriteria = null)
 {
     using (var repository = new ContinentRepository())
     {
         return(repository.GetAllContinents(searchCriteria).Select(x => x.ToModel()).ToList());
     }
 }
 //Return
 public ContinentViewModel ReturnContinent(int Id)
 {
     using (var repository = new ContinentRepository())
     {
         return(repository.FindContinent(Id)?.ToModel());
     }
 }
 //Delete
 public void DeleteContinent(int Id)
 {
     using (var repository = new ContinentRepository())
     {
         repository.RemoveContinent(Id);
     }
 }
        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
        }
Exemplo n.º 10
0
        public UnitOfWork(DataContext context)
        {
            this.context = context;

            Continents = new ContinentRepository(this.context);
            Countries  = new CountryRepository(this.context);
        }
Exemplo n.º 11
0
        public void ContinentRepositoryFunction_HasCountries_FunctionalityTest()
        {
            GeographyContextTest context = new GeographyContextTest(true);
            ContinentRepository  repo    = new ContinentRepository(context);

            repo.HasCountries(1).Should().BeFalse();
            repo.HasCountries(3).Should().BeTrue();
        }
Exemplo n.º 12
0
        public void ContinentRepositoryFunction_IsInDatabaseWithName_FunctionalityTest()
        {
            GeographyContextTest context = new GeographyContextTest(true);
            ContinentRepository  repo    = new ContinentRepository(context);

            repo.IsInDatabase(1).Should().BeTrue();

            repo.IsInDatabase(29).Should().BeFalse();
        }
Exemplo n.º 13
0
        public void ContinentRepositoryFunction_GetContinentWithName_FunctionalityTest()
        {
            GeographyContextTest context = new GeographyContextTest(true);
            ContinentRepository  repo    = new ContinentRepository(context);

            Continent continent = repo.GetContinent("Continent");

            continent.Name.Should().Be("Continent");
        }
Exemplo n.º 14
0
        /// <summary>Creates an instance for the given language.</summary>
        /// <param name="culture">The culture.</param>
        /// <returns>A repository.</returns>
        public IContinentRepository ForCulture(CultureInfo culture)
        {
            var size2DConverter              = new Size2DConverter();
            var continentConverter           = new ContinentConverter(size2DConverter);
            var continentCollectionConverter = new ContinentCollectionConverter(continentConverter);
            IContinentRepository repository  = new ContinentRepository(this.serviceClient, continentCollectionConverter);

            repository.Culture = culture;
            return(repository);
        }
Exemplo n.º 15
0
        public string GetLand()
        {
            var land =
                new LandRepository(new GeoContext()).FindAll()
                .FirstOrDefault(l => l.Klimatogrammen.Any(k => k.KlimatogramId == KlimatogramId));
            var continent =
                new ContinentRepository(new GeoContext()).FindAll()
                .FirstOrDefault(l => l.Landen.Any(la => la.LandId == land.LandId));

            return(", " + land.Naam + ", " + continent.Naam);
        }
Exemplo n.º 16
0
        public void ContinentRepositoryFunction_DeleteContinent_FunctionalityTest()
        {
            GeographyContextTest context = new GeographyContextTest(true);
            ContinentRepository  repo    = new ContinentRepository(context);

            repo.DeleteContinent(2);

            context.SaveChanges();

            repo.IsInDatabase(1).Should().BeTrue();
            repo.IsInDatabase(2).Should().BeFalse();
        }
        //Update
        public void UpdateContinent(ContinentViewModel continent)
        {
            using (var repository = new ContinentRepository())
            {
                var continentDbModel = new Continent
                {
                    Id   = continent.Id,
                    Name = continent.Name
                };

                repository.EditContinent(continentDbModel);
            }
        }
        //Create
        public void CreateContinent(ContinentViewModel continent)
        {
            using (var repository = new ContinentRepository())
            {
                var ContinentDbModel = new Continent
                {
                    Id   = continent.Id,
                    Name = continent.Name
                };

                repository.AddContinent(ContinentDbModel);
            }
        }
Exemplo n.º 19
0
        /// <summary>Creates an instance for the given language.</summary>
        /// <param name="culture">The culture.</param>
        /// <exception cref="ArgumentNullException">The value of <paramref name="culture"/> is a null reference.</exception>
        /// <returns>A repository.</returns>
        public override IContinentRepository ForCulture(CultureInfo culture)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }

            var continentConverter          = new ContinentConverter();
            var identifiersConverter        = new ResponseConverter <ICollection <int>, ICollection <int> >(new ConverterAdapter <ICollection <int> >());
            var responseConverter           = new ResponseConverter <ContinentDTO, Continent>(continentConverter);
            var pageResponseConverter       = new CollectionPageResponseConverter <ContinentDTO, Continent>(continentConverter);
            var bulkResponseConverter       = new DictionaryRangeResponseConverter <ContinentDTO, int, Continent>(continentConverter, cont => cont.ContinentId);
            IContinentRepository repository = new ContinentRepository(this.serviceClient, identifiersConverter, responseConverter, bulkResponseConverter, pageResponseConverter);

            repository.Culture = culture;
            return(repository);
        }
Exemplo n.º 20
0
        public void ContinentRepositoryFunction_GetContinentWithId_FunctionalityTest()
        {
            GeographyContextTest context = new GeographyContextTest(true);
            ContinentRepository  repo    = new ContinentRepository(context);

            Continent continent = repo.GetContinent(1);

            continent.Name.Should().Be("Continent");

            var continentWithCountries = repo.GetContinent(3);

            continentWithCountries.Name.Should().Be("Continent4");

            continentWithCountries.Countries.Count.Should().Be(1);
            continentWithCountries.Countries[0].Name.Should().Be("Country1");
            continentWithCountries.Countries[0].Population.Should().Be(12);
            continentWithCountries.Countries[0].Surface.Should().Be(20.0f);
        }
Exemplo n.º 21
0
        public void ContinentRepositoryFunction_UpdateContinent_FunctionalityTest()
        {
            GeographyContextTest context = new GeographyContextTest(true);
            ContinentRepository  repo    = new ContinentRepository(context);



            Continent continent = repo.GetContinent(1);

            continent.Name.Should().Be("Continent");

            repo.UpdateContinent(1, new Continent("Continent3"));
            context.SaveChanges();

            continent = repo.GetContinent(1);

            continent.Name.Should().Be("Continent3");
        }
Exemplo n.º 22
0
        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
        }
Exemplo n.º 23
0
        public async Task GetContinentAsync_ContinentNotExistInCache_GraphQLThrowException_LogErrorAndThrowException()
        {
            #region Arrange
            var expectedContinent = new Continent
            {
                code      = "AF",
                name      = "Africa",
                countries = new List <Country> {
                    new Country
                    {
                        code = "test",
                    }
                }
            };
            Mock <ICacheContinentRepository> cacheRepositoryMock = GenerateCacheRepositoryMock(continent: expectedContinent, isContinentInCache: false);
            Mock <IGraphQLRepository>        graphQLMock         = new Mock <IGraphQLRepository>();
            graphQLMock.Setup(g => g.GetContinentByCodeAsync(It.Is <string>(s => s == expectedContinent.code)))
            .ThrowsAsync(new Exception("test exception"));
            var continentRepository = new ContinentRepository(_logger, cacheRepositoryMock.Object, graphQLMock.Object);
            #endregion


            #region Act
            bool      isExceptionThrow = false;
            Continent result           = null;
            try
            {
                result = await continentRepository.GetContinentByCodeAsync(expectedContinent.code);
            }
            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
        }
Exemplo n.º 24
0
        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
        }
Exemplo n.º 25
0
        public async Task GetContinentAsync_CacheThrowException_LogErrorAndReturnContinentFromGraphQL()
        {
            #region Arrange
            var expectedContinent = new Continent
            {
                code      = "AF",
                name      = "Africa",
                countries = new List <Country> {
                    new Country
                    {
                        code = "test",
                    }
                }
            };
            Mock <ICacheContinentRepository> cacheRepositoryMock = new Mock <ICacheContinentRepository>();
            cacheRepositoryMock.Setup(c => c.GetContinentByCodeAsync(It.IsAny <string>()))
            .ThrowsAsync(new Exception("some exceptio"));
            cacheRepositoryMock.Setup(c => c.SaveContinentByCodeAsync(It.IsAny <string>(), It.IsAny <Continent>()))
            .ThrowsAsync(new Exception("some exceptio")); Mock <IGraphQLRepository> graphQLMock = GenerateGraphQLMock(continent: expectedContinent);
            var continentRepository = new ContinentRepository(_logger, cacheRepositoryMock.Object, graphQLMock.Object);
            #endregion


            #region Act
            var result = await continentRepository.GetContinentByCodeAsync(expectedContinent.code);

            #endregion


            #region Assert
            graphQLMock.Verify(g => g.GetContinentByCodeAsync(It.Is <string>(s => s == expectedContinent.code)));
            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(expectedContinent);

            InMemorySink.Instance.Should().HaveMessage(ContinentRepository.GetDataFromCacheError)
            .WithLevel(Serilog.Events.LogEventLevel.Error);
            InMemorySink.Instance.Should().HaveMessage(ContinentRepository.SaveDataInCacheError)
            .WithLevel(Serilog.Events.LogEventLevel.Error);
            #endregion
        }
Exemplo n.º 26
0
 public UnitOfWork(GeoServiceContext context)
 {
     this.context = context;
     Continents   = new ContinentRepository(context);
     Rivers       = new RiversRepository(context);
 }
 /// <summary>Creates an instance for the given language.</summary>
 /// <param name="culture">The culture.</param>
 /// <returns>A repository.</returns>
 public IContinentRepository ForCulture(CultureInfo culture)
 {
     var size2DConverter = new Size2DConverter();
     var continentConverter = new ContinentConverter(size2DConverter);
     var continentCollectionConverter = new ContinentCollectionConverter(continentConverter);
     IContinentRepository repository = new ContinentRepository(this.serviceClient, continentCollectionConverter);
     repository.Culture = culture;
     return repository;
 }
 /// <summary>Creates an instance for the given language.</summary>
 /// <param name="culture">The culture.</param>
 /// <returns>A repository.</returns>
 public IContinentRepository ForCulture(CultureInfo culture)
 {
     IContinentRepository repository = new ContinentRepository(this.serviceClient);
     repository.Culture = culture;
     return repository;
 }
Exemplo n.º 29
0
 public void Init()
 {
     continentRepository = new ContinentRepository();
 }