示例#1
0
        public void Should_add_feature()
        {
            var feature = new FeatureResult("name", "desc", "label");

            FeatureCoordinator.Instance.AddFeature(feature);
            _aggregator.AssertWasCalled(a => a.AddFeature(feature));
        }
示例#2
0
        /// <summary>
        /// SaveSiteFeaturesSettings
        /// </summary>
        /// <param name="siteFeaturesSettingsRequest"></param>
        /// <returns></returns>
        public ServiceResponse SaveSiteFeaturesSettings(List <ModuleFeatureDC> siteFeaturesSettingsRequest)
        {
            ServiceResponse addSiteFeaturesSettingsResponse = new ServiceResponse();

            try
            {
                SetContext();
                List <FeatureResult> lstFeatures = new List <FeatureResult>();
                foreach (ModuleFeatureDC feature in siteFeaturesSettingsRequest)
                {
                    FeatureResult featureResult = new FeatureResult();
                    featureResult.FeatureId           = feature.FeatureId;
                    featureResult.SiteContentSettings = new List <SiteContentSettingResult>();
                    foreach (SiteContentSettingDC siteContentSetting in feature.SiteContentSettings)
                    {
                        featureResult.SiteContentSettings.Add(new SiteContentSettingResult {
                            FeatureId = feature.FeatureId, ContentSettingId = siteContentSetting.ContentSettingId, IsAssigned = siteContentSetting.IsAssigned
                        });
                    }
                    lstFeatures.Add(featureResult);
                }
                UserContextDC userContextDC = OperationContext.Current.IncomingMessageHeaders.GetHeader <UserContextDC>("ActiveUser", "s");
                _securityManager.SaveSiteFeaturesSettings(userContextDC.SiteId, lstFeatures);
            }
            catch (Exception ex)
            {
                HandleError(ex, addSiteFeaturesSettingsResponse);
            }
            return(addSiteFeaturesSettingsResponse);
        }
示例#3
0
        public void Should_format_feature_with_description()
        {
            var result = new FeatureResult("My feature", string.Format("My feature{0}long description", Environment.NewLine), "Label 1");

            result.AddScenario(new ScenarioResult("name", new[] { new StepResult(1, "step1", ResultStatus.Passed), new StepResult(2, "step2", ResultStatus.Ignored, "Not implemented yet") }, "Label 2"));
            result.AddScenario(new ScenarioResult("name2", new[] { new StepResult(1, "step3", ResultStatus.Passed), new StepResult(2, "step4", ResultStatus.Failed, string.Format("  Expected: True{0}  But was: False", Environment.NewLine)) }, null));
            var          text         = _subject.Format(result);
            const string expectedText = @"Feature: [Label 1] My feature
	My feature
	long description

	Scenario: [Label 2] name - Ignored
		Step 1: step1 - Passed
		Step 2: step2 - Ignored

		Details: Not implemented yet

	Scenario: name2 - Failed
		Step 1: step3 - Passed
		Step 2: step4 - Failed

		Details: Expected: True
			  But was: False
";

            Assert.That(text, Is.EqualTo(expectedText));
        }
示例#4
0
        private static void FlashResultMessages(FeatureResult feature, ObjectResultContext m)
        {
            if (feature.Messages.Any())
            {
                var flashMessage = m.GetService <IFlashMessage>();

                foreach (var message in feature.Messages)
                {
                    switch (message.Key)
                    {
                    case FlashMessageType.Confirmation:
                        flashMessage.Confirmation(message.Value);
                        break;

                    case FlashMessageType.Danger:
                        flashMessage.Danger(message.Value);
                        break;

                    case FlashMessageType.Warning:
                        flashMessage.Warning(message.Value);
                        break;

                    case FlashMessageType.Info:
                        flashMessage.Info(message.Value);
                        break;
                    }
                }
            }
        }
示例#5
0
        public void Should_format_xml()
        {
            var result = new FeatureResult("Feature name", "feature\nlong description", "Label 1");

            result.AddScenario(new ScenarioResult("name", new[] { new StepResult(1, "step1", ResultStatus.Passed), new StepResult(2, "step2", ResultStatus.Ignored, "Not implemented yet") }, "Label 2"));
            result.AddScenario(new ScenarioResult("name2", new[] { new StepResult(1, "step3", ResultStatus.Passed), new StepResult(2, "step4", ResultStatus.Failed, "  Expected: True\n  But was: False") }, null));
            var text = _subject.Format(result);

            Console.WriteLine(text);

            const string expectedText = @"<?xml version=""1.0"" encoding=""utf-8""?>
<TestResults>
  <Feature Name=""Feature name"" Label=""Label 1"">
    <Description>feature
long description</Description>
    <Scenario Status=""Ignored"" Name=""name"" Label=""Label 2"">
      <Step Status=""Passed"" Number=""1"" Name=""step1"" />
      <Step Status=""Ignored"" Number=""2"" Name=""step2"" />
      <StatusDetails>Not implemented yet</StatusDetails>
    </Scenario>
    <Scenario Status=""Failed"" Name=""name2"">
      <Step Status=""Passed"" Number=""1"" Name=""step3"" />
      <Step Status=""Failed"" Number=""2"" Name=""step4"" />
      <StatusDetails>  Expected: True
  But was: False</StatusDetails>
    </Scenario>
  </Feature>
</TestResults>";

            Assert.That(text, Is.EqualTo(expectedText));
        }
