コード例 #1
0
        public async Task SeedAsync(ApplicationDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (!dbContext.SkinProblems.Any())
            {
                var skinProblemData = JsonConvert
                                      .DeserializeObject <List <SkinProblemDto> >(File.ReadAllText(GlobalConstants.SkinProblemSeederPath))
                                      .ToList();

                List <SkinProblem> skinProblems = new List <SkinProblem>();

                foreach (var currentSkinProblemData in skinProblemData)
                {
                    var skinProblem = new SkinProblem()
                    {
                        Name        = currentSkinProblemData.Name,
                        Description = currentSkinProblemData.Description,
                    };

                    skinProblems.Add(skinProblem);
                }

                await dbContext.SkinProblems.AddRangeAsync(skinProblems);

                await dbContext.SaveChangesAsync();
            }
        }
コード例 #2
0
        public async Task CheckGettingAllAndGettingAllAsSelectListItemAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfDeletableEntityRepository <SkinProblem>(db);
            var service    = new SkinProblemsService(repository);

            var firstSkinProblem = new SkinProblem()
            {
                Id = Guid.NewGuid().ToString()
            };
            var secondSkinProblem = new SkinProblem()
            {
                Id = Guid.NewGuid().ToString()
            };
            var thirdSkinProblem = new SkinProblem()
            {
                Id = Guid.NewGuid().ToString()
            };

            await db.SkinProblems.AddAsync(firstSkinProblem);

            await db.SkinProblems.AddAsync(secondSkinProblem);

            await db.SkinProblems.AddAsync(thirdSkinProblem);

            await db.SaveChangesAsync();

            var skinProblemsAsSelectListItems = await service.GetAllAsSelectListItemAsync();

            var skinProblems = await service.GetAllAsync <TestSkinProblemModel>();

            Assert.Equal(3, skinProblemsAsSelectListItems.Count());
            Assert.Equal(3, skinProblems.Count());
        }
コード例 #3
0
        private static async Task <Procedure> PrepareProcedureAsync(ApplicationDbContext db, ProceduresService service)
        {
            var firstSkinProblem = new SkinProblem()
            {
                Id   = "1",
                Name = "firstSkinProblemName",
            };

            var secondSkinProblem = new SkinProblem()
            {
                Id   = "2",
                Name = "secondSkinProblemName",
            };

            var thirdSkinProblem = new SkinProblem()
            {
                Id   = "3",
                Name = "thirdSkinProblemName",
            };

            SkinProblem[] skinProblems = new SkinProblem[]
            {
                firstSkinProblem,
                secondSkinProblem,
                thirdSkinProblem,
            };

            await db.SkinProblems.AddRangeAsync(skinProblems);

            await db.SaveChangesAsync();

            var skinProblemsAsSelectListItemt = skinProblems
                                                .Select(sp => new SelectListItem()
            {
                Value    = sp.Id,
                Text     = sp.Name,
                Selected = true,
            })
                                                .ToList();

            var procedureId = await service.CreateAsync("procedureName", "procedureDEscription", 12, "1", "1", "Yes", skinProblemsAsSelectListItemt);

            var procedure = await service.GetByIdAsync(procedureId);

            return(procedure);
        }
コード例 #4
0
        public async Task CheckAddingSkinTypeAndNonExistingSkinProblemsToUserAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository                   = new EfDeletableEntityRepository <ApplicationUser>(db);
            var skinProblemsRepository       = new EfDeletableEntityRepository <SkinProblem>(db);
            var clientSkinProblemsRepository = new EfRepository <ClientSkinProblem>(db);

            var service = new UsersService(
                repository,
                skinProblemsRepository,
                clientSkinProblemsRepository,
                this.cardsRepository.Object,
                this.cloudinaryService.Object);

            var skinType = new SkinType()
            {
                Id = "1"
            };

            var firstSkinProblem = new SkinProblem()
            {
                Id   = "1",
                Name = "first problem",
            };

            var secondSkinProblem = new SkinProblem()
            {
                Id   = "2",
                Name = "second problem",
            };

            var thirdSkinProblem = new SkinProblem()
            {
                Id   = "3",
                Name = "third problem",
            };

            SkinProblem[] skinProblems = new SkinProblem[]
            {
                firstSkinProblem,
                secondSkinProblem,
                thirdSkinProblem,
            };

            await db.SkinProblems.AddRangeAsync(skinProblems);

            await db.Users.AddAsync(this.client);

            await db.SkinTypes.AddAsync(skinType);

            await db.SaveChangesAsync();

            string[] skinProblemsNames = new string[]
            {
                firstSkinProblem.Name,
                secondSkinProblem.Name,
                thirdSkinProblem.Name,
            };

            await service.AddSkinTypeDataAsync(this.client.Id, true, skinType.Id, skinProblemsNames);

            await service.AddSkinTypeDataAsync(this.client.Id, true, skinType.Id, skinProblemsNames);

            Assert.True(this.client.IsSkinSensitive);
            Assert.Equal(3, this.client.ClientSkinProblems.Count());
        }