コード例 #1
0
        public async Task AddSurveyShouldAddOneObject()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "SurveyTest").Options;
            var dbContext    = new ApplicationDbContext(options);
            var surveyRepo   = new EfDeletableEntityRepository <Survey>(dbContext);
            var opinionsRepo = new EfDeletableEntityRepository <Opinion>(dbContext);
            var userOpRepo   = new EfDeletableEntityRepository <UserOpinion>(dbContext);
            var usersSurveys = new EfRepository <UserSurvey>(dbContext);
            var service      = new SurveyService(surveyRepo, opinionsRepo, userOpRepo, usersSurveys);

            dbContext.Users.Add(new ApplicationUser {
                Id = "123"
            });
            await service.AddSurveyAsync("test");

            await service.AddQuestionToSurveyAsync("testQuestion", "test");

            await service.AddOpinionToQuestionAsync("testQuestion", "testAnswer");

            Assert.Equal(1, await dbContext.Surveys.CountAsync());
            Assert.Single(service.GetAllQuestions("test"));
            Assert.Equal(1, await dbContext.UserOpinions.CountAsync());
            Assert.Single(service.GetAll("123"));
            await service.AddSurveyToUser("123", "test");

            Assert.Empty(service.GetAll("123"));
        }
コード例 #2
0
ファイル: CheckCommand.cs プロジェクト: rezor21/SurveySystem
        public bool Execute()
        {
            if (type == "Survey")
            {
                if (_receiver.GetAll().Any(x => x.Title == title))
                {
                    return(true);
                }
            }

            if (type == "Question")
            {
                if (_receiver.GetAllQuestions().Any(x => x.Title == title))
                {
                    return(true);
                }
            }

            if (type == "Answer")
            {
                if (_receiver.GetAllAnswers().Any(x => x.Title == title))
                {
                    return(true);
                }
            }

            return(false);
        }