/// <summary> /// Check that the Get<T>() method throws an exception /// when it contains no data of the requested type. /// </summary> protected void TypedMap_GetByTypeNoMatch() { string dataToStore = "TEST"; ITypedKey <string> key = new TypedKey <string>("datakey"); _map.Add(key, dataToStore); var result = _map.Get <int>(); }
/// <summary> /// Check that an <see cref="InvalidCastException"/> is thrown if the /// data is not of the expected type. /// </summary> protected void TypedMap_WrongKeyType() { KeyValuePair <int, string> dataToStore1 = new KeyValuePair <int, string>(1, "testdata"); ITypedKey <KeyValuePair <int, string> > key1 = new TypedKey <KeyValuePair <int, string> >("datakey"); _map.Add(key1, dataToStore1); ITypedKey <string> key2 = new TypedKey <string>("datakey"); var result = _map.Get(key2); }
/// <summary> /// Check that the Get<T>() method works as expected. /// </summary> protected void TypedMap_GetByType() { string dataToStore = "TEST"; ITypedKey <string> key = new TypedKey <string>("datakey"); _map.Add(key, dataToStore); var result = _map.Get <string>(); Assert.AreEqual("TEST", result); }
/// <summary> /// Check that a null value can be stored and retrieved successfully. /// </summary> protected void TypedMap_NullValue() { List <string> dataToStore = null; ITypedKey <List <string> > key = new TypedKey <List <string> >("datakey"); _map.Add(key, dataToStore); var result = _map.Get(key); Assert.IsNull(result); }
public async Task Test_EventPubSub_PubSub() { TypedKey <int> key = "test_key"; var expected = new Randomizer().Next(); var pubsub = new EventPubSub(); await pubsub.Sub(key, data => { Assert.AreEqual(expected, data); Assert.Pass(); return(default); });
/// <summary> /// Add an item to the map and retrieve it. /// </summary> protected void TypedMap_AddRetrieve() { string dataToStore = "testdata"; ITypedKey <string> key = new TypedKey <string>("datakey"); _map.Add(key, dataToStore); var result = _map.Get(key); Assert.AreEqual(dataToStore, result); }
/// <summary> /// Initialized an instance of <see cref="ConfigServiceBase{TSettings}"/> /// </summary> /// <param name="filePath">Path to the file where the settings are serialized/deserialized to and from</param> /// <param name="serializer">Serializer which will be used</param> /// <param name="pubSub">Pubsub implementation for signaling when settings are updated</param> /// <param name="changeKey">Key used to signal changed event</param> protected ConfigServiceBase(string filePath, IConfigSeria serializer, IPubSub pubSub, TypedKey <TSettings> changeKey) { _filePath = filePath; _serializer = serializer; _pubSub = pubSub; _changeKey = changeKey; Load(); _pubSub.Sub(_changeKey, OnChangePublished); }
/// <summary> /// Check that the Get<T>() method throws an exception /// when it contains multiple instances of the requested type. /// </summary> protected void TypedMap_GetByTypeMultiMatch() { string dataToStore = "TEST"; ITypedKey <string> key1 = new TypedKey <string>("datakey1"); ITypedKey <string> key2 = new TypedKey <string>("datakey2"); _map.Add(key1, dataToStore); _map.Add(key2, dataToStore); var result = _map.Get <string>(); }
/// <summary> /// Add a complex value type to the map and retrieve it. /// </summary> protected void TypedMap_ComplexValueType() { KeyValuePair <int, string> dataToStore = new KeyValuePair <int, string>(1, "testdata"); ITypedKey <KeyValuePair <int, string> > key = new TypedKey <KeyValuePair <int, string> >("datakey"); _map.Add(key, dataToStore); var result = _map.Get(key); Assert.IsTrue(result.Key == dataToStore.Key && result.Value == dataToStore.Value); }
private APCMap <int> GetStackDepthMap(Subroutine subroutine) { APCMap <int> result; var key = new TypedKey("stackDepthKey"); if (!subroutine.TryGetValue(key, out result)) { result = ComputeStackDepthMap(subroutine); subroutine.Add(key, result); } return(result); }
public void FlowData_AddDataTypedKey_GetDataElement() { _flowData.Process(); var element = new TestElement(); var typedKey = new TypedKey <TestElementData>(element.ElementDataKey); TestElementData data = _flowData.GetOrAdd( typedKey, (p) => new TestElementData(p)); var result = _flowData.GetFromElement(element); Assert.AreSame(data, result); }
/// <summary> /// Test that the TryGetValue method returns true and outputs /// the associated value when a valid key is supplied. /// </summary> protected void TypedMap_TryGetValue_GoodKey_String() { string dataToStore = "TEST"; ITypedKey <string> key1 = new TypedKey <string>("datakey1"); _map.Add(key1, dataToStore); string value = ""; var result = _map.TryGetValue(key1, out value); Assert.IsTrue(result); Assert.AreEqual(dataToStore, value); }
public void FlowData_AddDataTypedKey_GetDataTypedKey() { _flowData.Process(); string key = "key"; var typedKey = new TypedKey <TestElementData>(key); TestElementData data = _flowData.GetOrAdd( typedKey, (p) => new TestElementData(p)); var result = _flowData.Get(typedKey); Assert.AreSame(data, result); }
/// <summary> /// Check that the Get<T>() method works as expected when /// the requested type is an interface that the stored type implements. /// </summary> protected void TypedMap_GetByTypeInterface() { List <string> dataToStore = new List <string>() { "TEST" }; ITypedKey <List <string> > key = new TypedKey <List <string> >("datakey"); _map.Add(key, dataToStore); var result = _map.Get <IReadOnlyList <string> >(); Assert.AreEqual(1, result.Count); }
/// <summary> /// Test that the TryGetValue method returns false and outputs /// the default value when a key is supplied with a name that /// does exist in the map but with an mismatched type. /// </summary> protected void TypedMap_TryGetValue_BadKeyType_String() { string dataToStore = "TEST"; ITypedKey <string> key1 = new TypedKey <string>("datakey1"); ITypedKey <int> key2 = new TypedKey <int>("datakey1"); _map.Add(key1, dataToStore); int value; var result = _map.TryGetValue(key2, out value); Assert.IsFalse(result); Assert.AreEqual(0, value); }
/// <summary> /// Add an object to the map and then overwrite it using a key with /// the same name but a different type. /// Retrieve the object using the key and check that it contains /// the object that was used to overwrite the initial data. /// </summary> protected void TypedMap_Overwrite() { KeyValuePair <int, string> dataToStore1 = new KeyValuePair <int, string>(1, "testdata"); ITypedKey <KeyValuePair <int, string> > key1 = new TypedKey <KeyValuePair <int, string> >("datakey"); _map.Add(key1, dataToStore1); string dataToStore2 = "testdata"; ITypedKey <string> key2 = new TypedKey <string>("datakey"); _map.Add(key2, dataToStore2); var result = _map.Get(key2); Assert.AreEqual(dataToStore2, result); }
/// <summary> /// Test that the TryGetValue method returns true and outputs /// the associated value when a valid key is supplied and /// the key corresponds to a complex type. /// </summary> protected void TypedMap_TryGetValue_GoodKey_ComplexType() { List <string> dataToStore = new List <string>() { "TEST" }; ITypedKey <List <string> > key1 = new TypedKey <List <string> >("datakey1"); _map.Add(key1, dataToStore); List <string> value; var result = _map.TryGetValue(key1, out value); Assert.IsTrue(result); Assert.AreEqual(dataToStore[0], value[0]); }
/// <summary> /// Add a complex reference type to the map and retrieve it. /// </summary> protected void TypedMap_ComplexReferenceType() { List <string> dataToStore = new List <string>() { "a", "b", "c" }; ITypedKey <List <string> > key = new TypedKey <List <string> >("datakey"); _map.Add(key, dataToStore); var result = _map.Get(key); Assert.AreEqual(3, result.Count); Assert.IsTrue(result.Contains("a")); Assert.IsTrue(result.Contains("b")); Assert.IsTrue(result.Contains("c")); }
/// <summary> /// Test that the TryGetValue method returns false and outputs /// the default value when a key is supplied with a name that /// does exist in the map but with an mismatched type. /// </summary> protected void TypedMap_TryGetValue_BadKeyType_ComplexType() { List <string> dataToStore = new List <string>() { "TEST" }; ITypedKey <List <string> > key1 = new TypedKey <List <string> >("datakey1"); ITypedKey <Dictionary <string, int> > key2 = new TypedKey <Dictionary <string, int> >("datakey1"); _map.Add(key1, dataToStore); Dictionary <string, int> value; var result = _map.TryGetValue(key2, out value); Assert.IsFalse(result); Assert.AreEqual(null, value); }
/// <summary> /// Add two items to the map with different types and different keys. /// Retrieve them both and check that the values are as expected. /// </summary> protected void TypedMap_MultipleDataObjects() { KeyValuePair <int, string> dataToStore1 = new KeyValuePair <int, string>(1, "testdata"); ITypedKey <KeyValuePair <int, string> > key1 = new TypedKey <KeyValuePair <int, string> >("datakey1"); _map.Add(key1, dataToStore1); string dataToStore2 = "testdata"; ITypedKey <string> key2 = new TypedKey <string>("datakey2"); _map.Add(key2, dataToStore2); var result1 = _map.Get(key1); var result2 = _map.Get(key2); Assert.IsTrue(result1.Key == dataToStore1.Key && result1.Value == dataToStore1.Value); Assert.AreEqual(dataToStore2, result2); }
/// <summary>Load the object and verify the outcome.</summary> private void VerifyLoad <TKey, TRecord>(Context context, string dataSetName, TypedKey <TKey, TRecord> key) where TKey : TypedKey <TKey, TRecord>, new() where TRecord : TypedRecord <TKey, TRecord> { // Get dataset and try loading the record var dataSet = context.GetDataSet(dataSetName); TRecord record = context.LoadOrNull(key, dataSet); if (record == null) { // Not found context.Log.Verify($"Record {key} in dataset {dataSetName} not found."); } else { // Found, also checks that the key matches Assert.True(record.Key == key.ToString(), $"Record found for key={key} in dataset {dataSetName} " + $"has wrong key record.Key={record.Key}"); context.Log.Verify( $"Record {key} in dataset {dataSetName} found and " + $"has Type={record.GetType().Name}."); } }
static void server_registration(ContainerBuilder builder) { //builder.RegisterType<InMemoryDatabase>().As<PersonRepository>().SingleInstance(); builder.RegisterType <DB4OPersonRepository>().As <PersonRepository>().SingleInstance(); builder.RegisterType <ScopedContext>().As <Context>().SingleInstance(); //builder.Register(x => new SimpleContext(new Hashtable())).As<Context>().SingleInstance(); builder.RegisterType <PerThreadScopedStorage>().As <ScopedStorage>(); builder.RegisterType <CurrentThread>().As <ApplicationThread>(); builder.Register(x => { return(Lazy.load(() => { var context = Resolve.the <Context>(); var key = new TypedKey <Connection>(); return context.value_for(key); })); }); var unit_of_work_interceptor = new UnitOfWorkInterceptor(new DB40UnitOfWorkFactory(new DB4OConnectionFactory(), Lazy.load <Context>())); builder.RegisterProxy <Handles <FamilyMemberToAdd>, AddNewFamilyMemberHandler>(unit_of_work_interceptor); builder.RegisterProxy <Handles <FindAllFamily>, FindAllFamilyHandler>(unit_of_work_interceptor); builder.RegisterProxy <Handles <FindAllIncome>, FindAllIncomeHandler>(unit_of_work_interceptor); builder.RegisterProxy <Handles <AddIncomeCommandMessage>, AddIncomeCommandMessageHandler>(unit_of_work_interceptor); var run_in_background = new RunInBackgroundInterceptor(Lazy.load <CommandProcessor>()); builder.RegisterProxy <Handles <StockPriceRequestQuery>, StockPriceRequestQueryHandler>(run_in_background); builder.RegisterType <ConfigureServiceMappings>().As <NeedStartup>(); //builder.RegisterType<StubLookupService>().As<StockPriceLookupService>(); builder.RegisterType <GoogleLookupService>().As <StockPriceLookupService>(); new DB4OBootstrapper().run(); }
public bool Equals(TypedKey other) { return(Equals(other.key, this.key)); }
public bool TryGetValue <T> (TypedKey key, out T value) { return(this.properties.TryGetValue(key, out value)); }
public bool Equals (TypedKey other) { return Equals (other.key, this.key); }
public bool Contains(TypedKey key) { return(this.properties.Contains(key)); }
public void Add <T> (TypedKey key, T value) { this.properties.Add(key, value); }
/// <summary> /// Check that the map will throw an exception if there is no /// data for the given key. /// </summary> protected void TypedMap_NoData() { ITypedKey <string> key = new TypedKey <string>("datakey"); var result = _map.Get(key); }