public void Resolve_DbContext_for_API()
        {
            IEndPointConfiguration storeFrontep     = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.StoreFront);
            IEndPointConfiguration backOfficeep     = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.BackOffice);
            ResolutionHelper       resolutionHelper = Container.Resolve <ResolutionHelper>();
            DbContext storeFrontContext             = resolutionHelper.ResolveDbContext(storeFrontep);
            DbContext backOfficeContext             = resolutionHelper.ResolveDbContext(backOfficeep);

            Assert.IsNotNull(storeFrontContext);
            Assert.IsNotNull(backOfficeContext);
            Assert.IsTrue(storeFrontContext is Artifacts.StoreFront.Db);
            Assert.IsTrue(backOfficeContext is Artifacts.BackOffice.Db);

            if (CurrentDatabaseProviderName == DataBaseProviderName.MSSQL)
            {
                Assert.IsTrue(storeFrontContext.Database.GetDbConnection().ConnectionString == storeFrontep.ConnectionString);
                Assert.IsTrue(backOfficeContext.Database.GetDbConnection().ConnectionString == backOfficeep.ConnectionString);
            }
            else if (CurrentDatabaseProviderName == DataBaseProviderName.MySQL)
            {
                // MySql database connector changes the connection string.
                Assert.IsTrue(storeFrontContext.Database.GetDbConnection().ConnectionString.ToLower().Contains("database=adaptiveclientef_storefront"));
                Assert.IsTrue(backOfficeContext.Database.GetDbConnection().ConnectionString.ToLower().Contains("database=adaptiveclientef_backoffice"));
            }
        }
        public async Task Services_are_resolved_on_service_manifest()
        {
            // PaymentsService calls AccountsService internally.
            // In this test we mock AccountService so we know it is resolved and accessible from within PaymentsService.

            IEndPointConfiguration ep = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.BackOffice);

            await DropAndRecreate(ep);

            Mock <IAccountsService> fakeMSSQLAccountsService = new Mock <IAccountsService>();

            fakeMSSQLAccountsService.Setup(x => x.GetAccountByID(It.IsAny <int>())).ReturnsAsync(new Account {
                Name = "TEST"
            });

            using (var scope = Container.BeginLifetimeScope(builder =>
            {
                builder.RegisterInstance(fakeMSSQLAccountsService.Object).Keyed <IAccountsService>(EndPointType.DBMS + CurrentDatabaseProviderName);
            }))
            {
                IAdaptiveClient <IBOServiceManifest> client = scope.Resolve <IAdaptiveClient <IBOServiceManifest> >();
                Account account = await client.CallAsync(x => x.PaymentsService.GetAccountForPaymentID(1), ep.Name);

                Assert.AreEqual("TEST", account.Name);
            }
        }
        public void PostTo()
        {
            CoapClient c = new CoapClient(Program.Host)
            {
                UriPath  = "/.well-known/core",
                UriQuery = "ep=node1",
                Timeout  = 5000,
                EndPoint = EndPoints.First()
            };

            Response r = c.Post(new byte[] { }, MediaType.ApplicationLinkFormat);

            if (r == null)
            {
                Console.WriteLine("No response received");
            }
            else
            {
                if (r.StatusCode != StatusCode.Changed)
                {
                    Console.WriteLine("Incorrect response");
                }

                Console.WriteLine(Utils.ToString(r));
            }
        }
        public async Task Product_count_equals_two()
        {
            IEndPointConfiguration ep = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.StoreFront);

            await DropAndRecreateDatabase(ep);

            List <Product> products = await SFServiceClient.CallAsync(async x => await x.ProductsService.GetProducts(), ep.Name);

            Assert.AreEqual(2, products.Count);
        }
        public async Task TimeCard_count_equals_four()
        {
            IEndPointConfiguration ep = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.BackOffice);

            await DropAndRecreateDatabase(ep);

            List <TimeCard> timeCards = await BOServiceClient.CallAsync(async x => await x.TimeCardsService.GetTimeCards(), ep.Name);

            Assert.AreEqual(4, timeCards.Count);
        }
        public async Task Employee_count_equals_two()
        {
            IEndPointConfiguration ep = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.BackOffice);

            await DropAndRecreateDatabase(ep);

            List <Employee> employees = await BOServiceClient.CallAsync(async x => await x.EmployeesService.GetEmployees(), ep.Name);

            Assert.AreEqual(2, employees.Count);
        }
        public void Resolve_DatabaseInitalizer_for_API()
        {
            IEndPointConfiguration storeFrontep     = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.StoreFront);
            IEndPointConfiguration backOfficeep     = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.BackOffice);
            ResolutionHelper       resolutionHelper = Container.Resolve <ResolutionHelper>();

            IDatabaseInitializer storeFrontInitalizer = resolutionHelper.ResolveDatabaseInitializer(storeFrontep);
            IDatabaseInitializer backOfficeInitalizer = resolutionHelper.ResolveDatabaseInitializer(backOfficeep);

            Assert.IsTrue(storeFrontInitalizer is Artifacts.StoreFront.SFDatabaseInitializer);
            Assert.IsTrue(backOfficeInitalizer is Artifacts.BackOffice.BODatabaseInitializer);
        }
        public void Resolve_DbContextOptions_for_provider()
        {
            IEndPointConfiguration ep = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName);
            ResolutionHelper       resolutionHelper = Container.Resolve <ResolutionHelper>();
            IDbContextOptions      options          = resolutionHelper.ResolveDbContextOptions(ep);

            Assert.IsNotNull(options);

            if (CurrentDatabaseProviderName == DataBaseProviderName.MSSQL)
            {
                Assert.IsTrue(options is Artifacts.DbContextOptions_MSSQL);
            }
            else if (CurrentDatabaseProviderName == DataBaseProviderName.MySQL)
            {
                Assert.IsTrue(options is Artifacts.DbContextOptions_MySQL);
            }
        }
        private void GetUser()
        {
            IEndPointConfiguration endPoint = EndPoints.First(x => x.Name == SelectedEndPointName);

            Logger.Message = null;

            if (SelectedEndPointName == "Prod_WCF_01")
            {
                // This end point was registered with mocks so it will fail and fall back to Prod_MSSQL_01
                // If the current endpoint is Prod_MSSQL_01 you won't see an error message because AdaptiveClient
                // will continue to use that endpoint.
                DemoUser = client.Try(usersService => usersService.GetUserByID(1), endPoint.Name, "Prod_MSSQL_01");
            }
            else
            {
                DemoUser = client.Call(usersService => usersService.GetUserByID(1), endPoint.Name);
            }
        }
        public void Resolve_MigrationHelper_for_API()
        {
            IEndPointConfiguration storeFrontep     = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.StoreFront);
            IEndPointConfiguration backOfficeep     = EndPoints.First(x => x.ProviderName == CurrentDatabaseProviderName && x.API_Name == API_Name.BackOffice);
            ResolutionHelper       resolutionHelper = Container.Resolve <ResolutionHelper>();
            DbContext storeFrontContext             = resolutionHelper.ResolveMigrationContext(storeFrontep);
            DbContext backOfficeContext             = resolutionHelper.ResolveMigrationContext(backOfficeep);

            Assert.IsNotNull(storeFrontContext);
            Assert.IsNotNull(backOfficeContext);

            if (CurrentDatabaseProviderName == DataBaseProviderName.MSSQL)
            {
                Assert.IsTrue(storeFrontContext is Artifacts.StoreFront.Db_MSSQL);
                Assert.IsTrue(backOfficeContext is Artifacts.BackOffice.Db_MSSQL);
            }
            else if (CurrentDatabaseProviderName == DataBaseProviderName.MySQL)
            {
                Assert.IsTrue(storeFrontContext is Artifacts.StoreFront.Db_MySQL);
                Assert.IsTrue(backOfficeContext is Artifacts.BackOffice.Db_MySQL);
            }
        }
