public async Task AddAndGetMessages()
        {
            var       account = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var       newSurveyAnswerQueue = new AzureQueue <MessageForTests>(account);
            const int maxMessagesToReturn  = 2;

            await newSurveyAnswerQueue.AddMessageAsync(new MessageForTests());

            await newSurveyAnswerQueue.AddMessageAsync(new MessageForTests());

            var actualMessages = await newSurveyAnswerQueue.GetMessagesAsync(maxMessagesToReturn);

            Assert.AreEqual(2, actualMessages.Count());
        }
Exemplo n.º 2
0
        public void LockUnexistentResourceReturnsTrueWithNoLockId()
        {
            var azureBlobContainer = new TestAzureBlobContainer(
                CloudConfiguration.GetStorageAccount("DataConnectionString"),
                AzureBlobTestContainer);

            var lockContext = new PessimisticConcurrencyContext()
            {
                ObjectId = Guid.NewGuid().ToString()
            };

            Assert.IsTrue(azureBlobContainer.AcquireLock(lockContext));
            Assert.IsNull(lockContext.LockId);
        }
Exemplo n.º 3
0
        public void AddAndGetMessage()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var queue   = new AzureQueue <MessageForTests>(account);
            var message = new MessageForTests {
                Content = "content"
            };

            queue.Clear();
            queue.AddMessage(message);
            var actualMessage = queue.GetMessage();

            Assert.AreEqual(message.Content, actualMessage.Content);
        }
        public async Task DeleteShouldRemoveTheBlob()
        {
            var objId = Guid.NewGuid().ToString();

            var azureBlobContainer = new TestAzureBlobContainer(
                CloudConfiguration.GetStorageAccount("DataConnectionString"),
                AzureBlobTestContainer);
            await azureBlobContainer.SaveAsync(objId, "testText");

            Assert.IsNotNull(await azureBlobContainer.GetAsync(objId));

            await azureBlobContainer.DeleteAsync(objId);

            Assert.IsNull(await azureBlobContainer.GetAsync(objId));
        }
Exemplo n.º 5
0
        public void DeleteAndAddAndGet()
        {
            var account    = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var azureTable = new AzureTable <TestRow>(account, TableName);
            var row        = new TestRow
            {
                PartitionKey = "partition_key_DeleteAndAddAndGet",
                RowKey       = "row_key_DeleteAndAddAndGet",
                Content      = "content"
            };

            azureTable.Delete(row);
            TableQuery <TestRow> query = new TableQuery <TestRow>().Where(TableQuery.GenerateFilterCondition(("RowKey"), QueryComparisons.Equal, row.RowKey));
            var deletedRow             = azureTable.AzureCloudTable.ExecuteQuery(query).SingleOrDefault();

            //TestRow deletedRow = azureTable.AzureCloudTable.ExecuteQuery( (from o in azureTable.Query
            //                      where o.RowKey == row.RowKey
            //                      select o).SingleOrDefault();
            Assert.IsNull(deletedRow);

            azureTable.Add(row);

            TableQuery <TestRow> query1 = new TableQuery <TestRow>().Where
                                          (
                TableQuery.GenerateFilterCondition(("RowKey"), QueryComparisons.Equal, row.RowKey) +
                TableQuery.GenerateFilterCondition(("PartitionKey"), QueryComparisons.Equal, "partition_key_DeleteAndAddAndGet")
                                          );
            var tableSavedResult = azureTable.AzureCloudTable.Execute(TableOperation.Retrieve("partition_key_DeleteAndAddAndGet", row.RowKey));

            //TestRow savedRow = (TestRow)tableSavedResult.Result;

            //var savedRow = azureTable.AzureCloudTable.ExecuteQuery(query1).SingleOrDefault();
            //TestRow savedRow = (from o in azureTable.Query
            //                    where o.RowKey == row.RowKey &&
            //                          o.PartitionKey == "partition_key_DeleteAndAddAndGet" &&
            //                                  o.Content == "content"
            //                    select o).SingleOrDefault();
            Assert.IsNotNull(tableSavedResult.Result);

            azureTable.Delete(row);
            var tableActualResult = azureTable.AzureCloudTable.Execute(TableOperation.Retrieve("*", row.RowKey));

            //TestRow actualRow = (TestRow)tableActualResult.Result;
            //TestRow actualRow = (from o in azureTable.Query
            //                     where o.RowKey == row.RowKey
            //                     select o).SingleOrDefault();
            Assert.IsNull(tableActualResult.Result);
        }
        public async Task PurgeAndGetMessageReturnNull()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var queue   = new AzureQueue <MessageForTests>(account);
            var message = new MessageForTests {
                Content = "content"
            };

            await queue.AddMessageAsync(message);

            await queue.ClearAsync();

            var actualMessage = await queue.GetMessageAsync();

            Assert.IsNull(actualMessage);
        }
