Ejemplo n.º 1
0
        [TestMethod] // for bug #156
        public void TestAnnotationNotPickedUpOnInferredPropertyAfterAnnotatedProperty()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            var specification1 = new TestSpecification();
            var specification2 = new TestSpecificationWithId(new IdentifierImpl("Customer19", "Property"));

            PropertyInfo property1 = FindProperty(typeof(Customer19), "SomeProperty");
            PropertyInfo property2 = FindProperty(typeof(Customer19), "Property");

            metamodel = facetFactory.Process(Reflector, property1, MethodRemover, specification1, metamodel);
            Assert.IsNotNull(metamodel);

            metamodel = facetFactory.Process(Reflector, property2, MethodRemover, specification2, metamodel);
            IFacet facet1 = specification1.GetFacet(typeof(INamedFacet));
            IFacet facet2 = specification2.GetFacet(typeof(INamedFacet));

            Assert.IsNotNull(facet1);
            Assert.IsNull(facet2);
            Assert.IsTrue(facet1 is NamedFacetAnnotation);
            var namedFacet1 = (NamedFacetAnnotation)facet1;

            Assert.AreEqual("Property", namedFacet1.Value);
            AssertNoMethodsRemoved();
            Assert.IsNotNull(metamodel);
        }
Ejemplo n.º 2
0
        public void Should_ThrowUnableToCompileException_When_Null()
        {
            // Arrange
            var    spec   = new TestSpecification();
            Action action = () => spec.IsSatisfiedBy(new object());

            // Act & Assert
            action.ShouldThrow <UnableToCompileException>();
        }
        /// <summary>
        /// Refreshes the pages for the entire specification.
        /// </summary>
        private void RefreshEntireSpecification(TestSpecification specification)
        {
            RefreshSpecificationData(specification);
            RefreshSpecificationJson(clear: specification == null);

            bool clearListBoxes = specification == null;

            RefreshParameterListBoxes(clearListBoxes);
            RefreshExpectedResultListBoxes(clearListBoxes);
            RefreshCoverageGroupListBoxes(clearListBoxes);
        }
Ejemplo n.º 4
0
        public void CreateSpecificationRule_WithSpecification_SpecificationIsUsed()
        {
            var specification = new TestSpecification();
            var rule          = SpecificationRule.CreateSpecificationRule(specification, "Rule 1");

            var customer = new Customer();
            var context  = new RuleEngineContext <Customer> (customer);

            rule.WhenClause(context);

            Assert.IsTrue(specification.IsSatisfiedByCalled);
        }
Ejemplo n.º 5
0
        public void CreateAndConfigure_ShouldCallCreateLocalBrowser(BrowserEnum browserType)
        {
            // Arrange
            var testSpecification = new TestSpecification("Fancy scenario", "178wq76essf");

            _configurationProvider.LocalBrowser.Returns(browserType);

            // Act
            _sut.CreateAndConfigure(testSpecification, "configuration");

            // Assert
            _browserHostFactory.Received(1).CreateLocalWebDriver(browserType);
            _capabilitiesBuilder.Received().WithRunTestLocally(false);
        }
Ejemplo n.º 6
0
        public void CreateAndConfigure_ShouldAlwaysConfigureTestSpecifications(string browser)
        {
            // Arrange
            var testSpecification = new TestSpecification("Fancy scenario", "178wq76essf");

            // Act
            _sut.CreateAndConfigure(testSpecification, browser);

            // Assert

            _capabilitiesBuilder.DidNotReceive().WithCredentials(Arg.Any <string>(), Arg.Any <string>());
            _capabilitiesBuilder.Received().WithTestSpecification(testSpecification);
            _capabilitiesBuilder.Received().WithRunTestLocally(false);
        }
Ejemplo n.º 7
0
    public void AssignSpecificationcClass()
    {
        //It seems you can serialise a specification of a generic class.
        //Arrange
        TestSpecification myClass = new TestSpecification();

        myClass.n = 99;
        Serializer <TestSpecification> serializer = new Serializer <TestSpecification>(FilePath, myClass);

        //Act
        serializer.Save(false);
        Assert.True(serializer.Load());

        //Assert
        Assert.AreEqual(myClass.n, serializer.Value.n);
    }
