예제 #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;
                }
            }
        }
예제 #2
0
        public async Task IsExistsAsync_WhenBlobDeletedCreated_ReturnsFalse()
        {
            await Blob.UploadAsync(new MemoryStream(EmptyArray.Get <byte>()));

            await Blob.DeleteAsync();

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

            return(table.PrepareEntityPointQuery(partitionKey, EmptyArray.Get <string>()));
        }
예제 #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);
        }
예제 #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());
        }
예제 #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)));
        }
예제 #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);
        }
예제 #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]);
        }
예제 #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);
        }
예제 #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>());
        }
예제 #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>();
 }
예제 #15
0
 public DistributionPolicy GetUserSpecifiedPolicy(params int[] userIds)
 {
     return(new DistributionPolicy(userIds ?? EmptyArray.Get <int>()));
 }
예제 #16
0
        public static ICloudTableEntityRangeQuery PrepareEntityGetAllQuery(this ICloudTable table)
        {
            Require.NotNull(table, "table");

            return(table.PrepareEntityGetAllQuery(EmptyArray.Get <string>()));
        }
예제 #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>()));
        }
예제 #18
0
 public Task <List <Dictionary <string, object> > > ExecuteAsync()
 {
     return(FetchEntitiesAsync(m_filter, EmptyArray.Get <byte>()));
 }
예제 #19
0
        public async Task IsLeaseLocked_WhenBlobLeaseWasNotAcquired_ReturnsFalse()
        {
            await Blob.UploadAsync(new MemoryStream(EmptyArray.Get <byte>()));

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

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

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