Ejemplo n.º 1
0
        private async Task EnsureBlobExistsAsync()
        {
            if (await m_blob.ExistsAsync())
            {
                return;
            }

            try
            {
                await m_blob.UploadFromByteArrayAsync(
                    EmptyArray.Get <byte>(),
                    0,
                    0,
                    AccessCondition.GenerateIfNoneMatchCondition("*"),
                    null,
                    null);
            }
            catch (StorageException exception)
            {
                // 412 from trying to modify a blob that's leased
                var blobLeased = exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.PreconditionFailed;

                var blobExists =
                    exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict &&
                    exception.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.BlobAlreadyExists;

                if (!blobExists && !blobLeased)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public async Task IsExistsAsync_WhenBlobDeletedCreated_ReturnsFalse()
        {
            await Blob.UploadAsync(new MemoryStream(EmptyArray.Get <byte>()));

            await Blob.DeleteAsync();

            Assert.False(await Blob.IsExistsAsync());
        }
Ejemplo n.º 3
0
        public static ICloudTableEntityQuery PrepareEntityPointQuery(
            this ICloudTable table,
            string partitionKey)
        {
            Require.NotNull(table, "table");

            return(table.PrepareEntityPointQuery(partitionKey, EmptyArray.Get <string>()));
        }
Ejemplo n.º 4
0
        public List <Dictionary <string, object> > Execute()
        {
            var result = new List <Dictionary <string, object> >();

            do
            {
                result.AddRange(FetchEntities(m_filter, EmptyArray.Get <byte>()));
            }while (ReadNextSegment);

            return(result);
        }
Ejemplo n.º 5
0
        public async Task CreateBlockBlob_WithDirectoryPathTest()
        {
            var blob = Container.CreateBlockBlob(
                Guid.NewGuid().ToString("D") +
                "/" +
                Guid.NewGuid().ToString("D"));

            await blob.UploadAsync(new MemoryStream(EmptyArray.Get <byte>()));

            Assert.True(await blob.IsExistsAsync());
        }
Ejemplo n.º 6
0
 public static ICloudTableEntityRangeQuery PrepareEntityRangeQueryByRows(
     this ICloudTable table,
     string partitionKey,
     string fromRowKey,
     string toRowKey)
 {
     return(table.PrepareEntityRangeQueryByRows(
                partitionKey,
                fromRowKey,
                toRowKey,
                EmptyArray.Get <string>()));
 }
        public NotificationHubDataAttribute(
            bool emptyChannel  = false,
            bool hasSubscriber = true,
            bool startHub      = true)
        {
            Fixture.Customize <INotification>(composer => composer
                                              .FromFactory((EventStreamUpdated notification) => notification));

            Fixture.Customize <IReceivedNotification[]>(composer => composer
                                                        .FromFactory((IReceivedNotification n) => n.YieldArray()));

            Fixture.Customize <Mock <IReceivedNotificationProcessor> >(composer => composer
                                                                       .Do(mock => mock
                                                                           .Setup(self => self.ProcessingCount)
                                                                           .Returns(0)));

            Fixture.Customize <Mock <INotificationsChannel> >(composer => composer
                                                              .Do(mock => mock
                                                                  .Setup(self => self.ReceiveNotificationsAsync())
                                                                  .Returns(() => emptyChannel
                        ? EmptyArray.Get <IReceivedNotification>().YieldTask()
                        : Fixture.Create <IReceivedNotification[]>().YieldTask()))
                                                              .Do(mock => mock
                                                                  .Setup(self => self.SendAsync(It.IsAny <INotification>()))
                                                                  .Returns(TaskDone.Done)));

            Fixture.Customize <IPollingJob>(composer => composer.FromFactory((PollingJobStub stub) => stub));

            Fixture.Customize <Mock <INotificationFormatter> >(composer => composer
                                                               .Do(mock => mock
                                                                   .Setup(self => self.FromBytes(It.IsAny <Stream>()))
                                                                   .Returns(() => Fixture.Create <EventStreamUpdated>()))
                                                               .Do(mock => mock
                                                                   .Setup(self => self.ToBytes(It.IsAny <EventStreamUpdated>()))
                                                                   .ReturnsUsingFixture(Fixture)));

            Fixture.Customize <NotificationHub>(composer => composer
                                                .Do(hub =>
            {
                if (hasSubscriber)
                {
                    hub.Subscribe(Fixture.Create <INotificationListener>());
                }

                if (startHub)
                {
                    hub.StartNotificationProcessing(Fixture.Create <IEventStoreConnection>());
                }
            }));
        }
        protected byte[] GetContinuationTokenBytes()
        {
            if (m_continuationToken == null)
            {
                return(EmptyArray.Get <byte>());
            }

            return(Encoding.UTF8.GetBytes(
                       "{0} {1} {2} {3}".FormatString(
                           m_continuationToken.NextPartitionKey ?? string.Empty,
                           m_continuationToken.NextRowKey ?? string.Empty,
                           m_continuationToken.NextTableName ?? string.Empty,
                           m_continuationToken.TargetLocation)));
        }
Ejemplo n.º 9
0
        private async Task <IReceivedNotification[]> ReceiveNotificationsAsync()
        {
            var notifications = EmptyArray.Get <IReceivedNotification>();

            if (RequestNotificationsRequired())
            {
                notifications = await m_channel.ReceiveNotificationsAsync();

                s_logger.Debug(
                    "Receive {NotificationCount} notifications {NotificationIds}.",
                    notifications.Length,
                    notifications.Select(n => n.Notification.NotificationId));
            }

            return(notifications);
        }
Ejemplo n.º 10
0
        public Dictionary <string, object> Execute()
        {
            var entities = FetchEntities(
                PrepareFilter(),
                EmptyArray.Get <byte>());

            if (entities.Count == 0)
            {
                return(null);
            }

            if (entities.Count > 1)
            {
                throw new InvalidOperationException("Single entity query returns to much rows.");
            }

            return(entities[0]);
        }
Ejemplo n.º 11
0
        public async Task UpdateMessage_UpdatesVisibility()
        {
            // arrange
            await Queue.AddMessageAsync(EmptyArray.Get <byte>());

            var message = await Queue.GetMessageAsync();

            // act
            await Queue.UpdateMessageAsync(
                message.MessageId,
                message.PopReceipt,
                TimeSpan.FromSeconds(5));

            var updatedMessage = await Queue.GetMessageAsync();

            // assert
            Assert.Null(updatedMessage);
        }
Ejemplo n.º 12
0
        public async Task <IReceivedNotification[]> ReceiveNotificationsAsync()
        {
            var readedQueue = 0;

            do
            {
                var queue  = ChooseIncomingQueue();
                var result = await ReadNotificationsFromQueueAsync(queue);

                if (result.Any())
                {
                    return(result.ToArray());
                }

                readedQueue++;
            }while (readedQueue < m_queueCount);

            return(EmptyArray.Get <IReceivedNotification>());
        }
Ejemplo n.º 13
0
        public Developer(
            int userId,
            string firstName,
            string lastName,
            string email,
            ConfirmationStatus confirmationStatus,
            Uri photoUri,
            DateTime registrationDate,
            Uri vkProfileUri,
            string phoneNumber,
            int?studentAccessionYear,
            string studyingDirection,
            string instituteName,
            string specialization,
            string role,
            DeveloperPageProjectPreview[] projects)
        {
            Require.Positive(userId, nameof(userId));
            Require.NotEmpty(firstName, nameof(firstName));
            Require.NotEmpty(lastName, nameof(lastName));
            Require.NotEmpty(email, nameof(email));

            UserId               = userId;
            FirstName            = firstName;
            LastName             = lastName;
            Email                = email;
            ConfirmationStatus   = confirmationStatus;
            PhotoUri             = photoUri;
            RegistrationDate     = registrationDate;
            VkProfileUri         = vkProfileUri;
            PhoneNumber          = phoneNumber;
            StudentAccessionYear = studentAccessionYear;
            StudyingDirection    = studyingDirection;
            InstituteName        = instituteName;
            Specialization       = specialization;
            Role     = role;
            Projects = projects ?? EmptyArray.Get <DeveloperPageProjectPreview>();
        }
 public ReceivedNotificationProcessor()
 {
     m_handlers = EmptyArray.Get <INotificationHandler>();
 }
Ejemplo n.º 15
0
 public DistributionPolicy GetUserSpecifiedPolicy(params int[] userIds)
 {
     return(new DistributionPolicy(userIds ?? EmptyArray.Get <int>()));
 }
Ejemplo n.º 16
0
        public static ICloudTableEntityRangeQuery PrepareEntityGetAllQuery(this ICloudTable table)
        {
            Require.NotNull(table, "table");

            return(table.PrepareEntityGetAllQuery(EmptyArray.Get <string>()));
        }
Ejemplo n.º 17
0
        public static ICloudTableEntitySegmentedRangeQuery PrepareEntityFilterSegmentedRangeQuery(this ICloudTable table, string filter, int count)
        {
            Require.NotNull(table, "table");

            return(table.PrepareEntityFilterSegmentedRangeQuery(filter, count, EmptyArray.Get <string>()));
        }
Ejemplo n.º 18
0
 public Task <List <Dictionary <string, object> > > ExecuteAsync()
 {
     return(FetchEntitiesAsync(m_filter, EmptyArray.Get <byte>()));
 }
Ejemplo n.º 19
0
        public async Task IsLeaseLocked_WhenBlobLeaseWasNotAcquired_ReturnsFalse()
        {
            await Blob.UploadAsync(new MemoryStream(EmptyArray.Get <byte>()));

            Assert.False(await Blob.IsLeaseLocked());
        }
Ejemplo n.º 20
0
 public void Get_ReturnsSameInstance()
 {
     Assert.Same(EmptyArray.Get <int>(), EmptyArray.Get <int>());
 }
Ejemplo n.º 21
0
 public NotDisposableEmptyMemoryStream() : base(EmptyArray.Get <byte>(), false)
 {
 }
Ejemplo n.º 22
0
 public List <Dictionary <string, object> > Execute()
 {
     return(FetchEntities(m_filter, EmptyArray.Get <byte>()));
 }
Ejemplo n.º 23
0
        public async Task IsExistsAsync_WhenBlobCreated_ReturnsTrue()
        {
            await Blob.UploadAsync(new MemoryStream(EmptyArray.Get <byte>()));

            Assert.True(await Blob.IsExistsAsync());
        }
Ejemplo n.º 24
0
        public static ICloudTableEntityRangeQuery PrepareEntityFilterRangeQuery(this ICloudTable table, string filter)
        {
            Require.NotNull(table, "table");

            return(table.PrepareEntityFilterRangeQuery(filter, EmptyArray.Get <string>()));
        }
Ejemplo n.º 25
0
 public static ICloudTableEntityRangeQuery PrepareEntityRangeQueryByPartition(
     this ICloudTable table,
     string partitionKey)
 {
     return(table.PrepareEntityRangeQueryByPartition(partitionKey, EmptyArray.Get <string>()));
 }
Ejemplo n.º 26
0
 public void IsEmpty_WhenCollectionIsEmpty_ReturnsTrue()
 {
     Assert.True(EmptyArray.Get <int>().IsEmpty());
 }