public void Test_NoneMatches()
 {
     Assert.That(() => Maybe <int> .None.Match(new InvalidOperationException()), Throws.InstanceOf <InvalidOperationException>());
 }
 public void TestThatArgumentNullExceptionIsThrown()
 {
     Assert.That(() => _cut.Solve(0, null), Throws.InstanceOf <ArgumentNullException>());
 }
Example #3
0
        public void UserSettledPropertySetCorrectlyOnException()
        {
            var msg          = new ServiceBusReceivedMessage();
            var mockReceiver = new Mock <ServiceBusSessionReceiver>();

            mockReceiver
            .Setup(receiver => receiver.AbandonAsync(
                       It.IsAny <ServiceBusReceivedMessage>(),
                       It.IsAny <IDictionary <string, object> >(),
                       It.IsAny <CancellationToken>()))
            .Throws(new Exception());

            mockReceiver
            .Setup(receiver => receiver.DeferAsync(
                       It.IsAny <ServiceBusReceivedMessage>(),
                       It.IsAny <IDictionary <string, object> >(),
                       It.IsAny <CancellationToken>()))
            .Throws(new Exception());

            mockReceiver
            .Setup(receiver => receiver.CompleteAsync(
                       It.IsAny <ServiceBusReceivedMessage>(),
                       It.IsAny <CancellationToken>()))
            .Throws(new Exception());

            mockReceiver
            .Setup(receiver => receiver.DeadLetterAsync(
                       It.IsAny <ServiceBusReceivedMessage>(),
                       It.IsAny <IDictionary <string, object> >(),
                       It.IsAny <CancellationToken>()))
            .Throws(new Exception());

            mockReceiver
            .Setup(receiver => receiver.DeadLetterAsync(
                       It.IsAny <ServiceBusReceivedMessage>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <CancellationToken>()))
            .Throws(new Exception());

            var args = new ProcessSessionMessageEventArgs(
                msg,
                mockReceiver.Object,
                CancellationToken.None);

            Assert.IsFalse(msg.IsSettled);

            msg.IsSettled = false;
            Assert.That(async() => await args.AbandonAsync(msg),
                        Throws.InstanceOf <Exception>());
            Assert.IsFalse(msg.IsSettled);

            Assert.That(async() => await args.CompleteAsync(msg),
                        Throws.InstanceOf <Exception>());
            Assert.IsFalse(msg.IsSettled);

            msg.IsSettled = false;
            Assert.That(async() => await args.DeadLetterAsync(msg),
                        Throws.InstanceOf <Exception>());
            Assert.IsFalse(msg.IsSettled);

            msg.IsSettled = false;
            Assert.That(async() => await args.DeadLetterAsync(msg, "reason"),
                        Throws.InstanceOf <Exception>());
            Assert.IsFalse(msg.IsSettled);

            msg.IsSettled = false;
            Assert.That(async() => await args.DeferAsync(msg),
                        Throws.InstanceOf <Exception>());
            Assert.IsFalse(msg.IsSettled);
        }
        public void ValidateAccountSasCredentialsWithPermissions()
        {
            // Create a SharedKeyCredential that we can use to sign the SAS token

            var credential = new TableSharedKeyCredential(TestEnvironment.StorageAccountName, TestEnvironment.PrimaryStorageAccountKey);

            // Build a shared access signature with only Delete permissions and access to all service resource types.

            TableAccountSasBuilder sasDelete = service.GetSasBuilder(TableAccountSasPermissions.Delete, TableAccountSasResourceTypes.All, new DateTime(2040, 1, 1, 1, 1, 0, DateTimeKind.Utc));
            string tokenDelete = sasDelete.Sign(credential);

            // Build a shared access signature with the Write and Delete permissions and access to all service resource types.

            TableAccountSasBuilder sasWriteDelete = service.GetSasBuilder(TableAccountSasPermissions.Write, TableAccountSasResourceTypes.All, new DateTime(2040, 1, 1, 1, 1, 0, DateTimeKind.Utc));
            string tokenWriteDelete = sasWriteDelete.Sign(credential);

            // Build SAS URIs.

            UriBuilder sasUriDelete = new UriBuilder(TestEnvironment.StorageUri)
            {
                Query = tokenDelete
            };

            UriBuilder sasUriWriteDelete = new UriBuilder(TestEnvironment.StorageUri)
            {
                Query = tokenWriteDelete
            };

            // Create the TableServiceClients using the SAS URIs.

            var sasAuthedServiceDelete      = InstrumentClient(new TableServiceClient(sasUriDelete.Uri, InstrumentClientOptions(new TableClientOptions())));
            var sasAuthedServiceWriteDelete = InstrumentClient(new TableServiceClient(sasUriWriteDelete.Uri, InstrumentClientOptions(new TableClientOptions())));

            // Validate that we are unable to create a table using the SAS URI with only Delete permissions.

            var sasTableName = Recording.GenerateAlphaNumericId("testtable", useOnlyLowercase: true);

            Assert.That(async() => await sasAuthedServiceDelete.CreateTableAsync(sasTableName).ConfigureAwait(false), Throws.InstanceOf <RequestFailedException>().And.Property("Status").EqualTo((int)HttpStatusCode.Forbidden));

            // Validate that we are able to create a table using the SAS URI with Write and Delete permissions.

            Assert.That(async() => await sasAuthedServiceWriteDelete.CreateTableAsync(sasTableName).ConfigureAwait(false), Throws.Nothing);

            // Validate that we are able to delete a table using the SAS URI with only Delete permissions.

            Assert.That(async() => await sasAuthedServiceDelete.DeleteTableAsync(sasTableName).ConfigureAwait(false), Throws.Nothing);
        }
