public void ToBlobPath_IfMalformedBlobPath_ThrowsFormatException()
        {
            string requestedObjectKey      = "/account/malformed-blob-path";
            StorageAnalyticsLogEntry entry = CreateEntry("2014-09-08T18:44:18.9681025Z", StorageServiceOperationType.PutBlob, StorageServiceType.Blob, requestedObjectKey);

            ExceptionAssert.ThrowsFormat(() => entry.ToBlobPath(), "Failed to parse RequestedObjectKey property of the log entry. " +
                                         "Blob identifiers must be in the format container/blob.");
        }
        public void TryParse_IfMalformedStartTime_ReturnsNull()
        {
            string[] fields = CreateArray("<INVALID>", "PutBlob", "blob", @"/storagesample/sample-container/""0x8D199A96CB71468""/sample-blob.txt");

            StorageAnalyticsLogEntry entry = StorageAnalyticsLogEntry.TryParse(fields);

            Assert.Null(entry);
        }
        public void TryParseLogEntry_IfMalformedInput_ReturnsNull(string line)
        {
            StorageAnalyticsLogParser parser = new StorageAnalyticsLogParser(NullLogger <BlobListener> .Instance);

            StorageAnalyticsLogEntry entry = parser.TryParseLogEntry(line);

            Assert.Null(entry);
        }
        public void ToBlobPath_IfMalformedObjectKey_ReturnsNull(string requestedObjectKey)
        {
            StorageAnalyticsLogEntry entry = CreateEntry("2014-09-08T18:44:18.9681025Z", StorageServiceOperationType.PutBlob, StorageServiceType.Blob, requestedObjectKey);

            BlobPath blobPath = entry.ToBlobPath();

            Assert.Null(blobPath);
        }
        public void TryParseLogEntry_IfMalformedInput_ReturnsNull(string line)
        {
            StorageAnalyticsLogParser parser = new StorageAnalyticsLogParser();

            StorageAnalyticsLogEntry entry = parser.TryParseLogEntry(line);

            Assert.Null(entry);
        }
        public void ToBlobPath_IfMalformedObjectKey_ThrowsFormatException(string requestedObjectKey)
        {
            StorageAnalyticsLogEntry entry = CreateEntry("2014-09-08T18:44:18.9681025Z", StorageServiceOperationType.PutBlob, StorageServiceType.Blob, requestedObjectKey);

            ExceptionAssert.ThrowsFormat(() => entry.ToBlobPath(), "Failed to parse RequestedObjectKey property of the log entry. " +
                                         "It should be in one of the supported formats: " +
                                         @"""https://account.blob.core.windows.net/container/blob"", or" +
                                         @"""/account/container/blob""");
        }
        public void TryParse_IfUnrecognizedOperation_IgnoresIt()
        {
            string[] fields = CreateArray("2014-09-08T18:44:18.9681025Z", "INVALID", "blob", @"/storagesample/sample-container/""0x8D199A96CB71468""/sample-blob.txt");

            StorageAnalyticsLogEntry entry = StorageAnalyticsLogEntry.TryParse(fields);

            Assert.NotNull(entry);
            Assert.False(entry.OperationType.HasValue);
        }
        public void TryParseLogEntry_IfValidLogEnry_ReturnsEntryInstance(string line, string blobPath)
        {
            StorageAnalyticsLogParser parser = new StorageAnalyticsLogParser(NullLogger <BlobListener> .Instance);

            StorageAnalyticsLogEntry entry = parser.TryParseLogEntry(line);

            Assert.NotNull(entry);
            Assert.Equal(blobPath, entry.RequestedObjectKey);
        }
        internal void ToBlobPath_IfValidBlobOperationEntry_ReturnsBlobPath(StorageServiceOperationType operationType, StorageServiceType serviceType, string requestedObjectKey, string expectedContainerName, string expectedBlobName)
        {
            StorageAnalyticsLogEntry entry = CreateEntry("2014-09-08T18:44:18.9681025Z", operationType, serviceType, requestedObjectKey);

            BlobPath blobPath = entry.ToBlobPath();

            Assert.NotNull(blobPath);
            Assert.Equal(expectedContainerName, blobPath.ContainerName);
            Assert.Equal(expectedBlobName, blobPath.BlobName);
        }
        private static StorageAnalyticsLogEntry CreateEntry(string requestStartTime, StorageServiceOperationType operationType, StorageServiceType serviceType, string requestedObjectKey)
        {
            StorageAnalyticsLogEntry entry = new StorageAnalyticsLogEntry();

            entry.RequestStartTime   = DateTime.Parse(requestStartTime, CultureInfo.InvariantCulture);
            entry.OperationType      = operationType;
            entry.ServiceType        = serviceType;
            entry.RequestedObjectKey = requestedObjectKey;

            return(entry);
        }
        public void TryParse_IfValidFieldValues_ReturnsLogEntryInstance()
        {
            string requestStartTime   = "2014-09-08T18:44:18.9681025Z";
            string operationType      = "PutBlob";
            string serviceType        = "blob";
            string requestedObjectKey = @"/storagesample/sample-container/""0x8D199A96CB71468""/sample-blob.txt";

            string[] fields = CreateArray(requestStartTime, operationType, serviceType, requestedObjectKey);

            StorageAnalyticsLogEntry entry = StorageAnalyticsLogEntry.TryParse(fields);

            Assert.NotNull(entry);
            DateTime expectedRequestStartTime = new DateTime(635457986589681025L, DateTimeKind.Utc);

            Assert.Equal(expectedRequestStartTime, entry.RequestStartTime);
            Assert.Equal(DateTimeKind.Utc, entry.RequestStartTime.Kind);
            Assert.Equal(StorageServiceOperationType.PutBlob, entry.OperationType);
            Assert.Equal(StorageServiceType.Blob, entry.ServiceType);
            Assert.Equal(requestedObjectKey, entry.RequestedObjectKey);
        }
        public void ToBlobPath_IfMalformedUri_PropogatesUriFormatException(string requestedObjectKey)
        {
            StorageAnalyticsLogEntry entry = CreateEntry("2014-09-08T18:44:18.9681025Z", StorageServiceOperationType.PutBlob, StorageServiceType.Blob, requestedObjectKey);

            Assert.Throws <UriFormatException>(() => entry.ToBlobPath());
        }