public async Task PublishSurveyCallsSaveFromSurveyBlobWithQuestionPossibleAnswers() { var mockSurveyInformationTable = new Mock <IAzureTable <SurveyInformationRow> >(); var mockSurveyBlobContainer = new Mock <IAzureBlobContainer <Models.Survey> >(); mockSurveyInformationTable.Setup(t => t.GetByStringPropertiesAsync(It.IsAny <ICollection <KeyValuePair <string, string> > >())) .ReturnsAsync(new SurveyInformationRow[] { }); var target = new SurveyManagementService(null, (tableName) => mockSurveyInformationTable.Object, (containerName) => mockSurveyBlobContainer.Object); var question = new Client.Models.Question { PossibleAnswers = "possible answers" }; var survey = new Client.Models.Survey { Title = "title", Questions = new List <Client.Models.Question>(new[] { question }) }; await target.PublishSurveyAsync(survey); mockSurveyBlobContainer.Verify( c => c.SaveAsync( "title", It.Is <Models.Survey>(s => s.Questions.First().PossibleAnswers == "possible answers")), Times.Once()); }
public SurveyManagementServiceTests() { _guid = Guid.NewGuid(); _guid2 = Guid.NewGuid(); _nonMatchingGuid = Guid.NewGuid(); var survey1 = new Entities.Survey { Id = _guid }; var survey2 = new Entities.Survey { Id = _guid2 }; var allSurveys = new List <Entities.Survey>() { survey1, survey2 }; var filteredSurveys = new List <Entities.Survey>() { survey1 }; _surveyRepository = new Mock <ISurveyRepository>(); _surveyRepository.Setup(repo => repo.Create(It.IsAny <Entities.Survey>())).ReturnsAsync(survey1); _surveyRepository.Setup(repo => repo.Get(It.Is <Guid>(a => a.Equals(_guid)))).ReturnsAsync(new Entities.Survey { Id = _guid }); _surveyRepository.Setup(repo => repo.Get(It.Is <Guid>(a => a.Equals(_nonMatchingGuid)))).ReturnsAsync(null as Entities.Survey); _surveyRepository.Setup(repo => repo.Update(It.IsAny <Entities.Survey>())); _surveyRepository.Setup(repo => repo.List()).ReturnsAsync(allSurveys); _surveyRepository.Setup(repo => repo.List(It.IsAny <Expression <Func <Entities.Survey, bool> > >())).ReturnsAsync(filteredSurveys); _surveyRepository.Setup(repo => repo.Delete(It.IsAny <Entities.Survey>())); // Options Repository _optionsRepository = new Mock <ISurveyQuestionRepository>(); _optionsRepository.Setup(repo => repo.Delete(It.IsAny <Expression <Func <SurveyQuestion, bool> > >())); var logger = new Mock <ILogger>(); logger.Setup(l => l.Error(It.IsAny <Exception>(), It.IsAny <string>())); logger.Setup(l => l.Warning(It.IsAny <string>())); _svc = new SurveyManagementService(_surveyRepository.Object, logger.Object); }
public async Task PublishSurveyCallsAddFromSurveyTableWithAllTheQuestions() { var mockSurveyInformationTable = new Mock <IAzureTable <SurveyInformationRow> >(); var mockSurveyBlobContainer = new Mock <IAzureBlobContainer <Models.Survey> >(); mockSurveyInformationTable.Setup(t => t.GetByStringPropertiesAsync(It.IsAny <ICollection <KeyValuePair <string, string> > >())) .ReturnsAsync(new SurveyInformationRow[] { }); var target = new SurveyManagementService(null, (tableName) => mockSurveyInformationTable.Object, (containerName) => mockSurveyBlobContainer.Object); var survey = new Client.Models.Survey { Title = "title", Questions = new List <Client.Models.Question>(new[] { new Client.Models.Question(), new Client.Models.Question() }) }; await target.PublishSurveyAsync(survey); mockSurveyBlobContainer.Verify( c => c.SaveAsync( "title", It.Is <Models.Survey>(s => s.Questions.Count == 2)), Times.Once()); }
public async Task GetSurveyReturnsNullWhenNotFound() { var mock = new Mock <IAzureBlobContainer <Models.Survey> >(); var target = new SurveyManagementService(null, null, (containerName) => mock.Object); var survey = await target.GetSurveyAsync("slug-name"); Assert.IsNull(survey); }
public async Task GetSurveyReturnsTitle() { string slugName = "slug-name"; var surveyModel = new Models.Survey { Title = "title" }; var mock = new Mock <IAzureBlobContainer <Models.Survey> >(); mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable(); var target = new SurveyManagementService(null, null, (containerName) => mock.Object); var survey = await target.GetSurveyAsync(slugName); Assert.AreEqual("title", survey.Title); }
private static void listSurveys(string ticket) { var service = new SurveyManagementService(); service.Url = ConfigurationManager.AppSettings["CheckboxRoot"] + "/Services/SurveyManagementService.svc/soap"; var callRes = service.ListAvailableSurveys(ticket, 0, false, 100, true, null, false, false, null, null); if (!callRes.CallSuccess) { throw new Exception(callRes.FailureMessage); } foreach (var i in callRes.ResultData.ResultPage) { Console.WriteLine("ID = {0}, Name = {1}, Guid = {2}", i.ID, i.Name, i.SurveyGuid); } }
public async Task GetSurveyByTenantAndSlugNameReturnsCreatedOn() { string slugName = "slug-name"; var expectedDate = new DateTime(2000, 1, 1); var surveyModel = new Models.Survey { CreatedOn = expectedDate }; var mock = new Mock <IAzureBlobContainer <Models.Survey> >(); mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable(); var target = new SurveyManagementService(null, null, (containerName) => mock.Object); var survey = await target.GetSurveyAsync(slugName); Assert.AreEqual(expectedDate, survey.CreatedOn); }
public async Task ListSurveysReturnsSlugName() { var surveyInformationRow = new SurveyInformationRow { SlugName = "slug" }; var surveyRowsToReturn = new[] { surveyInformationRow }; var mock = new Mock <IAzureTable <SurveyInformationRow> >(); mock.Setup(t => t.GetByPartitionKeyAsync(It.IsAny <string>())).ReturnsAsync(surveyRowsToReturn); var mockSurveyInformationTable = new Mock <IAzureTable <SurveyInformationRow> >(); var target = new SurveyManagementService(null, (tableName) => mock.Object, null); var actualSurveys = await target.ListSurveysAsync(); Assert.AreEqual("slug", actualSurveys.First().SlugName); }
public async Task GetRecentSurveysReturnsTitle() { var surveyInformationRow = new SurveyInformationRow { Title = "title" }; var surveyRowsToReturn = new[] { surveyInformationRow }; var mock = new Mock <IAzureTable <SurveyInformationRow> >(); mock.Setup(t => t.GetLatestAsync(10)).ReturnsAsync(surveyRowsToReturn); var mockSurveyInformationTable = new Mock <IAzureTable <SurveyInformationRow> >(); var target = new SurveyManagementService(null, (tableName) => mock.Object, null); var actualSurveys = await target.GetLatestSurveysAsync(); Assert.AreEqual("title", actualSurveys.First().Title); }
public void TestInitialize() { target = new SurveyManagementService(null, (tableName) => { var azureTable = new AzureTable <Models.SurveyInformationRow>(account, tableName); azureTable.EnsureExistsAsync().Wait(); return(azureTable); }, (containerName) => { azureBlobContainer = new AzureBlobContainer <Models.Survey>( account, containerName); azureBlobContainer.EnsureExistsAsync().Wait(); return(azureBlobContainer); }); }
public async Task GetSurveyFiltersBySlugName() { string slugName = "slug-name"; var mock = new Mock <IAzureBlobContainer <Models.Survey> >(); var surveyModel = new Models.Survey { SlugName = slugName }; mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable(); var target = new SurveyManagementService(null, null, (containerName) => mock.Object); var survey = await target.GetSurveyAsync(slugName); Assert.IsNotNull(survey); mock.Verify(); Assert.AreEqual(surveyModel.SlugName, survey.SlugName); }
public async Task GetSurveyReturnsWithQuestionsFilteredBySlugName() { string slugName = "slug-name"; var mock = new Mock <IAzureBlobContainer <Models.Survey> >(); var question = new Models.Question { Type = Enum.GetName(typeof(QuestionType), QuestionType.SimpleText) }; var questions = new[] { question }; var surveyModel = new Models.Survey { Questions = questions }; mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable(); var target = new SurveyManagementService(null, null, (containerName) => mock.Object); var survey = await target.GetSurveyAsync(slugName); Assert.AreEqual(1, survey.Questions.Count); }
public async Task GetRecentSurveysReturnsUpto10Surveys() { var surveyInformationRowsToReturn = new List <SurveyInformationRow>(); for (int i = 0; i < 10; i++) { surveyInformationRowsToReturn.Add(new SurveyInformationRow()); } var mock = new Mock <IAzureTable <SurveyInformationRow> >(); mock.Setup(t => t.GetLatestAsync(10)).ReturnsAsync(surveyInformationRowsToReturn); var mockSurveyInformationTable = new Mock <IAzureTable <SurveyInformationRow> >(); var target = new SurveyManagementService(null, (tableName) => mock.Object, null); var actualSurveys = await target.GetLatestSurveysAsync(); Assert.AreEqual(10, actualSurveys.Count()); }
public async Task PublishSurveyCallsAddFromSurveyTableGeneratingTheSlugName() { var mockSurveyInformationTable = new Mock <IAzureTable <SurveyInformationRow> >(); var mockSurveyBlobContainer = new Mock <IAzureBlobContainer <Models.Survey> >(); mockSurveyInformationTable.Setup(t => t.GetByStringPropertiesAsync(It.IsAny <ICollection <KeyValuePair <string, string> > >())) .ReturnsAsync(new SurveyInformationRow[] { }); var target = new SurveyManagementService(null, (tableName) => mockSurveyInformationTable.Object, (containerName) => mockSurveyBlobContainer.Object); var survey = new Client.Models.Survey { Title = "title to slug" }; await target.PublishSurveyAsync(survey); mockSurveyInformationTable.Verify( c => c.AddAsync( It.Is <SurveyInformationRow>(s => s.SlugName == "title-to-slug")), Times.Once()); }