Example #5
0
        public async Task Should_handle_request_response_cancellation()
        {
            using var source = new CancellationTokenSource();

            var mediator = MassTransit.Bus.Factory.CreateMediator(cfg =>
            {
                cfg.Handler <PingMessage>(async context =>
                {
                    source.Cancel();

                    await Task.Yield();

                    await Task.Delay(5000, context.CancellationToken);

                    await context.RespondAsync(new PongMessage(context.Message.CorrelationId));
                });
            });

            IRequestClient <PingMessage> client = mediator.CreateRequestClient <PingMessage>();

            var pingMessage = new PingMessage();

            Assert.That(async() => await client.GetResponse <PongMessage>(pingMessage, source.Token), Throws.InstanceOf <OperationCanceledException>());
        }
Example #6
0
        public void Get_AccessTokenInvalid_ThrowAccessTokenInvalidException()
        {
            var cat = new MessagesCategory(vk: new VkApi());

            Assert.That(del: () => cat.Get(@params: new MessagesGetParams()), expr: Throws.InstanceOf <AccessTokenInvalidException>());
        }
Example #7
0
        public void GetLastActivity_AccessTokenInvalid_ThrowAccessTokenInvalidException()
        {
            var cat = new MessagesCategory(vk: new VkApi());

            Assert.That(del: () => cat.GetLastActivity(userId: 1), expr: Throws.InstanceOf <AccessTokenInvalidException>());
        }
 public void BinarySearch_Method_Array_Parameter_Throws_ArgumentNullException()
 {
     Assert.That(
         () => Search <int> .BinarySearch(null, 12),
         Throws.InstanceOf <ArgumentNullException>());
 }
 public void BinarySearch_Method_Array_Parameter_Target_ArgumentNullException()
 {
     Assert.That(
         () => Search <Person> .BinarySearch(TestCustom, null),
         Throws.InstanceOf <ArgumentNullException>());
 }
Example #10
0
 public void ResolveServiceShouldThrowIfServiceProviderReturnsNullAndServiceHasConstructorDependencies([Frozen] IServiceProvider resolver,
                                                                                                       ServiceProviderOrActivatorResolver sut)
 {
     Mock.Get(resolver).Setup(x => x.GetService(typeof(RuleWithConstructorDependency))).Returns(() => null);
     Assert.That(() => sut.ResolveService <object>(typeof(RuleWithConstructorDependency)), Throws.InstanceOf <ResolutionException>());
 }
Example #11
0
 public void ResolveServiceShouldThrowIfServiceProviderReturnsNullAndServiceIsAbstract([Frozen] IServiceProvider resolver,
                                                                                       ServiceProviderOrActivatorResolver sut)
 {
     Mock.Get(resolver).Setup(x => x.GetService(typeof(MyAbstractClass))).Returns(() => null);
     Assert.That(() => sut.ResolveService <object>(typeof(MyAbstractClass)), Throws.InstanceOf <ResolutionException>());
 }
 public void GetLongPollHistory_ThrowArgumentNullException()
 {
     Assert.That(() => Api.Messages.GetLongPollHistory(new MessagesGetLongPollHistoryParams()), Throws.InstanceOf <ArgumentNullException>());
 }
Example #13
0
 public void ConstructorValidatesExpandedArguments(string host,
                                                   string eventHubPath,
                                                   TokenCredential credential)
 {
     Assert.That(() => new EventHubClient(host, eventHubPath, credential), Throws.InstanceOf <ArgumentException>());
 }
Example #14
0
 public void Sort_Null_ThrowsArgumentNullException()
 {
     Assert.That(() => Utilities.Sort(null), Throws.InstanceOf <ArgumentNullException>());
 }
