Esempio n. 1
0
        public void CreateQuestion_Successful()
        {
            // ARRANGE
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            //ACT
            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var result = questionRepository.Create(question);

            //ASSERT
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("Je n'arrive pas à faire un test", result.Message);
            Assert.AreEqual("Problème avec Tests", result.Title);
            Assert.AreEqual(date, result.Date);
            Assert.AreEqual(false, result.IsResolved);
            Assert.AreEqual(1, result.AuthorId);
        }
Esempio n. 2
0
        public async Task SetUp()
        {
            _dbContext = ContextHelper.GetInMemoryContext();
            _cancelledTempSupportRequestId = Guid.NewGuid();
            await _dbContext.TempSupportRequests.AddRangeAsync(new List <TempSupportRequest>
            {
                new TempSupportRequest {
                    Id = Guid.NewGuid(), Status = TempSupportRequestStatus.Active
                },
                new TempSupportRequest {
                    Id = Guid.NewGuid(), Status = TempSupportRequestStatus.Active
                },
                new TempSupportRequest {
                    Id = Guid.NewGuid(), Status = TempSupportRequestStatus.Active
                },
                new TempSupportRequest {
                    Id = _cancelledTempSupportRequestId, Status = TempSupportRequestStatus.Active
                },
                new TempSupportRequest {
                    Id = Guid.NewGuid(), Status = TempSupportRequestStatus.Active
                },
            });

            await _dbContext.SaveChangesAsync();

            _sessionService = Substitute.For <ISessionService>();

            var handler = new CancelSupportRequestHandler(_dbContext, _sessionService);

            await handler.Handle(new CancelSupportRequestCommand(_cancelledTempSupportRequestId), CancellationToken.None);
        }
Esempio n. 3
0
        public void GetQuestionById_Successful()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            //ARRANGE
            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test!", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var question2 = new QuestionTO {
                IsResolved = false, Message = "Comment créer un projet MVC 6?", Title = "MVC6", Date = date, AuthorId = 2
            };
            var question3 = new QuestionTO {
                IsResolved = false, Message = "Comment faire boucle foreach?", Title = "foreach", Date = date, AuthorId = 2
            };
            var addedQuestion  = questionRepository.Create(question);
            var addedQuestion2 = questionRepository.Create(question2);
            var addedQuestion3 = questionRepository.Create(question3);

            context.SaveChanges();

            //ACT
            var test = questionRepository.GetById(2);

            //ASSERT
            Assert.AreEqual("Comment créer un projet MVC 6?", test.Message);
        }
Esempio n. 4
0
        public void CreateAnswer_AddExistingAnswer_DoNotInsertTwiceInDb()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            IAnswerRepository   answerRepository   = new AnswerRepository(context);


            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var addedQuestion = questionRepository.Create(question);

            context.SaveChanges();
            var answer = new AnswerTO {
                Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion,
            };
            var result = answerRepository.Create(answer);

            context.SaveChanges();
            //ACT
            answerRepository.Create(result);
            context.SaveChanges();

            //ASSERT
            Assert.AreEqual(1, context.Answers.Count());
        }
Esempio n. 5
0
        public void ModifyQuestion_Successful()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            //ACT
            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var result = questionRepository.Create(question);

            context.SaveChanges();
            //ACT
            result.IsResolved = true;
            var test = questionRepository.Modify(result);

            context.SaveChanges();

            //ASSERT
            Assert.AreEqual(true, test.IsResolved);
        }
 public SubmitSupportRequestHandler(AskContext context, ILogger <SubmitSupportRequestHandler> logger, IMediator mediator, ISessionService sessionService, IEmailService emailService)
 {
     _context        = context;
     _logger         = logger;
     _mediator       = mediator;
     _sessionService = sessionService;
     _emailService   = emailService;
 }
        public void Arrange()
        {
            var dbContextOptions = new DbContextOptionsBuilder <AskContext>()
                                   .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                   .Options;

            Context = new AskContext(dbContextOptions);

            Handler = new GetOrCreateOrganisationContactHandler(Context);
        }
Esempio n. 8
0
        public void CreateAnswer_AddNull_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IAnswerRepository answerRepository = new AnswerRepository(context);

            Assert.ThrowsException <ArgumentNullException>(() => answerRepository.Create(null));
        }
Esempio n. 9
0
        public void GetAllQuestions_NoQuestionInDb_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);

            Assert.ThrowsException <ArgumentNullException>(() => questionRepository.GetAll());
        }