示例#6
0
        public void Should_format_xml_without_description_nor_label_nor_details()
        {
            var result = new FeatureResult("Feature name", null, null);

            result.AddScenario(new ScenarioResult("name", new[] { new StepResult(1, "step1", ResultStatus.Passed), new StepResult(2, "step2", ResultStatus.Ignored) }, null));
            result.AddScenario(new ScenarioResult("name2", new[] { new StepResult(1, "step3", ResultStatus.Passed), new StepResult(2, "step4", ResultStatus.Failed) }, null));
            var text = _subject.Format(result);

            Console.WriteLine(text);

            const string expectedText = @"<?xml version=""1.0"" encoding=""utf-8""?>
<TestResults>
  <Feature Name=""Feature name"">
    <Scenario Status=""Ignored"" Name=""name"">
      <Step Status=""Passed"" Number=""1"" Name=""step1"" />
      <Step Status=""Ignored"" Number=""2"" Name=""step2"" />
    </Scenario>
    <Scenario Status=""Failed"" Name=""name2"">
      <Step Status=""Passed"" Number=""1"" Name=""step3"" />
      <Step Status=""Failed"" Number=""2"" Name=""step4"" />
    </Scenario>
  </Feature>
</TestResults>";

            Assert.That(text, Is.EqualTo(expectedText));
        }
        /// <summary>
        /// Initializes runner for given feature test class type with given progress notifier.
        /// Given featureTestClass type Name is used as feature name.
        /// If test class is annotated with [FeatureDescription] attribute or implementation specific description attribute, it's content is used as feature description.
        /// </summary>
        /// <param name="featureTestClass">Test class type.</param>
        /// <param name="progressNotifier">Progress notifier.</param>
        /// <param name="metadataProvider">Test metadata provider.</param>
        protected AbstractBDDRunner(Type featureTestClass, TestMetadataProvider metadataProvider, IProgressNotifier progressNotifier)
        {
            if (featureTestClass == null)
            {
                throw new ArgumentNullException("featureTestClass");
            }
            if (metadataProvider == null)
            {
                throw new ArgumentNullException("metadataProvider");
            }
            if (progressNotifier == null)
            {
                throw new ArgumentNullException("progressNotifier");
            }

            _metadataProvider = metadataProvider;
            ProgressNotifier  = progressNotifier;
            _stepsConverter   = new StepsConverter(_metadataProvider, MapExceptionToStatus);
            _result           = new FeatureResult(
                _metadataProvider.GetFeatureName(featureTestClass),
                _metadataProvider.GetFeatureDescription(featureTestClass),
                _metadataProvider.GetFeatureLabel(featureTestClass));
            _executor = new ScenarioExecutor(ProgressNotifier);
            _executor.ScenarioExecuted += _result.AddScenario;
            ProgressNotifier.NotifyFeatureStart(_result.Name, _result.Description, _result.Label);
        }
示例#8
0
        /// <summary>
        /// SaveRoleFeatures
        /// </summary>
        /// <param name="addroleFeaturesRequest"></param>
        /// <returns></returns>
        public ServiceResponse SaveRoleFeatures(AddRoleFeaturesRequest addroleFeaturesRequest)
        {
            ServiceResponse addRoleFeaturesResponse = new ServiceResponse();

            try
            {
                SetContext();
                List <FeatureResult> lstFeatures = new List <FeatureResult>();
                foreach (ModuleFeatureDC feature in addroleFeaturesRequest.Features)
                {
                    FeatureResult featureResult = new FeatureResult();
                    featureResult.FeatureId = feature.FeatureId;
                    featureResult.RoleFeaturePermissions = new List <FeaturePermissionResult>();
                    foreach (FeaturePermissionDC featurePermission in feature.RoleFeaturePermissions)
                    {
                        featureResult.RoleFeaturePermissions.Add(new FeaturePermissionResult {
                            FeatureId = feature.FeatureId, ContentPermissionId = featurePermission.ContentPermissionId
                        });
                    }
                    lstFeatures.Add(featureResult);
                }
                _securityManager.SaveRoleFeatures(addroleFeaturesRequest.RoleId, lstFeatures);
            }
            catch (Exception ex)
            {
                HandleError(ex, addRoleFeaturesResponse);
            }
            return(addRoleFeaturesResponse);
        }