Ejemplo n.º 8
0
        public void DoesNotMatchWithIdNotPresent()
        {
            // Arrange
            var testObjects = new[]
            {
                new TestObject(Guid.NewGuid(), "foo"),
                new TestObject(Guid.NewGuid(), "foo"),
                new TestObject(Guid.NewGuid(), "baz"),
            };
            var idToQueryFor  = Guid.NewGuid();
            var specification = new TestSpecification(idToQueryFor);

            // Act
            TestObject result = testObjects.AsQueryable().FirstOrDefault(specification.Criteria);

            // Assert
            Assert.Null(result);
        }
Ejemplo n.º 9
0
        public void Build_ShouldSetTestNameAndProjectAndBuildNumber()
        {
            //Arrange
            var buildNumber       = Guid.NewGuid().ToString();
            var testSpecification = new TestSpecification("my scenario", "some feature");

            _sut
            .WithTestSpecification(testSpecification)
            .WithBuildNumber(buildNumber);

            // Act
            var result = _sut.Build();

            // Assert
            result.GetCapability("name").Should().Be(testSpecification.ScenarioTitle);
            result.GetCapability("project").Should().Be(testSpecification.FeatureTitle);
            result.GetCapability("build").Should().Be(buildNumber);
        }
Ejemplo n.º 10
0
        public void MatchesWithId()
        {
            // Arrange
            var testObjects = new[]
            {
                new TestObject(Guid.NewGuid(), "foo"),
                new TestObject(Guid.NewGuid(), "bar"),
                new TestObject(Guid.NewGuid(), "baz"),
            };
            var idToQueryFor  = testObjects[0].Id;
            var specification = new TestSpecification(idToQueryFor);

            // Act
            TestObject result = testObjects.AsQueryable().FirstOrDefault(specification.Criteria);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(result.Id, idToQueryFor);
        }
Ejemplo n.º 11
0
        public void CreateAndConfigure_ShouldNotConfigureBrowserWhenNoBrowserConfigurationSpecified()
        {
            // Arrange
            var testSpecification = new TestSpecification("Fancy scenario", "178wq76essf");
            var browserHost       = Substitute.For <IBrowserHost>();
            var capabilities      = Substitute.For <ICapabilities>();

            _capabilitiesBuilder.Build().Returns(capabilities);
            _browserHostFactory.CreateWithCapabilities(capabilities).Returns(browserHost);

            // Act

            var result = _sut.CreateAndConfigure(testSpecification);

            // Assert
            result.Should().BeSameAs(browserHost);
            _capabilitiesBuilder.DidNotReceive().WithBrowserConfiguration(Arg.Any <BrowserConfiguration>());
            _capabilitiesBuilder.Received().WithRunTestLocally(false);
        }
