public async Task should_update_service_when_found_with_no_endpoints() { var command = new AddEndpoint(Guid.NewGuid(), Guid.NewGuid(), "ipsum", "dolor"); var service = new Mongo.Infrastructure.Entities.Service() { Id = command.ServiceId, Name = "lorem", Active = false, Endpoints = null }; var mockRepo = RepositoryUtils.MockRepository(service); var mockDbContext = new Mock <IDbContext>(); mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object); var validator = new NullValidator <AddEndpoint>(); var sut = new AddEndpointHandler(mockDbContext.Object, validator); await sut.Handle(command); mockRepo.Verify(m => m.UpsertOneAsync(It.IsAny <Expression <Func <Mongo.Infrastructure.Entities.Service, bool> > >(), It.Is <Mongo.Infrastructure.Entities.Service>(r => r.Id == command.ServiceId && r.Active == false && null != r.Endpoints && 1 == r.Endpoints.Count() && r.Endpoints.Any(es => es.Active == false && es.Id == command.EndpointId && es.Address == command.Address && es.Protocol == command.Protocol)) ), Times.Once()); }
public ServiceMatrixDiagramViewModel(ServiceMatrixDiagramAdapter adapter) { this.Adapter = adapter; this.Diagram = adapter.ViewModel; IsServiceMatrixLicenseExpired = !GlobalSettings.Instance.IsLicenseValid; this.OnShowAddEndpoint = new RelayCommand(() => { var window = new AddEndpoint(); var result = window.ShowDialog(); if ((result.HasValue ? result.Value : false) && !String.IsNullOrEmpty(window.EndpointName.Text)) { try { this.Adapter.AddEndpoint(window.EndpointName.Text, window.EndpointHostType.SelectedValue.ToString()); } catch (OperationCanceledException) { } } }); this.OnShowAddService = new RelayCommand(() => { var window = new AddService(); var result = window.ShowDialog(); if ((result.HasValue ? result.Value : false) && !String.IsNullOrEmpty(window.ServiceName.Text)) { try { this.Adapter.AddService(window.ServiceName.Text); } catch (OperationCanceledException) { } } }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { Func <ILogger <Startup>, string, string> helloApi = (logger, name) => { logger.LogInformation("Running the API using parameter {Name}", name); return($"Hello {name}!"); }; services.AddControllers(); services.AddApiFrameworkStarterKit() .AddApi(helloApi) .AddApi <CalculatorApi>() .AddSqlServer() .AddOpenApi() .AddEndpoint <CalculatorApi>("/mycal", 15) .AddEndpoint <CalculatorApi>("/second", 100) .AddEndpoint <CalculatorApi>("/third", 0) .AddEndpoint("/sqlserver", ("Weikio.ApiFramework.Plugins.SqlServer", Version.Parse("1.1.0.0")), new SqlServerOptions() { ConnectionString = "Server=tcp:adafydevtestdb001.database.windows.net,1433;User ID=docs;Password=3h1@*6PXrldU4F95;Integrated Security=false;Initial Catalog=adafyweikiodevtestdb001;" }) .AddEndpoint("/sqlserver_products", ("Weikio.ApiFramework.Plugins.SqlServer", Version.Parse("1.1.0.0")), new SqlServerOptions() { ConnectionString = "Server=tcp:adafydevtestdb001.database.windows.net,1433;User ID=docs;Password=3h1@*6PXrldU4F95;Integrated Security=false;Initial Catalog=adafyweikiodevtestdb001;", Tables = new[] { "Product*" }, }) .AddEndpoint("/pets", "Weikio.ApiFramework.Plugins.OpenApi", new ApiOptions() { SpecificationUrl = "https://petstore.swagger.io/v2/swagger.json", IncludeHttpMethods = new[] { "GET" } }); var endpointDefinition = new EndpointDefinition("/pets_writeonly", "Weikio.ApiFramework.Plugins.OpenApi", new ApiOptions() { SpecificationUrl = "https://petstore.swagger.io/v2/swagger.json", ExcludeHttpMethods = new[] { "GET" } }); services.AddSingleton(endpointDefinition); }
public async Task <IActionResult> PostEndpoint([FromBody] AddEndpoint model) { if (null == model) { throw new ArgumentNullException(nameof(model)); } await _servicesProxy.AddEndpoint(model); return(CreatedAtAction("GetByName", new { name = model.ServiceName }, null)); }
public async Task AddEndpoint(AddEndpoint dto) { if (null == dto) { throw new ArgumentNullException(nameof(dto)); } var request = new RequestData("/services/endpoint", dto); var response = await _servicesApiClient.PostAsync(request); await response.AssertSuccessfulAsync(); }
public async Task should_throw_when_service_not_found() { var command = new AddEndpoint(Guid.NewGuid(), Guid.NewGuid(), "ipsum", "dolor"); var mockRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.Service>(); var mockDbContext = new Mock <IDbContext>(); mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object); var validator = new NullValidator <AddEndpoint>(); var sut = new AddEndpointHandler(mockDbContext.Object, validator); await Assert.ThrowsAsync <NullReferenceException>(() => sut.Handle(command)); }
public async Task should_not_replace_endpoint_when_found_by_id() { var endpoint = new Mongo.Infrastructure.Entities.ServiceEndpoint() { Id = Guid.NewGuid(), Active = false, Address = "localhost", Protocol = "http" }; var service = new Mongo.Infrastructure.Entities.Service() { Id = Guid.NewGuid(), Name = "lorem", Active = false, Endpoints = new[] { endpoint } }; var command = new AddEndpoint(service.Id, endpoint.Id, "ipsum", "dolor"); var mockRepo = RepositoryUtils.MockRepository(service); var mockDbContext = new Mock <IDbContext>(); mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object); var validator = new NullValidator <AddEndpoint>(); var sut = new AddEndpointHandler(mockDbContext.Object, validator); await sut.Handle(command); mockRepo.Verify(m => m.UpsertOneAsync(It.IsAny <Expression <Func <Mongo.Infrastructure.Entities.Service, bool> > >(), It.IsAny <Mongo.Infrastructure.Entities.Service>()), Times.Never()); }