Esempio n. 1
0
        // GET: Countries2/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Country country = repo.Get(c => c.Id == id);

            if (country == null)
            {
                return(HttpNotFound());
            }
            return(View(country));
        }
        public void CountryRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            ICountryRepository countryRepository = new CountryRepository(unitOfWork);

            var country = new Country()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                CountryName = "France",
                CountryISOCode = "fr-FR"
            };

            //Act

            countryRepository.Add(country);
            countryRepository.UnitOfWork.Commit();

            //Assert

            var result = countryRepository.Get(country.Id);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id == country.Id);
        }
Esempio n. 3
0
        public string GetCountryByID(int id)
        {
            string country = null;

            country = countryRepo.Get(id);
            return(country);
        }
Esempio n. 4
0
        public void Get_ById_Returns_FoundItem()
        {
            var data = new List <Country>
            {
                new Country {
                    CountryId = 2, IsoCode = "BB", Name = "YYY"
                },
                new Country {
                    CountryId = 1, IsoCode = "AA", Name = "XXX"
                },
                new Country {
                    CountryId = 3, IsoCode = "CC", Name = "UUU"
                },
            };

            var mockSet = new Mock <DbSet <Country> >().SetupData(data,
                                                                  objects => data.SingleOrDefault(d => d.CountryId == (long)objects.First()));
            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Countries).Returns(mockSet.Object);
            mockContext.Setup(c => c.Set <Country>()).Returns(mockSet.Object);

            var service = new CountryRepository(mockContext.Object);

            // Act
            var item = service.Get(2);

            Assert.IsNotNull(item);
            Assert.AreEqual(item.IsoCode, "BB");
        }
Esempio n. 5
0
        public void Get_Returns_Sorted_Items()
        {
            var data = new List <Country>
            {
                new Country {
                    IsoCode = "BB", Name = "YYY"
                },
                new Country {
                    IsoCode = "AA", Name = "XXX"
                },
                new Country {
                    IsoCode = "CC", Name = "UUU"
                },
            };

            var mockSet     = new Mock <DbSet <Country> >().SetupData(data);
            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Countries).Returns(mockSet.Object);

            var service = new CountryRepository(mockContext.Object);

            // Act
            var items = service.Get().ToList();

            Assert.IsNotNull(items);
            Assert.AreEqual(items.Count, data.Count);
            Assert.AreEqual(items[0].IsoCode, "AA");
            Assert.AreEqual(items[1].IsoCode, "BB");
            Assert.AreEqual(items[2].IsoCode, "CC");
        }
Esempio n. 6
0
        public void Get_ByIsoCode_Returns_FoundItem()
        {
            var data = new List <Country>
            {
                new Country {
                    IsoCode = "BB", Name = "YYY"
                },
                new Country {
                    IsoCode = "AA", Name = "XXX"
                },
                new Country {
                    IsoCode = "CC", Name = "UUU"
                },
            };

            var mockSet     = new Mock <DbSet <Country> >().SetupData(data);
            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Countries).Returns(mockSet.Object);

            var service = new CountryRepository(mockContext.Object);

            // Act
            var item = service.Get("BB");

            Assert.IsNotNull(item);
            Assert.AreEqual(item.IsoCode, "BB");
        }
