public void ThreadingSafetySimpleTest() { var results = new ConcurrentDictionary <int, bool>(); const int threadsCount = 100; var threads = new List <Thread>(threadsCount); for (int i = 0; i < threadsCount; i++) { var thread = new Thread( o => { var password = o.ToString(); var number = (int)o; var exposed = Exposed.From(new ClassWithHiddenMethods()); Thread.Sleep(threadsCount - number); exposed.SetPassword(password); Thread.Sleep(threadsCount - number); string read = exposed.Password; results[number] = password == read; }); threads.Add(thread); thread.Start(i); } for (int i = 0; i < threadsCount; i++) { threads[i].Join(); Assert.True(results[i]); } Assert.AreEqual(threadsCount, results.Count); }
private static void RegisterVectorReader() { //ThreadHelper.ThrowIfNotOnUIThread(); var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE)); if (dte.ActiveDocument == null) { return; } var uiObject = Exposed.From(((dynamic)dte.ActiveDocument).ActiveWindow.Object).Content; //ManifestDesignerUserControlProxy mduc = (ManifestDesignerUserControlProxy) uiObject; if (!uiObject.IsLoading) { Mduc_Loaded((object)uiObject); return; } var pd = DependencyPropertyDescriptor.FromProperty(ManifestDesignerUserControlProxy.IsLoadingProperty, typeof(ManifestDesignerUserControlProxy)); pd.AddValueChanged((object)uiObject, Mduc_Loaded); }
public static IViewEngineManager GetViewManager() { var config = new MonoRailConfiguration(); config.ViewEngineConfig.ViewEngines.Add(new ViewEngineInfo(typeof(BooViewEngine), false)); config.ViewEngineConfig.ViewPathRoot = Path.Combine(@"..\..\..\AdminInterface", "Views"); var provider = new FakeServiceProvider(); var loader = new FileAssemblyViewSourceLoader(config.ViewEngineConfig.ViewPathRoot); loader.AddAssemblySource(new AssemblySourceInfo("Common.Web.Ui", "Common.Web.Ui.Views")); provider.Services.Add(typeof(IMonoRailConfiguration), config); provider.Services.Add(typeof(IViewSourceLoader), loader); var manager = new DefaultViewEngineManager(); manager.Service(provider); var options = Exposed.From(manager).viewEnginesFastLookup[0].Options; var namespaces = options.NamespacesToImport; namespaces.Add("Boo.Lang.Builtins"); namespaces.Add("AdminInterface.Helpers"); namespaces.Add("Common.Web.Ui.Helpers"); options.AssembliesToReference.Add(Assembly.Load("AdminInterface")); return(manager); }
public void MethodTest() { dynamic exposed = Exposed.From(Type.GetType("TestSubjects.StaticClass, TestSubjects")); decimal convertValue = exposed.ConvertValue(8); Assert.AreEqual(convertValue, exposed.Value); }
private void QueryBlockTest_WithNonExistingGenerationTransaction_ShouldBeOrphaned() { // test case: coin reports generation transaction hash as invalid. var block = new PersistedBlock(1, false, false, false, "BLOCK_HASH", "TX_HASH", 0, 0, DateTime.Now); _daemonClient.GetBlock("BLOCK_HASH").Returns(info => new Block { Tx = new List <string> { "TX_HASH" } }); _daemonClient.GetTransaction("TX_HASH").Returns(x => { throw new RpcErrorException(new RpcErrorResponse { Error = new RpcError { Code = -5 // 'Invalid or non-wallet transaction id' } }); }); // query the block. var exposed = Exposed.From(new BlockProcessor(_poolConfig, _daemonClient, _storageLayer)); exposed.QueryBlock(block); // block should be marked as orphaned. block.Status.Should().Equal(BlockStatus.Orphaned); }
public void Return_updated_addresses() { var client = DataMother.CreateTestClientWithAddressAndUser(); var user = client.Users[0]; var address = client.Addresses[0]; user.AvaliableAddresses.Add(address); var userAccount = user.Accounting; userAccount.IsFree = true; var addressAccount = address.Accounting; addressAccount.IsFree = true; session.Save(client); //анонимные объекты internal для того что бы получить доступ к полям использую exposed object var result = Exposed.From(controller.Update(userAccount.Id, null, false, null, null, null, null)); session.Refresh(addressAccount); Assert.That(addressAccount.IsFree, Is.False); Assert.That(result.message, Is.EqualTo(String.Format("Следующие адреса доставки стали платными: {0}", address.Value))); Assert.That(result.accounts.Length, Is.EqualTo(1)); var resultAccount = Exposed.From(result.accounts[0]); Assert.That(resultAccount.id, Is.EqualTo(addressAccount.Id)); Assert.That(resultAccount.free, Is.EqualTo(addressAccount.IsFree)); }
private void QueryBlockTest_WithIncorrectPoolOutputAccount_ShouldBeOrphaned() { // test case: generation transaction output doesn't match pool output account. var block = new PersistedBlock(1, false, false, false, "BLOCK_HASH", "TX_HASH", 0, 0, DateTime.Now); _daemonClient.GetBlock("BLOCK_HASH").Returns(info => new Block { Tx = new List <string> { "TX_HASH" } }); _daemonClient.GetTransaction("TX_HASH").Returns(info => new Transaction { Details = new List <TransactionDetail> { new TransactionDetail { Account = "DIFFERENT_ACCOUNT" } } }); // query the block. var exposed = Exposed.From(new BlockProcessor(_poolConfig, _daemonClient, _storageLayer)); exposed._poolAccount = "POOL_ACCOUNT"; exposed.QueryBlock(block); // block should be marked as orphaned. block.Status.Should().Equal(BlockStatus.Orphaned); }
private void QueryBlockTest_ShouldSetReward() { // test case: set block reward based on pool output value. var block = new PersistedBlock(1, false, false, false, "BLOCK_HASH", "TX_HASH", 0, 0, DateTime.Now); _poolConfig.Wallet.Adress.Returns("POOL_ADDRESS"); _daemonClient.GetBlock("BLOCK_HASH").Returns(info => new Block { Tx = new List <string> { "TX_HASH" } }); _daemonClient.GetTransaction("TX_HASH").Returns(info => new Transaction { Details = new List <TransactionDetail> { new TransactionDetail { Address = "POOL_ADDRESS", Amount = 999 } } }); // query the block. var exposed = Exposed.From(new BlockProcessor(_poolConfig, _daemonClient, _storageLayer)); exposed.QueryBlock(block); // block reward should be set to 999 block.Reward.Should().Equal((decimal)999); }
private void QueryBlockTest_WithOprhanedPoolOutputCategory_ShouldGetOrphaned() { // test case: we supply a pending block which should stay as pending as pool output category is still 'immature'. var block = new PersistedBlock(1, false, false, false, "BLOCK_HASH", "TX_HASH", 0, 0, DateTime.Now); _poolConfig.Wallet.Adress.Returns("POOL_ADDRESS"); _daemonClient.GetBlock("BLOCK_HASH").Returns(info => new Block { Tx = new List <string> { "TX_HASH" } }); _daemonClient.GetTransaction("TX_HASH").Returns(info => new Transaction { Details = new List <TransactionDetail> { new TransactionDetail { Address = "POOL_ADDRESS", Category = "orphan" } } }); // query the block. var exposed = Exposed.From(new BlockProcessor(_poolConfig, _daemonClient, _storageLayer)); exposed.QueryBlock(block); // block should still stay as pending block.Status.Should().Equal(BlockStatus.Orphaned); }
/// <summary> /// Ideally, I would register this using the MEF Export, but that isn't working and I'm not sure why... /// /// This also has the issue that any persisted notifications won't have their provider hooked up on next launch /// </summary> private static void RegisterNotificationProvider(IVsUserNotificationsManager vsUserNotificationsManager) { var exposedManager = Exposed.From(vsUserNotificationsManager); var notificationsProviders = (IDictionary <Guid, IVsUserNotificationsProvider>)exposedManager.NotificationsProviders; notificationsProviders[ExampleProvider.Guid] = new ExampleProvider(); }
public void ReturnVoidMethodTest() { dynamic exposed = Exposed.From(new ClassWithHiddenMethods()); exposed.SetPassword("new test password"); Assert.AreEqual("new test password", exposed.password); }
public void PrivateMethodTest() { dynamic exposed = Exposed.From(new ClassWithInheritedPrivateMembers()); exposed.SetPassword("test pass"); string password = exposed.Password; Assert.AreEqual("test pass", password); }
public void PropertyTest() { dynamic exposed = Exposed.From(Type.GetType("TestSubjects.StaticClass, TestSubjects")); exposed.Value = 9; decimal count = exposed.Value; Assert.AreEqual(9, count); }
public void PrivateFieldTest() { dynamic exposed = Exposed.From(new ClassWithInheritedPrivateMembers()); int count = exposed._count; Assert.AreEqual(0, count); exposed._count = 8; count = exposed.Count; Assert.AreEqual(8, count); }
private static Task <string> DownloadPlayerSourceAsync(this StreamClient streamClient, VideoId videoId, CancellationToken cancellationToken = default) { var streamClientExposed = Exposed.From(streamClient); HttpClient httpClient = streamClientExposed._httpClient; var youtubeControllerExposed = Exposed.From(streamClientExposed._controller); var watchPageExposed = Exposed.From(Exposed.From(youtubeControllerExposed.GetVideoWatchPageAsync(videoId, cancellationToken)).Result); string playerSourceUrl = watchPageExposed.TryGetPlayerSourceUrl(); return(httpClient.GetStringAsync(playerSourceUrl)); }
public void FieldTest() { dynamic exposed = Exposed.From(Type.GetType("TestSubjects.StaticClass, TestSubjects")); string testValue = exposed.testValue; Assert.AreEqual("testValue", testValue); exposed.testValue = "TestValue"; testValue = exposed.testValue; Assert.AreEqual("TestValue", testValue); }
public void FieldTest() { dynamic exposed = Exposed.From(new ClassWithHiddenMethods()); string password = exposed.password; Assert.IsNull(password); exposed.password = "******"; password = exposed.password; Assert.AreEqual("TestValue", password); }
public static TestContext GetTestContext(this ITestMethod testMethod) { // Obtain our test method options var testMethodOptions = Exposed.From(testMethod).TestMethodOptions; // Obtain our test context. var testContext = Exposed.From(testMethodOptions).TestContext as TestContext; // Return the test context return(testContext); }
public void PropertyTest() { dynamic exposed = Exposed.From(new ClassWithHiddenMethods()); int count = exposed.Count; Assert.AreEqual(0, count); exposed.Count = 9; count = exposed.Count; Assert.AreEqual(9, count); }
private static void ManifestDesignerUserControl_Loaded(object sender, RoutedEventArgs e) { ((FrameworkElement)sender).Loaded -= ManifestDesignerUserControl_Loaded; if (Exposed.From(sender).AppxDocData?.HasLoaded != true) { ((IManifestDocDataInternal)Exposed.From(sender).AppxDocData).Loaded += ManifestDocData_Loaded(sender); return; } ManifestDesignerUserControl_Loaded(sender); }
public static T GetUnboundValue <T>(this PSCmdlet cmdlet, string paramName, int unnamedPosition = -1) { var context = GetExecutionContext(cmdlet); var processor = Exposed.From(context).CurrentCommandProcessor; var parameterBinder = Exposed.From(processor).CmdletParameterBinderController; var args = Exposed.From(parameterBinder).UnboundArguments as System.Collections.IEnumerable; if (args != null) { var isSwitch = typeof(SwitchParameter) == typeof(T); var currentParameterName = string.Empty; object unnamedValue = null; var i = 0; foreach (var arg in args) { var isParameterName = Exposed.From(arg).ParameterNameSpecified; if (isParameterName != null && true.Equals(isParameterName)) { var parameterName = Exposed.From(arg).ParameterName as string; currentParameterName = parameterName; if (isSwitch && string.Equals(currentParameterName, paramName, StringComparison.OrdinalIgnoreCase)) { return((T)(object)new SwitchParameter(true)); } continue; } var parameterValue = Exposed.From(arg).ArgumentValue; if (!string.IsNullOrEmpty(currentParameterName)) { if (string.Equals(currentParameterName, paramName, StringComparison.OrdinalIgnoreCase)) { return(ConvertParameter <T>(parameterValue)); } } else if (i++ == unnamedPosition) { unnamedValue = parameterValue; } currentParameterName = string.Empty; } if (unnamedValue != null) { return(ConvertParameter <T>(unnamedValue)); } } return(default);
private static void Mduc_Loaded(object sender) { var exposed = Exposed.From(sender); var manifestDesignerUserControl = (FrameworkElement)exposed.contentPresenter.Content; if (Exposed.From(manifestDesignerUserControl).imageSetModel == null) { manifestDesignerUserControl.Loaded += ManifestDesignerUserControl_Loaded; return; } ManifestDesignerUserControl_Loaded(manifestDesignerUserControl); }
public async Task RightWindowCommandsAreOverFlyout() { await TestHost.SwitchToAppThread(); var window = await WindowHelpers.CreateInvisibleWindowAsync <FlyoutWindow>(); window.RightFlyout.IsOpen = true; var exposedWindow = Exposed.From(window); int windowCommandsZIndex = Panel.GetZIndex(exposedWindow.RightWindowCommandsPresenter); int flyoutindex = Panel.GetZIndex(window.RightFlyout); Assert.True(windowCommandsZIndex > flyoutindex); }
public void CompanyStructureRepository_GetEmployeeComponentById_UnexistingItemShouldReturnNull() { // Arrange var exposedRepository = Exposed.From(companyStructureRepository); var id = "wrong id"; var list = EmployeeComponentList; var expected = list.Where(e => e.Employee.Id.ToString() == id).FirstOrDefault(); // Act var result = exposedRepository.GetEmployeeComponentById(id); // Assert Assert.Null(result); }
public void CompanyStructureRepository_GetEmployeeComponentById_ExistingItemShouldBeFound(string id) { // Arrange var exposedRepository = Exposed.From(companyStructureRepository); var list = EmployeeComponentList; var expected = list.Where(e => e.Employee.Id.ToString() == id).FirstOrDefault(); // Act var result = exposedRepository.GetEmployeeComponentById(id); // Assert EmployeeComponent component = Assert.IsAssignableFrom <EmployeeComponent>(result); component.Employee.Should().BeEquivalentTo(expected.Employee); }
public void ProtectedMethodTest() { var exposed = Exposed.From(new ClassWithByRefParameters()); var param1 = 123; string param2 = null; var param3 = 2937842L; byte param4 = 111; int result = exposed.ProtectedMethod(param1, ref param2, ref param3, ref param4); Assert.Equal(0, result); Assert.Equal("2937842", param2); Assert.Equal(123, param4); }
private static void VisualAssetsControl_Loaded(object sender, RoutedEventArgs e) { var control = (VisualAssetsControl)sender; control.Loaded -= VisualAssetsControl_Loaded; var imageSetView = (ImageSetView)Exposed.From(control).ImageSetView; var assetGeneratorControl = (AssetGeneratorControl)Exposed.From(imageSetView).AssetGeneratorControl; if (!assetGeneratorControl.IsLoaded) { assetGeneratorControl.Loaded += AssetGeneratorControl_Loaded; } }
public async Task HiddenLeftWindowCommandsAreBelowFlyout() { await TestHost.SwitchToAppThread(); var window = await WindowHelpers.CreateInvisibleWindowAsync <FlyoutWindow>(); window.LeftWindowCommandsOverlayBehavior = WindowCommandsOverlayBehavior.Never; window.LeftFlyout.IsOpen = true; var exposedWindow = Exposed.From(window); int windowCommandsZIndex = Panel.GetZIndex(exposedWindow.LeftWindowCommandsPresenter); int flyoutindex = Panel.GetZIndex(window.LeftFlyout); Assert.True(flyoutindex < windowCommandsZIndex); }
public void EmployeeMaxSalaryVisitor_VisitEmployeeComponent_NullEmployeeCompositeShouldRaiseException() { // Arrange var exposedVisitor = Exposed.From(employeeMaxSalaryVisitor); EmployeeComponent employeeComponent = null; // Act Action act = () => exposedVisitor.VisitEmployeeComponent(employeeComponent); // Assert ArgumentNullException exception = Assert.Throws <ArgumentNullException>(act); Assert.Equal(nameof(employeeComponent), exception.ParamName); }
public async Task HiddenIconIsBelowFlyout() { await TestHost.SwitchToAppThread(); var window = await WindowHelpers.CreateInvisibleWindowAsync <FlyoutWindow>(); window.IconOverlayBehavior = OverlayBehavior.Never; window.LeftFlyout.IsOpen = true; var exposedWindow = Exposed.From(window); int iconZIndex = Panel.GetZIndex(exposedWindow.icon); int flyoutindex = Panel.GetZIndex(window.LeftFlyout); Assert.True(flyoutindex < iconZIndex); }