Exemplo n.º 7
0
        public async Task SaveAndGet()
        {
            var account              = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var surveyAnswerStorage  = new EntitiesBlobContainer <SurveyAnswer>(account, SurveyAnswersContainer);
            var surveyAnswerId       = new Guid("{DB0298D2-432B-41A7-B80F-7E7A025FA267}").ToString();
            var expectedSurveyAnswer = new SurveyAnswer {
                TenantId = "tenant", Title = "title", SlugName = "slugname"
            };
            var question1 = new QuestionAnswer {
                QuestionText = "text 1", QuestionType = QuestionType.SimpleText, PossibleAnswers = string.Empty
            };
            var question2 = new QuestionAnswer {
                QuestionText = "text 2", QuestionType = QuestionType.MultipleChoice, PossibleAnswers = "answer 1\nanswer2"
            };
            var question3 = new QuestionAnswer {
                QuestionText = "text 3", QuestionType = QuestionType.FiveStars, PossibleAnswers = string.Empty
            };

            (expectedSurveyAnswer.QuestionAnswers as List <QuestionAnswer>).AddRange(new[] { question1, question2, question3 });

            await surveyAnswerStorage.SaveAsync(surveyAnswerId, expectedSurveyAnswer);

            var actualSurveyAnswer = await surveyAnswerStorage.GetAsync(surveyAnswerId);

            Assert.AreEqual(expectedSurveyAnswer.TenantId, actualSurveyAnswer.TenantId);
            Assert.AreEqual(expectedSurveyAnswer.Title, actualSurveyAnswer.Title);
            Assert.AreEqual(expectedSurveyAnswer.SlugName, actualSurveyAnswer.SlugName);
            Assert.AreEqual(3, actualSurveyAnswer.QuestionAnswers.Count);
            var actualQuestionAnswer1 = actualSurveyAnswer.QuestionAnswers.SingleOrDefault(q =>
                                                                                           q.QuestionText == "text 1" &&
                                                                                           q.QuestionType == QuestionType.SimpleText &&
                                                                                           q.PossibleAnswers == string.Empty);

            Assert.IsNotNull(actualQuestionAnswer1);
            var actualQuestionAnswer2 = actualSurveyAnswer.QuestionAnswers.SingleOrDefault(q =>
                                                                                           q.QuestionText == "text 2" &&
                                                                                           q.QuestionType == QuestionType.MultipleChoice &&
                                                                                           q.PossibleAnswers == "answer 1\nanswer2");

            Assert.IsNotNull(actualQuestionAnswer2);
            var actualQuestionAnswer3 = actualSurveyAnswer.QuestionAnswers.SingleOrDefault(q =>
                                                                                           q.QuestionText == "text 3" &&
                                                                                           q.QuestionType == QuestionType.FiveStars &&
                                                                                           q.PossibleAnswers == string.Empty);

            Assert.IsNotNull(actualQuestionAnswer3);
        }
        public async Task GetBlobListReturnsAllBlobsInContainer()
        {
            var objId1 = Guid.NewGuid().ToString();
            var objId2 = Guid.NewGuid().ToString();

            var azureBlobContainer = new TestAzureBlobContainer(
                CloudConfiguration.GetStorageAccount("DataConnectionString"),
                AzureBlobTestContainer);
            await azureBlobContainer.SaveAsync(objId1, "testText");

            await azureBlobContainer.SaveAsync(objId2, "testText");

            var blobList = azureBlobContainer.GetBlobList().Select(b => b.Name).ToList();

            CollectionAssert.Contains(blobList, objId1);
            CollectionAssert.Contains(blobList, objId2);
        }
        public async Task CreateNewBlob()
        {
            var azureBlobContainer = new TestAzureBlobContainer(
                CloudConfiguration.GetStorageAccount("DataConnectionString"),
                AzureBlobTestContainer);

            var objId = Guid.NewGuid().ToString();

            var text = await azureBlobContainer.GetAsync(objId);

            Assert.IsNull(text);

            await azureBlobContainer.SaveAsync(objId, "testText");

            text = await azureBlobContainer.GetAsync(objId);

            Assert.IsNotNull(text);
        }
        public async Task SaveAndGetData()
        {
            var objId = Guid.NewGuid().ToString();

            var account     = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var logoStorage = new FilesBlobContainer(account, LogoStoreContainer, "xxx");

            var data = new byte[] { 1, 2, 3, 4 };
            await logoStorage.SaveAsync(objId, data);

            var retrievedData = await logoStorage.GetAsync(objId);

            var result = from x in data
                         join y in retrievedData on x equals y
                         select x;

            Assert.IsTrue(data.Length == retrievedData.Length && result.Count() == data.Length);
        }
