Skip to content

Commit

Permalink
Merge pull request #349 from Particular/better-installer-coverage-back
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach authored Nov 20, 2020
2 parents ced96c2 + 998ff1b commit 7fa57d9
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
namespace NServiceBus.AcceptanceTests
{
using System;
using System.Linq;
using System.Threading.Tasks;
using NServiceBus;
using AcceptanceTesting;
using Configuration.AdvancedExtensibility;
using NServiceBus.AcceptanceTesting.Support;
using Testing;
using EndpointTemplates;
using NUnit.Framework;

public partial class When_saga_table_doesnt_exist_and_installers_disabled : NServiceBusAcceptanceTest
{
private const string TableThatDoesntExist = "doesnotexist";

[SetUp]
public Task Setup()
{
return SetupFixture.TableClient.GetTableReference(TableThatDoesntExist).DeleteIfExistsAsync();
}

[Test]
public void Should_throw_not_supported()
{
var exception = Assert.ThrowsAsync<MessageFailedException>(async () =>
await Scenario.Define<Context>()
.WithEndpoint<EndpointWithInstallersOff>(b => b.When(session => session.SendLocal(new StartSagaMessage
{
SomeId = Guid.NewGuid()
})))
.Done(c => c.FailedMessages.Any())
.Run());

Assert.AreEqual(1, exception.ScenarioContext.FailedMessages.Count);
StringAssert.Contains(
ConnectionStringHelper.IsPremiumEndpoint(SetupFixture.TableClient)
? "The specified resource does not exist."
: "Element 0 in the batch returned an unexpected response code.",
exception.FailedMessage.Exception.Message);
}

public class Context : ScenarioContext
{
}

public class EndpointWithInstallersOff : EndpointConfigurationBuilder
{
public EndpointWithInstallersOff()
{
EndpointSetup<DefaultServer>(c =>
{
// so that we don't have to create a new endpoint template
c.GetSettings().Set("Installers.Enable", false);
var sagaPersistence = c.UsePersistence<AzureTablePersistence, StorageType.Sagas>();
sagaPersistence.DefaultTable(TableThatDoesntExist);
var subscriptionStorage = c.UsePersistence<AzureTablePersistence, StorageType.Subscriptions>();
});
}

public class SomeSaga : Saga<SomeSagaData>, IAmStartedByMessages<StartSagaMessage>
{
public Task Handle(StartSagaMessage message, IMessageHandlerContext context)
{
Data.SomeId = message.SomeId;
return Task.CompletedTask;
}

protected override void ConfigureHowToFindSaga(SagaPropertyMapper<SomeSagaData> mapper)
{
mapper.ConfigureMapping<StartSagaMessage>(m => m.SomeId)
.ToSaga(s => s.SomeId);
}
}

public class SomeSagaData : IContainSagaData
{
public Guid Id { get; set; }
public string Originator { get; set; }
public string OriginalMessageId { get; set; }
public Guid SomeId { get; set; }
}
}

public class StartSagaMessage : ICommand
{
public Guid SomeId { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ namespace NServiceBus.AcceptanceTests

public partial class When_saga_table_doesnt_exist_and_table_creation_disabled : NServiceBusAcceptanceTest
{
private const string TableThatDoesntExist = "doesnotexist";

[SetUp]
public Task Setup()
{
return SetupFixture.TableClient.GetTableReference(TableThatDoesntExist).DeleteIfExistsAsync();
}

[Test]
public void Should_throw_not_supported()
{
var exception = Assert.ThrowsAsync<MessageFailedException>(async () =>
await Scenario.Define<Context>()
.WithEndpoint<EndpointWithSchemaCreationOff>(b => b.When(session => session.SendLocal(new StartSagaMessage
.WithEndpoint<EndpointWithTableCreationDisabled>(b => b.When(session => session.SendLocal(new StartSagaMessage
{
SomeId = Guid.NewGuid()
})))
Expand All @@ -36,14 +44,14 @@ public class Context : ScenarioContext
{
}

public class EndpointWithSchemaCreationOff : EndpointConfigurationBuilder
public class EndpointWithTableCreationDisabled : EndpointConfigurationBuilder
{
public EndpointWithSchemaCreationOff()
public EndpointWithTableCreationDisabled()
{
EndpointSetup<DefaultServer>(c =>
{
var sagaPersistence = c.UsePersistence<AzureTablePersistence, StorageType.Sagas>();
sagaPersistence.DefaultTable("doesnotexist");
sagaPersistence.DefaultTable(TableThatDoesntExist);
sagaPersistence.DisableTableCreation();
var subscriptionStorage = c.UsePersistence<AzureTablePersistence, StorageType.Subscriptions>();
Expand Down

0 comments on commit 7fa57d9

Please sign in to comment.