public async Task TestGetVersions() { //Prepare TestingContext testingContext = new TestingContext(); SetUpTestingContext(testingContext); ApplicationDbContext dbContext = testingContext.GetSimple <ApplicationDbContext>(); Question question = dbContext.Questions.First(); testingContext.AddPrincipalMock(question.User.UserId, Roles.User); testingContext.AddBusinessSecurityService(); IQuestionService questionService = testingContext.GetService <QuestionService>(); testingContext.DependencyMap[typeof(IQuestionService)] = questionService; IVersionService versionService = testingContext.GetService <VersionService>(); int newId = await versionService.VersionQuestionAsync(question.Id); await versionService.AcceptQuestionAsync(newId); VersionInfoParametersDto versionInfoParametersDto = new VersionInfoParametersDto() { Page = 0, IdQuestion = newId, }; //Act PagedResultDto <VersionInfoDto> result = await versionService.GetVersionsAsync(versionInfoParametersDto); //Assert Assert.Equal(2, result.Count); }
public async Task TestVersionQuestion() { //Prepare TestingContext testingContext = new TestingContext(); SetUpTestingContext(testingContext); ApplicationDbContext dbContext = testingContext.GetSimple <ApplicationDbContext>(); Question question = dbContext.Questions.First(); testingContext.AddPrincipalMock(question.User.UserId, Roles.User); testingContext.AddBusinessSecurityService(); IQuestionService questionService = testingContext.GetService <QuestionService>(); testingContext.DependencyMap[typeof(IQuestionService)] = questionService; Mock <INotificationService> notificationMock = new Mock <INotificationService>(MockBehavior.Loose); notificationMock.Setup(x => x.SendNotificationAboutQuestionAsync(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.CompletedTask); testingContext.DependencyMap[typeof(INotificationService)] = notificationMock.Object; IVersionService versionService = testingContext.GetService <VersionService>(); //Act int newId = await versionService.VersionQuestionAsync(question.Id); //Assert Assert.True(question.Id != newId); Assert.True(newId > 0); await versionService.AcceptQuestionAsync(newId); //Assert QuestionDto oldDto = await questionService.GetQuestionAsync(question.Id); QuestionDto newDto = await questionService.GetQuestionAsync(newId); Assert.Contains(oldDto.Tags, x => x.Name == "Deprecated"); Assert.Equal(QuestionStatus.Released, (QuestionStatus)newDto.Status); Assert.Equal(QuestionStatus.Obsolete, (QuestionStatus)oldDto.Status); question = await dbContext.FindAsync <Question>(newId); Assert.NotNull(question.ApprovalDate); notificationMock.Verify(x => x.SendNotificationAboutQuestionAsync(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once()); }
public async Task TestVersionQuestion() { //Prepare TestingContext context = new TestingContext(); InitContext(context); ApplicationDbContext dbContext = context.GetSimple <ApplicationDbContext>(); Question question = dbContext.Questions.First(); context.AddPrincipalMock(question.User.UserId, Roles.User); IQuestionService questionService = context.GetService <QuestionService>(); context.DependencyMap[typeof(IQuestionService)] = questionService; IVersionService versionService = context.GetService <VersionService>(); //Act int newId = await versionService.VersionQuestionAsync(question.Id); //Assert Assert.True(question.Id != newId); Assert.True(newId > 0); await versionService.AcceptQuestionAsync(newId); //Assert QuestionDto oldDto = await questionService.GetQuestionAsync(question.Id); QuestionDto newDto = await questionService.GetQuestionAsync(newId); Assert.Contains(oldDto.Tags, x => x.Name == "Deprecated"); Assert.Equal(QuestionStatus.Released, (QuestionStatus)newDto.Status); Assert.Equal(QuestionStatus.Obsolete, (QuestionStatus)oldDto.Status); question = await dbContext.FindAsync <Question>(newId); Assert.NotNull(question.ApprovalDate); }
public async Task <JsonResult> AcceptQuestion([FromBody] int id) { await _versionService.AcceptQuestionAsync(id); return(Json(OkReturnString)); }