Esempio n. 10
0
        public void DeleteAnswer_ProvidingNull_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IAnswerRepository answerRepository = new AnswerRepository(context);

            Assert.ThrowsException <KeyNotFoundException>(() => answerRepository.Delete(null));
        }
Esempio n. 11
0
        public void GetQuestionById_ProvidingNonExistingId_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);

            //ASSERT
            Assert.ThrowsException <ArgumentNullException>(() => questionRepository.GetById(14));
        }
Esempio n. 12
0
        public void GetALlAnswers_Successful()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            IAnswerRepository   answerRepository   = new AnswerRepository(context);

            //ACT
            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var question2 = new QuestionTO {
                IsResolved = false, Message = "Comment créer un projet MVC 6", Title = "MVC6", Date = date, AuthorId = 2
            };
            var question3 = new QuestionTO {
                IsResolved = false, Message = "Comment faire boucle foreach", Title = "foreach", Date = date, AuthorId = 2
            };
            var addedQuestion  = questionRepository.Create(question);
            var addedQuestion2 = questionRepository.Create(question2);
            var addedQuestion3 = questionRepository.Create(question3);

            context.SaveChanges();
            var answer = new AnswerTO {
                Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion,
            };
            var answer2 = new AnswerTO {
                Message = "Oui c'est trop facile les tests avec InMemory", AuthorId = 3, AssociatedQuestion = addedQuestion,
            };
            var answer3 = new AnswerTO {
                Message = "Tu dois d'abord créer un projet web app avec .Net Core", AuthorId = 1, AssociatedQuestion = addedQuestion2,
            };
            var addedAnswer  = answerRepository.Create(answer);
            var addedAnswer2 = answerRepository.Create(answer2);
            var addedAnswer3 = answerRepository.Create(answer3);

            context.SaveChanges();
            //Archiving the question related to the answer 3
            addedQuestion2.IsResolved = true;
            questionRepository.Modify(addedQuestion2);
            context.SaveChanges();
            //ACT
            var test = answerRepository.GetAll();

            //ASSERT
            Assert.AreEqual(3, test.Count());
        }
Esempio n. 13
0
        public void ModifyQuestion_ProvidingNonExistingId_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);

            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                Id = 16783, IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };

            Assert.ThrowsException <KeyNotFoundException>(() => questionRepository.Modify(question));
        }
Esempio n. 14
0
        public void GetQuestionById_ProvidingNoId_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            //ARRANGE
            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };

            //ASSERT
            Assert.ThrowsException <ArgumentException>(() => questionRepository.GetById(question.Id));
        }
        public async Task SetUp()
        {
            _dbContext = ContextHelper.GetInMemoryContext();
            _requestId = Guid.NewGuid();
            await _dbContext.TempSupportRequests.AddAsync(new TempSupportRequest()
            {
                Id = _requestId
            });

            await _dbContext.SaveChangesAsync();

            var mediator = Substitute.For <IMediator>();

            _dfeSignInApiClient = Substitute.For <IDfeSignInApiClient>();
            _dfeOrganisationId  = Guid.NewGuid();

            _handler = new AddDfESignInInformationHandler(_dbContext, _dfeSignInApiClient, mediator);
        }
        public async Task ThenANewTempSupportRequestIsSaved()
        {
            var dbContextOptions = new DbContextOptionsBuilder <AskContext>()
                                   .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                   .Options;

            var context = new AskContext(dbContextOptions);

            var handler = new StartTempSupportRequestHandler(context);

            var result = await handler.Handle(new StartTempSupportRequestCommand(SupportRequestType.DfeSignIn), CancellationToken.None);

            (await context.TempSupportRequests.CountAsync()).Should().Be(1);

            var savedSupportRequest = await context.TempSupportRequests.SingleAsync();

            savedSupportRequest.SupportRequestType.Should().Be(SupportRequestType.DfeSignIn);

            result.RequestId.Should().Be(savedSupportRequest.Id);
        }