Exemplo n.º 11
0
        public static void RegisterTypes(IUnityContainer container)
        {
            container.RegisterInstance(CloudConfiguration.GetStorageAccount("DataConnectionString"));

            container.RegisterInstance <IRetryPolicyFactory>(new DefaultRetryPolicyFactory());

            var cloudStorageAccountType    = typeof(Microsoft.WindowsAzure.CloudStorageAccount);
            var retryPolicyFactoryProperty = new InjectionProperty("RetryPolicyFactory", typeof(IRetryPolicyFactory));

            container
            .RegisterType <IAzureBlobContainer <Tenant>, EntitiesBlobContainer <Tenant> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.Tenants),
                retryPolicyFactoryProperty)
            .RegisterType <IAzureBlobContainer <byte[]>, FilesBlobContainer>(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.Logos, "image/jpeg"),
                retryPolicyFactoryProperty);

            container.RegisterType <ITenantStore, TenantStore>();
        }
Exemplo n.º 12
0
        public AccountStore()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            this._accountingService = new AccountingService(
                new AzureRepository <AzureAccount, Account>(account),
                new AzureRepository <AzureCurrencyType, CurrencyType>(account),
                new AzureRepository <AzureAccountBalance, AccountBalance>(account),
                new AzureRepository <AzureAccountLogin, AccountLogin>(account),
                new AzureRepository <AzureAccountSetAccounts, AccountSetAccounts>(account),
                new AccountsFactory(
                    new AzureRepository <AzureAccount, Account>(account),
                    new AzureRepository <AzureCurrencyType, CurrencyType>(account),
                    new AzureRepository <AzureAccountBalance, AccountBalance>(account),
                    new AzureRepository <AzureAccountLogin, AccountLogin>(account),
                    new AzureRepository <AzureAccountSet, AccountSet>(account),
                    new AzureRepository <AzureAccountSetAccounts, AccountSetAccounts>(account),
                    new AzureScopeableUnitOfWorkFactory()));
        }
Exemplo n.º 13
0
        public void SaveAndDelete()
        {
            var account              = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var surveyAnswerStorage  = new EntitiesBlobContainer <SurveyAnswer>(account, SurveyAnswersContainer);
            var surveyAnswerId       = new Guid("{A0E27D4B-4CD9-43B0-B29E-FE61096A529A}").ToString();
            var expectedSurveyAnswer = new SurveyAnswer {
                Tenant = "tenant", Title = "title", SlugName = "slugname"
            };

            surveyAnswerStorage.Save(surveyAnswerId, expectedSurveyAnswer);
            SurveyAnswer savedSurveyAnswer = surveyAnswerStorage.Get(surveyAnswerId);

            Assert.IsNotNull(savedSurveyAnswer);

            surveyAnswerStorage.Delete(surveyAnswerId);
            SurveyAnswer deletedSurveyAnswer = surveyAnswerStorage.Get(surveyAnswerId);

            Assert.IsNull(deletedSurveyAnswer);
        }
Exemplo n.º 14
0
        public AccountController()
            : this(Startup.UserManagerFactory(), Startup.OAuthOptions.AccessTokenFormat)
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            this._accountingService = new AccountingService(
                new AzureRepository <AzureAccount, Account>(account),
                new AzureRepository <AzureCurrencyType, CurrencyType>(account),
                new AzureRepository <AzureAccountBalance, AccountBalance>(account),
                new AzureRepository <AzureAccountLogin, AccountLogin>(account),
                new AzureRepository <AzureAccountSetAccounts, AccountSetAccounts>(account),
                new AccountsFactory(
                    new AzureRepository <AzureAccount, Account>(account),
                    new AzureRepository <AzureCurrencyType, CurrencyType>(account),
                    new AzureRepository <AzureAccountBalance, AccountBalance>(account),
                    new AzureRepository <AzureAccountLogin, AccountLogin>(account),
                    new AzureRepository <AzureAccountSet, AccountSet>(account),
                    new AzureRepository <AzureAccountSetAccounts, AccountSetAccounts>(account),
                    new AzureScopeableUnitOfWorkFactory()));
        }
