public async Task SaveSurveyAnswerAddMessageToQueueWithSavedBlobId() { var mockTenantStore = new Mock <ITenantStore>(); var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >(); var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var mockSurveyAnswerStoredQueue = new Mock <IAzureQueue <SurveyAnswerStoredMessage> >(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, mockSurveyAnswerStoredQueue.Object, null, new Mock <IAzureBlobContainer <List <string> > >().Object); mockTenantStore.Setup(t => t.GetTenantAsync(It.IsAny <string>())).ReturnsAsync(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(mockSurveyAnswerBlobContainer.Object); string blobId = string.Empty; mockSurveyAnswerBlobContainer.Setup(c => c.SaveAsync(It.IsAny <string>(), It.IsAny <SurveyAnswer>())) .Returns(Task.Delay(0)) .Callback((string id, SurveyAnswer sa) => blobId = id); await store.SaveSurveyAnswerAsync(new SurveyAnswer()); mockTenantStore.Verify(t => t.GetTenantAsync(It.IsAny <string>())); mockSurveyAnswerStoredQueue.Verify( q => q.AddMessageAsync( It.Is <SurveyAnswerStoredMessage>(m => m.SurveyAnswerBlobId == blobId))); }
public async Task AppendSurveyAnswerIdToAnswersListSavesModifiedListToTheAnswersListBlob() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); var answerIdsList = new List <string> { "id 1", "id 2" }; mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name")).ReturnsAsync(answerIdsList); List <string> savedList = null; mockSurveyAnswerIdsListContainer.Setup(c => c.SaveAsync(It.IsAny <string>(), It.IsAny <List <string> >())) .Callback <string, List <string> >((str, l) => savedList = l) .Returns(Task.Delay(0)); await store.AppendSurveyAnswerIdToAnswersListAsync("tenant", "slug-name", "new id"); Assert.AreEqual(3, savedList.Count); Assert.AreEqual("new id", savedList.Last()); }
public void SaveSurveyAnswerAddMessageToQueueWithSurveySlugName() { var mockTenantStore = new Mock <ITenantStore>(); var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var mockSurveyAnswerStoredQueue = new Mock <IAzureQueue <SurveyAnswerStoredMessage> >(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, mockSurveyAnswerStoredQueue.Object, null, new Mock <IAzureBlobContainer <List <string> > >().Object); mockTenantStore.Setup(t => t.GetTenant(It.IsAny <string>())).Returns(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object); store.SaveSurveyAnswer(new SurveyAnswer { SlugName = "slug-name" }); mockTenantStore.Verify(t => t.GetTenant(It.IsAny <string>())); mockSurveyAnswerStoredQueue.Verify( q => q.AddMessage( It.Is <SurveyAnswerStoredMessage>(m => m.SurveySlugName == "slug-name"))); }
public void AppendSurveyAnswerIdsToAnswersListCreatesListWhenItDoesNotExistAndSavesIt() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); List <string> answerIdsList = null; var optContext = It.IsAny <OptimisticConcurrencyContext>(); mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name", out optContext)).Returns(answerIdsList); List <string> savedList = null; mockSurveyAnswerIdsListContainer.Setup(c => c.Save(optContext, It.IsAny <List <string> >())) .Callback <IConcurrencyControlContext, List <string> >((id, l) => savedList = l); store.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", new List <string>() { "new id" }); Assert.AreEqual(1, savedList.Count); Assert.AreEqual("new id", savedList.Last()); }
public void GetSurveyAnswerBrowsingContextGetTheAnswersListBlob() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", string.Empty); mockSurveyAnswerIdsListContainer.Verify(c => c.Get("tenant-slug-name"), Times.Once()); }
public async Task GetFirstSurveyAnswerIdGetTheAnswersListBlob() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); await store.GetFirstSurveyAnswerIdAsync("tenant", "slug-name"); mockSurveyAnswerIdsListContainer.Verify(c => c.GetAsync("tenant-slug-name"), Times.Once()); }
public void AppendSurveyAnswerIdsToAnswersListGetTheAnswersListBlob() { var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, new Mock<ISurveyAnswerContainerFactory>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, mockSurveyAnswerIdsListContainer.Object); store.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", new List<string>()); var optContext = It.IsAny<OptimisticConcurrencyContext>(); mockSurveyAnswerIdsListContainer.Verify(c => c.Get("tenant-slug-name", out optContext), Times.Once()); }
public void AppendSurveyAnswerIdsToAnswersListGetTheAnswersListBlob() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); store.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", new List <string>()); var optContext = It.IsAny <OptimisticConcurrencyContext>(); mockSurveyAnswerIdsListContainer.Verify(c => c.Get("tenant-slug-name", out optContext), Times.Once()); }
public async Task GetSurveyAnswerIdsReturnsList() { var azureBlobContainerMock = new Mock <IAzureBlobContainer <List <string> > >(); azureBlobContainerMock.Setup(b => b.GetAsync("tenant-slug")).ReturnsAsync(new List <string>() { "1", "2", "3" }); var surveyStore = new SurveyAnswerStore(null, null, null, null, azureBlobContainerMock.Object); var answers = await surveyStore.GetSurveyAnswerIdsAsync("tenant", "slug"); Assert.AreEqual(3, answers.Count()); azureBlobContainerMock.Verify(b => b.GetAsync("tenant-slug"), Times.Once()); }
public async Task DeleteSurveyAnswersCreatesBlobContainer() { var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureBlobContainer <List <string> > >().Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object); await store.DeleteSurveyAnswersAsync("tenant", "slug-name"); mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name"), Times.Once()); }
public async Task GetFirstSurveyAnswerIdReturnsEmprtyStringWhenListIsEmpty() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name")) .ReturnsAsync(default(List <string>)); var id = await store.GetFirstSurveyAnswerIdAsync("tenant", "slug-name"); Assert.AreEqual(string.Empty, id); }
public async Task GetSurveyAnswerCreatesBlobContainerForGivenTenantAndSurvey() { var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureBlobContainer <List <string> > >().Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object); await store.GetSurveyAnswerAsync("tenant", "slug-name", string.Empty); mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name")); }
public void GetSurveyAnswerEnsuresBlobContainerExists() { var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >(); var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureBlobContainer <List <string> > >().Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(mockSurveyAnswerBlobContainer.Object); store.GetSurveyAnswer("tenant", "slug-name", string.Empty); mockSurveyAnswerBlobContainer.Verify(c => c.EnsureExist()); }
public void DeleteSurveyAnswersDeletesAnswersList() { var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object); store.DeleteSurveyAnswers("tenant", "slug-name"); mockSurveyAnswerIdsListContainer.Verify(c => c.Delete("tenant-slug-name"), Times.Once()); }
public async Task GetSurveyAnswerGetsAnswerFromBlobContainer() { var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >(); var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureBlobContainer <List <string> > >().Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(mockSurveyAnswerBlobContainer.Object); await store.GetSurveyAnswerAsync("tenant", "slug-name", "id"); mockSurveyAnswerBlobContainer.Verify(c => c.GetAsync("id")); }
public async Task GetSurveyAnswerBrowsingContextReturnsNullNextIdAndPreviousIdWhenListDoesNotExist() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name")) .ReturnsAsync(default(List <string>)); var surveyAnswerBrowsingContext = await store.GetSurveyAnswerBrowsingContextAsync("tenant", "slug-name", "id"); Assert.IsNull(surveyAnswerBrowsingContext.PreviousId); Assert.IsNull(surveyAnswerBrowsingContext.NextId); }
public async Task GetSurveyAnswerBrowsingContextReturnsNextId() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name")) .ReturnsAsync(new List <string> { "id 1", "id 2", "id 3" }); var surveyAnswerBrowsingContext = await store.GetSurveyAnswerBrowsingContextAsync("tenant", "slug-name", "id 2"); Assert.AreEqual("id 3", surveyAnswerBrowsingContext.NextId); }
public void GetSurveyAnswerBrowsingContextReturnsNullPreviousIdWhenInBeginingOfList() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name")) .Returns(new List <string> { "id 1" }); var surveyAnswerBrowsingContext = store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", "id 1"); Assert.IsNull(surveyAnswerBrowsingContext.PreviousId); }
public async Task GetFirstSurveyAnswerIdReturnsTheAnswerWhichAppearsFirstOnTheListWhenListIsNotEmpty() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name")) .ReturnsAsync(new List <string> { "id" }); var id = await store.GetFirstSurveyAnswerIdAsync("tenant", "slug-name"); Assert.AreEqual("id", id); }
public void SaveSurveyAnswerEnsuresBlobContainerExists() { var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >(); var mockTenantStore = new Mock <ITenantStore>(); var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, null, new Mock <IAzureBlobContainer <List <string> > >().Object); mockTenantStore.Setup(t => t.GetTenant(It.IsAny <string>())).Returns(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(mockSurveyAnswerBlobContainer.Object); store.SaveSurveyAnswer(new SurveyAnswer()); mockTenantStore.Verify(t => t.GetTenant(It.IsAny <string>())); }
public async Task SaveSurveyAnswerSavesAnswerInBlobContainerWithId() { var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >(); var mockTenantStore = new Mock <ITenantStore>(); var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, null, new Mock <IAzureBlobContainer <List <string> > >().Object); mockTenantStore.Setup(t => t.GetTenantAsync(It.IsAny <string>())).ReturnsAsync(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(mockSurveyAnswerBlobContainer.Object); await store.SaveSurveyAnswerAsync(new SurveyAnswer()); mockTenantStore.Verify(t => t.GetTenantAsync(It.IsAny <string>())); mockSurveyAnswerBlobContainer.Verify(c => c.SaveAsync(It.Is <string>(s => s.Length == 19), It.IsAny <SurveyAnswer>())); }
public void AppendSurveyAnswerIdsToAnswersListSavesModifiedListToTheAnswersListBlob() { var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, new Mock<ISurveyAnswerContainerFactory>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, mockSurveyAnswerIdsListContainer.Object); var answerIdsList = new List<string> { "id 1", "id 2" }; var optContext = It.IsAny<OptimisticConcurrencyContext>(); mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name", out optContext)).Returns(answerIdsList); List<string> savedList = null; mockSurveyAnswerIdsListContainer.Setup(c => c.Save(optContext, It.IsAny<List<string>>())) .Callback<IConcurrencyControlContext, List<string>>((id, l) => savedList = l); store.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", new List<string>() { "new id" }); Assert.AreEqual(3, savedList.Count); Assert.AreEqual("new id", savedList.Last()); }
public async Task GetSurveyAnswerReturnsAnswerObtainedFromBlobContainer() { var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >(); var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureBlobContainer <List <string> > >().Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(mockSurveyAnswerBlobContainer.Object); var surveyAnswer = new SurveyAnswer(); mockSurveyAnswerBlobContainer.Setup(c => c.GetAsync(It.IsAny <string>())) .ReturnsAsync(surveyAnswer); var actualSurveyAnswer = await store.GetSurveyAnswerAsync("tenant", "slug-name", string.Empty); Assert.AreSame(surveyAnswer, actualSurveyAnswer); }
public async Task SaveSurveyAnswerCreatesBlobContainerForGivenTenantAndSurvey() { var mockTenantStore = new Mock <ITenantStore>(); var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, null, new Mock <IAzureBlobContainer <List <string> > >().Object); mockTenantStore.Setup(t => t.GetTenantAsync("tenant")).ReturnsAsync(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object); var surveyAnswer = new SurveyAnswer { TenantId = "tenant", SlugName = "slug-name" }; await store.SaveSurveyAnswerAsync(surveyAnswer); mockTenantStore.Verify(t => t.GetTenantAsync("tenant")); mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name")); }
public async Task SaveSurveyAnswerAddMessageToQueueWithTenant() { var mockTenantStore = new Mock <ITenantStore>(); var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>(); var mockSurveyAnswerStoredQueue = new Mock <IAzureQueue <SurveyAnswerStoredMessage> >(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, mockSurveyAnswerStoredQueue.Object, null, new Mock <IAzureBlobContainer <List <string> > >().Object); mockTenantStore.Setup(t => t.GetTenantAsync("tenant")).ReturnsAsync(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object); await store.SaveSurveyAnswerAsync(new SurveyAnswer { TenantId = "tenant" }); mockTenantStore.Verify(t => t.GetTenantAsync("tenant")); mockSurveyAnswerStoredQueue.Verify( q => q.AddMessageAsync( It.Is <SurveyAnswerStoredMessage>(m => m.TenantId == "tenant"))); }
public async Task AppendSurveyAnswerIdToAnswersListCreatesListWhenItDoesNotExistAndSavesIt() { var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var store = new SurveyAnswerStore( new Mock <ITenantStore>().Object, new Mock <ISurveyAnswerContainerFactory>().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object, mockSurveyAnswerIdsListContainer.Object); List <string> answerIdsList = null; mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name")).ReturnsAsync(answerIdsList); List <string> savedList = null; mockSurveyAnswerIdsListContainer.Setup(c => c.SaveAsync(It.IsAny <string>(), It.IsAny <List <string> >())) .Callback <string, List <string> >((str, l) => savedList = l) .Returns(Task.FromResult(0)); await store.AppendSurveyAnswerIdToAnswersListAsync("tenant", "slug-name", "new id"); Assert.AreEqual(1, savedList.Count); Assert.AreEqual("new id", savedList.Last()); }
public void GetSurveyAnswerBrowsingContextReturnsNullNextIdWhenEndOfList() { var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, new Mock<ISurveyAnswerContainerFactory>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name")) .Returns(new List<string> { "id 1" }); var surveyAnswerBrowsingContext = store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", "id 1"); Assert.IsNull(surveyAnswerBrowsingContext.NextId); }
public void GetSurveyAnswerBrowsingContextReturnsPreviousId() { var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, new Mock<ISurveyAnswerContainerFactory>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name")) .Returns(new List<string> { "id 1", "id 2", "id 3" }); var surveyAnswerBrowsingContext = store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", "id 2"); Assert.AreEqual("id 1", surveyAnswerBrowsingContext.PreviousId); }
public void GetSurveyAnswerCreatesBlobContainerForGivenTenantAndSurvey() { var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureBlobContainer<List<string>>>().Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>())) .Returns(new Mock<IAzureBlobContainer<SurveyAnswer>>().Object); store.GetSurveyAnswer("tenant", "slug-name", string.Empty); mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name")); }
public void GetSurveyAnswerGetsAnswerFromBlobContainer() { var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>(); var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureBlobContainer<List<string>>>().Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>())) .Returns(mockSurveyAnswerBlobContainer.Object); store.GetSurveyAnswer("tenant", "slug-name", "id"); mockSurveyAnswerBlobContainer.Verify(c => c.Get("id")); }
public void GetSurveyAnswerIdsReturnsList() { var azureBlobContainerMock = new Mock<IAzureBlobContainer<List<string>>>(); azureBlobContainerMock.Setup(b => b.Get("tenant-slug")).Returns(new List<string>() { "1", "2", "3" }); var surveyStore = new SurveyAnswerStore(null, null, null, null, azureBlobContainerMock.Object); var answers = surveyStore.GetSurveyAnswerIds("tenant", "slug"); Assert.AreEqual(3, answers.Count()); azureBlobContainerMock.Verify(b => b.Get("tenant-slug"), Times.Once()); }
public void DeleteSurveyAnswersCallsDeleteFromBlobContainer() { var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>(); var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureBlobContainer<List<string>>>().Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>())) .Returns(mockSurveyAnswerBlobContainer.Object); store.DeleteSurveyAnswers("tenant", "slug-name"); mockSurveyAnswerBlobContainer.Verify(c => c.DeleteContainer(), Times.Once()); }
public void GetFirstSurveyAnswerIdReturnsTheAnswerWhichAppearsFirstOnTheListWhenListIsNotEmpty() { var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, new Mock<ISurveyAnswerContainerFactory>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name")) .Returns(new List<string> { "id" }); var id = store.GetFirstSurveyAnswerId("tenant", "slug-name"); Assert.AreEqual("id", id); }
public void SaveSurveyAnswerAddMessageToQueueWithTenant() { var mockTenantStore = new Mock<ITenantStore>(); var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>(); var mockSurveyAnswerStoredQueue = new Mock<IAzureQueue<SurveyAnswerStoredMessage>>(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, mockSurveyAnswerStoredQueue.Object, null, new Mock<IAzureBlobContainer<List<string>>>().Object); mockTenantStore.Setup(t => t.GetTenant("tenant")).Returns(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>())) .Returns(new Mock<IAzureBlobContainer<SurveyAnswer>>().Object); store.SaveSurveyAnswer(new SurveyAnswer { Tenant = "tenant" }); mockTenantStore.Verify(t => t.GetTenant("tenant")); mockSurveyAnswerStoredQueue.Verify( q => q.AddMessage( It.Is<SurveyAnswerStoredMessage>(m => m.Tenant == "tenant"))); }
public void SaveSurveyAnswerCreatesBlobContainerForGivenTenantAndSurvey() { var mockTenantStore = new Mock<ITenantStore>(); var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, null, new Mock<IAzureBlobContainer<List<string>>>().Object); mockTenantStore.Setup(t => t.GetTenant("tenant")).Returns(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>())) .Returns(new Mock<IAzureBlobContainer<SurveyAnswer>>().Object); var surveyAnswer = new SurveyAnswer { Tenant = "tenant", SlugName = "slug-name" }; store.SaveSurveyAnswer(surveyAnswer); mockTenantStore.Verify(t => t.GetTenant("tenant")); mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name")); }
public void SaveSurveyAnswerSavesAnswerInBlobContainerWithId() { var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>(); var mockTenantStore = new Mock<ITenantStore>(); var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, null, new Mock<IAzureBlobContainer<List<string>>>().Object); mockTenantStore.Setup(t => t.GetTenant(It.IsAny<string>())).Returns(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>())) .Returns(mockSurveyAnswerBlobContainer.Object); store.SaveSurveyAnswer(new SurveyAnswer()); mockTenantStore.Verify(t => t.GetTenant(It.IsAny<string>())); mockSurveyAnswerBlobContainer.Verify(c => c.Save(It.Is<string>(s => s.Length == 36), It.IsAny<SurveyAnswer>())); }
public void GetSurveyAnswerBrowsingContextGetTheAnswersListBlob() { var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, new Mock<ISurveyAnswerContainerFactory>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, mockSurveyAnswerIdsListContainer.Object); store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", string.Empty); mockSurveyAnswerIdsListContainer.Verify(c => c.Get("tenant-slug-name"), Times.Once()); }
public void SaveSurveyAnswerAddMessageToQueueWithSavedBlobId() { var mockTenantStore = new Mock<ITenantStore>(); var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>(); var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>(); var mockSurveyAnswerStoredQueue = new Mock<IAzureQueue<SurveyAnswerStoredMessage>>(); var store = new SurveyAnswerStore( mockTenantStore.Object, mockSurveyContainerFactory.Object, mockSurveyAnswerStoredQueue.Object, null, new Mock<IAzureBlobContainer<List<string>>>().Object); mockTenantStore.Setup(t => t.GetTenant(It.IsAny<string>())).Returns(new Tenant()); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>())) .Returns(mockSurveyAnswerBlobContainer.Object); string blobId = string.Empty; mockSurveyAnswerBlobContainer.Setup(c => c.Save(It.IsAny<string>(), It.IsAny<SurveyAnswer>())) .Callback((string id, SurveyAnswer sa) => blobId = id); store.SaveSurveyAnswer(new SurveyAnswer()); mockTenantStore.Verify(t => t.GetTenant(It.IsAny<string>())); mockSurveyAnswerStoredQueue.Verify( q => q.AddMessage( It.Is<SurveyAnswerStoredMessage>(m => m.SurveyAnswerBlobId == blobId))); }
public void GetSurveyAnswerReturnsAnswerObtainedFromBlobContainer() { var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>(); var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, mockSurveyContainerFactory.Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureBlobContainer<List<string>>>().Object); mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>())) .Returns(mockSurveyAnswerBlobContainer.Object); var surveyAnswer = new SurveyAnswer(); mockSurveyAnswerBlobContainer.Setup(c => c.Get(It.IsAny<string>())) .Returns(surveyAnswer); var actualSurveyAnswer = store.GetSurveyAnswer("tenant", "slug-name", string.Empty); Assert.AreSame(surveyAnswer, actualSurveyAnswer); }
public void GetFirstSurveyAnswerIdReturnsEmprtyStringWhenListIsEmpty() { var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>(); var store = new SurveyAnswerStore( new Mock<ITenantStore>().Object, new Mock<ISurveyAnswerContainerFactory>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object, mockSurveyAnswerIdsListContainer.Object); mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name")) .Returns(default(List<string>)); var id = store.GetFirstSurveyAnswerId("tenant", "slug-name"); Assert.AreEqual(string.Empty, id); }