Example #15
0
        public void DeleteDialog_AccessTokenInvalid_ThrowAccessTokenInvalidException()
        {
            var cat = new MessagesCategory(vk: new VkApi());

            Assert.That(del: () => cat.DeleteDialog(userId: 111), expr: Throws.InstanceOf <AccessTokenInvalidException>());
        }
        public void BaselineThrowsIfMigrationsHaveAlreadyBeenApplied()
        {
            this.LoadMigrator(1);

            Expect(() => this.migrator.Baseline(1), Throws.InstanceOf <InvalidOperationException>());
        }
Example #17
0
        public void EditChat_AccessTokenInvalid_ThrowAccessTokenInvalidException()
        {
            var cat = new MessagesCategory(vk: new VkApi());

            Assert.That(del: () => cat.EditChat(chatId: 2, title: "new title"), expr: Throws.InstanceOf <AccessTokenInvalidException>());
        }
        public void MigrateToThrowsIfVersionNotFound()
        {
            this.LoadMigrator(0);

            Expect(() => this.migrator.MigrateTo(3), Throws.InstanceOf <MigrationNotFoundException>().With.Property("Version").EqualTo(3));
        }
Example #19
0
        public void AddChatUser_AccessTokenInvalid_ThrowAccessTokenInvalidException()
        {
            var cat = new MessagesCategory(vk: new VkApi());

            Assert.That(del: () => cat.AddChatUser(chatId: 2, userId: 2), expr: Throws.InstanceOf <AccessTokenInvalidException>());
        }
Example #20
0
 public void Constructor_WhenGivenANullExpression_ThrowsException()
 {
     Assert.That(() => new AndExpression(null), Throws.InstanceOf <ArgumentNullException>());
 }
Example #21
0
 public void GetLongPollServer_ThrowArgumentNullException()
 {
     Assert.That(del: () => Api.Messages.GetLongPollServer(), expr: Throws.InstanceOf <ArgumentException>());
 }
Example #22
0
        public void ConstructorValidatesArguments()
        {
            Assert.That(() => new TableClient(_url, null, new TableSharedKeyCredential(AccountName, string.Empty)), Throws.InstanceOf <ArgumentNullException>(), "The constructor should validate the tableName.");

            Assert.That(() => new TableClient(null, TableName, new TableSharedKeyCredential(AccountName, string.Empty)), Throws.InstanceOf <ArgumentNullException>(), "The constructor should validate the url.");

            Assert.That(() => new TableClient(_url, TableName, new TableSharedKeyCredential(AccountName, string.Empty), new TableClientOptions()), Throws.Nothing, "The constructor should accept valid arguments.");

            Assert.That(() => new TableClient(_url, TableName, credential: null), Throws.InstanceOf <ArgumentNullException>(), "The constructor should validate the TablesSharedKeyCredential.");

            Assert.That(() => new TableClient(_urlHttp, TableName), Throws.InstanceOf <ArgumentException>(), "The constructor should validate the Uri is https when using a SAS token.");

            Assert.That(() => new TableClient(_url, TableName), Throws.Nothing, "The constructor should accept a null credential");

            Assert.That(() => new TableClient(_url, TableName, new TableSharedKeyCredential(AccountName, string.Empty)), Throws.Nothing, "The constructor should accept valid arguments.");

            Assert.That(() => new TableClient(_urlHttp, TableName, new TableSharedKeyCredential(AccountName, string.Empty)), Throws.Nothing, "The constructor should accept an http url.");
        }
Example #23
0
        public void ThrowsWhenNotCalledOnQueryField()
        {
            TestDelegate call = () => (from d in documents orderby d.Name.Boost(5f) select d).ToList();

            Assert.That(call, Throws.InstanceOf <NotSupportedException>());
        }
