Exemplo n.º 1
0
 public void GolfCourseRepository_GetAll_ReturnsProperCount()
 {
     using (var context = Context)
     {
         var repo    = new GolfCourseRepository(context);
         var courses = repo.GetAll().ToArray();
         courses.Should().NotBeEmpty().And.HaveCount(c => c > 1);
         Console.WriteLine($"Number of GolfCourses is {courses.Count()}");
     }
 }
Exemplo n.º 2
0
        public void GolfCoursesRepo_AddItems_GetAllReturnsProperCount()
        {
            var options = new DbContextOptionsBuilder <GolfCoursesContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new GolfCoursesContext(options))
            {
                context.GolfCourses.Add(
                    new GolfCourse()
                {
                    Name    = "Tanners Brook Golf Club",
                    Address = "5810 190th St. N",
                    City    = "Forest Lake",
                    State   = "MN",
                    Zip     = "55025",
                    Phone   = "(651) 464-2300",
                });
                context.GolfCourses.Add(
                    new GolfCourse()
                {
                    Name    = "TPC of the Twin Cities",
                    Address = "1989 110th Ct.NE",
                    City    = "Blaine",
                    State   = "MN",
                    Zip     = "55449",
                    Phone   = "(763)785-0800",
                });

                context.GolfCourses.Add(
                    new GolfCourse
                {
                    Name      = "Bellwood Oaks Golf Course",
                    Address   = "13239 210th St. E",
                    City      = "Hastings",
                    State     = "MN",
                    Zip       = "55033",
                    Phone     = "(651)437-4141",
                    Architect = "",
                });
                context.SaveChanges();
            }
            // Use a clean instance of the context to run the test
            using (var context = new GolfCoursesContext(options))
            {
                var repo   = new GolfCourseRepository(context);
                var result = repo.GetAll();
                Assert.AreEqual(2, result.Count());
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            GolfCourseRepository repo = new GolfCourseRepository();
                Repository<FeatureType> fRepo = new Repository<FeatureType>();

            var Kml = XDocument.Load("BridlingtonLinks.kml");
            var name = Kml.Descendants().Where(x => x.Name.LocalName == "name").First().Value;
            var features = (from h in Kml.Descendants().Elements().Where(x => x.Name.LocalName == "Placemark") select h).ToList();
            GolfCourse gc = new GolfCourse();
            gc.name = name;
            foreach (var f in features)
            {

                Feature feature = new Feature();
                var featureValid = true;

                int fType = 0;
                string fName = f.Descendants().Where(x=>x.Name.LocalName =="name").First().Value ;
                Hole h = null;

                 int holeNo = 0;
                int count = 1;
                  while (count <  19)
                  {
                        if( fName.Contains("Hole " + count.ToString())){
                            holeNo = count;
                            break;
                        }

                      count = count + 1;
                  }

                if (holeNo == 0)
                {
                    featureValid = false;
                }
                else
                {
                     h = gc.holes.FirstOrDefault(x=>x.holeNumber==holeNo);
                    if (h == null)
                    {
                        h = new Hole() { holeNumber = holeNo, strokeIndex =0};
                        gc.AddHole(h);
                    }
                }

                if( fName.Contains("Tee")){
                    feature.featuretype = fRepo.Get(1);
                }
                  else if( fName.Contains("Middle of Green")){
                    feature.featuretype = fRepo.Get(5);
                }
                  else if( fName.Contains("bunker")){
                    feature.featuretype = fRepo.Get(4);
                }

              else if( fName.Contains("water")){
                    feature.featuretype = fRepo.Get(6);
                }
                else{
                  featureValid = false;
              }

                if(featureValid)
                {
                string coordinates = f.Descendants().Where(x=>x.Name.LocalName =="coordinates").First().Value;

                string[] longlat = coordinates.Split(",".ToCharArray());

                feature.latitude = Decimal.Parse(longlat[0]);
                feature.longitude = Decimal.Parse(longlat[1]);

                feature.hole = h;
                h.features.Add(feature);

                }

                }
        }
 public GolfCourseRepositoryTests()
 {
     db = new GolfCourseContext();
     db.Database.BeginTransaction();
     underTest = new GolfCourseRepository(db);
 }
 public void SetUp()
 {
     _golfCourseRepository = new GolfCourseRepository();
 }