Exemplo n.º 15
0
        public void AddOrUpdateUpdatesWhenExists()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            var azureTable = new AzureTable <TestRow>(account, TableName);

            azureTable.RetryPolicyFactory = new DefaultRetryPolicyFactory();

            var row = new TestRow
            {
                PartitionKey = "partition_key_AddOrUpdateUpdatesWhenExists",
                RowKey       = "row_key_AddOrUpdateUpdatesWhenExists",
                Content      = "content"
            };

            azureTable.Delete(row);
            TestRow deletedRow = (from o in azureTable.Query
                                  where o.RowKey == row.RowKey
                                  select o).SingleOrDefault();

            Assert.IsNull(deletedRow);

            azureTable.Add(row);
            TestRow savedRow = (from o in azureTable.Query
                                where o.RowKey == row.RowKey &&
                                o.PartitionKey == "partition_key_AddOrUpdateUpdatesWhenExists" &&
                                o.Content == "content"
                                select o).SingleOrDefault();

            Assert.IsNotNull(savedRow);

            row.Content = "content modified";
            azureTable.AddOrUpdate(row);
            TestRow updatedRow = (from o in azureTable.Query
                                  where o.RowKey == row.RowKey &&
                                  o.PartitionKey == "partition_key_AddOrUpdateUpdatesWhenExists" &&
                                  o.Content == "content modified"
                                  select o).SingleOrDefault();

            Assert.IsNotNull(updatedRow);
        }
Exemplo n.º 16
0
        public void AddOrUpdateMany()
        {
            var account    = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var azureTable = new AzureTable <TestRow>(account, TableName);
            var row1       = new TestRow {
                PartitionKey = "partition_key_AddOrUpdateMany", RowKey = "row_key_1_AddOrUpdateMany", Content = "content 1"
            };
            var row2 = new TestRow {
                PartitionKey = "partition_key_AddOrUpdateMany", RowKey = "row_key_2_AddOrUpdateMany", Content = "content 2"
            };

            azureTable.Delete(new[] { row1, row2 });
            var rowsToDelete = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_AddOrUpdateMany"
                                select o).ToList();

            Assert.AreEqual(0, rowsToDelete.Count);

            azureTable.Add(row1);
            var actualRows = (from o in azureTable.Query
                              where o.PartitionKey == "partition_key_AddOrUpdateMany"
                              select o).ToList();

            Assert.AreEqual(1, actualRows.Count);

            row1.Content = "content modified";
            azureTable.AddOrUpdate(new[] { row1, row2 });
            var insertedRows = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_AddOrUpdateMany"
                                select o).ToList();

            Assert.AreEqual(2, insertedRows.Count);

            TestRow updatedRow = (from o in azureTable.Query
                                  where o.RowKey == row1.RowKey &&
                                  o.PartitionKey == "partition_key_AddOrUpdateMany" &&
                                  o.Content == "content modified"
                                  select o).SingleOrDefault();

            Assert.IsNotNull(updatedRow);
        }
