public void CanMapInterfacesToConcreteTypes() { MockBuilderContext ctx = new MockBuilderContext(); TypeMappingStrategy strategy = new TypeMappingStrategy(); ctx.Policies.Set <ITypeMappingPolicy>(new TypeMappingPolicy(typeof(SalesFoo), null), typeof(IFoo), "sales"); ctx.Policies.Set <ITypeMappingPolicy>(new TypeMappingPolicy(typeof(Foo), null), typeof(IFoo), "marketing"); ctx.InnerChain.Add(strategy); MockStrategy mock = new MockStrategy(); ctx.InnerChain.Add(mock); strategy.BuildUp <IFoo>(ctx, null, "sales"); Assert.IsTrue(mock.WasRun); Assert.AreEqual(typeof(SalesFoo), mock.IncomingType); mock.WasRun = false; mock.IncomingType = null; strategy.BuildUp <IFoo>(ctx, null, "marketing"); Assert.IsTrue(mock.WasRun); Assert.AreEqual(typeof(Foo), mock.IncomingType); }
public void TestSelectionStrategy() { var data = new byte[TestSize]; for (int i = 0; i < TestSize; i++) { data[i] = (byte)i; } var compressors = new ICompressionStrategy[TestSize]; for (int i = 0; i < TestSize; i++) { compressors[i] = new MockStrategy((byte)i); } var strategy = new BruteCompressionStrategy(compressors); var memStream = new MemoryStream(); var compressingStream = new BruteCompressingStream(new BinaryWriter(memStream), 1, strategy); compressingStream.Write(data, 0, TestSize); compressingStream.Flush(); Assert.AreEqual(memStream.Position, TestSize * 4); Console.WriteLine("Compressed {0} to {1} ({2}%)", TestSize, memStream.Position, memStream.Position * 100 / TestSize); }
public TypeMocker(IWindsorContainer container, TypeHelpers typeHelpers, MockStrategy mockStrategy) { _container = container; _typeHelpers = typeHelpers; _mockStrategy = mockStrategy; _registeredParametersTypes = new List <Type>(); _typeOfGenericMock = typeof(Mock <>); }
public void PassingAnExistingObjectRunsLaterStrategies() { MockBuilderContext ctx = CreateContext(); MockStrategy mockStrategy = new MockStrategy(); ctx.InnerChain.Add(mockStrategy); object existing = new object(); object result = ctx.HeadOfChain.BuildUp(ctx, typeof(object), existing, null); Assert.IsTrue(mockStrategy.WasRun); }
public void TearDownWithNoLocatorDoesNotThrow() { IBuilder <BuilderStage> builder = new BuilderBase <BuilderStage>(); Locator locator = null; MockStrategy strategy = new MockStrategy(); builder.Strategies.Add(strategy, BuilderStage.PreCreation); builder.TearDown <object>(locator, ""); }
public void BuildUpWithNoLocatorDoesNotThrow() { IBuilder <BuilderStage> builder = new WCSFBuilderBase <BuilderStage>(); Locator locator = null; MockStrategy strategy = new MockStrategy(); builder.Strategies.Add(strategy, BuilderStage.PreCreation); builder.BuildUp <object>(locator, null, null); }
public void CanAddStrategiesToBuilder() { Builder builder = new Builder(); MockStrategy strategy = new MockStrategy(); Locator locator = CreateLocator(); builder.Strategies.Add(strategy, BuilderStage.PostInitialization); builder.BuildUp(locator, typeof(object), null, null); Assert.IsTrue(strategy.WasCalled); }
public void PassingAnExistingObjectRunsLaterStrategies() { MockBuilderContext ctx = CreateContext(); MockStrategy mockStrategy = new MockStrategy(); ctx.InnerChain.Add(mockStrategy); object existing = new object(); object result = ctx.HeadOfChain.BuildUp(ctx, typeof(object), existing, null); Assert.IsTrue(mockStrategy.WasRun); }
public void AddingStrategyByAnyStageRunsItDuringBuild() { IBuilder <BuilderStage> builder = new BuilderBase <BuilderStage>(); Locator locator = CreateLocator(); MockStrategy strategy = new MockStrategy(); builder.Strategies.Add(strategy, BuilderStage.PreCreation); builder.BuildUp <object>(locator, null, null); Assert.IsTrue(strategy.BuildWasRun); }
public void TestExecuteStrategy() { string code = "rb1710"; int start = 20170601; int end = 20170603; IStrategyExecutor_Single executor = StrategyTestUtils.CreateExecutor_CodePeriod(code, start, end); MockStrategy strategy = new MockStrategy(); executor.Strategy = strategy; executor.OnFinished += Executor_OnFinished; executor.Execute(); //AssertUtils.AssertEqual_List("executorhistory", GetType(), strategy.PrintData); }
public void UnbuildStrategiesRunInOppositeOrderOfBuild() { IBuilder <BuilderStage> builder = new BuilderBase <BuilderStage>(); Locator locator = CreateLocator(); MockStrategy strategy = new MockStrategy(); builder.Strategies.Add(new MockStrategy("Creation "), BuilderStage.Creation); builder.Strategies.Add(new MockStrategy("PostInitialization "), BuilderStage.PostInitialization); builder.Strategies.Add(new MockStrategy("PreCreation "), BuilderStage.PreCreation); builder.Strategies.Add(new MockStrategy("Initialization "), BuilderStage.Initialization); string s = builder.TearDown(locator, ""); Assert.AreEqual("PostInitialization Initialization Creation PreCreation ", s); }
public void StrategyStagesRunInProperOrder() { IBuilder <BuilderStage> builder = new BuilderBase <BuilderStage>(); Locator locator = CreateLocator(); MockStrategy strategy = new MockStrategy(); builder.Strategies.Add(new MockStrategy("Creation "), BuilderStage.Creation); builder.Strategies.Add(new MockStrategy("PostInitialization "), BuilderStage.PostInitialization); builder.Strategies.Add(new MockStrategy("PreCreation "), BuilderStage.PreCreation); builder.Strategies.Add(new MockStrategy("Initialization "), BuilderStage.Initialization); string s = builder.BuildUp <string>(locator, null, null); Assert.AreEqual("PreCreation Creation Initialization PostInitialization ", s); }
public void CanMapInterfacesToConcreteTypes() { MockBuilderContext ctx = new MockBuilderContext(); TypeMappingStrategy strategy = new TypeMappingStrategy(); ctx.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof(SalesFoo), null), typeof(IFoo), "sales"); ctx.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof(Foo), null), typeof(IFoo), "marketing"); ctx.InnerChain.Add(strategy); MockStrategy mock = new MockStrategy(); ctx.InnerChain.Add(mock); strategy.BuildUp<IFoo>(ctx, null, "sales"); Assert.IsTrue(mock.WasRun); Assert.AreEqual(typeof(SalesFoo), mock.IncomingType); mock.WasRun = false; mock.IncomingType = null; strategy.BuildUp<IFoo>(ctx, null, "marketing"); Assert.IsTrue(mock.WasRun); Assert.AreEqual(typeof(Foo), mock.IncomingType); }
public TestConfiguration(MockStrategy mockStrategy) { MockStrategy = mockStrategy; }