Пример #1
0
 public void Setup()
 {
     LogMessages        = new List <string>();
     builder            = new ContainerBuilder();
     EndPoints          = EndPointUtilities.LoadEndPoints("EndPoints.json").ToList();
     registrationHelper = new RegistrationHelper(builder);
     builder.RegisterModule(new AutofacModule());
     registrationHelper.RegisterModule(new AdaptiveClientModule(EndPoints, msg => this.LogMessages.Add(msg)));
 }
Пример #2
0
        protected async Task CreateTestArtifacts()
        {
            EndPoints = EndPointUtilities.LoadEndPoints("EndPoints.json");
            if (EndPoints.Any(x => x.ProviderName == DataBaseProviderName.MySQL))
            {
                EndPoints.First(x => x.API_Name == API_Name.BackOffice && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString = ConnectionstringUtility.BuildConnectionString(EndPoints.First(x => x.API_Name == API_Name.BackOffice && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString);
                EndPoints.First(x => x.API_Name == API_Name.StoreFront && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString = ConnectionstringUtility.BuildConnectionString(EndPoints.First(x => x.API_Name == API_Name.StoreFront && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString);
            }
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterModule(new LeaderAnalytics.AdaptiveClient.EntityFrameworkCore.AutofacModule());
            RegistrationHelper registrationHelper = new RegistrationHelper(builder);

            registrationHelper.RegisterEndPoints(EndPoints);
            registrationHelper.RegisterModule(new Zamagon.Services.BackOffice.AdaptiveClientModule());
            registrationHelper.RegisterModule(new Zamagon.Services.Common.AdaptiveClientModule());
            registrationHelper.RegisterModule(new Zamagon.Services.StoreFront.AdaptiveClientModule());
            Container         = builder.Build();
            BOServiceClient   = Container.Resolve <IAdaptiveClient <IBOServiceManifest> >();
            SFServiceClient   = Container.Resolve <IAdaptiveClient <ISFServiceManifest> >();
            DatabaseUtilities = Container.Resolve <IDatabaseUtilities>();
        }
Пример #3
0
        public static IContainer CreateContainer(IEnumerable <IEndPointConfiguration> endPoints, string apiName, Action <string> logger)
        {
            /*
             * AdaptiveClient filters the collection of EndPoints that is registered and only uses the ones where IsActive = true.
             * However, for this demo app we want to force AdaptiveClient to encounter EndPoints that throw exceptions.
             * To do this we create a copy of the EndPoints list (fakeEndPoints) and set IsActive to true for each EndPoint in the copied list.
             * This effectively fools AdaptiveClient into thinking that all EndPoints are valid and should be used.
             * At the end of this method we look in the original EndPoint list and create service mocks for EndPoints where IsActive = false.
             * The resulting functionality is that AdaptiveClient attempts to use every EndPoint that is registered.  When it encounters a mock
             * it fails and tries to use the next EndPoint.
             */

            List <IEndPointConfiguration> fakeEndPoints = new List <IEndPointConfiguration>();

            foreach (IEndPointConfiguration ep in endPoints)
            {
                fakeEndPoints.Add(new PresentationEndPoint(ep)
                {
                    IsActive = true
                });
            }

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterModule(new AutofacModule());
            builder.RegisterModule(new LeaderAnalytics.AdaptiveClient.EntityFrameworkCore.AutofacModule());
            RegistrationHelper registrationHelper = new RegistrationHelper(builder);

            registrationHelper
            .RegisterEndPoints(fakeEndPoints)
            .RegisterModule(new Zamagon.Services.Common.AdaptiveClientModule());

            if (apiName == API_Name.BackOffice || apiName == null)
            {
                registrationHelper.RegisterModule(new Zamagon.Services.BackOffice.AdaptiveClientModule());
            }

            if (apiName == API_Name.StoreFront || apiName == null)
            {
                registrationHelper.RegisterModule(new Zamagon.Services.StoreFront.AdaptiveClientModule());
            }


            if (logger != null)
            {
                registrationHelper.RegisterLogger(logger);
            }

            // Create mocks
            Mock <IOrdersService> ordersServiceMock = new Mock <IOrdersService>();

            ordersServiceMock.Setup(x => x.GetOrders()).Throws(new Exception("Mock failure"));
            IOrdersService ordersService = ordersServiceMock.Object;

            Mock <IProductsService> productsServiceMock = new Mock <IProductsService>();

            productsServiceMock.Setup(x => x.GetProducts()).Throws(new Exception("Mock failure"));
            IProductsService productsService = productsServiceMock.Object;

            Mock <IEmployeesService> empServiceMock = new Mock <IEmployeesService>();

            empServiceMock.Setup(x => x.GetEmployees()).Throws(new Exception("Mock failure"));
            IEmployeesService empService = empServiceMock.Object;

            Mock <ITimeCardsService> tcServiceMock = new Mock <ITimeCardsService>();

            tcServiceMock.Setup(x => x.GetTimeCards()).Throws(new Exception("Mock failure"));
            ITimeCardsService tcService = tcServiceMock.Object;

            // look at the list of endPoints that was passed to us and register a mock for each
            // one that is not marked active

            foreach (IEndPointConfiguration ep in endPoints.Where(x => !x.IsActive))
            {
                builder.RegisterInstance(ordersService).Keyed <IOrdersService>(ep.EndPointType + ep.ProviderName);
                builder.RegisterInstance(productsService).Keyed <IProductsService>(ep.EndPointType + ep.ProviderName);
                builder.RegisterInstance(empService).Keyed <IEmployeesService>(ep.EndPointType + ep.ProviderName);
                builder.RegisterInstance(tcService).Keyed <ITimeCardsService>(ep.EndPointType + ep.ProviderName);
            }

            return(builder.Build());
        }