Exemplo n.º 1
0
        public void CreateInstance_StateTypeDoesNotInheritFromIMptxStateThrowsInvalidOperationException()
        {
            // Arrange
            var stateProvider = new InMemoryMptxStateProvider();

            var services        = new ServiceCollection();
            var serviceProvider = services.BuildServiceProvider();

            var instanceContextFactory = new MptxInstanceContextFactory(stateProvider);

            var manager = new MptxManager(stateProvider, instanceContextFactory, serviceProvider);

            // Act & Assert
            var ex = Assert.Throws <ArgumentException>(
                () => manager.CreateInstance(typeof(BadFlowModel), contextItems: null));

            Assert.Equal($"State type must implement {typeof(IMptxState).FullName}. (Parameter 'stateType')", ex.Message);
        }
Exemplo n.º 2
0
        public void CreateInstance_CreatesNewStateForTypeNotInServices()
        {
            // Arrange
            var stateProvider = new InMemoryMptxStateProvider();

            var services        = new ServiceCollection();
            var serviceProvider = services.BuildServiceProvider();

            var instanceContextFactory = new MptxInstanceContextFactory(stateProvider);

            var manager = new MptxManager(stateProvider, instanceContextFactory, serviceProvider);

            // Act
            var instance = manager.CreateInstance(typeof(FlowModel), contextItems: null);

            // Assert
            Assert.IsType <FlowModel>(instance.State);
        }
Exemplo n.º 3
0
        public void CreateInstance_CreatesNewStateWithDependencies()
        {
            // Arrange
            var stateProvider = new InMemoryMptxStateProvider();

            var services = new ServiceCollection();

            services.AddSingleton <Dependency>();
            var serviceProvider = services.BuildServiceProvider();

            var instanceContextFactory = new MptxInstanceContextFactory(stateProvider);

            var manager = new MptxManager(stateProvider, instanceContextFactory, serviceProvider);

            // Act
            var instance = manager.CreateInstance(typeof(FlowModelWithDI), contextItems: null);

            // Assert
            Assert.IsType <FlowModelWithDI>(instance.State);
        }