Beispiel #1
0
        public void Table_CreateResourceToken_ReturnsExpectedStartDate()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read
            });

            // Assert.
            Assert.IsNotNull(token);

            // Calculate the expected start time give or take 4 seconds.
            DateTime startRangeBegin = DateTime.UtcNow - TimeSpan.FromMinutes(5) - TimeSpan.FromSeconds(2);
            DateTime startRangeEnd   = startRangeBegin + TimeSpan.FromSeconds(2);

            // Now convert these into strings using the SAS format.
            string startRangeBeginString = this.DateTimeToSASDateString(startRangeBegin);
            string startRangeEndString   = this.DateTimeToSASDateString(startRangeEnd);

            // Get the actual begin time from the SAS token.
            SASParts parts     = new SASParts(token.Uri);
            string   beginning = parts.Value("st");

            // Make sure it is within the range.
            Assert.IsTrue(string.CompareOrdinal(beginning, startRangeBeginString) >= 0 && string.CompareOrdinal(beginning, startRangeEndString) <= 0);
        }
Beispiel #2
0
        public void Table_ExtractConnectionString_AppSettingsTableConnectionStringIsNull_ThrowsArgumentException()
        {
            AzureTableBroker            broker      = new AzureTableBroker();
            Dictionary <string, string> appSettings = new Dictionary <string, string>();

            appSettings.Add("ResourceBrokerTableConnectionString", null);
            this.ExpectException <InvalidOperationException>(() => broker.ExtractConnectionString(appSettings));
        }
Beispiel #3
0
        public void Table_ExtractConnectionString_WithQueueConnectionString_ThrowsException()
        {
            // Setup
            AzureTableBroker            broker      = new AzureTableBroker();
            Dictionary <string, string> appSettings = new Dictionary <string, string>();

            appSettings.Add("ResourceBrokerQueueConnectionString", ConnectionString);

            // Act
            this.ExpectException <InvalidOperationException>(() => broker.ExtractConnectionString(appSettings));
        }
Beispiel #4
0
        public void Table_ExtractConnectionString_AppSettingsTableConnectionString_ReturnsTableConnectionString()
        {
            // Setup
            AzureTableBroker            broker      = new AzureTableBroker();
            Dictionary <string, string> appSettings = new Dictionary <string, string>();

            appSettings.Add("ResourceBrokerTableConnectionString", ConnectionString);

            // Act
            string c = broker.ExtractConnectionString(appSettings);

            // Assert
            Assert.AreEqual(c, ConnectionString);
        }
Beispiel #5
0
        public void Table_CreateResourceToken_WithAddUpdateDeletePermissions_ReturnsCorrectAccess()
        {
            AzureTableBroker broker = new AzureTableBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Add | ResourcePermissions.Update | ResourcePermissions.Delete, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("aud", parts.Value("sp"));
        }
Beispiel #6
0
        public void Table_CreateResourceToken_WithProcessPermissions_IgnoresProcessPermissions()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read | ResourcePermissions.Process, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("r", parts.Value("sp"));
        }
Beispiel #7
0
        public void Table_CreateResourceToken_ReturnsCorrectHostPath()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("https://test.table.core.windows.net/table", parts.HostName);
        }
Beispiel #8
0
        public void Table_CreateResourceToken_WithNoExpirationDate_ReturnsNoExpirationDate()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual(null, parts.Value("se"));
        }
Beispiel #9
0
        public void Table_CreateResourceToken_WithExpirationDate_ReturnsCorrectExpirationDate()
        {
            // Setup
            DateTime         expiration = new DateTime(2199, 3, 12, 1, 2, 3, DateTimeKind.Utc);
            AzureTableBroker broker     = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read, Expiration = expiration
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("2199-03-12T01%3A02%3A03Z", parts.Value("se"));
        }