Пример #1
0
        public async Task ShouldGetClosestPhysicians()
        {
            var options = new DbContextOptionsBuilder <PhysicianLookupDbContext>()
                          .UseInMemoryDatabase($"{nameof(GetNearestPhysiciansTests)}:{nameof(ShouldGetClosestPhysicians)}")
                          .Options;

            var context = new PhysicianLookupDbContext(options);

            var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);

            var physician = new Physician();

            //{
            //    Location = geometryFactory.CreatePoint(new Coordinate(-79.374770, 43.631460))
            //};

            context.Physicians.Add(physician);

            context.SaveChanges();

            var client = new HttpClient();

            GetNearByPhysicians.Request request = new GetNearByPhysicians.Request
            {
                Latitude  = 43.663790,
                Longitude = -79.395380
            };

            var handler = new GetNearByPhysicians.Handler(context);

            var response = await handler.Handle(request, default);

            Assert.Single(response.Physicians);
        }
Пример #2
0
            public static void Seed(PhysicianLookupDbContext context)
            {
                var json            = StaticFileLocator.GetAsString("physicians.json");
                var jArray          = JsonConvert.DeserializeObject <JObject>(json)["physicians"];
                var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);

                foreach (var token in jArray)
                {
                    var physician = (JObject)token;

                    _ = context.Physicians.Add(new ()
                    {
                        Title     = (string)physician["title"],
                        Firstname = (string)physician["firstname"],
                        Lastname  = (string)physician["lastname"],
                        Address   = new Address(
                            (string)physician["street"],
                            (string)physician["city"],
                            (string)physician["province"],
                            (string)physician["postalCode"],
                            (double)physician["longitude"],
                            (double)physician["latitude"],
                            geometryFactory.CreatePoint(new Coordinate((double)physician["longitude"], (double)physician["latitude"]))),
                        EmailAddress = (string)physician["emailAddress"],
                        Website      = (string)physician["website"],
                    });
                }

                context.SaveChanges();
            }
Пример #3
0
            public static void Seed(PhysicianLookupDbContext context, IConfiguration configuration)
            {
                foreach (var username in configuration["Seed:DefaultUser:Username"].Split(','))
                {
                    User user = default;

                    if (context.Users.SingleOrDefault(x => x.Username == username) == null)
                    {
                        user = new ()
                        {
                            Username = username,
                        };

                        user.UserRoles.Add(new ()
                        {
                            RoleId = context.Roles.Single(x => x.Name == "System").RoleId
                        });

                        user.Password = new PasswordHasher().HashPassword(user.Salt, configuration["Seed:DefaultUser:Password"]);

                        context.Users.Add(user);
                    }

                    context.SaveChanges();
                }
            }
Пример #4
0
            public static void Seed(PhysicianLookupDbContext context)
            {
                if (context.Roles.FirstOrDefault(x => x.Name == "Admin") == null)
                {
                    context.Roles.Add(new ()
                    {
                        Name = "Admin"
                    });
                }

                if (context.Roles.FirstOrDefault(x => x.Name == "System") == null)
                {
                    context.Roles.Add(new ()
                    {
                        Name = "System"
                    });
                }

                context.SaveChanges();
            }