public void ConvertToDictionaryParametersAndBackSucceeds() { // Arrange var stringProperty = "arbitrary-string"; var intProperty = 42; var networkCredentialProperty = new NetworkCredential("arbitrary-user", "arbitrary-password", "arbitrary-domain"); var arbitraryObject = new ArbitraryObject { StringProperty = stringProperty, IntProperty = intProperty, NetworkCredentialProperty = networkCredentialProperty }; var sut = new DictionaryParameters(); // Act var resultDictionaryParameters = sut.Convert(arbitraryObject); var result = resultDictionaryParameters.Convert <ArbitraryObject>(); // Assert Assert.AreEqual(arbitraryObject.StringProperty, result.StringProperty); Assert.AreEqual(arbitraryObject.IntProperty, result.IntProperty); Assert.AreEqual(arbitraryObject.NetworkCredentialProperty, result.NetworkCredentialProperty); }
public void Setup() { obj1 = new ArbitraryObject(1, "test"); // // threads interact with some object - either // Thread thread1 = new Thread(new ThreadStart(delegate () // { // for (int i = 0; i < iterations; i++) // { // CacheAccessSingleton.Instance.GetOrCreate(() => obj1.UselessMethod(1, 2)); // // check that object is not out of synch due to other thread // if (bad()) // { // failed = true; // } // } // })); // Thread thread2 = new Thread(new ThreadStart(delegate () // { // for (int i = 0; i < iterations; i++) // { // CacheAccessSingleton.Instance.GetOrCreate(() => obj1.UselessMethod(1, 2)); // // check that object is not out of synch due to other thread // if (bad()) // { // failed = true; // } // } // })); // thread1.Start(); // thread2.Start(); // thread1.Join(); // thread2.Join(); }
protected override void LoadDialogExtention() { var iDisplay = new ArbitraryObject(); AddObjectToUi(iDisplay, nextAction: () => { RemoveObjectFromUi(iDisplay); StartNextAction(); }, backAction: () => { RemoveObjectFromUi(iDisplay); MoveBackToPrevious(); }); }
static async Task Main(string[] args) { // Create a service Collection for registration // We will not create the full implementation for DI here var serviceProvider = new ServiceCollection(); var obj1 = new ArbitraryObject(1, "test"); CacheAccessSingleton.Instance.GetOrCreate(() => obj1.UselessMethod(1, 2)); CacheAccessSingleton.Instance.GetOrCreate(() => obj1.UselessMethod(1, 3)); var builder = new HostBuilder().ConfigureServices(services => { // The following does not register properly // services.AddHostedService<BackgroundService>(); // Other way to register a singleton directly through // Dependency Injection services.AddSingleton <ISimpleCache, SimpleCache>(); }); await builder.RunConsoleAsync(); }
public void ConvertToDictionaryParametersSucceeds() { // Arrange var stringProperty = "arbitrary-string"; var intProperty = 42; var networkCredentialProperty = new NetworkCredential("arbitrary-user", "arbitrary-password", "arbitrary-domain"); var arbitraryObject = new ArbitraryObject(); arbitraryObject.StringProperty = stringProperty; arbitraryObject.IntProperty = intProperty; arbitraryObject.NetworkCredentialProperty = networkCredentialProperty; var sut = new DictionaryParameters(); // Act var result = sut.Convert(arbitraryObject); // Assert Assert.AreEqual(arbitraryObject.StringProperty, result["StringProperty"]); Assert.AreEqual(arbitraryObject.IntProperty, result["IntProperty"]); Assert.AreEqual(arbitraryObject.NetworkCredentialProperty, result["NetworkCredentialProperty"]); }