Exemplo n.º 17
0
        public async Task ShouldSaveAndRetrieveCustomEntity()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            var key          = "ShouldSaveAndRetrieveCustomEntity_RowKey";
            var customEntity = new CustomEntity()
            {
                PartitionKey = "ShouldSaveAndRetrieveCustomEntity",
                RowKey       = key,
                Id           = 5,
                Name         = "five"
            };

            var udfAzureTable = new UDFAzureTable(account, TableName);
            await udfAzureTable.SaveAsync(customEntity);

            var storedEntity = await udfAzureTable.GetExtensionByPartitionRowKeyAsync(typeof(CustomEntity), "ShouldSaveAndRetrieveCustomEntity", key);

            Assert.IsNotNull(storedEntity);
            Assert.AreEqual(customEntity.ToString(), storedEntity.ToString());
        }
        public void OptimisticCreateNewBlob()
        {
            var azureBlobContainer = new EntitiesBlobContainer <string>(
                CloudConfiguration.GetStorageAccount("DataConnectionString"),
                AzureBlobTestContainer);

            var objId = Guid.NewGuid().ToString();

            OptimisticConcurrencyContext context;
            var text = azureBlobContainer.Get(objId, out context);

            Assert.IsNull(text);
            Assert.AreEqual(context.ObjectId, objId);

            azureBlobContainer.Save(context, "testText");

            text = azureBlobContainer.Get(objId);

            Assert.IsNotNull(text);
            Assert.AreEqual(context.ObjectId, objId);
        }
        public void LockBusyResourceReturnsFalseWithNoLockId()
        {
            var azureBlobContainer = new TestAzureBlobContainer(
                CloudConfiguration.GetStorageAccount("DataConnectionString"),
                AzureBlobTestContainer);

            var objId = Guid.NewGuid().ToString();

            azureBlobContainer.Save(objId, "testText");

            var lockContext = new PessimisticConcurrencyContext()
            {
                ObjectId = objId
            };

            Assert.IsTrue(azureBlobContainer.AcquireLock(lockContext));
            Assert.IsNotNull(lockContext.LockId);

            Assert.IsFalse(azureBlobContainer.AcquireLock(lockContext));
            Assert.IsNull(lockContext.LockId);
        }
Exemplo n.º 20
0
        protected override void InitializeTarget()
        {
            if (string.IsNullOrEmpty(TableName))
            {
                throw new ArgumentNullException("TableName");
            }

            base.InitializeTarget();
            var storageAccount = CloudConfiguration.GetStorageAccount("LogStorageConnectionString");

            logRepository = new ATSRepository <LogEntry>(storageAccount.CreateCloudTableClient(), TableName);

            try
            {
                applicationName = BuildManager.GetGlobalAsaxType().BaseType.Assembly.GetName().Name;
            }
            catch
            {
                applicationName = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CurrentRoleInstance.Role.Name;
            }

            try
            {
                roleInstance = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CurrentRoleInstance.Id;
            }
            catch
            {
                roleInstance = "N/A";
            }

            try
            {
                deploymentId = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.DeploymentId;
            }
            catch
            {
                deploymentId = "N/A";
            }
        }
        public async Task AddAndDeleteMessage()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var queue   = new AzureQueue <MessageForTests>(account);
            var message = new MessageForTests {
                Content = "content"
            };

            await queue.ClearAsync();

            await queue.AddMessageAsync(message);

            var retrievedMessage = await queue.GetMessageAsync();

            Assert.AreEqual(message.Content, retrievedMessage.Content);

            await queue.DeleteMessageAsync(retrievedMessage);

            var actualMessage = await queue.GetMessageAsync();

            Assert.IsNull(actualMessage);
        }
        public static ExpenseItem ToModel(this IExpenseItemEntity entity)
        {
            var expenseItem = new ExpenseItem
            {
                Id                  = new StorageKey(KeyGenerator.ExpenseItemEntitySuffix(entity.RowKey)).InvertedTicks,
                Amount              = entity.Amount.HasValue ? entity.Amount.Value : 0,
                Description         = entity.Description,
                ReceiptUrl          = null,
                ReceiptThumbnailUrl = null
            };

            if (entity.HasReceipt.HasValue && entity.HasReceipt.Value)
            {
                var    imageName = expenseItem.Id + ".jpg";
                var    account   = CloudConfiguration.GetStorageAccount(AzureConnectionStrings.DataConnection);
                string thumbnail = Path.Combine(account.BlobEndpoint.ToString(), AzureStorageNames.ReceiptContainerName, "thumbnails", imageName);
                string receipt   = Path.Combine(account.BlobEndpoint.ToString(), AzureStorageNames.ReceiptContainerName, imageName);
                expenseItem.ReceiptThumbnailUrl = new Uri(thumbnail);
                expenseItem.ReceiptUrl          = new Uri(receipt);
            }
            return(expenseItem);
        }
Exemplo n.º 23
0
        public void GetAndUpdateMessage()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var queue   = new AzureQueue <MessageForTests>(account, "messagefortests", TimeSpan.FromSeconds(1));
            var message = new MessageForTests {
                Content = "content"
            };

            queue.Clear();
            queue.AddMessage(message);
            var retrievedMessage = queue.GetMessage();

            Assert.AreEqual("content", retrievedMessage.Content);

            retrievedMessage.Content = "newContent";
            queue.UpdateMessage(retrievedMessage);

            // wait 1 second
            Thread.Sleep(1000);

            retrievedMessage = queue.GetMessage();
            Assert.AreEqual("newContent", retrievedMessage.Content);
        }