Esempio n. 7
0
        public ProfileViewModel GetProfileByUserProfileID(int userProfileID)
        {
            UserProfileRepository repo        = new UserProfileRepository();
            ICountryRepository    countryRepo = new CountryRepository();
            IStateRepository      stateRepo   = new StateRepository();
            ICityRepository       cityRepo    = new CityRepository();

            ProfileViewModel viewModel = new ProfileViewModel();

            var yourProfile = repo.Get().Where(s => s.UserProfileID == userProfileID).FirstOrDefault();

            if (yourProfile != null)
            {
                var city    = cityRepo.Get().Where(s => s.CityID == yourProfile.CityID).FirstOrDefault();
                var state   = stateRepo.Get().Where(s => s.StateID == city.StateID).FirstOrDefault();
                var country = countryRepo.Get().Where(s => s.CountryID == state.CountryID).FirstOrDefault();

                viewModel.UserID         = yourProfile.UserID;
                viewModel.UserProfileID  = yourProfile.UserProfileID;
                viewModel.OrganizationID = yourProfile.OrganizationID;
                viewModel.FirstName      = yourProfile.FirstName;
                viewModel.LastName       = yourProfile.LastName;
                viewModel.Address        = yourProfile.Address;
                viewModel.Gender         = yourProfile.Gender;
                viewModel.MobileNO       = yourProfile.PhoneNo;
                viewModel.ProfilePicPath = yourProfile.ProfilePicPath;
                viewModel.DOB            = yourProfile.DOB;
                viewModel.City           = city.CityName;
                viewModel.State          = state.StateName;
                viewModel.Country        = country.CoutnryName;
            }
            return(viewModel);
        }
        public void A_ChangedCountry_modifies_Existing_country_in_the_database()
        {
            var bootStrapper = new BootStrapper();
            bootStrapper.StartServices();
            var serviceEvents = bootStrapper.GetService<IServiceEvents>();
            //1.- Create message
            var aggr = GenerateRandomAggregate();

            //2.- Create the tuple in the database
            var repository = new CountryRepository(_configuration.TestServer);
            repository.Insert(aggr);

            //3.- Change the aggregate
            aggr.NameKeyId = StringExtension.RandomString(20);
            aggr.CurrencyId = Guid.NewGuid();

            //4.- Emit message
            var message = GenerateMessage(aggr);
            message.MessageType = typeof(ChangedCountry).Name;
            serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message });

            //5.- Load the saved country
            var country = repository.Get(aggr.Id);
            //6.- Check equality
            Assert.True(ObjectExtension.AreEqual(aggr, country));
            
        }
Esempio n. 9
0
      public void GetByIdCountryTest()
      {
          var contetx    = new ApplicationDbContext();
          var firstRawId = contetx.Country.FirstOrDefault().Id;
          var target     = new CountryRepository(contetx);
          var result     = target.Get(firstRawId);

          Assert.IsNotNull(result);
          Assert.IsTrue(firstRawId == result.Id);
      }
Esempio n. 10
0
        public void CountryRepositoryGetMethodReturnNullWhenIdIsEmpty()
        {
            //Arrange
            var countryRepository = new CountryRepository(fixture.unitOfWork, fixture.countryLogger);

            //Act
            var country = countryRepository.Get(Guid.Empty);

            //Assert
            Assert.Null(country);
        }
Esempio n. 11
0
        public HttpResponseMessage Get(int id)
        {
            var repo     = new CountryRepository();
            var entities = repo.Get(id);

            var json = JsonConvert.SerializeObject(entities);

            return(new HttpResponseMessage {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }
        public void CountryRepositoryGetMethodReturnNullWhenIdIsEmpty()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);

            //Act
            var country = countryRepository.Get(Guid.Empty);

            //Assert
            Assert.IsNull(country);
        }
Esempio n. 13
0
        public void CountryRepositoryGetMethodReturnNullWhenIdIsEmpty()
        {
            //Arrange
            var unitOfWork        = new MainBcUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);

            //Act
            var country = countryRepository.Get(Guid.Empty);

            //Assert
            Assert.IsNull(country);
        }
Esempio n. 14
0
        public void CountryRepositoryGetMethodReturnMaterializedEntityById()
        {
            //Arrange
            var countryRepository = new CountryRepository(fixture.unitOfWork, fixture.countryLogger);
            var countryId         = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C");

            //Act
            var country = countryRepository.Get(countryId);

            //Assert
            Assert.NotNull(country);
            Assert.True(country.Id == countryId);
        }
Esempio n. 15
0
      public void UpdateCountryTest()
      {
          var context = new ApplicationDbContext();
          var country = context.Country.FirstOrDefault();
          var target  = new CountryRepository(context);

          country.Title = Guid.NewGuid().ToString();
          target.Update(country);
          target.Complete();
          var actual = target.Get(country.Id);

          Assert.AreEqual(actual.Title, country.Title);
      }
        public void CountryRepositoryGetMethodReturnMaterializedEntityById()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);
            var countryId = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C");

            //Act
            var country = countryRepository.Get(countryId);
            
            //Assert
            Assert.IsNotNull(country);
            Assert.IsTrue(country.Id == countryId);
        }
