public async Task Returns_All_Items() { var model1 = new Service { ServiceId = "AllItem1", DisplayName = "Test Service" }; var model2 = new Service { ServiceId = "AllItem2", DisplayName = "Test Service 2" }; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { context.Services.RemoveRange(context.Services.ToArray()); context.Services.Add(model1.ToEntity()); context.Services.Add(model2.ToEntity()); context.SaveChanges(); } using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var store = new ServiceStore(context, new Mock <ILogger <ServiceStore> >().Object); var services = (await store.GetAllAsync()).ToList(); services.Should().HaveCount(2); services[0].ServiceId.Should().Be(model1.ServiceId); services[0].DisplayName.Should().Be(model1.DisplayName); services[1].ServiceId.Should().Be(model2.ServiceId); services[1].DisplayName.Should().Be(model2.DisplayName); } }
public async Task Updates_Endpoints_On_Existing_Item() { var model = new Service { ServiceId = "Updates_Endpoints_On_Existing_Item", DisplayName = "Test Service", Endpoints = new[] { new Uri("http://myservice01-qa.com") } }; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { context.Services.Add(model.ToEntity()); context.SaveChanges(); } model.Endpoints = new[] { new Uri("http://myservice01-qa.com"), new Uri("http://myservice02-qa.com") }; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var store = new ServiceStore(context, new Mock <ILogger <ServiceStore> >().Object); await store.StoreAsync(model); } using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var item = context.CreateServiceQuery().SingleOrDefault(s => s.ServiceId == model.ServiceId); item.Should().NotBeNull(); item.Endpoints.Should().HaveCount(2); } }
public async Task Removes_Existing_Item() { var model = new Service { ServiceId = "Removes_Existing_Item", DisplayName = "Test Service" }; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { context.Services.Add(model.ToEntity()); context.SaveChanges(); } using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var store = new ServiceStore(context, new Mock <ILogger <ServiceStore> >().Object); await store.RemoveAsync(model.ServiceId); } using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { context.Services.SingleOrDefault(s => s.ServiceId == model.ServiceId).Should().BeNull(); } }
public async Task Saves_New_Item() { var model = new Service { ServiceId = "Saves_New_Item", DisplayName = "Test Service", Endpoints = new[] { new Uri("http://myservice01-qa.com") }, PublicUrls = new[] { new Uri("http://myservice-qa.com") }, IpAddresses = new[] { "10.10.0.1" } }; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var store = new ServiceStore(context, new Mock <ILogger <ServiceStore> >().Object); await store.StoreAsync(model); } using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var service = context.CreateServiceQuery().SingleOrDefault(s => s.ServiceId == model.ServiceId); service.Should().NotBeNull(); service.ServiceId.Should().Be(model.ServiceId); service.DisplayName.Should().Be(model.DisplayName); service.Endpoints.Should().HaveCount(1); service.Endpoints[0].EndpointUri.Should().Be(model.Endpoints[0].ToString()); service.IpAddresses.Should().HaveCount(1); service.IpAddresses[0].IpAddress.Should().Be(model.IpAddresses[0]); service.PublicUrls.Should().HaveCount(1); service.PublicUrls[0].Url.Should().Be(model.PublicUrls[0].ToString()); } }
public async Task Updates_DisplayName_On_Existing_Item() { var model = new Service { ServiceId = "Updates_DisplayName_On_Existing_Item", DisplayName = "Test Service" }; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { context.Services.Add(model.ToEntity()); context.SaveChanges(); } model.DisplayName = "New name"; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var store = new ServiceStore(context, new Mock <ILogger <ServiceStore> >().Object); await store.StoreAsync(model); } using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var item = context.CreateServiceQuery().SingleOrDefault(s => s.ServiceId == model.ServiceId); item.Should().NotBeNull(); item.DisplayName.Should().Be(model.DisplayName); } }
public async Task Returns_Item_With_All_Properties_When_Service_Exists() { var serviceModel = new Service { ServiceId = "Returns_Item_With_All_Properties_When_Service_Exists", DisplayName = "Test Service", Endpoints = new[] { new Uri("http://myservice1-qa.com") }, IpAddresses = new[] { "10.10.0.1" }, PublicUrls = new[] { new Uri("http://myservice-qa.com") } }; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { context.Services.Add(serviceModel.ToEntity()); context.SaveChanges(); } Service service; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var store = new ServiceStore(context, new Mock <ILogger <ServiceStore> >().Object); service = await store.FindByServiceIdAsync(serviceModel.ServiceId); } service.Should().NotBeNull(); service.ServiceId.Should().Be(serviceModel.ServiceId); service.DisplayName.Should().Be(serviceModel.DisplayName); service.Endpoints.Should().HaveCount(1); service.Endpoints[0].Should().Be(serviceModel.Endpoints[0]); service.IpAddresses.Should().HaveCount(1); service.IpAddresses[0].Should().Be(serviceModel.IpAddresses[0]); service.PublicUrls.Should().HaveCount(1); service.PublicUrls[0].Should().Be(serviceModel.PublicUrls[0]); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ServiceStoreDAL serviceStoreDal = new ServiceStoreDAL(); ServiceStore providedServiceStore = serviceStoreDal.FindById((int)value); TeamDAL teamDal = new TeamDAL(); return(teamDal.FindById(providedServiceStore.ProviderTeamID).TeamName); }
public ServiceStoreTests() { var configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddJsonStream(new MemoryStream(Encoding.ASCII.GetBytes(ServicesConfiguration))); _configuration = configurationBuilder.Build(); _serviceStore = new ServiceStore(_configuration); }
public void Does_Not_Throw_On_NonExisting_Item() { using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var store = new ServiceStore(context, new Mock <ILogger <ServiceStore> >().Object); Func <Task> action = async() => await store.RemoveAsync("anyserviceid"); action.Should().NotThrow(); } }
public async Task Returns_Null_When_Service_Not_Exists() { Service service; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var store = new ServiceStore(context, new Mock <ILogger <ServiceStore> >().Object); service = await store.FindByServiceIdAsync("someServiceId"); } service.Should().BeNull(); }
public static void RegisterService(string serviceName, string serviceTypeName, Func <PluginParameter, dynamic> func) { if (!_services.ContainsKey(serviceName)) { var store = new ServiceStore { Provider = null, Service = func, TypeName = serviceTypeName, }; _services.Add(serviceName, store); } }
public void LoadServicesFromAppSettingsShouldLoadEmptyListIfThereIsNoServiceSectionInConfiguration() { var configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddJsonStream(new MemoryStream(Encoding.ASCII.GetBytes(EmptyConfiguration))); _configuration = configurationBuilder.Build(); var serviceStore = new ServiceStore(_configuration); var services = serviceStore.GetAll(); Assert.NotNull(services); Assert.Empty(services); }
public static void RegisterService(string serviceName, string serviceTypeName, Func<PluginParameter, dynamic> func) { if (!_services.ContainsKey(serviceName)) { var store = new ServiceStore { Provider = null, Service = func, TypeName = serviceTypeName, }; _services.Add(serviceName, store); } }
public async Task <IHttpActionResult> GetName(Guid serviceId) { ServiceStore serviceStore = new ServiceStore(this.db); var result = await serviceStore.GetNameAsync(serviceId); if (string.IsNullOrWhiteSpace(result)) { return(NotFound()); } return(Ok(result)); }
public async Task <IHttpActionResult> Add(AddServiceRequest addServiceRequest) { if (addServiceRequest == null) { return(BadRequest("No service information was posted with the request.")); } if (!ModelState.IsValid) { return(InvalidModel()); } if (!this.IsUserAuthenticated) { return(Content(HttpStatusCode.Unauthorized, "You must be logged in to add a service.")); } var business = db.Businesses.FirstOrDefault(business1 => business1.Id == addServiceRequest.BusinessId); if (business == null) { return(Content(HttpStatusCode.NotFound, $"A business with the given id {addServiceRequest.BusinessId} does not exist in the database")); } bool hasPermission = db.BusinessUsers.Any(user => user.BusinessId == addServiceRequest.BusinessId && user.UserId == this.UserId); if (!hasPermission) { return(Content(HttpStatusCode.Forbidden, $"The user current user {UserId} does not have access to the business {addServiceRequest.BusinessId}.")); } ServiceStore serviceStore = new ServiceStore(db); var result = await serviceStore.CreateAsync(addServiceRequest.BusinessId, addServiceRequest.Name, addServiceRequest.Description, addServiceRequest.Cost, addServiceRequest.Duration); return(Ok(result.Id)); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ServiceStore serviceStore = (ServiceStore)value; string retval = ""; foreach (var item in serviceStore.ServiceStoreUserTeams.Where(x => !x.Deleted)) { if (!item.Team.Deleted) { string shortTeamName = String.IsNullOrEmpty(item.Team.ShortTeamName) ? item.Team.TeamName : item.Team.ShortTeamName; retval += shortTeamName + ", "; } } if (!string.IsNullOrEmpty(retval)) { return(retval.Substring(0, retval.Length - 2)); } return(""); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ServiceStore param = (ServiceStore)value; string retval = ""; bool inout = false; if ((string)parameter == "IN") { inout = true; } foreach (var item in param.ServiceStoreParams.Where(x => !x.Deleted && x.InOut == inout)) { retval += item.ParamName + ","; } if (!string.IsNullOrEmpty(retval)) { return(retval.Substring(0, retval.Length - 1)); } return(""); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { ServiceStore serviceStore = (ServiceStore)values[0]; Student contextStudent = (Student)values[1]; if (contextStudent == null) { return(Visibility.Hidden); } if (parameter != null && parameter.ToString() == "V" && (contextStudent == null || serviceStore.ProviderTeamID != contextStudent.TeamID)) { return(Visibility.Hidden); } else if (parameter != null && parameter.ToString() == "V" && serviceStore.ProviderTeamID == contextStudent.TeamID) { return(Visibility.Visible); } else { return(serviceStore.ProviderTeamID == contextStudent.TeamID); } }
private void SaveRequest(object param) { ServiceStore selectedServiceStore = (ServiceStore)((DataGrid)param).SelectedItem; SelectedServiceRequest.RequestType = SelectedServiceRequestTypeID; if (SelectedServiceRequest.RequestType == DictionaryDal.DictionaryListByType(4).Where(x => x.ID == 19).FirstOrDefault().ID&& selectedServiceStore == null) { MessageBox.Show("Módosítási igényhez szolgáltatás kijelölése szükséges!", "Hiba", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { if (SelectedServiceRequest.RequestType == DictionaryDal.DictionaryListByType(4).Where(x => x.ID == 19).FirstOrDefault().ID&& selectedServiceStore != null) { SelectedServiceRequest.ServiceID = selectedServiceStore.ID; } else { SelectedServiceRequest.ServiceID = null; } SelectedServiceRequest.ProviderTeamID = SelectedProviderTeamID; if (SelectedServiceRequest.AssigneeID != null && SelectedServiceRequest.RequestState == DictionaryDal.DictionaryListByType(5).Where(x => x.ID == 21).FirstOrDefault().ID) { SelectedServiceRequest.RequestState = DictionaryDal.DictionaryListByType(5).Where(x => x.ID == 22).FirstOrDefault().ID; } if (SelectedServiceRequest.ID == 0) { SelectedServiceRequest.CreatorID = ContextStudent.ID; _contextDal.Create(SelectedServiceRequest); } else { _contextDal.Update(SelectedServiceRequest); } this.SourceWindow.Close(); } }
public async Task Returns_Item_When_Service_Exists() { var serviceModel = new Service { ServiceId = "Returns_Item_When_Service_Exists", DisplayName = "Test Service" }; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { context.Services.Add(serviceModel.ToEntity()); context.SaveChanges(); } Service service; using (var context = new RegistryDbContext(DbContextOptions, StoreOptions)) { var store = new ServiceStore(context, new Mock <ILogger <ServiceStore> >().Object); service = await store.FindByServiceIdAsync(serviceModel.ServiceId); } service.Should().NotBeNull(); }
public ServiceStoreServiceParamEditViewModel(ServiceStoreServiceParamEditWindow window, ServiceStore selectedServiceStore, ServiceStoreServiceParams selectedParam) { this._contextDal = new ServiceStoreServiceParamsDAL(); this.SourceWindow = window; this.SelectedServiceStore = selectedServiceStore; this.TeamDal = new TeamDAL(); this.ServiceStoreDal = new ServiceStoreDAL(); this.TeamFilter = TeamDal.FindById(SelectedServiceStore.ProviderTeamID); this.SelectedParam = selectedParam; this.SessionGroupID = TeamDal.FindById(SelectedServiceStore.ProviderTeamID).SessionGroupID; this.TeamList = new ObservableCollection <Team>(TeamDal.FindAll(x => x.SessionGroupID == SessionGroupID)); this.ServiceStoreList = ReloadServiceStoreList(); this.SaveCommand = new RelayCommand(SaveParameter); }
public ServiceStoreParamAddWindow(ServiceStore selectedServiceStore, ServiceStoreParams serviceStoreParam) { InitializeComponent(); this.DataContext = new ServiceStoreParamAddViewModel(this, selectedServiceStore, serviceStoreParam); }
public ServiceStoreParamAddViewModel(ServiceStoreParamAddWindow sourceWindow, ServiceStore selectedServiceStore, ServiceStoreParams serviceStoreParam) { this.SourceWindow = sourceWindow; this.SelectedServiceStore = selectedServiceStore; this._contextDal = new ServiceStoreParamsDAL(); this.TeamDal = new TeamDAL(); this.ServiceTableDal = new ServiceTableDAL(); this.ServiceTableFieldDal = new ServiceTableFieldDAL(); this.ServiceStoreParamsDal = new ServiceStoreParamsDAL(); this.ServiceStoreDal = new ServiceStoreDAL(); this.DictionaryDal = new DictionaryDAL(); this.SessionGroupID = TeamDal.FindById(selectedServiceStore.ProviderTeamID).SessionGroupID; this.TeamFilter = TeamDal.FindById(SelectedServiceStore.ProviderTeamID); this.SessionGroupTeamList = new ObservableCollection <Team>(TeamDal.FindAll(x => x.SessionGroupID == SessionGroupID)); this.TableList = ReloadServiceTableList(); this.TableFieldList = ReloadServiceTableFieldList(); this.SelectedServiceStoreParam = serviceStoreParam; SelectedServiceStoreParam.ServiceStore = SelectedServiceStore; CustomFieldTypeList = new ObservableCollection <Dictionary>(DictionaryDal.DictionaryListByType(3)); this.SaveCommand = new RelayCommand(SaveParameter, CanSaveParameter); }
public List <ServiceStoreParams> ReloadOutputFieldList(ServiceStore Service) { RefreshContext(); return(FindAll(x => x.ServiceStore == Service && !x.InOut)); }
public ServiceStoreServiceParamEditWindow(ServiceStore serviceStore, ServiceStoreServiceParams param) { InitializeComponent(); this.DataContext = new ServiceStoreServiceParamEditViewModel(this, serviceStore, param); }
public ServiceStoreEditWindow(ServiceStore serviceStore, Student contextStudent) { InitializeComponent(); this.DataContext = new ServiceStoreEditViewModel(this, serviceStore, contextStudent); }
public static async Task Run() { var t = typeof(IStateList <int>); var service = new BackgroundServiceBase(); var store = new ServiceStore <IData>(data => { data.Condition = false; data.Number = 42; data.Uid = "ABCC"; data.Numbers.Reset(2, 5, 8, 12); }); var condProp = store.CreateWriter(service, x => x.Condition); var numbersProp = store.CreateWriter(service, x => x.Numbers); await condProp.Changed.Subscribe(store, b => { Console.WriteLine("Condition changed to " + b); return(Task.CompletedTask); }); await condProp.Set(true); await condProp.Set(false); await store.Observe(d => d.Numbers).Subscribe(store, args => { Console.WriteLine("Numbers Changes"); Console.WriteLine(string.Join("\n", args)); return(Task.CompletedTask); }); await store.Observe(d => d.Uid).Subscribe(store, args => { Console.WriteLine("Uid changed to: " + args); return(Task.CompletedTask); }); await numbersProp.Modify(list => { var i = list[2]; list[2]++; list.MoveAt(1, 2); list.RemoveAt(3); }); var res = await store.Select(data => $"{data.Uid}: {data.Condition}, {data.Number}\n {string.Join(", ", data.Numbers)}"); Console.WriteLine(res); await store.Modify(data => { data.Number = 50; data.Uid = data.Uid + data.Number; data.Numbers.AddRange(20, 40); data.Numbers.InsertRange(2, 50, 60); }); res = await store.Select(data => $"{data.Uid}: {data.Condition}, {data.Number}\n {string.Join(", ", data.Numbers)}"); Console.WriteLine(res); }