public void TestSetup() { Mock <IEngineConfigurationType> type = new Mock <IEngineConfigurationType>(); type.SetupGet(x => x.RegisteredType).Returns(typeof(SimpleUser)); ObjectBuilder builder = new ObjectBuilder(type.Object); builder.AddAction( new ObjectPropertySetFromSourceAction( ReflectionHelper.GetMember <SimpleUser>(x => x.FirstName) as EngineTypePropertyMember, new SimpleDataSource(mTestPropertyValue) )); builder.AddAction( new ObjectPropertySetFromSourceAction( ReflectionHelper.GetMember <SimpleUser>(x => x.LastName) as EngineTypePropertyMember, new SimpleDataSource(mTestPropertyValue) )); builder.AddAction( new ObjectPropertySetFromSourceAction( ReflectionHelper.GetMember <SimpleUser>(x => x.EmailAddress) as EngineTypePropertyMember, new SimpleDataSource(mTestPropertyValue) )); Mock <IGenerationConfiguration> builderRepository = new Mock <IGenerationConfiguration>(); builderRepository.Setup(x => x.GetBuilderForType(typeof(SimpleUser))).Returns(builder); builderRepository.SetupGet(x => x.RecursionLimit).Returns(10); mGenerationContext = new GenerationContext(builderRepository.Object); mMethodGenerator = new ObjectGenerator <SimpleMethodClass>( mGenerationContext, builder); mUserGenerator = new ObjectGenerator <SimpleUser>(mGenerationContext, builder); }
public void ClearActions_RemovesAllActions() { Mock <IEngineConfigurationType> type = new Mock <IEngineConfigurationType>(); type.SetupGet(x => x.RegisteredType).Returns(typeof(SimpleUser)); ObjectBuilder builder = new ObjectBuilder(type.Object); Mock <IObjectAction> actionMock = new Mock <IObjectAction>(); Mock <IObjectAction> actionMock2 = new Mock <IObjectAction>(); builder.AddAction(actionMock.Object); builder.AddAction(actionMock2.Object); builder.ClearActions(); Assert.AreEqual(0, builder.Actions.Count()); }
public void AddAction_AddsAction() { Mock <IEngineConfigurationType> type = new Mock <IEngineConfigurationType>(); type.SetupGet(x => x.RegisteredType).Returns(typeof(SimpleUser)); ObjectBuilder builder = new ObjectBuilder(type.Object); Mock <IObjectAction> actionMock = new Mock <IObjectAction>(); builder.AddAction(actionMock.Object); Assert.AreEqual(1, builder.Actions.Count(x => x == actionMock.Object)); }
public void Create_Wraps_Context_With_TypeContext() { var builderRepository = new Mock <IGenerationConfiguration>(); builderRepository.SetupGet(x => x.RecursionLimit).Returns(10); IGenerationContextNode parent = new Mock <IGenerationContextNode>().Object; GenerationContext context = new GenerationContext(builderRepository.Object, parent); Mock <IObjectAction> actionMock = new Mock <IObjectAction>(); ObjectBuilder builder = new ObjectBuilder(new EngineConfigurationType(typeof(SimpleUser))); builder.AddAction(actionMock.Object); builder.CreateObject(context); actionMock.Verify( x => x.Enact(It.Is <IGenerationContext>(y => y.Node is TypeGenerationContextNode), It.IsAny <SimpleUser>()), Times.Once()); }
public void CreateObject_AppliesActionsToObject() { Mock <IEngineConfigurationType> type = new Mock <IEngineConfigurationType>(); type.SetupGet(x => x.RegisteredType).Returns(typeof(SimpleUser)); ObjectBuilder builder = new ObjectBuilder(type.Object); Mock <IObjectAction> actionMock = new Mock <IObjectAction>(); Object obj = null; actionMock.Setup(x => x.Enact(It.IsAny <IGenerationContext>(), It.IsAny <Object>())) .Callback((IGenerationSession session, Object enactObject) => { obj = enactObject; }); builder.AddAction(actionMock.Object); Object createdObject = builder.CreateObject(CreateDummyContext()); Assert.AreEqual(obj, createdObject); }