示例#9
0
 public void FeatureFinished(FeatureResult featureResult)
 {
     contextHandler.OnFeatureFinishedEvent();
     if (OnFeatureFinished != null)
     {
         OnFeatureFinished(this, new EventArgs <FeatureResult>(featureResult));
     }
 }
示例#10
0
        /// <summary>
        /// Initializes runner for given feature test class type with given progress notifier.
        /// Given featureTestClass type Name is used as feature name.
        /// If test class is annotated with [FeatureDescription] attribute or implementation specific description attribute, it's content is used as feature description.
        /// </summary>
        /// <param name="featureTestClass">Test class type.</param>
        /// <param name="progressNotifier">Progress notifier.</param>
        /// <param name="metadataProvider">Test metadata provider.</param>
        protected AbstractBDDRunner(Type featureTestClass, TestMetadataProvider metadataProvider, IProgressNotifier progressNotifier)
        {
            _metadataProvider = metadataProvider;
            ProgressNotifier  = progressNotifier;

            _result = new FeatureResult(_metadataProvider.GetFeatureName(featureTestClass), _metadataProvider.GetFeatureDescription(featureTestClass), _metadataProvider.GetFeatureLabel(featureTestClass));
            ProgressNotifier.NotifyFeatureStart(_result.Name, _result.Description, _result.Label);
        }
        public override void AfterFeature(Feature feature, FeatureResult result)
        {
            if (!errorMessages.Any()) return;

            WriteLine();
            errorMessages.ForEach(msg => WriteLineRaw(ConsoleColor.Red, 2, msg));
            errorMessages.Clear();
        }
示例#12
0
        public void Should_add_results()
        {
            var featureResult = new FeatureResult(string.Empty, string.Empty, string.Empty);

            _subject.AddResult(featureResult);

            Assert.That(_subject.Results, Is.EqualTo(new[] { featureResult }));
        }
示例#13
0
        public void Should_add_and_save_results()
        {
            var feature = new FeatureResult("name", "description", "label");

            _subject.AddFeature(feature);
            _subject.Finished();
            _writer.AssertWasCalled(w => w.Save(new IFeatureResult[] { feature }));
        }
示例#14
0
 public FeatureRunner(Type featureType, IntegrationContext integrationContext)
 {
     _featureType        = featureType;
     _integrationContext = integrationContext;
     _exceptionProcessor = new ExceptionProcessor(_integrationContext);
     _featureResult      = new FeatureResult(_integrationContext.MetadataProvider.GetFeatureInfo(featureType));
     integrationContext.FeatureProgressNotifier.NotifyFeatureStart(_featureResult.Info);
 }
 public static PSProviderFeature ToPSProviderFeature(this FeatureResult feature)
 {
     return(new PSProviderFeature
     {
         FeatureName = feature.Name.Substring(feature.Name.IndexOf('/') + 1),
         ProviderName = feature.Name.Substring(0, feature.Name.IndexOf('/')),
         RegistrationState = feature.Properties.State,
     });
 }
        private TaskResult GetFeatureTaskResult(FeatureResult result)
        {
            var results    = result.ScenarioResults;
            var taskResult = (results.Any()) ? TaskResult.Skipped : TaskResult.Exception;

            taskResult = (results.Any(_ => _.Result is Passed)) ? TaskResult.Success : taskResult;
            taskResult = (results.Any(_ => _.Result is Pending)) ? TaskResult.Inconclusive : taskResult;
            taskResult = (results.Any(_ => _.Result is Failed)) ? TaskResult.Error : taskResult;
            return(taskResult);
        }
示例#17
0
        public override void AfterFeature(Feature feature, FeatureResult result)
        {
            if (!errorMessages.Any())
            {
                return;
            }

            WriteLine();
            errorMessages.ForEach(msg => WriteLineRaw(ConsoleColor.Red, 2, msg));
            errorMessages.Clear();
        }
示例#18
0
        public FeatureRunner(Type featureType, IntegrationContext integrationContext)
        {
            _featureType        = featureType;
            _integrationContext = integrationContext;
            _featureResult      = new FeatureResult(_integrationContext.MetadataProvider.GetFeatureInfo(featureType));

            _scenarioExecutor = new ScenarioExecutor(new ExtendableExecutor(integrationContext.ExecutionExtensions));
            _scenarioExecutor.ScenarioExecuted += _featureResult.AddScenario;

            integrationContext.FeatureProgressNotifier.NotifyFeatureStart(_featureResult.Info);
        }
示例#19
0
        public void Should_create_feature_result_for_a_model()
        {
            // arrange
            var model = new UserList();

            // act
            var result = new FeatureResult(model);

            // arrange
            result.Model.ShouldBe(model);
        }
示例#20
0
        public void Should_set_success_message_in_the_result()
        {
            // arrange
            var model = new UserList();

            // act
            var result = new FeatureResult(model).Success("Redirect successfully");

            // arrange
            result.Messages.At(0).Key.ShouldBe(FlashMessageType.Confirmation);
            result.Messages.At(0).Value.ShouldBe("Redirect successfully");
        }
