Exemplo n.º 1
0
        public async Task CanListActiveCommunities()
        {
            var region = new Region {
                Name = "region1", Active = true
            };
            var source = new[]
            {
                new Community {
                    Name = "community1", RegionName = region.Name, Active = true
                },
                new Community {
                    Name = "community2", RegionName = region.Name, Active = true
                },
                new Community {
                    Name = "community3", RegionName = region.Name, Active = false
                },
                new Community {
                    Name = "community4", RegionName = region.Name, Active = true
                },
            };

            var repo = new SeederRepository(ctx);

            repo.AddOrUpdateRegions(new[] { region });
            repo.AddOrUpdateCommunities(source);

            var result = await di.GetCommunitiesAsync();

            Assert.Equal(source.Count(c => c.Active), result.Count());
            foreach (var item in result)
            {
                Assert.Contains(new { name = item.Name, regionName = item.Region.Name }, source.Select(e => new { name = e.Name, regionName = e.RegionName }));
            }
        }
Exemplo n.º 2
0
        private void SeedData()
        {
            var db = Services.ServiceProvider.GetService <EmbcDbContext>();

            if (!db.Database.IsInMemory())
            {
                return;
            }
            var repo = new SeederRepository(db);

            var types = new[]
            {
                new FamilyRelationshipType {
                    Code = "FMR1", Active = true
                },
                new FamilyRelationshipType {
                    Code = "FMR2", Active = true
                },
                new FamilyRelationshipType {
                    Code = "FMR3", Active = false
                },
                new FamilyRelationshipType {
                    Code = "FMR4", Active = true
                },
            };

            var regions = new[]
            {
                new Region {
                    Name = "region1", Active = true
                },
                new Region {
                    Name = "region2", Active = true
                },
                new Region {
                    Name = "region3", Active = true
                },
                new Region {
                    Name = "region4", Active = true
                },
            };

            var countries = new[]
            {
                new Country {
                    Name = "country1", CountryCode = "USA", Active = true
                },
                new Country {
                    Name = "country2", CountryCode = "CAN", Active = true
                },
                new Country {
                    Name = "country3", CountryCode = "IND", Active = false
                },
                new Country {
                    Name = "country4", CountryCode = "MEX", Active = true
                },
            };

            var communities = new[]
            {
                new Community {
                    Name = "community1", RegionName = regions[0].Name, Active = true
                },
                new Community {
                    Name = "community2", RegionName = regions[0].Name, Active = true
                },
                new Community {
                    Name = "community3", RegionName = regions[0].Name, Active = false
                },
                new Community {
                    Name = "community4", RegionName = regions[0].Name, Active = true
                },
            };

            repo.AddOrUpdateFamilyRelationshipTypes(types);
            repo.AddOrUpdateCountries(countries);
            repo.AddOrUpdateRegions(regions);
            repo.AddOrUpdateCommunities(communities);
        }