Exemplo n.º 24
0
 public ImageService(ILogger log)
 {
     try
     {
         this.log = log;
         this.cloudStorageAccount = CloudConfiguration.GetStorageAccount("StorageConnectionString");
         this.cloudBlobClient     = cloudStorageAccount.CreateCloudBlobClient();
         this.cloudBlobContainer  = cloudBlobClient.GetContainerReference("images");
         this.cloudBlobContainer.SetPermissions(
             new BlobContainerPermissions {
             PublicAccess = BlobContainerPublicAccessType.Blob
         }
             );
         this.cloudBlobContainer.CreateIfNotExistsAsync();
     }
     catch (System.Exception ex)
     {
         if (this.log != null)
         {
             this.log.Error("An error occurred in  ImageService(ILogger log) constructor.", ex);
         }
     }
 }
Exemplo n.º 25
0
        public BetsController()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            this._betsService = new BetsService(
                new AzureRepository <AzureBet, Bet>(account),
                new AzureRepository <AzureAccount, Account>(account),
                new AzureRepository <AzureEvent, Event>(account),
                new AzureRepository <AzureOutcomesType, OutcomesType>(account),
                new AzureRepository <AzureCurrencyType, CurrencyType>(account),
                new AzureRepository <AzureEventBetCondition, EventBetCondition>(account),
                new AzureRepository <AzureBetRateAlgorithm, BetRateAlgorithm>(account),
                new BetsFactory(
                    new AzureRepository <AzureBet, Bet>(account),
                    new AzureRepository <AzureEventBetCondition, EventBetCondition>(account),
                    new AzureRepository <AzureEventRelationType, EventRelationType>(account),
                    new AzureRepository <AzureCurrencyType, CurrencyType>(account),
                    new AzureRepository <AzureAlgorithmType, AlgorithmType>(account),
                    new AzureRepository <AzureAccountSetAccounts, AccountSetAccounts>(account),
                    new AzureRepository <AzureBetRateAlgorithm, BetRateAlgorithm>(account),
                    new AzureScopeableUnitOfWorkFactory()));

            this._userManager = Startup.UserManagerFactory();
        }
Exemplo n.º 26
0
        public async Task AzureRepositoryAddAccount()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            var repository = new AzureRepository <AzureAccount, Account>(account);

            var acc = new Account {
                Name = "misha", Email = "*****@*****.**"
            };

            await repository.Add(acc);

            var acc2 = await repository.Get(acc.Id);

            Assert.AreEqual(acc.Id, acc2.Id);
            Assert.AreEqual(acc.Name, acc2.Name);
            Assert.AreEqual(acc.Email, acc2.Email);

            await repository.Remove(acc);

            acc2 = await repository.Get(acc.Id);

            Assert.IsNull(acc2);
        }
Exemplo n.º 27
0
        public void ShouldSaveAndRetrieveCustomEntity()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            var key          = Guid.NewGuid().ToString();
            var customEntity = new CustomEntity()
            {
                PartitionKey = "CustomEntity",
                RowKey       = key,
                Id           = 5,
                Name         = "five"
            };

            var udfAzureTable = new UDFAzureTable(account, TableName);

            udfAzureTable.Save(customEntity);

            var storedEntity = udfAzureTable.BuildQueryFor(customEntity.GetType())
                               .Where(e => e.PartitionKey.Equals("CustomEntity") && e.RowKey.Equals(key))
                               .FirstOrDefault();

            Assert.IsNotNull(storedEntity);
            Assert.AreEqual(customEntity.ToString(), storedEntity.ToString());
        }
Exemplo n.º 28
0
        public void GetStorageAccountReturnsDevelopmentAccount()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            Assert.AreEqual(CloudStorageAccount.DevelopmentStorageAccount, account);
        }