示例#21
0
        private FeatureResult GetFeatureResult(IEnumerable <ScenarioResult> scenarioResults)
        {
            var title         = scenarioResults.Select(_ => _.FeatureTitle).FirstOrDefault() ?? "";
            var featureResult = new FeatureResult(title);

            foreach (var result in scenarioResults)
            {
                featureResult.AddResult(result);
            }

            return(featureResult);
        }
示例#22
0
        private int CountActionStepsOfType(FeatureResult featureResult, Predicate<Result> isOfType)
        {
            var sum = 0;
            foreach (var result in featureResult.ScenarioResults)
            {
                var count = from r in result.StepResults
                            where isOfType(r.Result)
                            select r;
                sum += count.Count();
            }

            return sum;
        }
示例#23
0
        public void WriteSummaryResults(FeatureResult featureResult)
        {
            _writer.WriteLine(
                "Scenarios run: {0}, Failures: {1}, Pending: {2}",
                featureResult.NumberOfScenariosFound,
                featureResult.NumberOfFailingScenarios,
                featureResult.NumberOfPendingScenarios);

            var actionSteps = CountActionSteps(featureResult);
            var failedSteps = CountFailedActionSteps(featureResult);
            var pendingSteps = CountPendingActionSteps(featureResult);
            _writer.WriteLine("Steps {0}, failed {1}, pending {2}", actionSteps, failedSteps, pendingSteps);
        }
示例#24
0
        public void WriteSummaryResults(FeatureResult featureResult)
        {
            _writer.WriteLine(
                "Scenarios run: {0}, Failures: {1}, Pending: {2}",
                featureResult.NumberOfScenariosFound,
                featureResult.NumberOfFailingScenarios,
                featureResult.NumberOfPendingScenarios);

            var actionSteps  = CountActionSteps(featureResult);
            var failedSteps  = CountFailedActionSteps(featureResult);
            var pendingSteps = CountPendingActionSteps(featureResult);

            _writer.WriteLine("Steps {0}, failed {1}, pending {2}", actionSteps, failedSteps, pendingSteps);
        }
示例#25
0
            public override void SetUp()
            {
                base.SetUp();
                Action <string> action = name => Assert.AreEqual("Morgan", name);

                actionCatalog.Add(new ActionMethodInfo(new Regex(@"my name is (?<name>\w+)"), action, action.Method, "Given"));

                var f        = FeatureWithScenario();
                var scenario = f.Scenarios[0];

                scenario.AddStep(new StringStep("And", "my name is Morgan", ""));
                scenario.AddStep(new StringStep("Given", "my name is Axel", ""));
                featureResult = featureRunner.Run(f);
            }
示例#26
0
        private int CountActionStepsOfType(FeatureResult featureResult, Predicate <Result> isOfType)
        {
            var sum = 0;

            foreach (var result in featureResult.ScenarioResults)
            {
                var count = from r in result.StepResults
                            where isOfType(r.Result)
                            select r;
                sum += count.Count();
            }

            return(sum);
        }
示例#27
0
 public FeatureResult Run(Feature feature)
 {
     var featureResult = new FeatureResult(feature.Title);
     foreach (var scenario in feature.Scenarios)
     {
         var backgroundResults = RunBackground(scenario.Feature.Background);
         context.ScenarioStartedEvent(scenario);
         ScenarioResult scenarioResult = scenario.Examples.Any() ? RunExamples(scenario) : RunScenario(scenario);
         scenarioResult.AddActionStepResults(backgroundResults);
         featureResult.AddResult(scenarioResult);
         context.ScenarioFinishedEvent(scenarioResult);
     }
     return featureResult;
 }
示例#28
0
        public void Should_format_feature_without_description_nor_label_nor_details()
        {
            var result = new FeatureResult("My feature", null, null);

            result.AddScenario(new ScenarioResult("name", new[] { new StepResult(1, "step1", ResultStatus.Passed), new StepResult(2, "step2", ResultStatus.Ignored) }, null));
            var          text         = _subject.Format(result);
            const string expectedText = @"Feature: My feature

	Scenario: name - Ignored
		Step 1: step1 - Passed
		Step 2: step2 - Ignored
";

            Assert.That(text, Is.EqualTo(expectedText));
        }
示例#29
0
        public FeatureResult Run(Feature feature)
        {
            var featureResult = new FeatureResult(feature.Title);

            foreach (var scenario in feature.Scenarios)
            {
                var backgroundResults = RunBackground(scenario.Feature.Background);
                context.ScenarioStartedEvent(scenario);
                ScenarioResult scenarioResult = scenario.Examples.Any() ? RunExamples(scenario) : RunScenario(scenario);
                scenarioResult.AddActionStepResults(backgroundResults);
                featureResult.AddResult(scenarioResult);
                context.ScenarioFinishedEvent(scenarioResult);
            }
            return(featureResult);
        }
示例#30
0
 public void EstablishContext()
 {
     _writer = new StringWriter();
     _output = new SummaryWriter(_writer);
     var feature = new Feature("feature title");
     var featureResult = new FeatureResult(feature.Title);
     var scenarioResult = new ScenarioResult(feature, "scenario title");
     scenarioResult.AddActionStepResult(new StepResult("a".AsStringStep(""), new Passed()));
     scenarioResult.AddActionStepResult(new StepResult("b".AsStringStep(""), new Passed()));
     scenarioResult.AddActionStepResult(new StepResult("c".AsStringStep(""), new Pending("pending reason")));
     scenarioResult.AddActionStepResult(new StepResult("c".AsStringStep(""), new PendingNotImplemented("not implemented")));
     scenarioResult.AddActionStepResult(new StepResult("d".AsStringStep(""), new Failed(new Exception("why it failed"))));
     scenarioResult.AddActionStepResult(new StepResult("c".AsStringStep(""), new Skipped("previous step failed")));
     featureResult.AddResult(scenarioResult);
     _output.WriteSummaryResults(featureResult);
 }
示例#31
0
        public void EstablishContext()
        {
            _writer = new StringWriter();
            _output = new SummaryWriter(_writer);
            var feature        = new Feature("feature title");
            var featureResult  = new FeatureResult(feature.Title);
            var scenarioResult = new ScenarioResult(feature, "scenario title");

            scenarioResult.AddActionStepResult(new StepResult("a".AsStringStep(""), new Passed()));
            scenarioResult.AddActionStepResult(new StepResult("b".AsStringStep(""), new Passed()));
            scenarioResult.AddActionStepResult(new StepResult("c".AsStringStep(""), new Pending("pending reason")));
            scenarioResult.AddActionStepResult(new StepResult("c".AsStringStep(""), new PendingNotImplemented("not implemented")));
            scenarioResult.AddActionStepResult(new StepResult("d".AsStringStep(""), new Failed(new Exception("why it failed"))));
            scenarioResult.AddActionStepResult(new StepResult("c".AsStringStep(""), new Skipped("previous step failed")));
            featureResult.AddResult(scenarioResult);
            _output.WriteSummaryResults(featureResult);
        }
示例#32
0
        public void Should_save_results_to_file_even_if_directory_does_not_exist()
        {
            const string expectedText = "some expected text";
            var          feature      = new FeatureResult("name", "description", "label");

            try
            {
                _formatter.Stub(f => f.Format(Arg <IFeatureResult[]> .Matches(l => l.Contains(feature)))).Return(expectedText);
                _subject.Save(feature);
                Assert.That(File.ReadAllText(_filePath), Is.EqualTo(expectedText));
            }
            finally
            {
                File.Delete(_filePath);
                Directory.Delete(_dirPath);
            }
        }
示例#33
0
        public void Should_add_and_save_results()
        {
            const string expectedText = "some expected text";
            var          feature      = new FeatureResult("name", "description", "label");

            try
            {
                _formatter.Stub(f => f.Format(Arg <IFeatureResult[]> .Matches(l => l.Contains(feature)))).Return(expectedText);
                _subject.AddFeature(feature);
                _subject.Finished();
                Assert.That(File.ReadAllText(_filePath), Is.EqualTo(expectedText));
            }
            finally
            {
                File.Delete(_filePath);
            }
        }
示例#34
0
        public void RegisterResourceProviderFeatureTests()
        {
            const string ProviderName = "Providers.Test";
            const string FeatureName  = "Feature1";

            var registeredFeature = new FeatureResult
            {
                Id         = "featureId1",
                Name       = ProviderName + "/" + FeatureName,
                Properties = new FeatureProperties
                {
                    State = ProviderFeatureClient.RegisteredStateName,
                },
                Type = "Microsoft.Features/feature"
            };

            this.featureOperationsMock
            .Setup(client => client.RegisterWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(), null, It.IsAny <CancellationToken>()))
            .Callback((string providerName, string featureName, Dictionary <string, List <string> > customHeaders, CancellationToken ignored) =>
            {
                Assert.Equal(ProviderName, providerName, StringComparer.OrdinalIgnoreCase);
                Assert.Equal(FeatureName, featureName, StringComparer.OrdinalIgnoreCase);
            })
            .Returns(() => Task.FromResult(new AzureOperationResponse <FeatureResult>()
            {
                Body = registeredFeature
            }));

            this.cmdlet.Force             = true;
            this.cmdlet.ProviderNamespace = ProviderName;
            this.cmdlet.FeatureName       = FeatureName;

            this.commandRuntimeMock
            .Setup(m => m.WriteObject(It.IsAny <object>()))
            .Callback((object obj) =>
            {
                Assert.IsType <PSProviderFeature>(obj);
                var feature = (PSProviderFeature)obj;
                Assert.Equal(ProviderName, feature.ProviderName, StringComparer.OrdinalIgnoreCase);
                Assert.Equal(FeatureName, feature.FeatureName, StringComparer.OrdinalIgnoreCase);
            });

            this.cmdlet.ExecuteCmdlet();

            this.VerifyCallPatternAndReset(succeeded: true);
        }
        public void Notify(FeatureResult result)
        {
            List <TaskState> nodes;

            if (this.nodes.TryGetValue(typeof(NBehaveFeatureTask), out nodes) == false)
            {
                return;
            }
            var taskState = nodes.FirstOrDefault(_ => ((NBehaveFeatureTask)_.Task).FeatureTitle == result.FeatureTitle);

            if (taskState == null)
            {
                return;
            }
            server.TaskProgress(taskState.Task, "");
            PublishTaskResult(taskState.Task, result);
        }
示例#36
0
 public virtual void FeatureFinished(FeatureResult result)
 {
 }
示例#37
0
        private FeatureResult GetFeatureResult(IEnumerable<ScenarioResult> scenarioResults)
        {
            var title = scenarioResults.Select(_ => _.FeatureTitle).FirstOrDefault() ?? "";
            var featureResult = new FeatureResult(title);
            foreach (var result in scenarioResults)
                featureResult.AddResult(result);

            return featureResult;
        }
示例#38
0
 private int CountPendingActionSteps(FeatureResult featureResult)
 {
     return CountActionStepsOfType(featureResult, r => r is Pending);
 }
 /// <summary>
 /// Checks if a feature is registered with the current subscription
 /// </summary>
 /// <param name="feature">The feature</param>
 private bool IsFeatureRegistered(FeatureResult feature)
 {
     return string.Equals(feature.Properties.State, ProviderFeatureClient.RegisteredStateName, StringComparison.InvariantCultureIgnoreCase);
 }
示例#40
0
        private void WriteFailures(FeatureResult featureResult)
        {
            if (featureResult.NumberOfFailingScenarios > 0)
            {
                WriteSeparator();
                _writer.WriteLine("Failures:");
                var failureNumber = 1;

                foreach (var result in featureResult.ScenarioResults)
                {
                    if (result.Result.GetType() == typeof(Failed))
                    {
                        _writer.WriteLine(
                            "{0}) {1} ({2}) FAILED", failureNumber, result.FeatureTitle, result.ScenarioTitle);
                        _writer.WriteLine("  {0}", result.Message);
                        _writer.WriteLine("{0}", result.StackTrace);
                        failureNumber++;
                    }
                }
            }
        }
示例#41
0
 private int CountPassedActionSteps(FeatureResult featureResult)
 {
     return CountActionStepsOfType(featureResult, r => r is Passed);
 }
示例#42
0
 private int CountActionSteps(FeatureResult featureResult)
 {
     return CountPassedActionSteps(featureResult) +
         CountPendingActionSteps(featureResult) +
         CountFailedActionSteps(featureResult);
 }
示例#43
0
 public override void FeatureFinished(FeatureResult result)
 {
     featureFinished();
 }
示例#44
0
 public override void FeatureFinished(FeatureResult result)
 {
     eventsReceived.Add(new EventReceived(feature, EventType.FeatureFinished));
 }
        public void RegisterResourceProviderFeatureTests()
        {
            const string ProviderName = "Providers.Test";
            const string FeatureName = "Feature1";

            var registeredFeature = new FeatureResult
            {
                Id = "featureId1",
                Name = ProviderName + "/" + FeatureName,
                Properties = new FeatureProperties
                {
                    State = ProviderFeatureClient.RegisteredStateName,
                },
                Type = "Microsoft.Features/feature"
            };

            this.featureOperationsMock
                .Setup(client => client.RegisterWithHttpMessagesAsync(It.IsAny<string>(), It.IsAny<string>(), null, It.IsAny<CancellationToken>()))
                .Callback((string providerName, string featureName, Dictionary<string, List<string>> customHeaders, CancellationToken ignored) =>
                {
                    Assert.Equal(ProviderName, providerName, StringComparer.OrdinalIgnoreCase);
                    Assert.Equal(FeatureName, featureName, StringComparer.OrdinalIgnoreCase);
                })
                .Returns(() => Task.FromResult(new AzureOperationResponse<FeatureResult>()
                {
                    Body = registeredFeature
                }));
            
            this.cmdlet.ProviderNamespace = ProviderName;
            this.cmdlet.FeatureName = FeatureName;

            this.commandRuntimeMock
                .Setup(m => m.WriteObject(It.IsAny<object>()))
                .Callback((object obj) =>
                {
                    Assert.IsType<PSProviderFeature>(obj);
                    var feature = (PSProviderFeature)obj;
                    Assert.Equal(ProviderName, feature.ProviderName, StringComparer.OrdinalIgnoreCase);
                    Assert.Equal(FeatureName, feature.FeatureName, StringComparer.OrdinalIgnoreCase);
                });

            this.cmdlet.ExecuteCmdlet();

            this.VerifyCallPatternAndReset(succeeded: true);
        }
 public override void FeatureFinished(FeatureResult result)
 {
     publisher.Notify(result);
 }
 public override void FeatureFinished(FeatureResult result)
 {
     Invoke(l => l.FeatureFinished(result));
 }
        public void GetProviderFeatureTests()
        {
            // setup return values
            const string Provider1Namespace = "Providers.Test1";
            const string Feature1Name = "feature1";

            const string Provider2Namespace = "Providers.Test2";
            const string Feature2Name = "feature2";

            var provider1RegisteredFeature = new FeatureResult
            {
                Id = "featureId1",
                Name = Provider1Namespace + "/" + Feature1Name,
                Properties = new FeatureProperties
                {
                    State = ProviderFeatureClient.RegisteredStateName,
                },
                Type = "Microsoft.Features/feature"
            };

            var provider1UnregisteredFeature = new FeatureResult
            {
                Id = "featureId1",
                Name = Provider1Namespace + "/" + Feature2Name,
                Properties = new FeatureProperties
                {
                    State = "Unregistered",
                },
                Type = "Microsoft.Features/feature"
            };

            var provider2UnregisteredFeature = new FeatureResult
            {
                Id = "featureId2",
                Name = Provider2Namespace + "/" + Feature1Name,
                Properties = new FeatureProperties
                {
                    State = "Unregistered",
                },
                Type = "Microsoft.Features/feature"
            };

            var pagableResult = new Page<FeatureResult>();
            //var listResult = new[] { provider1RegisteredFeature, provider1UnregisteredFeature, provider2UnregisteredFeature };
            var listResult = new List<FeatureResult>() { provider1RegisteredFeature, provider1UnregisteredFeature, provider2UnregisteredFeature };
            pagableResult.SetItemValue<FeatureResult>(listResult);
            var result = new AzureOperationResponse<IPage<FeatureResult>>()
            {
                Body = pagableResult
            };

            this.featureOperationsMock
                .Setup(f => f.ListAllWithHttpMessagesAsync(null, It.IsAny<CancellationToken>()))
                .Returns(() => Task.FromResult(result));

            // 1. List only registered features of providers
            this.commandRuntimeMock
                .Setup(m => m.WriteObject(It.IsAny<object>()))
                .Callback((object obj) =>
                {
                    Assert.IsType<PSProviderFeature[]>(obj);

                    var features = (PSProviderFeature[])obj;
                    Assert.Equal(1, features.Length);

                    var provider = features.Single();
                    Assert.Equal(Provider1Namespace, provider.ProviderName, StringComparer.OrdinalIgnoreCase);
                    Assert.Equal(Feature1Name, provider.FeatureName, StringComparer.OrdinalIgnoreCase);
                    Assert.Equal(ProviderFeatureClient.RegisteredStateName, provider.RegistrationState, StringComparer.OrdinalIgnoreCase);
                });

            this.cmdlet.ParameterSetOverride = GetAzureProviderFeatureCmdlet.ListAvailableParameterSet;

            this.cmdlet.ExecuteCmdlet();

            this.VerifyListAllCallPatternAndReset();

            // 2. List all features of all providers
            this.cmdlet.ListAvailable = true;

            this.commandRuntimeMock
              .Setup(m => m.WriteObject(It.IsAny<object>()))
              .Callback((object obj) =>
              {
                  Assert.IsType<PSProviderFeature[]>(obj);
                  var features = (PSProviderFeature[])obj;
                  Assert.Equal(listResult.Count(), features.Length);
              });

            this.cmdlet.ExecuteCmdlet();

            this.VerifyListAllCallPatternAndReset();

            // 3.a. List only registered features of a particular provider - and they exist
            string providerOfChoice = Provider1Namespace;
            this.cmdlet.ListAvailable = false;
            this.cmdlet.ProviderNamespace = providerOfChoice;
            //pagableResult.SetItemValue<FeatureResult>(new List<FeatureResult>() { provider1RegisteredFeature, provider1UnregisteredFeature });

            this.featureOperationsMock
                .Setup(f => f.ListWithHttpMessagesAsync(It.IsAny<string>(), null, It.IsAny<CancellationToken>()))
                .Callback((string providerName, Dictionary<string, List<string>> customHeaders, CancellationToken ignored) => Assert.Equal(providerOfChoice, providerName, StringComparer.OrdinalIgnoreCase))
                .Returns(() => Task.FromResult(
                    new AzureOperationResponse<IPage<FeatureResult>>()
                    {
                        Body = pagableResult
                    }));

            this.commandRuntimeMock
                .Setup(m => m.WriteObject(It.IsAny<object>()))
                .Callback((object obj) =>
                {
                    Assert.IsType<PSProviderFeature[]>(obj);

                    var features = (PSProviderFeature[])obj;
                    Assert.Equal(1, features.Length);

                    var provider = features.Single();
                    Assert.Equal(Provider1Namespace, provider.ProviderName, StringComparer.OrdinalIgnoreCase);
                    Assert.Equal(Feature1Name, provider.FeatureName, StringComparer.OrdinalIgnoreCase);
                    Assert.Equal(ProviderFeatureClient.RegisteredStateName, provider.RegistrationState, StringComparer.OrdinalIgnoreCase);
                });

            this.cmdlet.ParameterSetOverride = GetAzureProviderFeatureCmdlet.GetFeatureParameterSet;

            this.cmdlet.ExecuteCmdlet();

            this.VerifyListProviderFeaturesCallPatternAndReset();

            // 3.b. List only registered features of a particular provider - and they do not exist
            providerOfChoice = Provider2Namespace;
            this.cmdlet.ListAvailable = false;
            this.cmdlet.ProviderNamespace = providerOfChoice;
            //pagableResult.SetItemValue<FeatureResult>(new List<FeatureResult>() { provider2UnregisteredFeature });

            this.commandRuntimeMock
                .Setup(m => m.WriteObject(It.IsAny<object>()))
                .Callback((object obj) =>
                {
                    Assert.IsType<PSProviderFeature[]>(obj);

                    var features = (PSProviderFeature[])obj;
                    Assert.Equal(0, features.Length);
                });

            this.cmdlet.ExecuteCmdlet();

            this.VerifyListProviderFeaturesCallPatternAndReset();

            // 4. List all features of a particular provider
            providerOfChoice = Provider1Namespace;
            this.cmdlet.ProviderNamespace = providerOfChoice;
            this.cmdlet.ListAvailable = true;
            //pagableResult.SetItemValue<FeatureResult>(new List<FeatureResult>() { provider1RegisteredFeature, provider1UnregisteredFeature });

            this.commandRuntimeMock
              .Setup(m => m.WriteObject(It.IsAny<object>()))
              .Callback((object obj) =>
              {
                  Assert.IsType<PSProviderFeature[]>(obj);
                  var features = (PSProviderFeature[])obj;
                  Assert.Equal(2, features.Length);
                  Assert.True(features.Any(feature => string.Equals(feature.FeatureName, Feature1Name, StringComparison.OrdinalIgnoreCase)));
                  Assert.True(features.Any(feature => string.Equals(feature.FeatureName, Feature2Name, StringComparison.OrdinalIgnoreCase)));
                  Assert.True(features.All(feature => string.Equals(feature.ProviderName, Provider1Namespace, StringComparison.OrdinalIgnoreCase)));
              });

            this.cmdlet.ParameterSetOverride = GetAzureProviderFeatureCmdlet.ListAvailableParameterSet;

            this.cmdlet.ExecuteCmdlet();

            this.VerifyListProviderFeaturesCallPatternAndReset();

            // 5. get a single provider feature by name
            this.cmdlet.ProviderNamespace = Provider2Namespace;
            this.cmdlet.FeatureName = Feature1Name;
            this.cmdlet.ListAvailable = false;

            this.featureOperationsMock
              .Setup(f => f.GetWithHttpMessagesAsync(It.IsAny<string>(), It.IsAny<string>(), null, It.IsAny<CancellationToken>()))
              .Callback((string providerName, string featureName, Dictionary<string, List<string>> customHeaders, CancellationToken ignored) =>
              {
                  Assert.Equal(Provider2Namespace, providerName, StringComparer.OrdinalIgnoreCase);
                  Assert.Equal(Feature1Name, featureName, StringComparer.OrdinalIgnoreCase);
              })
              .Returns(() => Task.FromResult(new AzureOperationResponse<FeatureResult>()
              {
                  Body = provider2UnregisteredFeature
              }));

            this.commandRuntimeMock
                .Setup(m => m.WriteObject(It.IsAny<object>()))
                .Callback((object obj) =>
                {
                    Assert.IsType<PSProviderFeature[]>(obj);
                    var features = (PSProviderFeature[])obj;
                    Assert.Equal(1, features.Length);
                    var feature = features.Single();
                    Assert.Equal(Provider2Namespace, feature.ProviderName, StringComparer.OrdinalIgnoreCase);
                    Assert.Equal(Feature1Name, feature.FeatureName, StringComparer.OrdinalIgnoreCase);
                    Assert.Equal("Unregistered", feature.RegistrationState, StringComparer.OrdinalIgnoreCase);
                });

            this.cmdlet.ParameterSetOverride = GetAzureProviderFeatureCmdlet.GetFeatureParameterSet;

            this.cmdlet.ExecuteCmdlet();

            this.VerifyGetCallPatternAndReset();
        }
示例#49
0
 public void FeatureFinished(FeatureResult featureResult)
 {
     contextHandler.OnFeatureFinishedEvent();
     if (OnFeatureFinished != null)
         OnFeatureFinished(this, new EventArgs<FeatureResult>(featureResult));
 }