Esempio n. 17
0
        public void CountryRepositoryGetMethodReturnMaterializedEntityById()
        {
            //Arrange
            var unitOfWork        = new MainBcUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);
            var countryId         = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C");

            //Act
            var country = countryRepository.Get(countryId);

            //Assert
            Assert.IsNotNull(country);
            Assert.IsTrue(country.Id == countryId);
        }
Esempio n. 18
0
 public void A_RegisteredCountry_creates_a_new_country_in_the_database()
 {
     var bootStrapper = new BootStrapper();
     bootStrapper.StartServices();
     var serviceEvents = bootStrapper.GetService<IServiceEvents>();
     //1.- Create message
     var aggr = GenerateRandomAggregate();
     var message = GenerateMessage(aggr);
     //2.- Emit message
     serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message });
     //3.- Load the saved country
     var repository = new CountryRepository(_configuration.TestServer);
     var country = repository.Get(aggr.Id);
     //4.- Check equality
     Assert.True(ObjectExtension.AreEqual(aggr, country));
 }
Esempio n. 19
0
        public override void Create(UserDto userDto)
        {
            var countryRepository  = new CountryRepository();
            var languageRepository = new LanguageRepository();

            if (userDto.Country == null ||
                userDto.Language == null ||
                languageRepository.Get(userDto.Language.Id) == null ||
                countryRepository.Get(userDto.Country.Id) == null)
            {
                throw new Exception("Country and/or Language cannot be null value");
            }

            _repository.Create(new User
            {
                Language_Id  = userDto.Language.Id,
                Country_Id   = userDto.Country.Id,
                Email        = userDto.Email,
                Id           = userDto.Id,
                PasswordHash = HashPassword(userDto.PasswordHash),
                Nickname     = userDto.Nickname,
                Timestamp    = DateTime.Now
            });
        }
Esempio n. 20
0
        public async Task <bool> UpdateCountryAsync(CountryDVM entity)
        {
            bool result = false;

            if (entity != null)
            {
                Country d = countryRepository.Get(entity.Code);
                if (d != null)
                {
                    d.Name = entity.Name;
                    try
                    {
                        await countryRepository.UpdateAsync(d);

                        result = true;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            return(result);
        }
Esempio n. 21
0
        public void A_UnregisteredCountry_modifies_Existing_country_in_the_database()
        {
            var bootStrapper = new BootStrapper();
            bootStrapper.StartServices();
            var serviceEvents = bootStrapper.GetService<IServiceEvents>();
            //1.- Create message
            var aggr = GenerateRandomAggregate();

            //2.- Create the tuple in the database
            var repository = new CountryRepository(_configuration.TestServer);
            repository.Insert(aggr);

            //2.- Emit message
            var message = GenerateMessage(aggr);
            message.MessageType = typeof(UnregisteredCountry).Name;
            serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message });

            var country = repository.Get(aggr.Id);
            Assert.Null(country);
            
        }
 public async Task <CountryEntity> Get(string countryCode)
 {
     return(await countryRepo.Get(countryCode));
 }
Esempio n. 23
0
        public IEnumerable <Country> GetCountries()
        {
            ICountryRepository countryRepo = new CountryRepository();

            return(countryRepo.Get());
        }
Esempio n. 24
0
        public ActionResult GetCountryIso(int id)
        {
            var repo = new CountryRepository();

            return(Json(repo.Get(id).Iso2, JsonRequestBehavior.AllowGet));
        }
Esempio n. 25
0
 public Country Get(int id)
 {
     return(CountryRepository.Get(t => t.CountryId == id));
 }
        public void CountryRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            ICountryRepository countryRepository = new CountryRepository(unitOfWork);

            Country country = new Country()
            {
                CountryName = "England",
                CountryISOCode = "en-EN"
            };

            country.Id = IdentityGenerator.NewSequentialGuid();

            countryRepository.Add(country);
            countryRepository.UnitOfWork.Commit();

            //Act

            countryRepository.Remove(country);
            countryRepository.UnitOfWork.Commit();

            var result = countryRepository.Get(country.Id);

            //Assert
            Assert.IsNull(result);
        }