Exemplo n.º 1
0
        public void Execute <TSut>(IScenario <TSut> testObject, string scenarioTitle = null) where TSut : class
        {
            using (var container = Configuration.ApplicationContainer.Get <IContainer>())
            {
                var scenario = (IScenario <TSut>)container.Get(testObject.GetType());
                scenario.SetContainer(container);

                foreach (var action in Configuration.PerScenarioActions)
                {
                    if (action.ShouldExecute(scenario.GetType()))
                    {
                        action.Before(scenario);
                    }
                }

                _testEngine.Execute(scenario);

                foreach (var action in Configuration.PerScenarioActions.AsEnumerable().Reverse())
                {
                    if (action.ShouldExecute(scenario.GetType()))
                    {
                        action.After();
                    }
                }
            }
        }
 private StoryMetadata CreateSpecificationMetadata(IScenario specification)
 {
     var title = specification.GetType().GetProperty("SUT").PropertyType.Name;
     var story = (Story)Activator.CreateInstance(specification.Story);
     var storyAttribute = new StoryAttribute() { Title = title, TitlePrefix = story.TitlePrefix };
     return new StoryMetadata(specification.Story, storyAttribute);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Get scenario of specified type from data session
        /// </summary>
        /// <typeparam name="TScenario">Type of scenario</typeparam>
        /// <param name="instance">Instance</param>
        /// <returns>Returns scenario</returns>
        public static TScenario GetScenario <TScenario>(this IDataSession instance)
        {
            //Arguments validation
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            //Try to cast to IMockDataSession
            IMockDataSession mockupSession = instance.AsMockDataSession();

            //Get scenario from data session
            IScenario scenarioFromDataSession = mockupSession.GetScenario();

            //Try cast of scenario to provided type
            if (!(scenarioFromDataSession is TScenario castedScenario))
            {
                throw new InvalidCastException("Scenario contained on data session is of " +
                                               $"type '{scenarioFromDataSession.GetType().FullName}' and cannot be converted " +
                                               $"to type '{typeof(TScenario).FullName}'.");
            }

            //Return scenario
            return(castedScenario);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dataSession">Active data session</param>
        /// <param name="entitiesExpression">Entities expression</param>
        protected MockRepositoryBase(IDataSession dataSession, Func <TScenarioInterface, IList <TEntity> > entitiesExpression)
        {
            //Arguments validation
            if (dataSession == null)
            {
                throw new ArgumentNullException(nameof(dataSession));
            }

            //Convert to IMockDataSession
            var mockupSession = dataSession.AsMockDataSession();

            //Get scenario from data session
            IScenario scenarioFromDataSession = mockupSession.GetScenario();

            //Try cast of scenario to provided interface
            if (!(scenarioFromDataSession is TScenarioInterface castedScenario))
            {
                throw new InvalidCastException("Scenario contained on data session is of " +
                                               $"type '{scenarioFromDataSession.GetType().FullName}' and cannot be converted " +
                                               $"to type '{typeof(TScenarioInterface).FullName}'.");
            }

            //Set data session and scenario
            DataSession = mockupSession;
            Scenario    = castedScenario;

            //Initialize working mocked entities
            MockedEntities = entitiesExpression(Scenario);
        }
Exemplo n.º 5
0
        public void Show(IScenario scenario)
        {
            if (scenario == null)
            {
                throw new System.ArgumentNullException(nameof(scenario));
            }

            _tw.Write($" - {scenario.GetType().Name}");
            _tw.WriteLine();
        }
Exemplo n.º 6
0
        private StoryMetadata CreateSpecificationMetadata(IScenario specification)
        {
            var title          = specification.GetType().GetProperty("SUT").PropertyType.Name;
            var story          = specification.Story.Create <Story>();
            var storyAttribute = new StoryAttribute()
            {
                Title = title, TitlePrefix = story.TitlePrefix
            };

            return(new StoryMetadata(specification.Story, storyAttribute));
        }
        private StoryMetadata CreateScenarioMetadata(IScenario scenario)
        {
            var storyAttribute = (StoryNarrativeAttribute)scenario.GetType()
                .GetCustomAttributes(typeof(StoryNarrativeAttribute), true)
                .FirstOrDefault();

            if (storyAttribute != null)
            {
                return new StoryMetadata(scenario.Story, storyAttribute);
            }

            var story = (Story)Activator.CreateInstance(scenario.Story);
            return new StoryMetadata(scenario.Story, story.Narrative1, story.Narrative2,
                story.Narrative3, story.Title, story.TitlePrefix);
        }
Exemplo n.º 8
0
        public BrowserFluent <TPageTo> Play <TPageTo>(IScenario <TPageTo> scenario)
            where TPageTo : IPageBase
        {
            var scenarioId = Guid.NewGuid();

            this.logger.Log(new LogScenarioStart {
                ScenarioId = scenarioId, Name = scenario.GetType().Name
            });
            var result = scenario.Play(this);

            this.logger.Log(new LogScenarioEnd {
                ScenarioId = scenarioId
            });
            return(result);
        }
Exemplo n.º 9
0
        private StoryMetadata CreateScenarioMetadata(IScenario scenario)
        {
            var storyAttribute = (StoryNarrativeAttribute)scenario.GetType()
                .GetCustomAttributes(typeof(StoryNarrativeAttribute), true)
                .FirstOrDefault();

            if (storyAttribute != null)
            {
                return new StoryMetadata(scenario.Story, storyAttribute);
            }

            var story = scenario.Story.Create<Story>(); 
            return new StoryMetadata(scenario.Story, story.Narrative1, story.Narrative2,
                story.Narrative3, story.Title, story.TitlePrefix, story.ImageUri, story.StoryUri);
        }
Exemplo n.º 10
0
        private StoryMetadata CreateScenarioMetadata(IScenario scenario)
        {
            var storyAttribute = (StoryNarrativeAttribute)scenario.GetType()
                                 .GetCustomAttributes(typeof(StoryNarrativeAttribute), true)
                                 .FirstOrDefault();

            if (storyAttribute != null)
            {
                return(new StoryMetadata(scenario.Story, storyAttribute));
            }

            var story = (Story)Activator.CreateInstance(scenario.Story);

            return(new StoryMetadata(scenario.Story, story.Narrative1, story.Narrative2,
                                     story.Narrative3, scenario.Title, story.TitlePrefix));
        }
Exemplo n.º 11
0
        public void Execute(IScenario testObject, string scenarioTitle = null)
        {
            using (var container = Configuration.ApplicationContainer.Resolve<IContainer>())
            {
                foreach (var action in Configuration.PerScenarioActions)
                {
                    action.Before(container);
                }

                var scenario = (IScenario)container.Resolve(testObject.GetType());
                scenario.SetContainer(container);
                _testEngine.Execute(scenario);

                foreach (var action in Configuration.PerScenarioActions.AsEnumerable().Reverse())
                {
                    action.After();
                }
            }
        }
Exemplo n.º 12
0
        public void Execute(IScenario testObject, string scenarioTitle = null)
        {
            using (var container = Configuration.ApplicationContainer.Resolve <IContainer>())
            {
                foreach (var action in Configuration.PerScenarioActions)
                {
                    action.Before(container);
                }

                var scenario = (IScenario)container.Resolve(testObject.GetType());
                scenario.SetContainer(container);
                _testEngine.Execute(scenario);

                foreach (var action in Configuration.PerScenarioActions.AsEnumerable().Reverse())
                {
                    action.After();
                }
            }
        }
Exemplo n.º 13
0
 public void StartScenario(IScenario view)
 {
     if (_currentScenarios.ContainsKey(view.GetType()))
     {
         D.LogWarning(LoggingTags.Services,
                      string.Format("scenario {0} overriden by {1}", _currentScenarios.GetType(), view.GetType()));
         CleanScenario(view.GetType());
     }
     _currentScenarios[view.GetType()]     = view;
     _currentScenarioSteps[view.GetType()] = view.Scenario().GetEnumerator();
     _currentScenarioName = view.GetType().ToString();
     D.Log(LoggingTags.Services, "=> Start scenario: " + _currentScenarioName);
     MoveNextStep(view.GetType());
 }
Exemplo n.º 14
0
        public void Execute(IScenario testObject, string scenarioTitle = null)
        {
            foreach (var action in _configuration.PerTestActions)
            {
                action.Before();
            }

            using (var scenarioScope = _dependencyResolver.CreateChildContainer())
            {
                var scenario  = (IScenario)scenarioScope.Resolve(testObject.GetType());
                var container = scenarioScope.Resolve <IContainer>();
                scenario.SetContainer(container);
                _testEngine.Execute(scenario);
            }

            foreach (var action in _configuration.PerTestActions.AsEnumerable().Reverse())
            {
                action.After();
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Executes cast of specified instance to target type
        /// </summary>
        /// <typeparam name="TScenario">Target type</typeparam>
        /// <param name="instance">Instance</param>
        /// <returns>Returns casted type</returns>
        public static TScenario OfType <TScenario>(this IScenario instance)
            where TScenario : IScenario
        {
            //Arguments validation
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            try
            {
                //Tento il cast esplicito, all'interno di un blocco
                //try/catch per gestire eventuali problemi di conversione
                return((TScenario)instance);
            }
            catch (InvalidCastException exc)
            {
                //Sollevo l'evento di cast invalido
                throw new InvalidCastException(
                          "Unable to " +
                          $"cast instance of type '{instance.GetType().FullName}' to target type '{typeof(TScenario).FullName}'.", exc);
            }
        }
Exemplo n.º 16
0
 internal static Type SutType(this IScenario specification)
 {
     return(specification.GetType().GetPropertyInfo("SUT").PropertyType);
 }