Exemplo n.º 29
0
 public ExpenseExportRepository()
 {
     this.account = CloudConfiguration.GetStorageAccount(AzureConnectionStrings.DataConnection);
 }
        public static void RegisterTypes(IUnityContainer container, bool roleInitialization)
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            container.RegisterInstance(account);

            // http://msdn.microsoft.com/en-us/library/hh680900(v=pandp.50).aspx
            container.RegisterInstance <IRetryPolicyFactory>(roleInitialization
                ? new DefaultRetryPolicyFactory() as IRetryPolicyFactory
                : new ConfiguredRetryPolicyFactory() as IRetryPolicyFactory);

            var cloudStorageAccountType    = typeof(Microsoft.WindowsAzure.Storage.CloudStorageAccount);
            var retryPolicyFactoryProperty = new InjectionProperty("RetryPolicyFactory", typeof(IRetryPolicyFactory));

            // registering IAzureTable types
            container
            .RegisterType <IAzureTable <SurveyRow>, AzureTable <SurveyRow> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Tables.Surveys))
            .RegisterType <IAzureTable <QuestionRow>, AzureTable <QuestionRow> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Tables.Questions))
            .RegisterType <IUDFAzureTable, UDFAzureTable>(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Tables.SurveyExtensions));

            // registering IAzureQueue types
            container
            .RegisterType <IAzureQueue <SurveyAnswerStoredMessage>, AzureQueue <SurveyAnswerStoredMessage> >(
                SubscriptionKind.Standard.ToString(),
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Queues.SurveyAnswerStoredStandard))
            .RegisterType <IAzureQueue <SurveyAnswerStoredMessage>, AzureQueue <SurveyAnswerStoredMessage> >(
                SubscriptionKind.Premium.ToString(),
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Queues.SurveyAnswerStoredPremium))
            .RegisterType <IAzureQueue <SurveyTransferMessage>, AzureQueue <SurveyTransferMessage> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Queues.SurveyTransferRequest));

            // registering IAzureBlobContainer types
            container
            .RegisterType <IAzureBlobContainer <List <string> >, EntitiesBlobContainer <List <string> > >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.SurveyAnswersLists))
            .RegisterType <IAzureBlobContainer <Tenant>, EntitiesBlobContainer <Tenant> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.Tenants))
            .RegisterType <IAzureBlobContainer <byte[]>, FilesBlobContainer>(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.Logos, "image/jpeg"))
            .RegisterType <IAzureBlobContainer <SurveyAnswersSummary>, EntitiesBlobContainer <SurveyAnswersSummary> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.SurveyAnswersSummaries))
            .RegisterType <IAzureBlobContainer <Tenant>, EntitiesBlobContainer <Tenant> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.Tenants))
            .RegisterType <IAzureBlobContainer <byte[]>, FilesBlobContainer>(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.Logos, "image/jpeg"));

            var cacheEnabledProperty = new InjectionProperty("CacheEnabled", !roleInitialization);

            // registering Store types
            container
            .RegisterType <ISurveyStore, SurveyStore>(cacheEnabledProperty)
            .RegisterType <ITenantStore, TenantStore>(cacheEnabledProperty)
            .RegisterType <ISurveyAnswerStore, SurveyAnswerStore>(new InjectionFactory((c, t, s) => new SurveyAnswerStore(
                                                                                           container.Resolve <ITenantStore>(),
                                                                                           container.Resolve <ISurveyAnswerContainerFactory>(),
                                                                                           container.Resolve <IAzureQueue <SurveyAnswerStoredMessage> >(SubscriptionKind.Standard.ToString()),
                                                                                           container.Resolve <IAzureQueue <SurveyAnswerStoredMessage> >(SubscriptionKind.Premium.ToString()),
                                                                                           container.Resolve <IAzureBlobContainer <List <string> > >())))
            .RegisterType <ISurveyTransferStore, SurveyTransferStore>()
            .RegisterType <ISurveyAnswersSummaryStore, SurveyAnswersSummaryStore>()
            .RegisterType <ITenantStore, TenantStore>();

            // Container for resolving the survey answer containers
            var surveyAnswerBlobContainerResolver = new UnityContainer();

            surveyAnswerBlobContainerResolver.RegisterInstance(account);

            surveyAnswerBlobContainerResolver.RegisterType <IAzureBlobContainer <SurveyAnswer>, EntitiesBlobContainer <SurveyAnswer> >(
                new InjectionConstructor(cloudStorageAccountType, typeof(string)));

            container.RegisterType <ISurveyAnswerContainerFactory, SurveyAnswerContainerFactory>(
                new InjectionConstructor(surveyAnswerBlobContainerResolver));


            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }