Beispiel #1
0
            public void OneTimeTearDown()
            {
                var scenarios = BDTestUtil.GetScenarios().Where(x => x.GetScenarioText() == "RetryOnStoryTests").ToList();

                Assert.That(scenarios.Count, Is.EqualTo(1));
                Assert.That(scenarios.First().Status, Is.EqualTo(Status.Passed));
            }
Beispiel #2
0
        public static string GetTestJsonData(BDTestRunDescriptor bdTestRunDescriptor)
        {
            var scenarios = BDTestUtil.GetScenarios();

            var testTimer = GetTestTimer(scenarios);

            var dataToOutput = new BDTestOutputModel
            {
                Id          = BDTestUtil.GetCurrentReportId,
                Environment = bdTestRunDescriptor?.Environment ?? BDTestSettings.Environment,
                Tag         = bdTestRunDescriptor?.Tag ?? BDTestSettings.Tag,
                BranchName  = bdTestRunDescriptor?.BranchName ?? BDTestSettings.BranchName,
                MachineName = Environment.MachineName,
                Scenarios   = scenarios,
                TestTimer   = testTimer,
                NotRun      = BDTestUtil.GetNotRunScenarios(),
                Version     = BDTestVersionHelper.CurrentVersion
            };

            var settings = new JsonSerializerSettings
            {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            };

            return(JsonConvert.SerializeObject(dataToOutput, Formatting.Indented, settings));
        }
Beispiel #3
0
        public void ThrowsExceptionOnThen(Type exceptionType, Status status)
        {
            try
            {
                When(() => Console.WriteLine("my test has an exception"))
                .Then(() => Console.WriteLine("the exception should be serialized to the json output"))
                .And(() => Console.WriteLine("the step is marked as failed"))
                .And(() => ThrowException(exceptionType))
                .And(() => Console.WriteLine("subsequent steps are inconclusive"))
                .And(() => Console.WriteLine("Previous steps should be marked as passed"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch
            {
                var scenario = BDTestUtil.GetScenarios().First();

                Assert.That(scenario.Steps[3].Exception.Message.Contains("BDTest Exception!"));

                Assert.That(scenario.Steps[0].Status, Is.EqualTo(Status.Passed));
                Assert.That(scenario.Steps[1].Status, Is.EqualTo(Status.Passed));
                Assert.That(scenario.Steps[2].Status, Is.EqualTo(Status.Passed));
                Assert.That(scenario.Steps[3].Status, Is.EqualTo(status));
                Assert.That(scenario.Steps[4].Status, Is.EqualTo(Status.Inconclusive));
                Assert.That(scenario.Steps[5].Status, Is.EqualTo(Status.Inconclusive));

                Assert.That(scenario.Status, Is.EqualTo(status));

                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[3].Exception")
                    .ToString().Contains("BDTest Exception!"));

                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[0].Status").ToString(),
                    Is.EqualTo("Passed"));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[1].Status").ToString(),
                    Is.EqualTo("Passed"));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[2].Status").ToString(),
                    Is.EqualTo("Passed"));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[3].Status").ToString(),
                    Is.EqualTo(status.ToString()));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[4].Status").ToString(),
                    Is.EqualTo("Inconclusive"));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[5].Status").ToString(),
                    Is.EqualTo("Inconclusive"));

                Assert.That(JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Status").ToString(),
                            Is.EqualTo(status.ToString()));
            }
        }