Esempio n. 11
0
        public void Reslove_InProcessClient3_of_type_IDummyAPI1()
        {
            Moq.Mock <IEndPointValidator> MSSQL_Validator_Mock = new Mock <IEndPointValidator>();
            MSSQL_Validator_Mock.Setup(x => x.IsInterfaceAlive(It.IsAny <IEndPointConfiguration>())).Returns(false);
            Moq.Mock <IEndPointValidator> MySQL_Validator_Mock = new Mock <IEndPointValidator>();
            MySQL_Validator_Mock.Setup(x => x.IsInterfaceAlive(It.Is <IEndPointConfiguration>(z => z == EndPoints.First(y => y.Name == "Application_MySQL1")))).Returns(true);
            Moq.Mock <IEndPointValidator> HTTP_Validator_Mock = new Mock <IEndPointValidator>();
            HTTP_Validator_Mock.Setup(x => x.IsInterfaceAlive(Moq.It.IsAny <IEndPointConfiguration>())).Returns(false);
            builder.RegisterInstance(MSSQL_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.InProcess + ProviderName.MSSQL);
            builder.RegisterInstance(MySQL_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.InProcess + ProviderName.MySQL);
            builder.RegisterInstance(HTTP_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.HTTP + ProviderName.HTTP);
            IContainer container = builder.Build();

            IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >();
            string result = client1.Call(x => x.GetString());

            Assert.AreEqual("Application_MySQL1", client1.CurrentEndPoint.Name);
            Assert.AreEqual("InProcessClient3", result);
        }
Esempio n. 12
0
        public void Reslove_InProcessClient3_of_type_IDummyAPI1()
        {
            Moq.Mock <INetworkUtilities> networkUtilMock = new Mock <INetworkUtilities>();
            networkUtilMock.Setup(x => x.VerifyDBServerConnectivity(It.Is <string>(z => z == EndPoints.First(y => y.Name == "Application_MySQL1").ConnectionString))).Returns(true);
            networkUtilMock.Setup(x => x.VerifyHttpServerAvailability(Moq.It.IsAny <string>())).Returns(false);
            INetworkUtilities networkUtil = networkUtilMock.Object;

            builder.RegisterInstance(networkUtil).As <INetworkUtilities>();
            IContainer container = builder.Build();

            IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >();
            string result = client1.Call(x => x.GetString());

            Assert.AreEqual("Application_MySQL1", client1.CurrentEndPoint.Name);
            Assert.AreEqual("InProcessClient3", result);
        }