// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISampleInterface sample) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); app.Use(async(ctx, next) => { sample.PrintTest(); await ctx.Response.WriteAsync("From the first run"); await next(); }); app.Run(async(ctx) => { sample.PrintTest(); await ctx.Response.WriteAsync("Look we have written to the response"); }); //app.UseRouting(); //app.UseEndpoints(endpoints => //{ // endpoints.MapGet("/", async context => // { // await context.Response.WriteAsync(env.EnvironmentName); // }); //}); }
public void Sample_Property() { dynamic isolated = new DynamicMock(); isolated.GetOnlyProperty = "Hello world"; ISampleInterface result = isolated; Assert.AreEqual("Hello world", result.GetOnlyProperty); }
static void Main(string[] args) { Assembly sampleAssembly = Assembly.Load("TypeEquivalenceRuntime"); ISampleInterface sampleClass = (ISampleInterface)sampleAssembly.CreateInstance("TypeEquivalenceRuntime.SampleClass"); sampleClass.GetUserInput(); Console.WriteLine(sampleClass.UserInput); Console.WriteLine(sampleAssembly.GetName().Version.ToString()); Console.ReadLine(); }
public void Sample_MethodWithGround() { dynamic isolated = new DynamicMock(); isolated.Execute(_, _, _, _).Returns(42); ISampleInterface result = isolated; var actual = result.Execute(1, "", 10m, null); Assert.AreEqual(42, actual); }
public void CanRetrieveDecoupledType() { Container.Add <ISampleInterface, SampleClassWithInterface>(); ISampleInterface sample = Container.Get <ISampleInterface>(); Assert.NotNull(sample); Assert.IsType <SampleClassWithInterface>(sample); Assert.Equal(1, sample.DoSomething()); Container.Clear(); }
public void Sample_MethodWithOut() { dynamic isolated = new DynamicMock(); isolated.TryDoSomething(_, 42).Returns(true); ISampleInterface result = isolated; int actualOut; var actual = result.TryDoSomething("subbotnik", out actualOut); Assert.AreEqual(true, actual); Assert.AreEqual(42, actualOut); }
public void InlineAutoNSubstituteData_Should_Call_For_Each_Value( SampleEnum value, [Frozen] ISampleInterface interfaceType, SampleClass concreteType, SampleDependantClass dependantType) { value.Should().BeOneOf(SampleEnum.One, SampleEnum.Two, SampleEnum.Three); interfaceType.Should().NotBeNull(); interfaceType.IsSubstitute().Should().BeTrue(); concreteType.Should().NotBeNull(); concreteType.IsSubstitute().Should().BeFalse(); dependantType.Should().NotBeNull(); dependantType.Dependency.Should().Be(interfaceType); }
static void Main(string[] args) { AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); InterceptionConfiguration cfg = new InterceptionConfiguration(); cfg.AddInterceptor(new MefContrib.Hosting.Interception.Castle.DynamicProxyInterceptor(new CastleLoggingInterceptor())); InterceptingCatalog interceptingCatalog = new InterceptingCatalog(assemblyCatalog, cfg); CompositionContainer container = new CompositionContainer(interceptingCatalog); ISampleInterface intercepted = container.GetExportedValue <ISampleInterface>(); intercepted.Say("Hello World!"); intercepted.Say(new SayArgs("Hello World with args!")); }
public void Sample_MethodWithLambda() { dynamic isolated = new DynamicMock(); isolated.Execute(_, _, If(a => a > 0m), _).Returns(42); isolated.Execute(_, _, If(a => a < 0m), _).Returns(18); ISampleInterface result = isolated; var actual1 = result.Execute(1, "", 10m, null); var actual2 = result.Execute(1, "", -5m, null); Assert.AreEqual(42, actual1); Assert.AreEqual(18, actual2); }
public void Sample_MethodResultIsDto() { dynamic isolated = new DynamicMock(); isolated.LoadSomeDtoWithVeryLongName().Returns(new { Id = 42, Name = "subbotnik" }); ISampleInterface result = isolated; var actual = result.LoadSomeDtoWithVeryLongName(); var expected = new SomeDtoWithVeryLongName { Id = 42, Name = "subbotnik" }; Assert.AreEqual(expected, actual); }
public void CanRetrieveTypeWithDependency() { Container.Add <ISampleInterface, SampleClassWithInterface>(); Container.Add <SampleClassWithDependency>(); SampleClassWithDependency sample = Container.Get <SampleClassWithDependency>(); Assert.NotNull(sample); ISampleInterface sampleInterface = sample.GetSampleInterface(); Assert.NotNull(sampleInterface); Assert.Equal(1, sampleInterface.DoSomething()); Container.Clear(); }
public void Sample_MethodResultSimplifiedNames() { dynamic isolated = new DynamicMock(); isolated.Load_().Returns(new { _Value = 156 }); ISampleInterface result = isolated; var actual = result.LoadSomeDtoWithVeryLongName(); var expected = new SomeDtoWithVeryLongName { VeryLongPropertyButAnywayItMeansValue = 156 }; Assert.AreEqual(expected, actual); }
public CachedInterfaceSample(ISampleInterface originalImpl, Dictionary <MethodInfo, object> config) { var methods = InterfaceMethodsResolver.GetAllMethods(typeof(ISampleInterface)); var singleKeyAsync0ConfigManager = new CachedFunctionConfigurationManagerAsync_1Param <string, string>(originalImpl.SingleKeyAsync); var singleKeyAsync0ConfigFunc = (Func <ISingleKeyCachedFunctionConfigurationManagerAsync_1Param_KeySelector <string, string>, ICachedFunctionConfigurationManagerAsync_1Param <string, string> >)config[methods[0]]; _singleKeyAsync0 = singleKeyAsync0ConfigFunc(singleKeyAsync0ConfigManager).Build(); var singleKeySync1ConfigManager = new CachedFunctionConfigurationManagerSync_1Param <string, string>(originalImpl.SingleKeySync); var singleKeySync1ConfigFunc = (Func <ISingleKeyCachedFunctionConfigurationManagerSync_1Param_KeySelector <string, string>, ICachedFunctionConfigurationManagerSync_1Param <string, string> >)config[methods[1]]; _singleKeySync1 = singleKeySync1ConfigFunc(singleKeySync1ConfigManager).Build(); var singleKeyAsyncCanx2ConfigManager = new CachedFunctionConfigurationManagerAsyncCanx_1Param <string, string>(originalImpl.SingleKeyAsyncCanx); var singleKeyAsyncCanx2ConfigFunc = (Func <ISingleKeyCachedFunctionConfigurationManagerAsyncCanx_1Param_KeySelector <string, string>, ICachedFunctionConfigurationManagerAsyncCanx_1Param <string, string> >)config[methods[2]]; _singleKeyAsyncCanx2 = singleKeyAsyncCanx2ConfigFunc(singleKeyAsyncCanx2ConfigManager).Build(); var singleKeySyncCanx3ConfigManager = new CachedFunctionConfigurationManagerSyncCanx_1Param <string, string>(originalImpl.SingleKeySyncCanx); var singleKeySyncCanx3ConfigFunc = (Func <ISingleKeyCachedFunctionConfigurationManagerSyncCanx_1Param_KeySelector <string, string>, ICachedFunctionConfigurationManagerSyncCanx_1Param <string, string> >)config[methods[3]]; _singleKeySyncCanx3 = singleKeySyncCanx3ConfigFunc(singleKeySyncCanx3ConfigManager).Build(); var enumerableKeyAsync4ConfigManager = new Configuration.EnumerableKeys.CachedFunctionConfigurationManagerAsync <IEnumerable <string>, Dictionary <string, string>, string, string>(originalImpl.EnumerableKeyAsync); var enumerableKeyAsync4ConfigFunc = (Func <Configuration.EnumerableKeys.CachedFunctionConfigurationManagerAsync <IEnumerable <string>, Dictionary <string, string>, string, string>, ICachedFunctionConfigurationManagerAsync_1Param <IEnumerable <string>, Dictionary <string, string> > >)config[methods[4]]; _enumerableKeyAsync4 = enumerableKeyAsync4ConfigFunc(enumerableKeyAsync4ConfigManager).Build(); var enumerableKeySync5ConfigManager = new Configuration.EnumerableKeys.CachedFunctionConfigurationManagerSync <IEnumerable <string>, Dictionary <string, string>, string, string>(originalImpl.EnumerableKeySync); var enumerableKeySync5ConfigFunc = (Func <Configuration.EnumerableKeys.CachedFunctionConfigurationManagerSync <IEnumerable <string>, Dictionary <string, string>, string, string>, ICachedFunctionConfigurationManagerSync_1Param <IEnumerable <string>, Dictionary <string, string> > >)config[methods[5]]; _enumerableKeySync5 = enumerableKeySync5ConfigFunc(enumerableKeySync5ConfigManager).Build(); var enumerableKeyAsyncCanx6ConfigManager = new Configuration.EnumerableKeys.CachedFunctionConfigurationManagerAsyncCanx <IEnumerable <string>, Dictionary <string, string>, string, string>(originalImpl.EnumerableKeyAsyncCanx); var enumerableKeyAsyncCanx6ConfigFunc = (Func <Configuration.EnumerableKeys.CachedFunctionConfigurationManagerAsyncCanx <IEnumerable <string>, Dictionary <string, string>, string, string>, ICachedFunctionConfigurationManagerAsyncCanx_1Param <IEnumerable <string>, Dictionary <string, string> > >)config[methods[6]]; _enumerableKeyAsyncCanx6 = enumerableKeyAsyncCanx6ConfigFunc(enumerableKeyAsyncCanx6ConfigManager).Build(); var enumerableKeySyncCanx7ConfigManager = new Configuration.EnumerableKeys.CachedFunctionConfigurationManagerSyncCanx <IEnumerable <string>, Dictionary <string, string>, string, string>(originalImpl.EnumerableKeySyncCanx); var enumerableKeySyncCanx7ConfigFunc = (Func <Configuration.EnumerableKeys.CachedFunctionConfigurationManagerSyncCanx <IEnumerable <string>, Dictionary <string, string>, string, string>, ICachedFunctionConfigurationManagerSyncCanx_1Param <IEnumerable <string>, Dictionary <string, string> > >)config[methods[7]]; _enumerableKeySyncCanx7 = enumerableKeySyncCanx7ConfigFunc(enumerableKeySyncCanx7ConfigManager).Build(); }
public void Should_Create_Abstract_Type_With_NSubstitute( ISampleInterface abstractType, string str, int i) { abstractType .Should().NotBeNull(); abstractType.IsSubstitute() .Should().BeTrue(); abstractType.StringProperty .Returns(str); abstractType.StringProperty .Should().Be(str); abstractType.IntProperty .Returns(i); abstractType.IntProperty .Should().Be(i); }
public void Sample_MethodResultEnumerableDto() { dynamic isolated = new DynamicMock(); isolated.LoadItems().Returns(new[] { new { Id = 1, Name = "1" }, new { Id = 2, Name = "2" } }); ISampleInterface result = isolated; var actual = result.LoadItems(); Assert.IsTrue(actual.SequenceEqual(new[] { new SomeDtoWithVeryLongName { Id = 1, Name = "1" }, new SomeDtoWithVeryLongName { Id = 2, Name = "2" } })); }
public Sample(ISampleInterface sample) { //sample.Value1 = 14; not possible this.Value1 = sample.Value1; this.Value2 = sample.Value2; }
public HomeController(ISampleInterface sampleService, ILoggerFactory loggerFactory) { _sampleService = sampleService; _logger = loggerFactory.CreateLogger <ManageController>(); }
public SampleClassWithDependency(ISampleInterface sampleInterface) { _sampleInterface = sampleInterface; }
void test6(ISampleInterface i) { int r = i.SampleMethod(); }
public SampleDependantClass(ISampleInterface dependency) { Dependency = dependency; }