public static IViewEngineManager GetViewManager() { var config = new MonoRailConfiguration(); config.ViewEngineConfig.ViewEngines.Add(new ViewEngineInfo(typeof(BooViewEngine), false)); config.ViewEngineConfig.ViewPathRoot = Path.Combine(@"..\..\..\AdminInterface", "Views"); var provider = new FakeServiceProvider(); var loader = new FileAssemblyViewSourceLoader(config.ViewEngineConfig.ViewPathRoot); loader.AddAssemblySource(new AssemblySourceInfo("Common.Web.Ui", "Common.Web.Ui.Views")); provider.Services.Add(typeof(IMonoRailConfiguration), config); provider.Services.Add(typeof(IViewSourceLoader), loader); var manager = new DefaultViewEngineManager(); manager.Service(provider); var options = Exposed.From(manager).viewEnginesFastLookup[0].Options; var namespaces = options.NamespacesToImport; namespaces.Add("Boo.Lang.Builtins"); namespaces.Add("AdminInterface.Helpers"); namespaces.Add("Common.Web.Ui.Helpers"); options.AssembliesToReference.Add(Assembly.Load("AdminInterface")); return(manager); }
public PipelineProviderTests() { _serviceProvider = new FakeServiceProvider(); _logger = new FakeLogger <RabbitMqPipelineProvider>(); _sut = new RabbitMqPipelineProvider(_serviceProvider, _logger); }
public async Task PrepareTest() { serviceProvider = FakeServiceProvider.Create($"{nameof(DeliveryServiceTests)}_{TestContext.TestName}"); scope = serviceProvider.CreateScope(); connections = scope.ServiceProvider.GetRequiredService <ConnectionsService>(); packets = scope.ServiceProvider.GetRequiredService <PacketService>(); database = scope.ServiceProvider.GetRequiredService <DatabaseContext>(); delivery = scope.ServiceProvider.GetRequiredService <DeliveryService>(); database.Accounts.Add(new Account { AccountId = alice }); database.MailConfirmations.Add(new MailConfirmation { AccountId = alice, MailAddress = "*****@*****.**", Token = SkynetRandom.String(10) }); database.Accounts.Add(new Account { AccountId = bob }); database.MailConfirmations.Add(new MailConfirmation { AccountId = bob, MailAddress = "*****@*****.**", Token = SkynetRandom.String(10) }); database.Accounts.Add(new Account { AccountId = charlie }); database.MailConfirmations.Add(new MailConfirmation { AccountId = charlie, MailAddress = "*****@*****.**", Token = SkynetRandom.String(10) }); await database.SaveChangesAsync().ConfigureAwait(false); }
public void GetService_TypeOfFakeServiceProvider_ReturnsNewFakeServiceProvider() { CreateServiceProvider(); FakeServiceProvider service = serviceProvider.GetService(typeof(FakeServiceProvider)) as FakeServiceProvider; Assert.IsNotNull(service); }
public async Task StartAsync_with_one_funk_without_dependencies_should_start() { var optionsMonitor = new FakeOptionsMonitor <VesselControllerServiceOptions>(new VesselControllerServiceOptions { FunkDefs = new FunkDefOption[] { new FunkDefOption { Type = "Funky.Fakes.EmptyFunk, Funky.Fakes", Topic = "test1" } } }); var serviceProvider = new FakeServiceProvider(new FakeConsumerFactory()); var vesselFactory = new VesselFactory(serviceProvider); var service = new VesselControllerService(vesselFactory, optionsMonitor, this.logger); await service.StartAsync(CancellationToken.None) .ConfigureAwait(false); Assert.Single(service.Vessels); var evt = new SysEvent(Guid.NewGuid()); var consumerFactory = serviceProvider.GetService <FakeConsumerFactory>(); await consumerFactory.SendToTopicAsync("funky.sys", evt) .ConfigureAwait(false); }
public KafkaPipelineProviderTests() { _serviceProvider = new FakeServiceProvider(); _logger = new FakeLogger <KafkaPipelineProvider <string, string> >(); _sut = new KafkaPipelineProvider <string, string>(_serviceProvider, _logger); }
public void TestMethod1() { var config = @" { fullname: { Format: ""{0} {1} {2}"", Args: [ ""lastname"", ""firstname"", ""middlename"", ] } }"; var entity = new Entity("contact", Guid.NewGuid()) { ["firstname"] = "РОМАН", ["lastname"] = "копаев-ЗаДуНайский", ["middlename"] = "анатольевич" }; IPluginExecutionContext context = new FakePluginExecutionContext(entity); IServiceProvider serviceProvider = new FakeServiceProvider(context); var plugin = new Format(config); plugin.Execute(serviceProvider); var result = context.GetContextEntity(); Assert.AreEqual("копаев-ЗаДуНайский РОМАН анатольевич", result["fullname"]); }
public void CreateInstance_AdditionalParameter_NotSupported() { var serviceProvider = new FakeServiceProvider(); var activator = new CoconaLiteInstanceActivator(); var ex = Assert.Throws <NotSupportedException>(() => activator.CreateInstance(serviceProvider, typeof(CreateInstance_NoAdditionalParameter_Target), new object[] { 123, "Hello Konnichiwa!" })); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceProviderBuilderBase{TDerived}" /> class. /// </summary> /// <param name="service">The service.</param> /// <param name="context">The context.</param> /// <param name="trace">The tracing service.</param> protected ServiceProviderBuilderBase(IOrganizationService service, IPluginExecutionContext context, ITracingService trace) { ServiceProvider = new FakeServiceProvider(); ServiceProvider.AddService <IOrganizationServiceFactory>(new FakeOrganizationServiceFactory(service)); ServiceProvider.AddService(context); ServiceProvider.AddService(trace); }
public void UseInternalServiceProvider_on_generic_builder_returns_generic_builder() { var serviceProvider = new FakeServiceProvider(); var optionsBuilder = GenericCheck(new DbContextOptionsBuilder <UnkoolContext>().UseInternalServiceProvider(serviceProvider)); Assert.Same(serviceProvider, optionsBuilder.Options.FindExtension <CoreOptionsExtension>().InternalServiceProvider); }
public void GetServiceOrCreateInstance_CreateInstance() { var serviceProvider = new FakeServiceProvider(); var activator = new CoconaLiteInstanceActivator(); var obj = activator.GetServiceOrCreateInstance(serviceProvider, typeof(GetServiceOrCreateInstance_CreateInstance_Target)); obj.Should().NotBeNull(); }
public void CreateInstance_Insufficient() { var serviceProvider = new FakeServiceProvider(); var activator = new CoconaLiteInstanceActivator(); var ex = Assert.Throws <InvalidOperationException>(() => activator.CreateInstance(serviceProvider, typeof(CreateInstance_NoAdditionalParameter_Target), Array.Empty <object>())); ex.Message.Should().Be("Unable to resolve service for type 'System.String' while attempting to activate 'Cocona.Lite.Test.CoconaLiteInstanceActivatorTest+CreateInstance_NoAdditionalParameter_Target'"); }
void CreateHost(string applicationBase) { host = new TestableTextTemplatingHost(applicationBase); fakeTextTemplatingAppDomainFactory = host.FakeTextTemplatingAppDomainFactory; fakeTextTemplatingAppDomain = fakeTextTemplatingAppDomainFactory.FakeTextTemplatingAppDomain; fakeAssemblyResolver = host.FakeTextTemplatingAssemblyResolver; fakeTextTemplatingVariables = host.FakeTextTemplatingVariables; fakeServiceProvider = host.FakeServiceProvider; hostContext = host.HostContext; }
public void Externally_owned_container_should_not_be_disposed() { var fakesServiceProvider = new FakeServiceProvider(); var container = new ServicesObjectBuilder(fakesServiceProvider, false); container.Dispose(); Assert.False(fakesServiceProvider.Disposed); }
public void Owned_container_should_be_disposed() { var fakesServiceProvider = new FakeServiceProvider(); var container = new ServicesObjectBuilder(fakesServiceProvider, true); container.Dispose(); Assert.True(fakesServiceProvider.Disposed); }
public void GetServiceOrCreateInstance_FromService() { var serviceProvider = new FakeServiceProvider(); serviceProvider.ValueByType[typeof(GetServiceOrCreateInstance_FromService_Target)] = new GetServiceOrCreateInstance_FromService_Target(); var activator = new CoconaLiteInstanceActivator(); var obj = activator.GetServiceOrCreateInstance(serviceProvider, typeof(GetServiceOrCreateInstance_FromService_Target)); obj.Should().Be(serviceProvider.ValueByType[typeof(GetServiceOrCreateInstance_FromService_Target)]); }
public void IServiceProvider_GetFake_Should_RetrieveTheInstance() { var provider = new FakeServiceProvider(); var service = new FakeIOrganizationService(new LocalCrmDatabaseOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>())); provider.AddService <IOrganizationService>(service); var fake = provider.GetFake <FakeIOrganizationService>(); Assert.IsNotNull(fake); Assert.AreEqual(service, fake); }
public void Can_load_active_taxProvider() { var serviceProvider = new FakeServiceProvider(_genericAttributeService.Object, _taxService, _taxSettings); var nopEngine = new FakeNopEngine(serviceProvider); EngineContext.Replace(nopEngine); var provider = _taxPluginManager.LoadPrimaryPlugin(); provider.Should().NotBeNull(); EngineContext.Replace(null); }
public void JobToBeExecuted_Positive() { var fakeServiceProvider = new FakeServiceProvider(); var listener = new DIJobListener(fakeServiceProvider); var fakeJob = new FakeJob(); var context = new FakeJobExecutionContext { JobInstance = fakeJob }; listener.JobToBeExecuted(context).Wait(); Assert.Equal(fakeServiceProvider, fakeJob.ServiceProvider); }
public void CreateInstance_NoAdditionalParameter() { var serviceProvider = new FakeServiceProvider(); serviceProvider.ValueByType[typeof(int)] = 123; serviceProvider.ValueByType[typeof(string)] = "Hello Konnichiwa!"; var activator = new CoconaLiteInstanceActivator(); var obj = activator.CreateInstance(serviceProvider, typeof(CreateInstance_NoAdditionalParameter_Target), Array.Empty <object>()); obj.Should().BeOfType <CreateInstance_NoAdditionalParameter_Target>(); ((CreateInstance_NoAdditionalParameter_Target)obj).Value0.Should().Be("Hello Konnichiwa!"); ((CreateInstance_NoAdditionalParameter_Target)obj).Value1.Should().Be(123); }
public ConnectionTestsSandbox() : base() { // Arrange by registering our fake services into the test container. FakeOrgService = this.RegisterMockInstance <IOrganizationService, IDisposable>(); FakeServiceProvider = this.RegisterMockInstance <ICrmServiceProvider>(); FakeServiceProvider.Stub(c => c.GetOrganisationService()).Return(FakeOrgService); FakeConnectionProvider = this.RegisterMockInstance <ICrmConnectionProvider>(); FakeConnectionProvider.Stub(c => c.OrganisationServiceConnectionString).Return("fakeconn=true"); FakeServiceProvider.Stub(c => c.ConnectionProvider).Return(FakeConnectionProvider); FakeMetadataProvider = new FakeContactMetadataProvider(); this.Container.Register <ICrmMetaDataProvider>(FakeMetadataProvider); }
public void It_disposes_scope() { var fakeServiceProvider = new FakeServiceProvider(); var context = new DbContext( new DbContextOptionsBuilder().UseInternalServiceProvider(fakeServiceProvider).UseInMemoryDatabase(Guid.NewGuid().ToString()).Options); var scopeService = Assert.IsType <FakeServiceProvider.FakeServiceScope>(context.GetService <IServiceScopeFactory>().CreateScope()); Assert.False(scopeService.Disposed); context.Dispose(); Assert.True(scopeService.Disposed); Assert.Throws <ObjectDisposedException>(() => ((IInfrastructure <IServiceProvider>)context).Instance); }
public void SimpleData() { var entity = new Entity("contact", Guid.NewGuid()) { ["quote"] = "никогда НЕ быЛО, И ВОТ опЯть!" }; IPluginExecutionContext context = new FakePluginExecutionContext(entity); IServiceProvider serviceProvider = new FakeServiceProvider(context); var plugin = new ToFirstTitleCase(CONFIG_STR); plugin.Execute(serviceProvider); var result = context.GetContextEntity(); Assert.AreEqual("Никогда НЕ быЛО, И ВОТ опЯть!", result["quote"]); }
public void Can_get_productPrice_priceIncludesTax_includingTax_taxable() { var customer = new Customer(); var product = new Product(); var serviceProvider = new FakeServiceProvider(_genericAttributeService.Object, _taxService, _taxSettings); var nopEngine = new FakeNopEngine(serviceProvider); EngineContext.Replace(nopEngine); _taxService.GetProductPrice(product, 0, 1000M, true, customer, true, out _).Should().Be(1000); _taxService.GetProductPrice(product, 0, 1000M, true, customer, false, out _).Should().Be(1100); _taxService.GetProductPrice(product, 0, 1000M, false, customer, true, out _).Should() .Be(909.0909090909090909090909091M); _taxService.GetProductPrice(product, 0, 1000M, false, customer, false, out _).Should().Be(1000); EngineContext.Replace(null); }
public static IViewEngineManager Init(Assembly assembly = null) { if (assembly == null) { assembly = Assembly.GetEntryAssembly(); } ActiveRecordStarter.Initialize( new[] { Assembly.Load("AdminInterface"), Assembly.Load("Common.Web.Ui") }, ActiveRecordSectionHandler.Instance); var config = new MonoRailConfiguration(); config.ViewEngineConfig.ViewEngines.Add(new ViewEngineInfo(typeof(BooViewEngine), false)); var loader = new FileAssemblyViewSourceLoader(""); loader.AddAssemblySource(new AssemblySourceInfo(assembly, assembly.GetName().Name + ".Views")); var provider = new FakeServiceProvider(); provider.Services.Add(typeof(IMonoRailConfiguration), config); provider.Services.Add(typeof(IViewSourceLoader), loader); var manager = new DefaultViewEngineManager(); manager.Service(provider); var options = ((BooViewEngine)manager.ResolveEngine(".brail")).Options; options.AssembliesToReference.Add(Assembly.Load("Common.Web.Ui")); var namespaces = options.NamespacesToImport; namespaces.Add("Boo.Lang.Builtins"); namespaces.Add("AdminInterface.Helpers"); namespaces.Add("Common.Web.Ui.Helpers"); BaseMailer.ViewEngineManager = manager; return(manager); }
public void PartialData() { var entity = new Entity("contact", Guid.NewGuid()) { ["firstname"] = "рОМАН", ["middlename"] = "анатольевич" }; IPluginExecutionContext context = new FakePluginExecutionContext(entity); IServiceProvider serviceProvider = new FakeServiceProvider(context); var plugin = new ToTitleCase(CONFIG_STR); plugin.Execute(serviceProvider); var result = context.GetContextEntity(); Assert.AreEqual("Роман", result.GetAttributeValue <string>("firstname")); Assert.IsNull(result.GetAttributeValue <string>("lastname")); Assert.AreEqual("Анатольевич", result.GetAttributeValue <string>("middlename")); }
public void SimpleData() { var entity = new Entity("contact", Guid.NewGuid()) { ["firstname"] = "РОМАН", ["lastname"] = "копаев-ЗаДуНайский", ["middlename"] = "анатольевич" }; IPluginExecutionContext context = new FakePluginExecutionContext(entity); IServiceProvider serviceProvider = new FakeServiceProvider(context); var plugin = new ToUpperCase(CONFIG_STR); plugin.Execute(serviceProvider); var result = context.GetContextEntity(); Assert.AreEqual("РОМАН", result["firstname"]); Assert.AreEqual("КОПАЕВ-ЗАДУНАЙСКИЙ", result["lastname"]); Assert.AreEqual("АНАТОЛЬЕВИЧ", result["middlename"]); }
public void CheckRequirement_restrictedRoleId_Valid() { var serviceProvider = new FakeServiceProvider(_customerService.Object); var nopEngine = new FakeNopEngine(serviceProvider); EngineContext.Replace(nopEngine); var rule = _discountPluginManager.LoadPluginBySystemName(SystemName); var result = rule.CheckRequirement(new DiscountRequirementValidationRequest() { DiscountRequirementId = 1, Store = null, Customer = new Customer() { Id = 1 } }); Assert.IsInstanceOf <DiscountRequirementValidationResult>(result); Assert.AreEqual(result.IsValid, true); EngineContext.Replace(null); }
public void It_disposes_scope() { var fakeServiceProvider = new FakeServiceProvider(); var context = new DbContext(fakeServiceProvider, new DbContextOptions<DbContext>()); var scopeService = Assert.IsType<FakeServiceProvider.FakeServiceScope>(context.GetService<IServiceScopeFactory>().CreateScope()); Assert.False(scopeService.Disposed); context.Dispose(); Assert.True(scopeService.Disposed); Assert.Throws<ObjectDisposedException>(() => ((IInfrastructure<IServiceProvider>)context).Instance); }
public OrderTotalCalculationServiceTests() { _shippingSettings = new ShippingSettings { ActiveShippingRateComputationMethodSystemNames = new List <string> { "FixedRateTestShippingRateComputationMethod" }, AllowPickupInStore = true, IgnoreAdditionalShippingChargeForPickupInStore = false }; _taxSettings = new TaxSettings { ShippingIsTaxable = true, PaymentMethodAdditionalFeeIsTaxable = true, DefaultTaxAddressId = 10 }; var products = new List <Product> { new Product { Id = 1, Weight = 1.5M, Height = 2.5M, Length = 3.5M, Width = 4.5M, AdditionalShippingCharge = 5.5M, IsShipEnabled = true }, new Product { Id = 2, Weight = 11.5M, Height = 12.5M, Length = 13.5M, Width = 14.5M, AdditionalShippingCharge = 6.5M, IsShipEnabled = true }, new Product { Id = 3, Weight = 11.5M, Height = 12.5M, Length = 13.5M, Width = 14.5M, AdditionalShippingCharge = 7.5M, IsShipEnabled = false } }; var productRepository = _fakeDataStore.RegRepository(products); _productService = new FakeProductService(productRepository: productRepository); var store = new Store { Id = 1 }; _storeContext.Setup(x => x.CurrentStore).Returns(store); _currencyService.Setup(x => x.GetCurrencyById(1)).Returns(new Currency { Id = 1, RoundingTypeId = 0 }); _addressService.Setup(x => x.GetAddressById(_taxSettings.DefaultTaxAddressId)).Returns(new Address { Id = _taxSettings.DefaultTaxAddressId }); _paymentService.Setup(ps => ps.GetAdditionalHandlingFee(It.IsAny <IList <ShoppingCartItem> >(), "test1")).Returns(20); _genericAttributeService.Setup(x => x.GetAttribute <PickupPoint>(It.IsAny <Customer>(), NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.Object.CurrentStore.Id, null)) .Returns(new PickupPoint()); _genericAttributeService.Setup(x => x.GetAttribute <string>(It.IsAny <Customer>(), NopCustomerDefaults.SelectedPaymentMethodAttribute, _storeContext.Object.CurrentStore.Id, null)) .Returns("test1"); _customerRoleRepository = _fakeDataStore.RegRepository(new[] { new CustomerRole { Id = 1, Active = true, FreeShipping = true }, new CustomerRole { Id = 2, Active = true, FreeShipping = false } }); var customerRepository = _fakeDataStore.RegRepository(new[] { new Customer() { Id = 1 } }); var customerCustomerRoleMappingRepository = _fakeDataStore.RegRepository <CustomerCustomerRoleMapping>(); _customerService = new FakeCustomerService( customerRepository: customerRepository, customerRoleRepository: _customerRoleRepository, customerCustomerRoleMappingRepository: customerCustomerRoleMappingRepository, storeContext: _storeContext.Object); var pluginService = new FakePluginService(); var pickupPluginManager = new PickupPluginManager(_customerService, pluginService, _shippingSettings); _shippingPluginManager = new ShippingPluginManager(_customerService, pluginService, _shippingSettings); var taxPluginManager = new TaxPluginManager(_customerService, pluginService, _taxSettings); var discountPluginManager = new DiscountPluginManager(_customerService, pluginService); var currencySettings = new CurrencySettings { PrimaryStoreCurrencyId = 1 }; var discountRepository = _fakeDataStore.RegRepository <Discount>(); _discountService = new FakeDiscountService( customerService: _customerService, discountPluginManager: discountPluginManager, productService: _productService, discountRepository: discountRepository, storeContext: _storeContext.Object); IPriceCalculationService priceCalculationService = new FakePriceCalculationService( currencySettings: currencySettings, currencyService: _currencyService.Object, customerService: _customerService, discountService: _discountService, productService: _productService, storeContext: _storeContext.Object); _shoppingCartService = new FakeShoppingCartService( productService: _productService, customerService: _customerService, genericAttributeService: _genericAttributeService.Object, priceCalculationService: priceCalculationService, shoppingCartSettings: _shoppingCartSettings); IShippingService shippingService = new FakeShippingService(customerSerice: _customerService, genericAttributeService: _genericAttributeService.Object, pickupPluginManager: pickupPluginManager, productService: _productService, shippingPluginManager: _shippingPluginManager, storeContext: _storeContext.Object, shippingSettings: _shippingSettings); _taxService = new FakeTaxService( addressService: _addressService.Object, customerService: _customerService, genericAttributeService: _genericAttributeService.Object, storeContext: _storeContext.Object, taxPluginManager: taxPluginManager, shippingSettings: _shippingSettings, taxSettings: _taxSettings); _orderTotalCalcService = new FakeOrderTotalCalculationService( addressService: _addressService.Object, customerService: _customerService, discountService: _discountService, genericAttributeService: _genericAttributeService.Object, paymentService: _paymentService.Object, priceCalculationService: priceCalculationService, productService: _productService, shippingPluginManager: _shippingPluginManager, shippingService: shippingService, shoppingCartService: _shoppingCartService, storeContext: _storeContext.Object, taxService: _taxService, shippingSettings: _shippingSettings, taxSettings: _taxSettings, rewardPointsSettings: _rewardPointsSettings); var serviceProvider = new FakeServiceProvider(_shoppingCartService, _paymentService.Object, _genericAttributeService.Object, _orderTotalCalcService, _taxService, _taxSettings); var nopEngine = new FakeNopEngine(serviceProvider); EngineContext.Replace(nopEngine); }
public FakeSyncServiceScope() { ServiceProvider = new FakeServiceProvider(); }