void Ex02() { Extension = new TestExtension(); Given("a controller", () => Controller = new TestUwpControllers.TestUwpController()); When("an extension is added", () => UwpController.AddExtension(Extension)); Then("the container of the extension should be retrieved", () => UwpController.Retrieve <TestExtension, object>(Controller) == TestExtension.TestExtensionContainer); }
public void Fetch_ClearsCachedExtension_AndFetchesNewExtension_WhenUnderlyingCollectionChanged() { // Arrange int revision = 1; var createdExtension = new TestExtension(); var replacementExtension = new TestExtension(); TestExtension capturedExtension = null; var collection = CreateCollection <TestExtension>( onRevision: () => revision, extension: null, onSet: e => capturedExtension = e); var refs = new WorkContextExtensionReferences <ExtensionCache>(collection); refs.Fetch <TestExtension>(ref refs.Cache.Test, e => createdExtension); // Act revision++; var extension = refs.Fetch <TestExtension>(ref refs.Cache.Test, e => replacementExtension); // Assert Assert.NotNull(extension); Assert.Same(replacementExtension, extension); Assert.Equal(2, refs.Revision); Assert.NotNull(capturedExtension); Assert.Same(replacementExtension, capturedExtension); }
public void Test() { MyProg prog = new MyProg(); var activator = new FakeActivator(); activator.Add(prog); JobHostConfiguration config = TestHelpers.NewConfig <MyProg>(activator); var ext = new TestExtension(); config.AddExtension(ext); var host = new TestJobHost <MyProg>(config); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); Assert.Equal(1, ext._counter); // Callable host.Call("Test"); Assert.Equal(1, ext._counter); // Fact that we registered a Widget converter is enough to add the assembly Assembly asm; bool resolved; resolved = metadataProvider.TryResolveAssembly(typeof(Widget).Assembly.GetName().Name, out asm); Assert.True(resolved); Assert.Same(asm, typeof(Widget).Assembly); // check with full name resolved = metadataProvider.TryResolveAssembly(typeof(Widget).Assembly.GetName().FullName, out asm); Assert.True(resolved); Assert.Same(asm, typeof(Widget).Assembly); // This requires the target attribute to be unique within the assembly. var attrType = metadataProvider.GetAttributeTypeFromName("Test9"); Assert.Equal(typeof(Test9Attribute), attrType); // JObject --> Attribute var attr = GetAttr <Test9Attribute>(metadataProvider, new { Flag = "xyz" }); Assert.Equal("xyz", attr.Flag); // Getting default type. var defaultType = metadataProvider.GetDefaultType(attr, FileAccess.Read, null); Assert.Equal(typeof(JObject), defaultType); // If we have no match for output, we'll try IAsyncCollector<string> Assert.Equal(typeof(IAsyncCollector <string>), metadataProvider.GetDefaultType(attr, FileAccess.Write, typeof(object))); }
public void Test() { MyProg prog = new MyProg(); var activator = new FakeActivator(); activator.Add(prog); JobHostConfiguration config = TestHelpers.NewConfig <MyProg>(activator); var ext = new TestExtension(); config.AddExtension(ext); IJobHostMetadataProvider tooling = config.CreateMetadataProvider(); Assert.Equal(1, ext._counter); // Callable var host = new TestJobHost <MyProg>(config); host.Call("Test"); Assert.Equal(1, ext._counter); // Fact that we registered a Widget converter is enough to add the assembly Assembly asm; bool resolved; resolved = tooling.TryResolveAssembly(typeof(Widget).Assembly.GetName().Name, out asm); Assert.True(resolved); Assert.Same(asm, typeof(Widget).Assembly); // check with full name resolved = tooling.TryResolveAssembly(typeof(Widget).Assembly.GetName().FullName, out asm); Assert.True(resolved); Assert.Same(asm, typeof(Widget).Assembly); var attrType = tooling.GetAttributeTypeFromName("Test"); Assert.Equal(typeof(TestAttribute), attrType); // JObject --> Attribute var attr = GetAttr <TestAttribute>(tooling, new { Flag = "xyz" }); Assert.Equal("xyz", attr.Flag); // Getting default type. var defaultType = tooling.GetDefaultType(attr, FileAccess.Read, null); Assert.Equal(typeof(JObject), defaultType); Assert.Throws <InvalidOperationException>(() => tooling.GetDefaultType(attr, FileAccess.Write, typeof(object))); }
private static void ClearDB(ISession session) { TestExtension.CleanUpTable <PlanReceiptOrderPersonalAccount>(session.SessionFactory); TestExtension.CleanUpTable <PlanCertificate>(session.SessionFactory); TestExtension.CleanUpTable <Destination>(session.SessionFactory); TestExtension.CleanUpTable <Pass>(session.SessionFactory); TestExtension.CleanUpTable <CertificateQuality>(session.SessionFactory); TestExtension.CleanUpTable <PlanReceiptOrder>(session.SessionFactory); TestExtension.CleanUpTable <ChemicalIndicatorValue>(session.SessionFactory); TestExtension.CleanUpTable <MechanicIndicatorValue>(session.SessionFactory); TestExtension.CleanUpTable <DictionaryChemicalIndicator>(session.SessionFactory); TestExtension.CleanUpTable <DictionaryMechanicalIndicator>(session.SessionFactory); TestExtension.CleanUpTable <DictionaryPass>(session.SessionFactory); }
public void Fetch_FetchesExtension_FromCollection_WhenNotCached_AndExtensionExists() { // Arrange var existingExtension = new TestExtension(); TestExtension capturedExtension = null; var collection = CreateCollection <TestExtension>( revision: 1, extension: existingExtension, onSet: e => capturedExtension = e); var refs = new WorkContextExtensionReferences <ExtensionCache>(collection); // Act var extension = refs.Fetch <TestExtension>(ref refs.Cache.Test, e => new TestExtension()); // Assert Assert.NotNull(extension); Assert.Same(existingExtension, extension); Assert.Null(capturedExtension); }
/// <summary> /// Creates a new test extension. /// </summary> /// <typeparam name="TTestExtension">Type of test extension.</typeparam> /// <typeparam name="TType">Type the test extension is for.</typeparam> /// <param name="type">Object which is passed to the test extension constructor.</param> /// <param name="currentTestExtension">TestExtension from where this is called.</param> /// <returns>Test extension created.</returns> public static TTestExtension Create <TTestExtension, TType>(TType type, TestExtension currentTestExtension) where TType : class where TTestExtension : TestExtension { Type testExtensionType = typeof(TTestExtension); object[] parameters = { type }; TTestExtension extension = (TTestExtension)testExtensionType.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, parameters, CultureInfo.InvariantCulture); LifeTimeManagmentServiceTestExtension lifeTimeManagmentService = currentTestExtension.Container.GetFirstTestExtension <LifeTimeManagmentServiceTestExtension>(); // This is a temporary workaround to get any test extension to be able to get the lifetime managment service till we implement our own test extension factory. if (extension.Container == null) { extension.Container = currentTestExtension.Container; } lifeTimeManagmentService.AddToCompositionContainer(extension); return(extension); }
public void Fetch_ReturnsCachedExtension_WhenCollectionUnchanged() { // Arrange int revision = 1; var createdExtension = new TestExtension(); TestExtension capturedExtension = null; var collection = CreateCollection <TestExtension>( onRevision: () => revision, onGet: () => createdExtension, onSet: e => capturedExtension = e); var refs = new WorkContextExtensionReferences <ExtensionCache>(collection); refs.Fetch <TestExtension>(ref refs.Cache.Test, e => createdExtension); // Act var extension = refs.Fetch <TestExtension>(ref refs.Cache.Test, e => new TestExtension()); // Assert Assert.NotNull(extension); Assert.Same(createdExtension, extension); Assert.Equal(1, refs.Revision); }
public void Fetch_CreatesExtension_UsingFactory_WhenNotCached_AndExtensionDoesNotExist() { // Arrange int revision = 1; var existingExtension = new TestExtension(); TestExtension capturedExtension = null; var collection = CreateCollection <TestExtension>( onRevision: () => revision, extension: null, onSet: e => capturedExtension = e); var refs = new WorkContextExtensionReferences <ExtensionCache>(collection); // Act revision++; var extension = refs.Fetch <TestExtension>(ref refs.Cache.Test, e => new TestExtension()); // Assert Assert.NotNull(extension); Assert.NotSame(existingExtension, extension); Assert.NotNull(capturedExtension); Assert.Equal(2, refs.Revision); }
public TestControl(SimFeedbackExtensionFacade facade, TestExtension extension, int startStopButton = -1, int decreaseIntensity1Button = -1, int increaseIntensity1Button = -1, int decreaseIntensity5Button = -1, int increaseIntensity5Button = -1, int decreaseIntensity10Button = -1, int increaseIntensity10Button = -1, int decreaseIntensity20Button = -1, int increaseIntensity20Button = -1) { this.startStopButton = startStopButton; this.decreaseIntensity1Button = decreaseIntensity1Button; this.increaseIntensity1Button = increaseIntensity1Button; this.decreaseIntensity5Button = decreaseIntensity5Button; this.increaseIntensity5Button = increaseIntensity5Button; this.decreaseIntensity10Button = decreaseIntensity10Button; this.increaseIntensity10Button = increaseIntensity10Button; this.decreaseIntensity20Button = decreaseIntensity20Button; this.increaseIntensity20Button = increaseIntensity20Button; this.facade = facade; this.extension = extension; directInput = new DirectInput(); startStopDelay = extension.GetStartStopDelay(); refreshBtn_Click(null, null); if (joystickList.Count > 0) { enableExtensionButton_Click(null, null); } InitializeComponent(); }
/// <summary> /// Responsible for creating the build manager. /// For MSBuild backend testing BuildManager is the Entry point for all tests. That is - the environment /// for testing starts with the BuildManager. Configuration can specify which components should be mocked /// and which test extension should be attached to which component. /// </summary> /// <returns>TextExtensions created.</returns> protected override TestExtensionContainer Generate() { List <TestExtension> testExtensions = new List <TestExtension>(); // To workaround the problem where extensions derived out from Testextension does not have a LifeTimeManagmentService. LifeTimeManagmentServiceTestExtension lifetimeServiceExtension = new LifeTimeManagmentServiceTestExtension(LifetimeService); LifetimeService.Compose(lifetimeServiceExtension); testExtensions.Add(lifetimeServiceExtension); // Create the build manager and the associated test extension first. BuildManagerTestExtension buildManagerTestExtension = new BuildManagerTestExtension(BuildManager.DefaultBuildManager); LifetimeService.Compose(buildManagerTestExtension); testExtensions.Add(buildManagerTestExtension); // When the BuildManager is created it registers a default set of components. // Loop through each of the components that we want to mock and then replace the component in the BuildManager. foreach (KeyValuePair <ComponentType, string> componentTypePair in this.Configuration.ComponentsToMock) { buildManagerTestExtension.ReplaceRegisterdFactory(GetBuildComponentTypeFromComponentType(componentTypePair.Key.ToString()), this.CreateMockComponent); } // Loop through each of the components that we want to wrap with a test extension - create the test extension and aggregate the internal component. // This component could be a mock that we create above or the real implementation. foreach (KeyValuePair <ComponentType, string> componentTypePair in this.Configuration.TestExtensionForComponents) { TestExtension extension = CreateTestExtensionForComponent(componentTypePair.Key.ToString(), componentTypePair.Value, buildManagerTestExtension); LifetimeService.Compose(extension); testExtensions.Add(extension); } TestExtensionContainer testContainer = new TestExtensionContainer(testExtensions); return(testContainer); }
static void Main() { var testExtension = new TestExtension(); testExtension.Run(); }