[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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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()); }
/// <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); } }
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); }
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; }
/// <summary> /// Resets the data of the model. /// </summary> public void Reset() { workingTestSpecification = null; savedTestSpecificationAsJson = null; workingTestGenerator = null; }
/// <summary> /// Sets the current, working test specification. /// </summary> public void SetWorkingSpecification(TestSpecification specification) { workingTestSpecification = specification; }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Discards the current working specification and reverts it to the most recently saved version. /// </summary> public void DiscardSpecification() { workingTestSpecification = JsonConvert.DeserializeObject <TestSpecification>(savedTestSpecificationAsJson); }
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); }
public ICapabilitiesBuilder WithTestSpecification(TestSpecification testSpecification) { _testSpecification = testSpecification; return(this); }
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); } }