public string FetchTestDataOwner() { var testDataService = new TestDataService(_mongoDbHandler); var guid = new Guid("a987c35c-1c7a-4bd3-a449-a071ffeb71e7"); return(testDataService.GetDataOwner(guid)); }
public ReviewScenarios() { _previousDataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory"); AppDomain.CurrentDomain.SetData("DataDirectory", TempPath); _databaseName = "ReviewsTest"; _Service = new TestDataService(typeof(TestDSReviewService)); }
public async Task GetCategories_ShouldContain_Data() { var service = new TestDataService(); var categories = await service.GetCategories(); Assert.True(categories.Any()); }
/// <summary> /// 添加测试数据 /// </summary> /// <param name="sender">按钮对象</param> /// <param name="e">按钮对象事件参数信息</param> private void button1_Click(object sender, EventArgs e) { // 生成随机数据并发送至监听服务器 String userInfoJson = TestDataService.CreateTestData(); HttpClientTest.Instance.SendRequestMsg(userInfoJson); }
public async Task UpdateQuestion() { if (SelectedTest == null) { MessageBox.Show("Please select a test to take"); } else { IQuestionService questionService = new QuestionDataService(); ITestService testService = new TestDataService(); Test selectedTest = await testService.Get(SelectedTest.Id); IEnumerable <Question> selectedTestQuestions = await questionService.GetAllQuestionsForGivenTestName(selectedTest.TestName); if (selectedTest.TotalMark != selectedTestQuestions.Select(q => q.QuestionMark).Sum()) { MessageBox.Show("This test needs more questions in order to be eligible to be taken."); } else { SelectedTest = selectedTest; QuestionName = (selectedTest.Questions.ToList())[CurrentQuestion].QuestionText; QuestionText = (selectedTest.Questions.ToList())[CurrentQuestion].QuestionText; QuestionOptions = (selectedTest.Questions.ToList())[CurrentQuestion].QuestionOptions.ToList(); ListVisibility = Visibility.Collapsed; DescriptionVisibility = Visibility.Collapsed; MainVisibility = Visibility.Visible; CreateQuestionVisibility = Visibility.Collapsed; } } }
public async Task GetUsers_ShouldContain_Admin_UseShouldly() { var service = new TestDataService(); var users = await service.GetUsers(); users.ShouldNotBeEmpty(); users.ShouldContain(users.Where(x => x.RoleType == RoleType.Admin).FirstOrDefault()); }
public async Task GetUsers_ShouldContain_Member() { var service = new TestDataService(); var users = await service.GetUsers(); Assert.True(users.Any()); Assert.NotEmpty(users.Where(x => x.RoleType == RoleType.Member)); }
public override void Init(RepositoryProvider provider) { if (provider == RepositoryProvider.DataService) { _Service = new TestDataService(typeof(TestDSCatalogService)); } base.Init(provider); }
public void LoadData_ReturnsValidData_FileExists() { var dataLoader = new TestDataService(); var config = new TestConfigurationSettings(); var result = dataLoader.LoadData <DataLoaderResult>(config); Assert.IsNotNull(result); Assert.AreEqual(typeof(DataLoaderResult), result.GetType()); }
public void DataCanBeGet() { var userId = "0000-0000-0000-0000"; var testString = "test string content"; var testData = new TestDataDto { TestString = testString }; var savedId = TestDataRepository.SaveTestData(testData, userId); var gettedData = TestDataService.GetBy(savedId); Assert.AreEqual(gettedData, TestDataRepository.GetTestDataById(savedId)); }
public void TestInitialize() { IDepartment department = new TestDepartment(); TestLocalDataContext _tldc = new TestLocalDataContext(); TestDataFiller.Fill(_tldc); ITestDataService _testDataService = new TestDataService(_tldc); IDataContext _dataContext = new DataContext(_testDataService); _mainWindowViewModel = new MainWindowViewModel(_dataContext, department); }
private async void FuncToCall6(object context) { if (SelectedTest == null) { MessageBox.Show("Please select a test to delete"); } else { ITestService service = new TestDataService(); await service.Delete(SelectedTest.Id); TestList = Context.Tests.Where(q => q.TestName.Contains(SearchText)).ToList(); } }
public async Task GetItemsByCategoryName_ShouldHandle_IgnoreCase() { var service = new TestDataService(); var categoryName = "MOBILE"; var items_MOBILE = await service.GetItemsByCategoryName(categoryName); Assert.True(items_MOBILE.Any()); categoryName = "mobile"; var items_mobile = await service.GetItemsByCategoryName(categoryName); Assert.True(items_mobile.Any()); Assert.Equal(items_MOBILE.Count(), items_mobile.Count()); }
public async Task GetItems_ShouldContain_Data() { var service = new TestDataService(); var items = await service.GetItems(); Assert.True(items.Any()); foreach (var i in items) { Assert.NotNull(i.Category); Assert.NotNull(i.Seller); Assert.True(i.ItemBidHistories.Any()); foreach (var ibh in i.ItemBidHistories) { Assert.NotNull(ibh.Bidder); } } }
public void DataReallySaved() { var userId = "0000-0000-0000-0000"; var testString = "test string content"; var testData = new TestDataDto { TestString = testString }; var savedId = TestDataService.Save(testData, userId); var expectedData = new DataAccessLayer.TestData { Id = savedId, TestString = testString, UserId = userId }; Assert.AreEqual(TestDataRepository.GetTestDataById(savedId), expectedData); }
protected override async Task OnInitializedAsync() { var authenticationState = await authenticationStateTask; if (authenticationState.User.Identity.IsAuthenticated && !string.IsNullOrWhiteSpace(authenticationState.User.Claims.FirstOrDefault(c => c.Type == "name").Value)) { var tdv = await TestDataService.GetSecureDataAsync(); tdv.TestValue += authenticationState.User.Claims.FirstOrDefault(c => c.Type == "name").Value; TestDataValue = tdv; } else { var tdv = await TestDataService.GetUnsecuredDataAsync(); tdv.TestValue += " Not signed in"; TestDataValue = tdv; } //await base.OnInitializedAsync(); await InvokeAsync(StateHasChanged); }
private async void FuncToCall4(object context) { if (NewTestMark == 0) { MessageBox.Show("Please enter a total mark for this test"); } else if (NewTestName == null || NewTestName == "") { MessageBox.Show("Please enter a test name"); } else if (SelectedSeriesForNewTest == null || SelectedSeriesForNewTest == "") { MessageBox.Show("Please select a test series to assign this test to"); } else { Test newTest = new Test() { TestName = NewTestName, TotalMark = NewTestMark, }; ITestService testService = new TestDataService(); Test createdTest = await testService.CreateNewTest(newTest, SelectedSeriesForNewTest); if (createdTest == null) { MessageBox.Show("A test already exists with this name."); } else { AllTests = Context.Tests.Select(q => q.TestName).ToList(); NewTestName = null; NewTestMark = 0; SelectedSeriesForNewTest = null; } } }
public override void ViewDidLoad() { base.ViewDidLoad(); this.RegisterButton.TouchUpInside += (sender, e) => { RegistrationViewController vc = new RegistrationViewController(); this.PresentViewController(vc, true, null); }; this.LoginButton.TouchUpInside += (sender, e) => { LoginViewController vc = new LoginViewController(); this.PresentViewController(vc, true, null); }; this.GetDataButton.TouchUpInside += async(sender, e) => { TestDataService service = new TestDataService(); await service.AddTestData(); try { TestData data = await service.GetMostRecentItem(); this.BeginInvokeOnMainThread(() => { this.StatusLabel.Text = "Data retrieved! Date created was"; this.DataLabel.Text = data.DateCreated.ToString("G"); }); } catch (Exception ex) { this.BeginInvokeOnMainThread(() => { this.StatusLabel.TextColor = UIColor.Red; this.StatusLabel.Text = ex.Message; }); } }; }
/// <summary> /// Initializes a new instance of the TaskViewModel class. /// </summary> public TaskViewModel() { if (IsInDesignMode) { TestDataService testData = new TestDataService(); TaskData = testData.Output; } else { string FileName = @".\TaskData.xml"; if (File.Exists(FileName)) { XmlSerializer reader = new XmlSerializer(typeof(ObservableCollection <Category>)); StreamReader file = new System.IO.StreamReader(FileName); TaskData = reader.Deserialize(file) as ObservableCollection <Category>; } else { TaskData = new ObservableCollection <Category>(); TaskData.Add(new Category() { CategoryName = "Inbox", Index = Guid.NewGuid().ToString(), TaskList = new ObservableCollection <Task>() }); TaskData[0].TaskList.Add(new Task() { TaskName = "Welcome", TaskNote = "", IsFinished = false, SubtaskList = new ObservableCollection <Subtask>() } ); TaskData.Add(new Category() { CategoryName = "Today", Index = Guid.NewGuid().ToString(), TaskList = new ObservableCollection <Task>() }); TaskData.Add(new Category() { CategoryName = "Someday", Index = Guid.NewGuid().ToString(), TaskList = new ObservableCollection <Task>() }); TaskData.Add(new Category() { CategoryName = "Log", Index = Guid.NewGuid().ToString(), TaskList = new ObservableCollection <Task>() }); } } Category_State = "Normal"; AddTaskCommand = new RelayCommand(() => AddTask()); FilterTaskCommand = new RelayCommand(() => FilterTask()); ClearFilterCommand = new RelayCommand(() => { FilterStr = string.Empty; }); AddTask_EnterKeyCommand = new RelayCommand <KeyEventArgs>((e) => { if (e.Key == Key.Enter) { AddTask(); } }); EditCategory_DoubleClick_Command = new RelayCommand <MouseButtonEventArgs>((e) => { if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2) { EditCategoryCommand.Execute(new object()); e.Handled = true; } }); EditCategory_Key_Command = new RelayCommand <KeyEventArgs>((e) => { if (e.Key == Key.Enter) { EditCategoryCommand.Execute(new object()); } }); EditCategoryCommand = new RelayCommand(() => { if (Category_State == "Normal") { Messenger.Default.Send <MessengerToken>(MessengerToken.Category_EditMode, "RequestSending_from_TaskVM_to_TaskView_EditCategory"); Category_State = "Edit"; } else { foreach (Category c in TaskData) { if (string.IsNullOrEmpty(c.CategoryName)) { c.CategoryName = "Unnamed"; } } Messenger.Default.Send <MessengerToken>(MessengerToken.Category_NormalMode, "RequestSending_from_TaskVM_to_TaskView_EditCategory"); Category_State = "Normal"; } }); DeleteCategoryCommand = new RelayCommand <string>((index) => { for (int i = 0; i < TaskData.Count; i++) { if (TaskData[i].Index == index) { TaskData.RemoveAt(i); break; } } }); AddCategoryCommand = new RelayCommand(() => { TaskData.Insert(TaskData.Count - 1, new Category() { CategoryName = "Unnamed", Index = Guid.NewGuid().ToString(), TaskList = new ObservableCollection <Task>() }); Messenger.Default.Send <MessengerToken>(MessengerToken.Category_EditMode, "RequestSending_from_TaskVM_to_TaskView_EditCategory"); Category_State = "Edit"; }); Messenger.Default.Register <MessengerToken>(this, "RequestSending_from_MainVM_to_TaskVM_SaveTaskData", false, (msg) => { if (msg == MessengerToken.Save) { try { XmlSerializer writer = new XmlSerializer(typeof(ObservableCollection <Category>)); StreamWriter file = new StreamWriter(@".\TaskData.xml"); writer.Serialize(file, TaskData); file.Close(); } catch (Exception e) { Exception ie = e.InnerException; } } }); Messenger.Default.Register <MessengerToken>(this, "RequestSending_from_DetailsVM_to_TaskVM_SelectedTask", false, (msg) => { if (msg == MessengerToken.Delete_this_task) { RemoveTask(); } }); }
public TestDataController(TestDataService testDataSvc) { this.testDataService = testDataSvc; }
protected override async Task OnInitializedAsync() { TestData = await TestDataService.GetData(); }
public TestPricelistRepositoryFactory(TestDataService service) { _service = service; }
private MoviesController() { _service = new TestDataService(); }
protected override void Setup() { base.Setup(); TestDataService = new TestDataService(TestDataRepository); }
public static void Init() { Tests = new TestDataService(); }
public TestAppConfigRepositoryFactory(TestDataService service) { _service = service; }
public TestCatalogRepositoryFactory(TestDataService service) { _service = service; }
private async void FuncToCall3(object context) { if (QuestionTextForNewTest == null || QuestionTextForNewTest == "") { MessageBox.Show("Please populate the question text field"); } else if (FirstOptionForNewTest == null || FirstOptionForNewTest == "") { MessageBox.Show("Please populate the first option text field"); } else if (SecondOptionForNewTest == null || SecondOptionForNewTest == "") { MessageBox.Show("Please populate the second option text field"); } else if (ThirdOptionForNewTest == null || ThirdOptionForNewTest == "") { MessageBox.Show("Please populate the third option text field"); } else if (FourthOptionForNewTest == null || FourthOptionForNewTest == "") { MessageBox.Show("Please populate the fourth option text field"); } else if (SelectedTestForNewQuestion == null || SelectedTestForNewQuestion == "") { MessageBox.Show("Please select an associated test for this question"); } else if (CorrectAnswerForNewTest == null || CorrectAnswerForNewTest == "") { MessageBox.Show("Please populate the correct answer text field"); } else { Question newQuestion = new Question() { QuestionText = QuestionTextForNewTest, CorrectAnswer = CorrectAnswerForNewTest, QuestionMark = 10, }; IQuestionService questionService = new QuestionDataService(); ITestService testService = new TestDataService(); IEnumerable <Question> selectedTestQuestions = await questionService.GetAllQuestionsForGivenTestName(SelectedTestForNewQuestion); if (selectedTestQuestions.Count() > 0) { if (selectedTestQuestions.ToList()[0].Test.TotalMark == selectedTestQuestions.Select(q => q.QuestionMark).Sum()) { MessageBox.Show("This test cannot support any more questions (maximum score reached)."); } else { await questionService.CreateNewQuestion(newQuestion, SelectedTestForNewQuestion, FirstOptionForNewTest, SecondOptionForNewTest, ThirdOptionForNewTest, FourthOptionForNewTest); } } else { await questionService.CreateNewQuestion(newQuestion, SelectedTestForNewQuestion, FirstOptionForNewTest, SecondOptionForNewTest, ThirdOptionForNewTest, FourthOptionForNewTest); } QuestionTextForNewTest = null; FirstOptionForNewTest = null; SecondOptionForNewTest = null; ThirdOptionForNewTest = null; FourthOptionForNewTest = null; SelectedTestForNewQuestion = null; CorrectAnswerForNewTest = null; } }
public async Task UnitOfWorkTest() { var dataService = new TestDataService(null); var newEntry = new TestEntity { Id = 1, TextField = "This is a test", PrecisionField = 56.31m }; var newEntry2 = new TestEntity { Id = 2, TextField = "This is another test" }; Assert.AreEqual(dataService.Repository.GetAll <TestEntity>().Count(), 0); //With no transaction started there should be nothing to be commited await dataService.Repository.CreateAsync(newEntry); await dataService.UnitOfWork.CommitAsync(); Assert.AreEqual(dataService.Repository.GetAll <TestEntity>().Count(), 0); //With proper use of begin / commit there should be no issue dataService.UnitOfWork.BeginTransaction(); await dataService.Repository.CreateAsync(newEntry); await dataService.UnitOfWork.CommitAsync(); Assert.AreEqual(dataService.Repository.GetAll <TestEntity>().Count(), 1); //After commit is executed nothing else should be persisted await dataService.Repository.DeleteAsync(newEntry); await dataService.UnitOfWork.CommitAsync(); Assert.AreEqual(dataService.Repository.GetAll <TestEntity>().Count(), 1); //...until a new begin transaction is initiated dataService.UnitOfWork.BeginTransaction(); await dataService.Repository.DeleteAsync(newEntry); await dataService.UnitOfWork.CommitAsync(); Assert.AreEqual(dataService.Repository.GetAll <TestEntity>().Count(), 0); //Using ExecuteInUnitOfWork with an open transaction //in any thread should result in an exception dataService.UnitOfWork.BeginTransaction(); Action <TestEntity> executeInUnitOfWorkAction = async ent => { try { await dataService.ExecuteInUnitOfWorkAsync(async repository => { await repository.CreateAsync(ent); }); Assert.Fail("Should have raised an exception"); } catch (Exception ex) { if (ex is AssertionException) { Assert.Fail("Should not be an assertion exception"); } } }; //Main thread Exception executeInUnitOfWorkAction(newEntry); //Worker thread Exception var workerThread = new Thread(() => { executeInUnitOfWorkAction(newEntry); }); workerThread.Name = "Worker Thread"; workerThread.Start(); workerThread.Join(); //Commit to dispose the open tranaction and open a new one //when needed await dataService.UnitOfWork.CommitAsync(); executeInUnitOfWorkAction = async ent => { try { await dataService.ExecuteInUnitOfWorkAsync(async repository => { await repository.CreateAsync(ent); }); } catch (Exception ex) { Assert.Fail(ex.Message); } }; //Using ExecuteInUnitOfWork of NHibernateDataService should be thread //safe and having multiple threads using this call should have them //await each other to finish workerThread = new Thread(() => { executeInUnitOfWorkAction(newEntry); Thread.Sleep(500); }); workerThread.Name = "Worker Thread"; var slowerWorkerThread = new Thread(() => { Thread.Sleep(10); executeInUnitOfWorkAction(newEntry2); Thread.Sleep(1000); }); slowerWorkerThread.Name = "Slower Worker Thread"; slowerWorkerThread.Start(); workerThread.Start(); workerThread.Join(); slowerWorkerThread.Join(); Assert.AreEqual(dataService.Repository.GetAll <TestEntity>().Count(), 2); }
public IServiceProvider ConfigureServices(IServiceCollection services) { IServiceProvider serviceProvider; try { services.AddAuthentication(o => { o.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(o => { o.Authority = $"https://login.microsoftonline.com/{Configuration.ApiAuthentication.TenantId}"; o.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { RoleClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role", ValidAudiences = new List <string> { UseSandbox?Configuration.SandboxApiAuthentication.Audience: Configuration.ApiAuthentication.Audience, UseSandbox ? Configuration.SandboxApiAuthentication.ClientId : Configuration.ApiAuthentication.ClientId } }; o.Events = new JwtBearerEvents() { OnTokenValidated = context => { return(Task.FromResult(0)); } }; }); services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; }); services.Configure <RequestLocalizationOptions>(options => { options.DefaultRequestCulture = new RequestCulture("en-GB"); options.SupportedCultures = new List <CultureInfo> { new CultureInfo("en-GB") }; options.SupportedUICultures = new List <CultureInfo> { new CultureInfo("en-GB") }; options.RequestCultureProviders.Clear(); }); IMvcBuilder mvcBuilder; if (_env.IsDevelopment()) { mvcBuilder = services.AddMvc(opt => { opt.Filters.Add(new AllowAnonymousFilter()); }); } else { mvcBuilder = services.AddMvc(); } mvcBuilder .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, opts => { opts.ResourcesPath = "Resources"; }) .AddDataAnnotationsLocalization() .AddControllersAsServices() .AddFluentValidation(fvc => fvc.RegisterValidatorsFromAssemblyContaining <Startup>()); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "SFA.DAS.AssessorService.Application.Api", Version = "v1" }); c.CustomSchemaIds(i => i.FullName); if (_env.IsDevelopment()) { var basePath = AppContext.BaseDirectory; var xmlPath = Path.Combine(basePath, "SFA.DAS.AssessorService.Application.Api.xml"); c.IncludeXmlComments(xmlPath); } }); services.AddHttpClient <ProviderRegisterApiClient>("ProviderRegisterApiClient", config => { config.BaseAddress = new Uri(Configuration.ProviderRegisterApiAuthentication.ApiBaseAddress); // "https://findapprenticeshiptraining-api.sfa.bis.gov.uk" config.DefaultRequestHeaders.Add("Accept", "Application/json"); }) .SetHandlerLifetime(TimeSpan.FromMinutes(5)); services.AddHttpClient <ReferenceDataApiClient>("ReferenceDataApiClient", config => { config.BaseAddress = new Uri(Configuration.ReferenceDataApiAuthentication.ApiBaseAddress); // "https://at-refdata.apprenticeships.sfa.bis.gov.uk/api" config.DefaultRequestHeaders.Add("Accept", "Application/json"); }) .SetHandlerLifetime(TimeSpan.FromMinutes(5)); services.AddHttpClient <CompaniesHouseApiClient>("CompaniesHouseApiClient", config => { config.BaseAddress = new Uri(Configuration.CompaniesHouseApiAuthentication.ApiBaseAddress); // "https://api.companieshouse.gov.uk" config.DefaultRequestHeaders.Add("Accept", "Application/json"); }) .SetHandlerLifetime(TimeSpan.FromMinutes(5)); services.AddHttpClient <RoatpApiClient>("RoatpApiClient", config => { config.BaseAddress = new Uri(Configuration.RoatpApiAuthentication.ApiBaseAddress); // "https://at-providers-api.apprenticeships.education.gov.uk" config.DefaultRequestHeaders.Add("Accept", "Application/json"); }) .SetHandlerLifetime(TimeSpan.FromMinutes(5)); services.AddHealthChecks(); serviceProvider = ConfigureIOC(services); if (_env.IsDevelopment()) { TestDataService.AddTestData(serviceProvider.GetService <AssessorDbContext>()); } } catch (Exception e) { _logger.LogError(e, "Error during Startup Configure Services"); throw; } return(serviceProvider); }