Exemplo n.º 1
0
        public void ShouldRedistributeCreationOfAssetBetweenAllStorageAccounts()
        {
            // Defining list of accounts to select from.
            string[] storageAccountNames = new[] { "account1", "account2", "account3" };

            IAccountSelectionStrategy selectionStrategy = new RandomAccountSelectionStrategy(storageAccountNames);

            var selectedStorageAccounts = new Dictionary <string, int>();

            for (int i = 0; i < 50; i++)
            {
                var selectedStorageAccount = selectionStrategy.SelectAccountForAsset();
                if (!selectedStorageAccounts.ContainsKey(selectedStorageAccount))
                {
                    selectedStorageAccounts.Add(selectedStorageAccount, 0);
                }
                else
                {
                    selectedStorageAccounts[selectedStorageAccount] += 1;
                }

                Thread.Sleep(100);
            }

            // Check if all storage accounts participated in redistribution.
            Assert.AreEqual(storageAccountNames.Length, selectedStorageAccounts.Keys.Count);
        }
Exemplo n.º 2
0
        public void ShouldCreateAssetFromFolderWithRandomAccountSelectionStrategy()
        {
            RandomAccountSelectionStrategy strategy = RandomAccountSelectionStrategy.FromAccounts(this.context);
            var folderName = "Media";

            this.asset = this.context.Assets.CreateFromFolder(folderName, strategy, AssetCreationOptions.None, null);
            var assetId = this.asset.Id;

            Assert.IsNotNull(this.asset);
            Assert.AreEqual(folderName, this.asset.Name);
            IList <string> storageAccountNames = strategy.GetStorageAccounts();

            CollectionAssert.Contains((ICollection)storageAccountNames, this.asset.StorageAccountName);

            var assetFiles = this.asset.AssetFiles.ToList().OrderBy(a => a.Name);

            Assert.AreEqual(3, assetFiles.Count());
            Assert.AreEqual("dummy.ism", assetFiles.ElementAt(0).Name);
            Assert.IsTrue(assetFiles.ElementAt(0).IsPrimary);
            Assert.AreEqual("smallwmv1.wmv", assetFiles.ElementAt(1).Name);
            Assert.IsFalse(assetFiles.ElementAt(1).IsPrimary);
            Assert.AreEqual("smallwmv2.wmv", assetFiles.ElementAt(2).Name);
            Assert.IsFalse(assetFiles.ElementAt(2).IsPrimary);

            this.context = TestHelper.CreateContext();
            Assert.AreEqual(0, this.context.Locators.Where(l => l.AssetId == assetId).Count());
        }
Exemplo n.º 3
0
        public void ShouldThrowCreatingStrategyIfStorageAccountsArrayIsEmpty()
        {
            // Defining list of accounts to select from.
            string[] nullStorageAccountNames = new string[0];

            IAccountSelectionStrategy strategy = new RandomAccountSelectionStrategy(nullStorageAccountNames);
        }
Exemplo n.º 4
0
        public void ShouldCreateAssetFromFileWithRandomAccountSelectionStrategy()
        {
            RandomAccountSelectionStrategy strategy = RandomAccountSelectionStrategy.FromAccounts(this.context);

            var filePath = @"Media\smallwmv1.wmv";

            this.asset = this.context.Assets.CreateFromFile(filePath, strategy, AssetCreationOptions.None, null);
            var assetId = this.asset.Id;

            Assert.IsNotNull(this.asset);
            Assert.AreEqual("smallwmv1.wmv", this.asset.Name);
            IList <string> storageAccountNames = strategy.GetStorageAccounts();

            CollectionAssert.Contains((ICollection)storageAccountNames, this.asset.StorageAccountName);

            var assetFiles = this.asset.AssetFiles.ToList().OrderBy(a => a.Name);

            Assert.AreEqual(1, assetFiles.Count());
            Assert.AreEqual("smallwmv1.wmv", assetFiles.ElementAt(0).Name);

            this.context = TestHelper.CreateContext();
            Assert.AreEqual(0, this.context.Locators.Where(l => l.AssetId == assetId).Count());
        }
Exemplo n.º 5
0
        public void ShouldCreateAssetWithRandomAccountSelectionStrategy()
        {
            IAccountSelectionStrategy selectionStrategy = RandomAccountSelectionStrategy.FromAccounts(this.context);

            this.asset = this.context.Assets.Create(Guid.NewGuid().ToString(), selectionStrategy, AssetCreationOptions.None);
        }