Ejemplo n.º 12
0
        public void MatchesWithName()
        {
            // Arrange
            var testObjects = new[]
            {
                new TestObject(Guid.NewGuid(), "foo"),
                new TestObject(Guid.NewGuid(), "foo"),
                new TestObject(Guid.NewGuid(), "bar"),
            };
            var nameToQueryFor = testObjects[0].Name;
            var specification  = new TestSpecification(nameToQueryFor);

            // Act
            TestObject[] result = testObjects.AsQueryable().Where(specification.Criteria).ToArray();

            // Assert
            Assert.NotEmpty(result);
            Assert.All(result, i => Assert.Equal(nameToQueryFor, i.Name));
            Assert.Equal(2, result.Count());
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Returns the value of one of the text attributes from the working specification.
        /// </summary>
        public string GetSpecificationText(EntityEnum entity, TestSpecification specification)
        {
            if (specification == null)
            {
                return(string.Empty);
            }

            switch (entity)
            {
            case EntityEnum.Given:
                return(workingTestSpecification.Given);

            case EntityEnum.Name:
                return(workingTestSpecification.Name);

            case EntityEnum.Description:
                return(workingTestSpecification.Text);

            default:
                return(string.Empty);
            }
        }
Ejemplo n.º 14
0
        public void CreateAndConfigure_ShouldThrowExceptionWhenParserFailsToExtractBrowserConfiguration()
        {
            // Arrange
            var          testSpecification  = new TestSpecification("Fancy scenario", "178wq76essf");
            var          capabilities       = Substitute.For <ICapabilities>();
            const string unsupportedBrowser = "jsdhfjsg";

            var expectedException = new InvalidBrowserConfigurationException("Unsupported browser");

            _parser.When(x => x.Parse(unsupportedBrowser)).Do(x => { throw expectedException; });

            _capabilitiesBuilder.Build().Returns(capabilities);

            Action unsupportedActionBrowser = () => _sut.CreateAndConfigure(testSpecification, unsupportedBrowser);

            // Act && Assert
            unsupportedActionBrowser
            .ShouldThrow <InvalidBrowserConfigurationException>()
            .And.Should().BeSameAs(expectedException);

            _browserHostFactory
            .DidNotReceive()
            .CreateWithCapabilities(capabilities);
        }
Ejemplo n.º 15
0
        static int Main(string[] args)
        {
            testParameters = new TestParameters();

            testParameters.MaxWaitSeconds = 5;

            Type[] lockTypes = new Type[]
            {
                typeof(NoOpLock),
                typeof(SimpleSpinLock),
                typeof(LockTest.Synchronization.SpinLock),
                typeof(Lock)
            };

            TestSpecification[] testSpecifications = new TestSpecification[]
            {
                new TestSpecification(typeof(UnbalancedCallTest), "Unbalanced calls"),
                new TestSpecification(typeof(AutoLockTest), "Automatic lock management"),
                new TestSpecification(typeof(ConcurrencyTest), ConcurrencyTest.Variant.Default, "Concurrent access - 2 threads"),
                new TestSpecification(typeof(ConcurrencyTest), ConcurrencyTest.Variant.ObjectLock, "Concurrent access - 2 threads"),
                new TestSpecification(typeof(ConcurrencyTest), ConcurrencyTest.Variant.ManyThreads, "Concurrent access - many threads"),
                new TestSpecification(typeof(ConcurrencyTest), ConcurrencyTest.Variant.BoundedWait, "Concurrent access - bounded wait sanity"),
                new TestSpecification(typeof(TimeoutTest), "Waits with maximum timeouts")
            };

            if (args.Length > 0 && args[0] == "-?")
            {
                PrintUsage(lockTypes, testSpecifications);
                return -1;
            }

            int argStart = 0;

            if (args.Length > 0)
            {
                if (args[0] == "-t")
                {
                    if (args.Length > 1)
                    {
                        testParameters.MaxWaitSeconds = int.Parse(args[1]);
                    }
                    else
                    {
                        PrintUsage(lockTypes, testSpecifications);
                        return -1;
                    }

                    argStart+=2;
                }
            }

            bool[] variationMask = null;

            int variationsIncluded = lockTypes.Length * testSpecifications.Length;

            if (argStart < args.Length)
            {
                variationsIncluded = 0;
                variationMask = new bool[lockTypes.Length * testSpecifications.Length];

                for (int argumentIndex = argStart; argumentIndex < args.Length; argumentIndex++)
                {
                    uint variationIndex = 0;
                    bool invalidIndex = false;

                    try
                    {
                        variationIndex = uint.Parse(args[argumentIndex]);
                    }
                    catch (FormatException)
                    {
                        invalidIndex = true;
                    }

                    if (!invalidIndex && variationIndex >= variationMask.Length)
                    {
                        invalidIndex = true;
                    }

                    if (invalidIndex)
                    {
                        Console.WriteLine("{0} is not a valid integer test variation", args[argumentIndex]);

                        PrintUsage(lockTypes, testSpecifications);

                        return -1;
                    }

                    variationMask[variationIndex] = true;
                    variationsIncluded++;
                }
            }

            List<Thread> testThreads = new List<Thread>();
            Dictionary<Thread, ILockTest> threadToTestMap = new Dictionary<Thread, ILockTest>();

            int currentVariationIndex = 0;

            foreach (Type lockType in lockTypes)
            {
                ISyncLock syncLock = (ISyncLock)CreateTypeInstance(lockType);

                foreach (TestSpecification testSpecification in testSpecifications)
                {
                    int thisVariationIndex = currentVariationIndex++;

                    if (variationMask != null && !variationMask[thisVariationIndex])
                    {
                        continue;
                    }

                    ILockTest test = CreateTest(testSpecification.TestType, testSpecification.Parameters);

                    Console.WriteLine("Testing: {3}: {0} - Variation: {1}: {2}", (syncLock == null) ? "No lock" : syncLock.ToString(), test, test.Description, thisVariationIndex);

                    test.Initialize();

                    currentTest = test;

                    Thread testThread = new Thread(TestThread);

                    testThreads.Add(testThread);
                    threadToTestMap.Add(testThread, test);

                    testThread.Start(syncLock);

                    int testWaitTime = testParameters.MaxWaitSeconds * 2;

                    bool completedInTime = testThread.Join(testWaitTime * 1000);

                    if (!completedInTime)
                    {
                        if (null == lastTestException)
                        {
                            lastTestException = new TimeoutException(string.Format("Variation failed to complete within {0} seconds", testWaitTime));
                        }
                    }

                    if (lastTestException != null)
                    {
                        Console.Error.WriteLine("Error: {0}: {1}", lastTestException.GetType(), lastTestException.Message);
                        failedTests++;
                        Console.WriteLine("FAILED: {0} - Variation: {1}", syncLock == null ? "No lock" : syncLock.ToString(), currentTest);
                        continue;
                    }

                    passedTests++;
                    Console.WriteLine("PASSED: {0} - Variation: {1}", syncLock, test);
                }
            }

            Console.WriteLine("\t{0} passed, {1} failed, {2} skipped, {3} total", passedTests, failedTests, lockTypes.Length * testSpecifications.Length - variationsIncluded, lockTypes.Length * testSpecifications.Length);

            if (failedTests == 0)
            {
                Console.WriteLine("Success -- all variations passed.");
            }
            else
            {
                Console.WriteLine("Failure -- one or more variations failed");
            }

            foreach (Thread testThread in testThreads)
            {
                Console.WriteLine("Thread id: {0}, State: {1}", testThread.ManagedThreadId, testThread.ThreadState.ToString());

                if (testThread.ThreadState == ThreadState.Running || testThread.ThreadState == ThreadState.WaitSleepJoin)
                {
                    ILockTest runningTest = threadToTestMap[testThread];

                    Console.WriteLine("Unfinished test will be forcibly terminated: {0}: {1}", runningTest.GetType().ToString(), runningTest.Description);

                    testThread.Abort();
                }
            }

            int exitCode = ( failedTests == 0 ) ? 0 : 1;

            Console.WriteLine("Exiting test with {0}\n", exitCode);

            return exitCode;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Resets the data of the model.
 /// </summary>
 public void Reset()
 {
     workingTestSpecification     = null;
     savedTestSpecificationAsJson = null;
     workingTestGenerator         = null;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Sets the current, working test specification.
 /// </summary>
 public void SetWorkingSpecification(TestSpecification specification)
 {
     workingTestSpecification = specification;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Sets the saved (or original) version of the test specification as a JSON text string.
 /// </summary>
 public void SetSavedSpecification(TestSpecification specification)
 {
     savedTestSpecificationAsJson = (specification == null) ? null : JsonConvert.SerializeObject(specification);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Creates a new test specification and sets the working and saved versions to it.
 /// </summary>
 public void SetNewSpecificationAndName(string newSpecificationName)
 {
     workingTestSpecification      = new TestSpecification();
     workingTestSpecification.Name = newSpecificationName;
     savedTestSpecificationAsJson  = JsonConvert.SerializeObject(workingTestSpecification);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Creates a new test specification from the contents of a file, and sets the
 /// working and saved versions of it.
 /// </summary>
 public void SetNewSpecificationFromFile(string specificationFilename)
 {
     workingTestSpecification     = new TestSpecification(specificationFilename);
     savedTestSpecificationAsJson = JsonConvert.SerializeObject(workingTestSpecification);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Discards the current working specification and reverts it to the most recently saved version.
 /// </summary>
 public void DiscardSpecification()
 {
     workingTestSpecification = JsonConvert.DeserializeObject <TestSpecification>(savedTestSpecificationAsJson);
 }
Ejemplo n.º 22
0
        static void PrintUsage(Type[] lockTypes, TestSpecification[] testSpecifications)
        {
            Console.WriteLine("\nLocktest -t [<test-timeout>] [<test-variation> [<test-variation> [<test-variation>]...]]");
            Console.WriteLine("\nWhere <test-variation> is an integer from the list below indicating lock / test");
            Console.WriteLine("combination to execute\n");

            int testIndex = 0;

            foreach (Type lockType in lockTypes)
            {
                foreach (TestSpecification testSpecification in testSpecifications)
                {
                    ILockTest test = CreateTest(testSpecification.TestType, testSpecification.Parameters);

                    Console.Write("\t{0} ", testIndex);
                    PrintTest(lockType, test);
                    testIndex++;
                }
            }
        }
 /// <summary>
 /// Refreshes the data fields for the specification.
 /// </summary>
 /// <param name="specification"></param>
 private void RefreshSpecificationData(TestSpecification specification)
 {
     richTextBox9.Text = model.GetSpecificationText(EntityEnum.Given, specification);
     textBox6.Text     = model.GetSpecificationText(EntityEnum.Name, specification);
     textBox5.Text     = model.GetSpecificationText(EntityEnum.Description, specification);
 }
Ejemplo n.º 24
0
 public ICapabilitiesBuilder WithTestSpecification(TestSpecification testSpecification)
 {
     _testSpecification = testSpecification;
     return(this);
 }
Ejemplo n.º 25
0
        private static void Main(string[] args)
        {
            Logger.Debug(string.Concat(Enumerable.Repeat("-", 60)));
            Logger.Debug("Fixed Form Packager Initialized");
            try
            {
                var options = new Options();
                if (Parser.Default.ParseArgumentsStrict(args, options,
                                                        () =>
                {
                    Logger.Fatal(
                        $"Incorrect parameters provided at the command line [{args.Aggregate((x, y) => $"{x},{y}")}]. Terminating.");
                }))
                {
                    ExtractionSettings.GitLabInfo = new GitLabInfo
                    {
                        BaseUrl  = options.GitLabBaseUrl,
                        Group    = options.GitLabGroup,
                        Password = options.GitLabPassword,
                        Username = options.GitLabUsername
                    };
                    ExtractionSettings.AssessmentScoring =
                        CsvExtractor.Extract <AssessmentScoringComputationRule>(options.AssessmentScoringInput).ToList();
                    ExtractionSettings.ItemInput      = CsvExtractor.Extract <Item>(options.ItemInput).ToList();
                    ExtractionSettings.AssessmentInfo =
                        CsvExtractor.Extract <Assessment>(options.AssessmentInput).First();
                    ExtractionSettings.ItemInput.ForEach(
                        x =>
                    {
                        ResourceGenerator.Retrieve(ExtractionSettings.GitLabInfo, $"Item-{x.ItemId}");
                        // If there is no scoring information provided in the input document, look for it in the item XML
                        if (x.ItemScoringInformation.All(y => string.IsNullOrEmpty(y.MeasurementModel)))
                        {
                            ExtractionSettings.ItemInput[ExtractionSettings.ItemInput.FindIndex(
                                                             y => y.ItemId.Equals(x.ItemId, StringComparison.OrdinalIgnoreCase))]
                            .ItemScoringInformation = IrtMapper.RetrieveIrtParameters(x.ItemId);
                        }
                    });

                    var uniqueHash = HashGenerator.Hash(ExtractionSettings.AssessmentInfo.UniqueId.GetHashCode(),
                                                        ExtractionSettings.ItemInput.First().SegmentId.GetHashCode(),
                                                        ExtractionSettings.ItemInput.First().FormPartitionId.GetHashCode());


                    Logger.Debug($"Generated unique hash: {uniqueHash}");

                    ExtractionSettings.AssessmentInfo.UniqueId += $"{uniqueHash}";
                    ExtractionSettings.ItemInput = ExtractionSettings.ItemInput.Select(x => new Item
                    {
                        ItemId = x.ItemId,
                        AssociatedStimuliId    = x.AssociatedStimuliId,
                        FormPartitionId        = x.FormPartitionId + $"{uniqueHash}",
                        FormPartitionPosition  = x.FormPartitionPosition,
                        FormPosition           = x.FormPosition,
                        ItemScoringInformation = x.ItemScoringInformation,
                        SegmentId       = x.SegmentId + $"{uniqueHash}",
                        SegmentPosition = x.SegmentPosition
                    }).ToList();
                    // Validate that the segment unique IDs and assessment IDs are either the same or different depending on # of segments
                    var segmentIds = ExtractionSettings.ItemInput.Select(x => x.SegmentId).Distinct().ToList();
                    if (segmentIds.Count() > 1 &&
                        segmentIds.Any(
                            x =>
                            x.Equals(ExtractionSettings.AssessmentInfo.UniqueId, StringComparison.OrdinalIgnoreCase)))
                    {
                        throw new Exception(
                                  "Identifiers of segments and assessments must not match in multi-segmented assessments. Please adjust the assessment and/or item inputs.");
                    }
                    if (segmentIds.Count() == 1 &&
                        !segmentIds.First()
                        .Equals(ExtractionSettings.AssessmentInfo.UniqueId, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new Exception(
                                  "Identifiers of segments and assessments must match in single-segmented assessments. Please adjust the assessment and/or item inputs.");
                    }
                    var result = TestSpecification.Construct();
                    result.ToList().ForEach(x =>
                                            x.Save(
                                                $"{x.XPathSelectElement("./identifier").Attribute("uniqueid")?.Value}_{x.Attribute("purpose")?.Value}.xml"));
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
            finally
            {
                Console.Write("Press any key to exit.");
                Console.ReadKey(true);
            }
        }