public void Uses_cached_endpoint_on_second_call() { int inProcessCalls = 0; Moq.Mock <IDummyAPI1> inProcessClientMock = new Mock <IDummyAPI1>(); inProcessClientMock.Setup(x => x.GetString()).Callback(() => inProcessCalls++).Throws(new Exception("OMG")); IDummyAPI1 inProcessClient = inProcessClientMock.Object; builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MSSQL); builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MySQL); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result = client1.Try(x => x.GetString()); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(2, inProcessCalls); // do it again and use the cached endpoint: IAdaptiveClient <IDummyAPI1> client2 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result2 = client2.Try(x => x.GetString()); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(2, inProcessCalls); }
public void Uses_cached_endpoint_on_second_call() { int inProcessCalls = 0; int webAPICalls = 0; // NetworkUtilities Mock Moq.Mock <INetworkUtilities> networkUtilMock = new Mock <INetworkUtilities>(); networkUtilMock.Setup(x => x.VerifyDBServerConnectivity(Moq.It.IsAny <string>())).Callback(() => inProcessCalls++).Returns(false); networkUtilMock.Setup(x => x.VerifyHttpServerAvailability(Moq.It.IsAny <string>())).Callback(() => webAPICalls++).Returns(true); 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_WebAPI1", client1.CurrentEndPoint.Name); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(3, inProcessCalls); Assert.AreEqual(1, webAPICalls); // do it again and use the cached endpoint: IAdaptiveClient <IDummyAPI1> client2 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result2 = client2.Call(x => x.GetString()); Assert.AreEqual("Application_WebAPI1", client2.CurrentEndPoint.Name); Assert.AreEqual("WebAPIClient1", result2); Assert.AreEqual(3, inProcessCalls); // We should not test the in process endpoint again - we go directly to the cached HTTP endpoint. Assert.AreEqual(1, webAPICalls); }
public async Task Inner_exceptions_are_maintained_for_each_client_call_async() { // We catch and log the error if a client throws - however we don't propagate errors unless // we run out of endpoints to try. This test asserts that errors from each client are maintained // and propagated as inner exceptions when we exhaust all endpoints. Moq.Mock <IDummyAPI1> inProcessClientMock = new Mock <IDummyAPI1>(); inProcessClientMock.Setup(x => x.GetString()).Throws(new Exception("InProcess Exception")); IDummyAPI1 inProcessClient = inProcessClientMock.Object; builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MSSQL); builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MySQL); Moq.Mock <IDummyAPI1> webAPIClientMock = new Mock <IDummyAPI1>(); webAPIClientMock.Setup(x => x.GetString()).Throws(new Exception("WebAPI Exception")); IDummyAPI1 webAPIClient = webAPIClientMock.Object; builder.RegisterInstance(webAPIClient).Keyed <IDummyAPI1>(EndPointType.HTTP + ProviderName.HTTP); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); Exception ex = Assert.ThrowsAsync <Exception>(async() => await client1.TryAsync(async x => { await Task.Delay(0); x.GetString(); })); Assert.AreEqual(4, ((AggregateException)(ex.InnerException)).InnerExceptions.Count); // Assert that the error thrown by the client is maintained Assert.AreEqual("InProcess Exception", ((AggregateException)(ex.InnerException)).InnerExceptions[0].InnerException.Message); Assert.AreEqual("InProcess Exception", ((AggregateException)(ex.InnerException)).InnerExceptions[1].InnerException.Message); Assert.AreEqual("WebAPI Exception", ((AggregateException)(ex.InnerException)).InnerExceptions[2].InnerException.Message); Assert.AreEqual("WebAPI Exception", ((AggregateException)(ex.InnerException)).InnerExceptions[3].InnerException.Message); }
public void Uses_cached_endpoint_on_third_call_after_override_on_second_call() { int inProcessCalls = 0; Moq.Mock <IDummyAPI1> inProcessClientMock = new Mock <IDummyAPI1>(); inProcessClientMock.Setup(x => x.GetString()).Callback(() => inProcessCalls++).Throws(new Exception("OMG")); IDummyAPI1 inProcessClient = inProcessClientMock.Object; builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MSSQL); builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MySQL); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result = client1.Try(x => x.GetString()); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(2, inProcessCalls); // use the Application_WebAPI1A EndPoint by passing it to the client as an override LogMessages = null; result = client1.Try(x => x.GetString(), "Application_WebAPI1A"); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(client1.CurrentEndPoint.Name, "Application_WebAPI1A"); // do it again and use the cached endpoint which is still Application_WebAPI1A: IAdaptiveClient <IDummyAPI1> client2 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result2 = client2.Try(x => x.GetString()); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(client1.CurrentEndPoint.Name, "Application_WebAPI1A"); Assert.AreEqual(2, inProcessCalls); }
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 async Task AdaptiveClient_falls_back_to_MySQL_on_Try() { Mock <IAccountsService> fakeMSSQLAccountsService = new Mock <IAccountsService>(); fakeMSSQLAccountsService.Setup(x => x.GetAccountByID(It.Is <int>(i => i == 1))).ReturnsAsync(new Account { Name = DataBaseProviderName.MSSQL }); fakeMSSQLAccountsService.Setup(x => x.GetAccountByID(It.Is <int>(i => i == 2))).Throws(new Exception("boo")); Mock <IAccountsService> fakeMySQLAccountsService = new Mock <IAccountsService>(); fakeMySQLAccountsService.Setup(x => x.GetAccountByID(It.IsAny <int>())).ReturnsAsync(new Account { Name = DataBaseProviderName.MySQL }); using (var scope = Container.BeginLifetimeScope(builder => { builder.RegisterInstance(fakeMSSQLAccountsService.Object).Keyed <IAccountsService>(EndPointType.DBMS + DataBaseProviderName.MSSQL); builder.RegisterInstance(fakeMySQLAccountsService.Object).Keyed <IAccountsService>(EndPointType.DBMS + DataBaseProviderName.MySQL); })) { IAdaptiveClient <IBOServiceManifest> client = scope.Resolve <IAdaptiveClient <IBOServiceManifest> >(); Account account = await client.TryAsync(async x => await x.AccountsService.GetAccountByID(1)); Assert.AreEqual(DataBaseProviderName.MSSQL, account.Name); // We are passing 2 as an ID so the call to the MSSQL instance will throw. // We fall back to the MySQL instance which returns "MySQL" account = await client.TryAsync(async x => await x.AccountsService.GetAccountByID(2)); Assert.AreEqual(DataBaseProviderName.MySQL, account.Name); } }
public void Uses_cached_endpoint_on_second_call() { int inProcessCalls = 0; int webAPICalls = 0; Moq.Mock <IEndPointValidator> InProcess_Validator_Mock = new Mock <IEndPointValidator>(); InProcess_Validator_Mock.Setup(x => x.IsInterfaceAlive(Moq.It.IsAny <IEndPointConfiguration>())).Callback(() => inProcessCalls++).Returns(false); Moq.Mock <IEndPointValidator> HTTP_Validator_Mock = new Mock <IEndPointValidator>(); HTTP_Validator_Mock.Setup(x => x.IsInterfaceAlive(Moq.It.IsAny <IEndPointConfiguration>())).Callback(() => webAPICalls++).Returns(true); builder.RegisterInstance(InProcess_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.InProcess + ProviderName.MSSQL); builder.RegisterInstance(InProcess_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_WebAPI1", client1.CurrentEndPoint.Name); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(2, inProcessCalls); Assert.AreEqual(1, webAPICalls); // do it again and use the cached endpoint: IAdaptiveClient <IDummyAPI1> client2 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result2 = client2.Call(x => x.GetString()); Assert.AreEqual("Application_WebAPI1", client2.CurrentEndPoint.Name); Assert.AreEqual("WebAPIClient1", result2); Assert.AreEqual(2, inProcessCalls); // We should not test the in process endpoint again - we go directly to the cached HTTP endpoint. Assert.AreEqual(1, webAPICalls); }
public async Task AdaptiveClient_Resolves_to_MSSQL_on_Try() { Mock <IAccountsService> fakeMSSQLAccountsService = new Mock <IAccountsService>(); fakeMSSQLAccountsService.Setup(x => x.GetAccountByID(It.IsAny <int>())).ReturnsAsync(new Account { Name = DataBaseProviderName.MSSQL }); Mock <IAccountsService> fakeMySQLAccountsService = new Mock <IAccountsService>(); fakeMySQLAccountsService.Setup(x => x.GetAccountByID(It.IsAny <int>())).ReturnsAsync(new Account { Name = DataBaseProviderName.MySQL }); using (var scope = Container.BeginLifetimeScope(builder => { builder.RegisterInstance(fakeMSSQLAccountsService.Object).Keyed <IAccountsService>(EndPointType.DBMS + DataBaseProviderName.MSSQL); builder.RegisterInstance(fakeMySQLAccountsService.Object).Keyed <IAccountsService>(EndPointType.DBMS + DataBaseProviderName.MySQL); })) { IAdaptiveClient <IBOServiceManifest> client = scope.Resolve <IAdaptiveClient <IBOServiceManifest> >(); Account account = await client.TryAsync(async x => await x.AccountsService.GetAccountByID(1)); Assert.AreEqual(DataBaseProviderName.MSSQL, account.Name); } }
public void Throws_when_invalid_EndPoint_name_is_passed_as_override() { int inProcessCalls = 0; Moq.Mock <IDummyAPI1> inProcessClientMock = new Mock <IDummyAPI1>(); inProcessClientMock.Setup(x => x.GetString()).Callback(() => inProcessCalls++).Throws(new Exception("OMG")); IDummyAPI1 inProcessClient = inProcessClientMock.Object; builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MSSQL); builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess); builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MySQL); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result = client1.Try(x => x.GetString()); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(3, inProcessCalls); // cached EndPoint is set but we are going to pass an invalid name IAdaptiveClient <IDummyAPI1> client2 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); Assert.Throws <Exception>(() => client2.Try(x => x.GetString(), "does not exist")); }
public void Client_exception_is_propagated() { Moq.Mock <IEndPointValidator> InProcess_Validator_Mock = new Mock <IEndPointValidator>(); InProcess_Validator_Mock.Setup(x => x.IsInterfaceAlive(Moq.It.IsAny <IEndPointConfiguration>())).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(InProcess_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.InProcess + ProviderName.MSSQL); builder.RegisterInstance(InProcess_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.InProcess + ProviderName.MySQL); builder.RegisterInstance(HTTP_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.HTTP + ProviderName.HTTP); Moq.Mock <IDummyAPI1> inProcessClientMock = new Mock <IDummyAPI1>(); inProcessClientMock.Setup(x => x.GetString()).Throws(new Exception("InProcess Exception")); IDummyAPI1 inProcessClient = inProcessClientMock.Object; builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MSSQL); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); Exception ex = Assert.Throws <Exception>(() => client1.Call(x => x.GetString())); Assert.AreEqual("Application_SQL1", client1.CurrentEndPoint.Name); Assert.AreEqual("InProcess Exception", ex.Message); }
/// <summary> /// Initializes boards and tasks. /// Sorts the tasks by column index so that they are /// loaded in as they were left when the app was last closed. /// </summary> public MainViewModel( Func <PresentationBoard, IAppNotificationService, BoardViewModel> boardViewModelFactory, IAdaptiveClient <IServiceManifest> dataProvider, INavigationService navigationService, IAppNotificationService appNotificationService, IDialogService dialogService) { this.boardViewModelFactory = boardViewModelFactory; this.dataProvider = dataProvider; this._navigationService = navigationService; this._appNotificationService = appNotificationService; this._dialogService = dialogService; PropertyChanged += MainViewModel_PropertyChanged; NewBoardCommand = new Base.RelayCommand(NewBoard, () => true); EditBoardCommand = new Base.RelayCommand(EditBoard, () => CurrentBoard != null); SaveBoardCommand = new Base.RelayCommand(SaveBoard, () => true); CancelSaveBoardCommand = new Base.RelayCommand(CancelSaveBoard, () => true); DeleteBoardCommand = new Base.RelayCommand(DeleteBoard, () => CurrentBoard != null); OpenSettingsCommand = new AsyncRelayCommand(OpenSettingsDialog, () => true); OpenCalendarCommand = new AsyncRelayCommand(OpenCalendarDialog, () => true); OpenBoardListCommand = new AsyncRelayCommand(OpenBoardListDialog, () => true); InitializeBoards(); }
public IndexModel(IAdaptiveClient <IUsersService> client, List <IEndPointConfiguration> endPoints) { // EndPoints are injected here because this is a demo and we need to populate the dropdown list on this page. // AdaptiveClient does not require EndPoints be passed to any object so you should not inject EndPoints into // your Controller, ViewModel, etc. unless you specifically need them. this.client = client; this.EndPoints = endPoints; }
public async Task CurrentEndPoint_is_thread_safe() { Moq.Mock <IEndPointValidator> InProcess_Validator_Mock = new Mock <IEndPointValidator>(); InProcess_Validator_Mock.Setup(x => x.IsInterfaceAlive(Moq.It.IsAny <IEndPointConfiguration>())).Returns(true); builder.RegisterInstance(InProcess_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.InProcess + ProviderName.MSSQL); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); IAdaptiveClient <IDummyAPI2> client2 = container.Resolve <IAdaptiveClient <IDummyAPI2> >(); string result1 = client1.Call(x => x.GetString()); Assert.AreEqual("Application_SQL1", client1.CurrentEndPoint.Name); Assert.AreEqual("InProcessClient1", result1); int result2 = client2.Call(x => x.GetInt()); Assert.AreEqual("Application_SQL2", client2.CurrentEndPoint.Name); Assert.AreEqual(1, result2); Task t1 = Task.Run(() => { for (int i = 0; i < 1000; i++) { string r1 = client1.Call(x => x.GetString()); Assert.AreEqual("Application_SQL1", client1.CurrentEndPoint.Name); Assert.AreEqual("InProcessClient1", r1); int r2 = client2.Call(x => x.GetInt()); Assert.AreEqual("Application_SQL2", client2.CurrentEndPoint.Name); Assert.AreEqual(1, r2); } }); Task t2 = Task.Run(() => { for (int i = 0; i < 1000; i++) { int r2 = client2.Call(x => x.GetInt()); Assert.AreEqual("Application_SQL2", client2.CurrentEndPoint.Name); Assert.AreEqual(1, r2); string r1 = client1.Call(x => x.GetString()); Assert.AreEqual("Application_SQL1", client1.CurrentEndPoint.Name); Assert.AreEqual("InProcessClient1", r1); } }); try { await Task.WhenAll(t1, t2); } catch (Exception) { throw; } }
public void EndPoint_is_validated_once_only_when_override_endpoint_is_passed() { int inProcessCalls = 0; int webAPICalls = 0; Moq.Mock <IEndPointValidator> InProcess_Validator_Mock = new Mock <IEndPointValidator>(); InProcess_Validator_Mock.Setup(x => x.IsInterfaceAlive(Moq.It.IsAny <IEndPointConfiguration>())).Callback(() => inProcessCalls++).Returns(true); Moq.Mock <IEndPointValidator> HTTP_Validator_Mock = new Mock <IEndPointValidator>(); HTTP_Validator_Mock.Setup(x => x.IsInterfaceAlive(Moq.It.IsAny <IEndPointConfiguration>())).Callback(() => webAPICalls++).Returns(true); builder.RegisterInstance(InProcess_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.InProcess + ProviderName.MSSQL); builder.RegisterInstance(InProcess_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(), "Application_SQL1"); Assert.AreEqual("Application_SQL1", client1.CurrentEndPoint.Name); Assert.AreEqual("InProcessClient1", result); Assert.AreEqual(1, inProcessCalls); Assert.AreEqual(0, webAPICalls); // do it again and use the webpai endpoint: client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); result = client1.Call(x => x.GetString(), "Application_WebAPI1"); Assert.AreEqual("Application_WebAPI1", client1.CurrentEndPoint.Name); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(1, inProcessCalls); // validate only once Assert.AreEqual(1, webAPICalls); // do it again and use the inprocess endpoint: result = client1.Call(x => x.GetString(), "Application_SQL1"); Assert.AreEqual("Application_SQL1", client1.CurrentEndPoint.Name); Assert.AreEqual("InProcessClient1", result); Assert.AreEqual(1, inProcessCalls); Assert.AreEqual(1, webAPICalls); // do it again and use the webpai endpoint: client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); result = client1.Call(x => x.GetString(), "Application_WebAPI1"); Assert.AreEqual("Application_WebAPI1", client1.CurrentEndPoint.Name); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(1, inProcessCalls); Assert.AreEqual(1, webAPICalls); }
public void Uses_next_endpoint_when_cached_endpoint_fails_on_second_call() { int inProcessCalls = 0; int webAPICalls = 0; Moq.Mock <IDummyAPI1> inProcessClientMock = new Mock <IDummyAPI1>(); inProcessClientMock.Setup(x => x.GetString()).Callback(() => inProcessCalls++).Throws(new Exception("OMG")); IDummyAPI1 inProcessClient = inProcessClientMock.Object; builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MSSQL); builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess); builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MySQL); Moq.Mock <IDummyAPI1> webAPIClientMock = new Mock <IDummyAPI1>(); webAPIClientMock.Setup(x => x.GetString()).Callback(() => { if (webAPICalls++ == 1) { throw new Exception("OMG"); } }).Returns("WebAPIClient1"); IDummyAPI1 webAPIClient = webAPIClientMock.Object; builder.RegisterInstance(webAPIClient).Keyed <IDummyAPI1>(EndPointType.HTTP); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result = client1.Try(x => x.GetString()); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(3, inProcessCalls); Assert.AreEqual(1, webAPICalls); // Application_WebAPI1 is the cached EndPoint. We expect it to fail on this call and we use Application_WebAPI1A result = client1.Try(x => x.GetString()); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual("Application_WebAPI1A", client1.CurrentEndPoint.Name); Assert.AreEqual(3, webAPICalls); // do it again and use the cached endpoint which is still Application_WebAPI1A: IAdaptiveClient <IDummyAPI1> client2 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result2 = client2.Try(x => x.GetString()); Assert.AreEqual("WebAPIClient1", result); Assert.AreEqual(client1.CurrentEndPoint.Name, "Application_WebAPI1A"); Assert.AreEqual(3, inProcessCalls); }
public void Reslove_WebAPIClient_of_type_IDummyAPI1() { Moq.Mock <IDummyAPI1> inProcessClientMock = new Mock <IDummyAPI1>(); inProcessClientMock.Setup(x => x.GetString()).Throws(new Exception("OMG")); IDummyAPI1 inProcessClient = inProcessClientMock.Object; builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MSSQL); builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess); builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MySQL); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result = client1.Try(x => x.GetString(), null); Assert.AreEqual("WebAPIClient1", result); }
public void Reslove_InProcessClientAsync_of_type_IDummyAPI1() { Moq.Mock <IEndPointValidator> MSSQL_Validator_Mock = new Mock <IEndPointValidator>(); MSSQL_Validator_Mock.Setup(x => x.IsInterfaceAlive(Moq.It.IsAny <IEndPointConfiguration>())).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(HTTP_Validator_Mock.Object).Keyed <IEndPointValidator>(EndPointType.HTTP + ProviderName.HTTP); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); string result = client1.Try(async api => await api.GetStringAsync(), null).Result; Assert.AreEqual("Application_SQL1", client1.CurrentEndPoint.Name); Assert.AreEqual("InProcessClient1", result); }
public void Reslove_WebAPIClient_of_type_IDummyAPI1() { Moq.Mock <INetworkUtilities> networkUtilMock = new Mock <INetworkUtilities>(); networkUtilMock.Setup(x => x.VerifyDBServerConnectivity(Moq.It.IsAny <string>())).Returns(false); networkUtilMock.Setup(x => x.VerifyHttpServerAvailability(Moq.It.IsAny <string>())).Returns(true); 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_WebAPI1", client1.CurrentEndPoint.Name); Assert.AreEqual("WebAPIClient1", result); }
protected async Task CreateTestArtifacts() { EndPoints = EndPointUtilities.LoadEndPoints("appsettings.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); } Builder = new ContainerBuilder(); Builder.RegisterModule(new AutofacModule()); Builder.RegisterModule(new LeaderAnalytics.AdaptiveClient.EntityFrameworkCore.AutofacModule()); RegistrationHelper registrationHelper = new RegistrationHelper(Builder); registrationHelper.RegisterModule(new AdaptiveClientModule()); Container = Builder.Build(); BOServiceClient = Container.Resolve <IAdaptiveClient <IBOServiceManifest> >(); }
/// <summary> /// Initializes the commands and tasks for the current board. /// </summary> public BoardViewModel( PresentationBoard board, IAdaptiveClient <IServiceManifest> dataProvider, IAppNotificationService appNotificationService, IToastService toastService) { Board = board; DataProvider = dataProvider; _appNotificationService = appNotificationService; _toastService = toastService; CurrentTask = new PresentationTask(new TaskDTO()); NewTaskCommand = new RelayCommand <ColumnTag>(NewTask, () => true); EditTaskCommand = new RelayCommand <int>(EditTask, () => true); SaveTaskCommand = new RelayCommand(SaveTask, () => true); DeleteTaskCommand = new RelayCommand <int>(DeleteTask, () => PaneTitle.Equals("Edit Task") || PaneTitle.Equals("")); DeleteTagCommand = new RelayCommand <string>(DeleteTag, () => true); CancelEditCommand = new RelayCommand(CancelEdit, () => true); UpdateColumnCommand = new RelayCommand <string>(UpdateColumn, () => true); Columns = new ObservableCollection <PresentationColumn>(); ColorKeys = new ObservableCollection <string> { "Low", "Medium", "High" }; ReminderTimes = new ObservableCollection <string> { "None", "At Time of Due Date", "5 Minutes Before", "10 Minutes Before", "15 Minutes Before", "1 Hour Before", "2 Hours Before", "1 Day Before", "2 Days Before" }; PaneTitle = "New Task"; //ConfigureBoardColumns(); }
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); }
public void Client_exception_is_propagated() { Moq.Mock <INetworkUtilities> networkUtilMock = new Mock <INetworkUtilities>(); networkUtilMock.Setup(x => x.VerifyDBServerConnectivity(Moq.It.IsAny <string>())).Returns(true); networkUtilMock.Setup(x => x.VerifyHttpServerAvailability(Moq.It.IsAny <string>())).Returns(false); INetworkUtilities networkUtil = networkUtilMock.Object; builder.RegisterInstance(networkUtil).As <INetworkUtilities>(); Moq.Mock <IDummyAPI1> inProcessClientMock = new Mock <IDummyAPI1>(); inProcessClientMock.Setup(x => x.GetString()).Throws(new Exception("InProcess Exception")); IDummyAPI1 inProcessClient = inProcessClientMock.Object; builder.RegisterInstance(inProcessClient).Keyed <IDummyAPI1>(EndPointType.InProcess + ProviderName.MSSQL); IContainer container = builder.Build(); IAdaptiveClient <IDummyAPI1> client1 = container.Resolve <IAdaptiveClient <IDummyAPI1> >(); Exception ex = Assert.Throws <Exception>(() => client1.Call(x => x.GetString())); Assert.AreEqual("Application_SQL1", client1.CurrentEndPoint.Name); Assert.AreEqual("InProcess Exception", ex.Message); }
public ProductsController(IAdaptiveClient <IProductsService> serviceClient) { this.serviceClient = serviceClient; }
public Demo(IAdaptiveClient <IUsersService> client) { this.client = client; }
public EmployeesController(IAdaptiveClient <IEmployeesService> serviceClient) { this.serviceClient = serviceClient; }
public BoardsController(IAdaptiveClient <IBoardServices> serviceClient) => this.serviceClient = serviceClient;
public OrdersViewModel(IAdaptiveClient <ISFServiceManifest> serviceClient) : base(API_Name.StoreFront) { Banner = "Orders"; }
public TasksController(IAdaptiveClient <ITaskServices> serviceClient) => this.serviceClient = serviceClient;
public void Single_DbContext_instance_is_injected_into_all_services() { IAdaptiveClient <ISFServiceManifest> client = Container.Resolve <IAdaptiveClient <ISFServiceManifest> >(); Assert.IsTrue(client.Call(x => x.OrdersService.AreDbContextsEqual())); }
public EmployeesViewModel(IAdaptiveClient <IBOServiceManifest> serviceClient) : base(API_Name.BackOffice) { Banner = "Employees"; }