Exemplo n.º 6
0
        //
        // GET: /Import/
        //[AcceptVerbs(HttpVerbs.Get)]
        //public ActionResult ImportKML()
        //{
        //}
        //[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ImportKML(string KMLUrl)
        {
            GolfCourseRepository repo = new GolfCourseRepository();
            Repository<FeatureType> fRepo = new Repository<FeatureType>();

            var Kml = XDocument.Load(KMLUrl); //Server.MapPath("../kml/BridlingtonLinks.kml"));
            var name = Kml.Descendants().Where(x => x.Name.LocalName == "name").First().Value;
            var features = (from h in Kml.Descendants().Elements().Where(x => x.Name.LocalName == "Placemark") select h).ToList();
            GolfCourse gc = new GolfCourse();
            gc.name = name;
            foreach (var f in features)
            {

                Feature feature = new Feature();
                var featureValid = true;

                int fType = 0;
                string fName = f.Descendants().Where(x=>x.Name.LocalName =="name").First().Value ;
                Hole h = null;

                 int holeNo = 0;
                int count = 18;
                  while (count >  0)
                  {
                        if( fName.Contains("Hole " + count.ToString())){
                            holeNo = count;
                            break;
                        }

                      count = count - 1;
                  }

                if (holeNo == 0)
                {
                    featureValid = false;
                }
                else
                {
                     h = gc.holes.FirstOrDefault(x=>x.holeNumber==holeNo);
                    if (h == null)
                    {
                        h = new Hole() { holeNumber = holeNo, strokeIndex =0};
                        gc.AddHole(h);
                    }
                }

                if( fName.Contains("Tee")){
                    feature.featuretypeID = 1;
                    feature.featuretype = fRepo.Get(1);
                }
                  else if( fName.Contains("Middle of Green")){
                    feature.featuretypeID = 5;
                    feature.featuretype = fRepo.Get(5);
                }
                  else if( fName.Contains("bunker")){
                    feature.featuretypeID = 4;
                    feature.featuretype = fRepo.Get(4);
                }

              else if( fName.Contains("water")){

                    feature.featuretypeID = 6;
                    feature.featuretype = fRepo.Get(6);

                }
                else{
                  featureValid = false;
              }

                if(featureValid)
                {
                string coordinates = f.Descendants().Where(x=>x.Name.LocalName =="coordinates").First().Value;

                string[] longlat = coordinates.Split(",".ToCharArray());

                Random rnd = new Random();

                feature.longitude = Decimal.Parse(longlat[0]);
                feature.latitude = Decimal.Parse(longlat[1]);

                feature.hole = h;

                    // don't add multiple tees or greens or too many features in general...
                    var teeCount = h.features.Where(x=>x.featuretypeID == 1).ToList().Count() ;
                    var greenCount = h.features.Where(x=>x.featuretypeID == 5).ToList().Count();
                    var thisTypeCount = h.features.Where(x => x.featuretypeID == feature.featuretypeID).ToList().Count();

                    if((feature.featuretypeID ==1) )
                    {
                        if (teeCount == 0)
                        {
                            h.features.Add(feature);
                        }
                    }
                    else if ((feature.featuretypeID == 5))
                    {
                        if (greenCount == 0)
                        {
                            h.features.Add(feature);
                        }
                    }
                    else if (thisTypeCount <3)
                    {
                        h.features.Add(feature);
                    }

                }

                }

            gc.longitude = gc.holes[0].features.Single(x => x.featuretypeID == 1).longitude;
            gc.latitude = gc.holes[0].features.Single(x => x.featuretypeID == 1).latitude;

                gc.area = GetGeoCodeData(gc.longitude, gc.latitude);
                repo.SaveOrUpdate(gc);
                return View();
        }