public ViewModelBehaviorContextHelper() { //var fields = new FieldDefinitionCollection(); var descriptor = new DescriptorStub(); InitializationContext = new BehaviorInitializationContext(descriptor); // Is this correct? //var fieldValues = new Lazy<FieldValueHolder>(() => // fields.CreateValueHolder() //); VM = new ViewModelStub(descriptor); IBehaviorContext ctx = VM.Kernel; ContextMock = new Mock <IBehaviorContext>(); ContextMock .Setup(x => x.FieldValues) .Returns(ctx.FieldValues); ContextMock .Setup(x => x.VM) .Returns(VM); Context = ContextMock.Object; }
public ContextTestHelper(IViewModel viewModel = null, IVMPropertyDescriptor property = null) { if (property == null) { property = new Mock <IVMPropertyDescriptor>().Object; } var descriptor = new DescriptorStub(); InitializationContext = new BehaviorInitializationContext( descriptor, property ); var fieldValues = new Lazy <FieldValueHolder>(() => descriptor.Fields.CreateValueHolder() ); VM = viewModel ?? new ViewModelStub(); ContextMock = new Mock <IBehaviorContext>(); ContextMock .Setup(x => x.FieldValues) .Returns(() => fieldValues.Value); ContextMock .Setup(x => x.VM) .Returns(VM); Context = ContextMock.Object; Property = property; }
/// <summary> /// Use the <see cref="ViewModelStubBuilder"/> to create configured /// instances. /// </summary> public ViewModelStub(string description = null) : this( DescriptorStub .WithBehaviors(new ValidationResultAggregatorStub()) .Build(), description ) { }
public void GetItemProperties_ReturnsPropertyDescriptorCollection() { var itemTypeDescriptorBehavior = new TypeDescriptorProviderBehavior(); var itemDescriptor = DescriptorStub .WithBehaviors(itemTypeDescriptorBehavior) .Build(); var ownerProperty = PropertyStub .WithBehaviors(new ItemDescriptorProviderBehavior(itemDescriptor)) .Build(); var ownerVM = ViewModelStub .WithProperties(ownerProperty) .Build(); var collection = new VMCollection <IViewModel>(ViewModelStub.Build(), ownerProperty); Assert.AreSame(itemTypeDescriptorBehavior.PropertyDescriptors, collection.GetItemProperties(null)); }