Esempio n. 17
0
        public void ModifyAnswer_Successful()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            IAnswerRepository   answerRepository   = new AnswerRepository(context);

            //ACT
            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var question2 = new QuestionTO {
                IsResolved = false, Message = "Comment créer un projet MVC 6", Title = "MVC6", Date = date, AuthorId = 2
            };
            var question3 = new QuestionTO {
                IsResolved = false, Message = "Comment faire boucle foreach", Title = "foreach", Date = date, AuthorId = 2
            };
            var addedQuestion  = questionRepository.Create(question);
            var addedQuestion2 = questionRepository.Create(question2);
            var addedQuestion3 = questionRepository.Create(question3);

            context.SaveChanges();
            var answer = new AnswerTO {
                Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion,
            };
            var result = answerRepository.Create(answer);

            context.SaveChanges();
            //ACT
            result.Message = "Message modifié";
            var test = answerRepository.Modify(result);

            context.SaveChanges();

            //ASSERT
            Assert.AreEqual("Message modifié", test.Message);
        }
Esempio n. 18
0
        T AskInner <T>(string question, params string[] options)
        {
            Console.WriteLine(question);
            bool unanswered = true;


            for (int i = 0; i < options.Length; i++)
            {
                Console.WriteLine("{0}. {1}", i, options[i]);
            }


            Console.Write("Answer:");

            Silly <T> silly = null;

            do
            {
                try
                {
                    string result = Console.ReadLine();

                    var dict = new Dictionary <string, object>()
                    {
                        { "answer", result }
                    };
                    var fmd = new FastModelBinder();
                    var cxt = new AskContext(dict);
                    silly = fmd.Bind <Silly <T> >(cxt);

                    unanswered = false;
                }
                catch (Exception)
                {
                    Console.WriteLine("Whoops. Looks like something went wrong.");
                }
            } while (unanswered);

            return(silly.answer);
        }
        public async Task SetUp()
        {
            DbContext            = ContextHelper.GetInMemoryContext();
            TempSupportRequestId = Guid.NewGuid();
            DfeSignInId          = Guid.NewGuid();
            await DbContext.TempSupportRequests.AddRangeAsync(new List <TempSupportRequest>
            {
                new TempSupportRequest {
                    Id = Guid.NewGuid()
                },
                new TempSupportRequest {
                    Id = TempSupportRequestId, DfeSignInId = DfeSignInId
                },
            });

            await DbContext.SaveChangesAsync();

            DfeSignInApiClient = Substitute.For <IDfeSignInApiClient>();

            SelectedOrganisationId = Guid.NewGuid();

            Handler = new AddDfeSignInOrganisationHandler(DbContext, DfeSignInApiClient);
        }
Esempio n. 20
0
        public void ModifyAnswer_ProvidingNonExistingId_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            IAnswerRepository   answerRepository   = new AnswerRepository(context);

            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var addedQuestion = questionRepository.Create(question);

            context.SaveChanges();
            var answer = new AnswerTO {
                Id = 16783, Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion,
            };

            Assert.ThrowsException <KeyNotFoundException>(() => answerRepository.Modify(answer));
        }
Esempio n. 21
0
        public void CreateQuestion_AddExistingQuestion_DoNotInsertTwiceInDb()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);

            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var result = questionRepository.Create(question);

            context.SaveChanges();
            //ACT
            questionRepository.Create(result);
            context.SaveChanges();

            //ASSERT
            Assert.AreEqual(1, context.Questions.Count());
        }
Esempio n. 22
0
 public SaveTempSupportHandler(AskContext askContext)
 {
     _askContext = askContext;
 }
Esempio n. 23
0
 public CancelSupportRequestHandler(AskContext context, ISessionService sessionService)
 {
     _context        = context;
     _sessionService = sessionService;
 }
Esempio n. 24
0
 public AddDfeSignInOrganisationHandler(AskContext context, IDfeSignInApiClient dfeSignInApiClient)
 {
     _context            = context;
     _dfeSignInApiClient = dfeSignInApiClient;
 }
 public AddDfESignInInformationHandler(AskContext context, IDfeSignInApiClient dfeClient, IMediator mediator)
 {
     _context   = context;
     _dfeClient = dfeClient;
     _mediator  = mediator;
 }
 public GetVisitFeedbackHandler(AskContext dbContext)
 {
     _dbContext = dbContext;
 }
Esempio n. 27
0
 public GetOrCreateOrganisationContactHandler(AskContext context)
 {
     _context = context;
 }
Esempio n. 28
0
 public GetTempSupportRequestHandler(AskContext askContext)
 {
     _askContext = askContext;
 }
 public AddAmendmentCommentHandler(AskContext dbContext)
 {
     _dbContext = dbContext;
 }
Esempio n. 30
0
 public QuestionRepository(AskContext askContext)
 {
     this.askContext = askContext;
 }