public void Throws_friendly_exception_when_IFindSagas_FindBy_returns_null()
        {
            var availableTypes = new List <Type>
            {
                typeof(ReturnsNullFinder)
            };

            var messageType = typeof(StartSagaMessage);

            var messageConventions = new Conventions();

            messageConventions.DefineCommandTypeConventions(t => t == messageType);

            var sagaMetadata = SagaMetadata.Create(typeof(TestSaga), availableTypes, messageConventions);

            if (!sagaMetadata.TryGetFinder(messageType.FullName, out var finderDefinition))
            {
                throw new Exception("Finder not found");
            }

            var services = new ServiceCollection();

            services.AddTransient(sp => new ReturnsNullFinder());

            var customerFinderAdapter = new CustomFinderAdapter <TestSaga.SagaData, StartSagaMessage>();

            Assert.That(async() => await customerFinderAdapter.Find(services.BuildServiceProvider(), finderDefinition, new FakeSynchronizedStorageSession(), new ContextBag(), new StartSagaMessage(), new Dictionary <string, string>()),
                        Throws.Exception.With.Message.EqualTo("Return a Task or mark the method as async."));
        }
Exemplo n.º 2
0
        public void Throws_friendly_exception_when_IFindSagas_FindBy_returns_null()
        {
            var availableTypes = new List <Type>
            {
                typeof(ReturnsNullFinder)
            };

            var messageType = typeof(StartSagaMessage);

            var messageConventions = new Conventions
            {
                IsCommandTypeAction = t => t == messageType
            };

            var sagaMetadata = SagaMetadata.Create(typeof(TestSaga), availableTypes, messageConventions);

            SagaFinderDefinition finderDefinition;

            if (!sagaMetadata.TryGetFinder(messageType.FullName, out finderDefinition))
            {
                throw new Exception("Finder not found");
            }

            var builder = new FakeBuilder();

            builder.Register(() => new ReturnsNullFinder());

            var customerFinderAdapter = new CustomFinderAdapter <TestSaga.SagaData, StartSagaMessage>();

            Assert.That(async() => await customerFinderAdapter.Find(builder, finderDefinition, new InMemorySynchronizedStorageSession(), new ContextBag(), new StartSagaMessage()),
                        Throws.Exception.With.Message.EqualTo("Return a Task or mark the method as async."));
        }