Beispiel #4
0
        public void NUNitSuccessException()
        {
            try
            {
                Given(() => Console.WriteLine("NUnit throws a success exception"))
                .When(() => Assert.Pass())
                .Then(() => Console.WriteLine("the test has passed"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch (SuccessException)
            {
                var scenario = BDTestUtil.GetScenarios().First();
                Assert.That(scenario.Status, Is.EqualTo(Status.Passed));
            }
        }
Beispiel #5
0
        public void NUNitIgnoreException()
        {
            try
            {
                Given(() => Console.WriteLine("NUnit throws an ignore exception"))
                .When(() => Assert.Ignore())
                .Then(() => Console.WriteLine("the test is ignored"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch (IgnoreException)
            {
                var scenario = BDTestUtil.GetScenarios().First();

                Assert.That(scenario.Status, Is.EqualTo(Status.Inconclusive));
            }
        }
Beispiel #6
0
        public void CustomException()
        {
            BDTestSettings.CustomExceptionSettings.SuccessExceptionTypes.Add(typeof(MyAllowedException));

            try
            {
                Given(() => Console.WriteLine("NUnit throws a success exception"))
                .When(() => ThrowException())
                .Then(() => Console.WriteLine("the test has passed"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch (MyAllowedException)
            {
                var scenario = BDTestUtil.GetScenarios().First();
                Assert.That(scenario.Status, Is.EqualTo(Status.Passed));
            }
        }
Beispiel #7
0
        public void CustomIgnoreException()
        {
            BDTestSettings.CustomExceptionSettings.InconclusiveExceptionTypes.Add(typeof(MyCustomIgnoreException));
            try
            {
                Given(() => Console.WriteLine("NUnit throws an ignore exception"))
                .When(() => ThrowException())
                .Then(() => Console.WriteLine("the test is ignored"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch (MyCustomIgnoreException)
            {
                var scenario = BDTestUtil.GetScenarios().First();

                Assert.That(scenario.Status, Is.EqualTo(Status.Inconclusive));
            }
        }
Beispiel #8
0
        public void CanDeserializeJsonResultsSuccessfully()
        {
            When(() => Console.WriteLine("A persistent json file is written")).WithStepText(() => "I write custom when step text")
            .Then(() => CustomStep("1", "2"))
            .BDTest();

            var inMemoryScenario = BDTestUtil.GetScenarios().Single();

            var json    = BDTestJsonHelper.GetTestJsonData();
            var jObject = JObject.Load(new JsonTextReader(new StringReader(json)));

            var scenarios = JsonConvert.DeserializeObject <List <Scenario> >(jObject.GetValue("Scenarios").ToString());

            Assert.That(scenarios, Is.Not.Null);
            Assert.That(scenarios.Count, Is.EqualTo(1));

            var deserializedScenario = scenarios.First();

            Assert.That(deserializedScenario.Steps[0].StepText, Is.EqualTo("When I write custom when step text"));
            Assert.That(deserializedScenario.Steps[1].StepText, Is.EqualTo("Then 1 2"));

            var compareLogic = new CompareLogic
            {
                Config = new ComparisonConfig
                {
                    MaxDifferences = int.MaxValue,
                    // The below are runtime only, and so we don't serialize.
                    MembersToIgnore =
                    {
                        nameof(Scenario.BdTestBaseClass)
                    }
                }
            };

            var comparisonResult = compareLogic.Compare(inMemoryScenario, deserializedScenario);

            Assert.That(comparisonResult.AreEqual, Is.True);
        }
Beispiel #9
0
        public void Test()
        {
            SuccessTest();

            NotRunTest1();

            NotRunTest2();

            NotRunTest3();

            var notRunScenarios = BDTestUtil.GetNotRunScenarios();

            Assert.That(notRunScenarios.Count, Is.EqualTo(3));

            Assert.That(notRunScenarios.Any(scenario => scenario.GetScenarioText() == "Custom NotRunTest1"));
            Assert.That(notRunScenarios.Any(scenario => scenario.GetScenarioText() == "Custom NotRunTest2"));
            Assert.That(notRunScenarios.Any(scenario => scenario.GetScenarioText() == "Custom NotRunTest3"));

            Assert.That(notRunScenarios.All(scenario => scenario.GetStoryText() == @"As a BDTest developer
I want to make sure that BDTest flags tests not executed
So that consumers aren't missing any test coverage accidentally
"));
        }
Beispiel #10
0
 public static void ResetData()
 {
     ClearedScenarios.AddRange(BDTestUtil.GetScenarios());
     BDTestUtil.ClearScenarios();
 }
Beispiel #11
0
        public async Task <IActionResult> AllScenarios([FromRoute] string id)
        {
            var data = await GetData(id).ConfigureAwait(false);

            if (data == null)
            {
                return(View("NotFoundSingle", id));
            }

            var filterByQueryParameter = Request.GetQueryParameter(StatusConstants.FilterByStatusQueryParameterName);

            IEnumerable <Scenario> scenarios = data.Scenarios;

            if (!string.IsNullOrEmpty(filterByQueryParameter) && filterByQueryParameter != StatusConstants.All)
            {
                scenarios = data.Scenarios
                            .Where(scenario => string.Equals(filterByQueryParameter, scenario.Status.ToString(), StringComparison.OrdinalIgnoreCase));
            }

            var orderByQueryParameter = Request.GetQueryParameter(OrderConstants.OrderByQueryParameterName);

            var scenariosGroupedByScenarioTextEnumerable = scenarios.GroupBy(scenario => scenario.GetScenarioText())
                                                           .OrderBy(group => group.GetTotalStatus().GetOrder())
                                                           .ThenBy(group => group.Key);

            switch (orderByQueryParameter)
            {
            case OrderConstants.Name:
                scenariosGroupedByScenarioTextEnumerable =
                    scenariosGroupedByScenarioTextEnumerable.OrderBy(scenarios => scenarios.Key);
                break;

            case OrderConstants.DurationDescending:
                scenariosGroupedByScenarioTextEnumerable =
                    scenariosGroupedByScenarioTextEnumerable.OrderByDescending(scenarios =>
                                                                               scenarios.Select(scenario => scenario.TimeTaken).Max());
                break;

            case OrderConstants.DurationAscending:
                scenariosGroupedByScenarioTextEnumerable =
                    scenariosGroupedByScenarioTextEnumerable.OrderBy(scenarios =>
                                                                     scenarios.Select(scenario => scenario.TimeTaken).Max());
                break;

            case OrderConstants.DateAscending:
                scenariosGroupedByScenarioTextEnumerable = scenariosGroupedByScenarioTextEnumerable.OrderBy(scenarios =>
                                                                                                            BDTestUtil.GetTestTimer(scenarios.ToList()).TestsStartedAt);
                break;

            case OrderConstants.DateDescending:
                scenariosGroupedByScenarioTextEnumerable =
                    scenariosGroupedByScenarioTextEnumerable.OrderByDescending(scenarios =>
                                                                               BDTestUtil.GetTestTimer(scenarios.ToList()).TestsStartedAt);
                break;

            case OrderConstants.Status:
                // Defaults to status. We don't need to do anything :)
                break;

            default:
                _bdTestReportServerOptions.Logger?.LogWarning("Unknown order: {OrderByQueryParameter}", orderByQueryParameter);
                break;
            }

            return(View("AllScenarios", scenariosGroupedByScenarioTextEnumerable.ToArray()));
        }