Example #24
0
        public void ServiceMethodsValidateArguments()
        {
            Assert.That(async() => await client.AddEntityAsync <TableEntity>(null), Throws.InstanceOf <ArgumentNullException>(), "The method should validate the entity is not null.");

            Assert.That(async() => await client.UpsertEntityAsync <TableEntity>(null, TableUpdateMode.Replace), Throws.InstanceOf <ArgumentNullException>(), "The method should validate the entity is not null.");
            Assert.That(async() => await client.UpsertEntityAsync(new TableEntity {
                PartitionKey = null, RowKey = "row"
            }, TableUpdateMode.Replace), Throws.InstanceOf <ArgumentException>(), $"The method should validate the entity has a {TableConstants.PropertyNames.PartitionKey}.");

            Assert.That(async() => await client.UpsertEntityAsync(new TableEntity {
                PartitionKey = "partition", RowKey = null
            }, TableUpdateMode.Replace), Throws.InstanceOf <ArgumentException>(), $"The method should validate the entity has a {TableConstants.PropertyNames.RowKey}.");

            Assert.That(async() => await client.UpdateEntityAsync <TableEntity>(null, new ETag("etag"), TableUpdateMode.Replace), Throws.InstanceOf <ArgumentNullException>(), "The method should validate the entity is not null.");
            Assert.That(async() => await client.UpdateEntityAsync(validEntity, default, TableUpdateMode.Replace), Throws.InstanceOf <ArgumentException>(), "The method should validate the eTag is not null.");
 public void ShouldDiallowIllegalCompression()
 {
     Assert.That(() => new EpochHDF5Persistor("unused", null, 10), Throws.InstanceOf <ArgumentException>());
 }
Example #26
0
        public void Restore_AccessTokenInvalid_ThrowAccessTokenInvalidException()
        {
            var cat = new MessagesCategory(vk: new VkApi());

            Assert.That(del: () => cat.Restore(messageId: 1), expr: Throws.InstanceOf <AccessTokenInvalidException>());
        }
 public void MembersWithSameName_InitializationException()
 {
     Assert.That(() => PoorlyDefinedEnumerated.One, Throws.InstanceOf <TypeInitializationException>());
 }
Example #28
0
        public void SearchDialogs_AccessTokenInvalid_ThrowAccessTokenInvalidException()
        {
            var cat = new MessagesCategory(vk: new VkApi());

            Assert.That(del: () => cat.SearchDialogs(query: "hello"), expr: Throws.InstanceOf <AccessTokenInvalidException>());
        }
Example #29
0
        public void CannotAddTwoHandlersToTheSameEvent()
        {
            var processor = new ServiceBusSessionProcessor(
                GetMockedConnection(),
                "entityPath",
                new ServiceBusSessionProcessorOptions());

            processor.ProcessMessageAsync      += eventArgs => Task.CompletedTask;
            processor.ProcessErrorAsync        += eventArgs => Task.CompletedTask;
            processor.SessionInitializingAsync += eventArgs => Task.CompletedTask;
            processor.SessionClosingAsync      += eventArgs => Task.CompletedTask;

            Assert.That(() => processor.ProcessMessageAsync      += eventArgs => Task.CompletedTask, Throws.InstanceOf <NotSupportedException>());
            Assert.That(() => processor.ProcessErrorAsync        += eventArgs => Task.CompletedTask, Throws.InstanceOf <NotSupportedException>());
            Assert.That(() => processor.SessionInitializingAsync += eventArgs => Task.CompletedTask, Throws.InstanceOf <NotSupportedException>());
            Assert.That(() => processor.SessionClosingAsync      += eventArgs => Task.CompletedTask, Throws.InstanceOf <NotSupportedException>());
        }
        public async Task Test_FdbDatabase_Key_Validation()
        {
            using (var db = await Fdb.OpenAsync())
            {
                // IsKeyValid
                Assert.That(db.IsKeyValid(Slice.Nil), Is.False, "Null key is invalid");
                Assert.That(db.IsKeyValid(Slice.Empty), Is.True, "Empty key is allowed");
                Assert.That(db.IsKeyValid(Slice.FromString("hello")), Is.True);
                Assert.That(db.IsKeyValid(Slice.Create(Fdb.MaxKeySize + 1)), Is.False, "Key is too large");
                Assert.That(db.IsKeyValid(Fdb.System.Coordinators), Is.True, "System keys are valid");

                // EnsureKeyIsValid
                Assert.That(() => db.EnsureKeyIsValid(Slice.Nil), Throws.InstanceOf <ArgumentException>());
                Assert.That(() => db.EnsureKeyIsValid(Slice.Empty), Throws.Nothing);
                Assert.That(() => db.EnsureKeyIsValid(Slice.FromString("hello")), Throws.Nothing);
                Assert.That(() => db.EnsureKeyIsValid(Slice.Create(Fdb.MaxKeySize + 1)), Throws.InstanceOf <ArgumentException>());
                Assert.That(() => db.EnsureKeyIsValid(Fdb.System.Coordinators), Throws.Nothing);

                // EnsureKeyIsValid ref
                Assert.That(() => { Slice key = Slice.Nil; db.EnsureKeyIsValid(ref key); }, Throws.InstanceOf <ArgumentException>());
                Assert.That(() => { Slice key = Slice.Empty; db.EnsureKeyIsValid(ref key); }, Throws.Nothing);
                Assert.That(() => { Slice key = Slice.FromString("hello"); db.EnsureKeyIsValid(ref key); }, Throws.Nothing);
                Assert.That(() => { Slice key = Slice.Create(Fdb.MaxKeySize + 1); db.EnsureKeyIsValid(ref key); }, Throws.InstanceOf <ArgumentException>());
                Assert.That(() => { Slice key = Fdb.System.Coordinators; db.EnsureKeyIsValid(ref key); }, Throws.Nothing);
            }
        }