public void MapValueAdds() { var instance = CollectionMapper <MyOptions, int> .Create(opt => opt.Collection); var options = new MyOptions(); instance.MapValue(options, 10); options.Collection.Single().ShouldBe(10); }
public void MapValueWithNullCollectionThrows() { var myOptions = new MyOptions { Collection = null }; var instance = CollectionMapper <MyOptions, int> .Create(opt => opt.Collection); Should.Throw <ConfigurationException>(() => instance.MapValue(myOptions, 0)); }
public void MapValueWithFaultyAddThrows() { var collectionMock = new Mock <ICollection <int> >(); collectionMock.Setup(m => m.Add(It.IsAny <int>())).Throws <Exception>(); var myOptions = new MyOptions { Collection = collectionMock.Object }; var instance = CollectionMapper <MyOptions, int> .Create(opt => opt.Collection); Should.Throw <ConfigurationException>(() => instance.MapValue(myOptions, 0)); }
/// <summary> /// Maps one or more argument values to the collection specified by the expression. /// </summary> /// <param name="expression">Expression that identifies the collection.</param> /// <returns>Configuration.</returns> public MultiValueArgumentConfiguration <TOptions, TValue> ToCollection( Expression <Func <TOptions, ICollection <TValue> > > expression) { Using(CollectionMapper <TOptions, TValue> .Create(expression)); return(Configuration); }
public void CreateReturnsMultivaluedMapper() { CollectionMapper <MyOptions, int> .Create(opt => opt.Collection).MultiValued.ShouldBeTrue(); }
public void CreateReturnsInstance() { CollectionMapper <MyOptions, int> .Create(opt => opt.Collection).ShouldNotBeNull(); }