static void WriteExample() { var parser = new FixedWidthParser <SampleRecord>(); var fs = new FileInfo("test2.txt").OpenWrite(); var records = new List <SampleRecord>(); var sample1 = new SampleRecord() { FirstName = "Daniel", LastName = "Davis", Email = "*****@*****.**" }; var sample2 = new SampleRecord() { FirstName = "Some", LastName = "Guy" }; records.Add(sample1); records.Add(sample2); parser.Write(fs, records); fs.Close(); }
public async Task DeleteAndGetPreviousAsyncWorks() { // --- Arrange var db = new SqlDatabase(DB_CONN); await db.ExecuteAsync(@"create table sample(Id int not null, Name varchar(50) null)"); var record1 = new SampleRecord { Id = 1, Name = "First" }; var record2 = new SampleRecord { Id = 2, Name = "Second" }; await db.InsertAsync(record1); await db.InsertAsync(record2); // --- Act var prev1 = await db.DeleteAndGetPreviousAsync(record1); var prev2 = await db.DeleteAndGetPreviousAsync(record2); var prev3 = await db.DeleteAndGetPreviousAsync(record1); // --- Assert prev1.ShouldNotBeNull(); prev1.Id.ShouldEqual(1); prev1.Name.ShouldEqual("First"); prev2.ShouldNotBeNull(); prev2.Id.ShouldEqual(2); prev2.Name.ShouldEqual("Second"); prev3.ShouldBeNull(); }
private TaggedProcessResult ProcessElement([NotNull] SampleRecord record, [NotNull] IAccumulator processor) { var processResult = processor.Process(record.PulseSequence); return(new TaggedProcessResult(processResult, record.Id)); }
public void SingleIntoWorksAsExpected() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); db.Execute(@"insert into ""sample"" values(1, 'First')"); db.Execute(@"insert into ""sample"" values(2, 'Second')"); // --- Act var instance = new SampleRecord { Id = 3 }; var row1 = db.SingleInto(instance, @"select ""Name"" from ""sample"" where ""Id"" = 1"); var row2 = db.SingleInto(instance, SqlExpression.CreateFrom( @"select ""Name"" from ""sample"" where ""Id"" = 1")); // --- Assert row1.Id.ShouldEqual(3); row1.Name.ShouldEqual("First"); row2.Id.ShouldEqual(3); row2.Name.ShouldEqual("First"); }
private RefTaggedResult ProcessElement([NotNull] SampleRecord record, [NotNull] ISplitter processor) { var splitResult = processor.Process(record.PulseSequence); return(new RefTaggedResult(splitResult, record.Id)); }
public void SimpleUpdateWorksAsExpected() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); var record = new SampleRecord { Name = "First" }; db.Insert(record); // --- Act record.Name = "NewFirst"; db.Update(record); // --- Assert var back = db.FirstOrDefault <SampleRecord>(@"where ""Id"" = @0", record.Id); back.ShouldNotBeNull(); back.Id.ShouldEqual(record.Id); back.Name.ShouldEqual("NewFirst"); }
public void FirstOrDefaultIntoWorksAsExpected() { // --- Arrange var db = new SqlDatabase(DB_CONN); db.Execute(@"create table sample(Id int not null, Name varchar(50) null)"); db.Execute("insert into sample values(1, 'First')"); db.Execute("insert into sample values(2, 'Second')"); // --- Act var instance = new SampleRecord { Id = 3 }; var row1 = db.FirstOrDefaultInto(instance, "select Name from sample order by Id"); var row2 = db.FirstOrDefaultInto(instance, SqlExpression.CreateFrom("select Name from sample order by Id")); var row3 = db.FirstOrDefaultInto(instance, "select Name from sample where Id = 3"); var row4 = db.FirstOrDefaultInto(instance, SqlExpression.CreateFrom("select Name from sample where Id = 3")); // --- Assert row1.Id.ShouldEqual(3); row1.Name.ShouldEqual("First"); row2.Id.ShouldEqual(3); row2.Name.ShouldEqual("First"); row3.ShouldBeNull(); row4.ShouldBeNull(); }
public async Task FirstAsyncIntoWorksAsExpected() { // --- Arrange var db = new FbDatabase(DB_CONN); await db.BeginTransactionAsync(); await db.ExecuteAsync(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); await db.CompleteTransactionAsync(); await db.ExecuteAsync(@"insert into ""sample"" values(1, 'First')"); await db.ExecuteAsync(@"insert into ""sample"" values(2, 'Second')"); // --- Act var instance = new SampleRecord { Id = 3 }; var row1 = await db.FirstIntoAsync(instance, @"select ""Name"" from ""sample"" order by ""Id"""); var row2 = await db.FirstIntoAsync(instance, SqlExpression.CreateFrom( @"select ""Name"" from ""sample"" order by ""Id""")); // --- Assert row1.Id.ShouldEqual(3); row1.Name.ShouldEqual("First"); row2.Id.ShouldEqual(3); row2.Name.ShouldEqual("First"); }
public async Task ForceNavigate(OpeningPage openingPage, SampleRecord sampleRecord) { var p = new NavigationParameters { { "sampleRecord", sampleRecord } }; await NavigationService.NavigateAsync("NavigationPage/" + openingPage.ToString(), p); }
//public static SampleWriter1 Create(out string dbFilepath) //{ // dbFilepath = Path.GetTempFileName(); // return new SampleWriter1(dbFilepath); //} public void Insert(string text) { using (var db = ConnectToRepo()) { var rec = new SampleRecord { Text1 = text }; db.Insert(rec); } }
public void SaveSampleRecord(SampleRecord recordMeasurement) { var context = Realm.GetInstance(); // 下記のようにトランザクションを利用可能 using (var transaction = context.BeginWrite()) { context.Add(recordMeasurement); transaction.Commit(); } }
public IResult ProcessElement([NotNull] SampleRecord record) { var result = _worker.GetPhase(record.PulseSequence); if (result.HasSpectrum) { Adapter.UpdatePhase(result.Data); // Writer?.Write(new TracedSpectrum(result.Data, record.Id.ToString())); } return(new PhaseResultAdapter(result)); }
public void Success() { //setup A.CallTo(() => connection.Get <SampleRecord>(A <long> .Ignored, transaction)).Returns(new SampleRecord()); //execution SampleRecord record = null; Action action = () => { record = sampleRepository.SearchById(1); }; //assertions action.Should().NotThrow <Exception>(); record.Should().NotBeNull(); }
public void Load() { using (var context = CreateMethodContext()) { // Create data log record and save var dataLog = new DataLog(); dataLog.LogName = "SampleLog"; context.SaveOne(dataLog); // Create queue record and save, then get its id var queue = new JobQueue(); queue.JobQueueName = "SampleQueue"; queue.Log = dataLog.ToKey(); context.SaveOne(queue, context.DataSet); var queueId = queue.Id; // Create sample record var sampleRecord = new SampleRecord(); sampleRecord.SampleName = "SampleName"; context.SaveOne(sampleRecord); // Create job record and save, then get its id var job = new Job(); job.Queue = queue.ToKey(); job.CollectionName = DataTypeInfo.GetOrCreate <SampleRecord>().GetCollectionName(); job.RecordId = sampleRecord.Id; job.MethodName = "SampleMethod"; context.SaveOne(job); var jobId = job.Id; // Load the records back var queueKey = queue.ToKey(); var loadedQueue = context.Load(queueKey); var jobKey = new JobKey { Id = jobId }; var loadedJob = context.Load(jobKey); // Check that TemporalId based key works correctly Assert.True(loadedJob.Queue.Value == loadedQueue.ToKey().Value); // Run the job // TODO - incomment when implemented // loadedJob.Run(); context.Log.Verify("Completed"); } }
public async Task DeleteAndGetPreviousAsyncWorksWithCancellation() { // --- Arrange var db = new SqlDatabase(DB_CONN); await db.ExecuteAsync(@"create table sample(Id int not null, Name varchar(50) null)"); var record1 = new SampleRecord { Id = 1, Name = "First" }; await db.InsertAsync(record1); var cts = new CancellationTokenSource(); // --- Act cts.Cancel(); await db.DeleteAndGetPreviousAsync(record1, cts.Token); }
public void UpdateAfterDeleteRaisesAnIssue() { // --- Arrange using (var prepdb = new SqlDatabase(DB_CONN)) { prepdb.Execute(CREATE_SAMPLE_TABLE); prepdb.Insert(new SampleRecord { Id1 = 1, Id2 = 2, Name = "First" }); } // --- Act SqlDatabaseChangeSet changeSet = null; using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked)) { db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; }; db.DeleteById <SampleRecord>(1, 2); var record = new SampleRecord(); ((IDataRecord)record).SignLoaded(); record.Id1 = 1; record.Id2 = 2; record.Name = "First"; db.Update(record); } // --- Assert var tableChangeSet = changeSet["[dbo].[sample]"]; var recordChangeSet = tableChangeSet[new PrimaryKeyValue(new List <object> { 1, 2 })]; recordChangeSet.State.ShouldEqual(ChangedRecordState.Deleted); recordChangeSet.IssueList.ShouldHaveCountOf(2); recordChangeSet.IssueList[1].Description.ShouldContainIgnoringCase("has already been deleted"); recordChangeSet.ShouldHaveCountOf(3); recordChangeSet["Id1"].PreviousValue.ShouldEqual(1); recordChangeSet["Id1"].NewValue.ShouldBeNull(); recordChangeSet["Id2"].PreviousValue.ShouldEqual(2); recordChangeSet["Id2"].NewValue.ShouldBeNull(); recordChangeSet["Name"].PreviousValue.ShouldEqual("First"); recordChangeSet["Name"].NewValue.ShouldBeNull(); }
public void MultipleUpdateAfterInsertIsCaughtByTracking() { // --- Arrange using (var prepdb = new SqlDatabase(DB_CONN)) { prepdb.Execute(CREATE_SAMPLE_TABLE); } // --- Act SqlDatabaseChangeSet changeSet = null; using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked)) { db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; }; var record = new SampleRecord { Id1 = 1, Id2 = 2, Name = "First" }; db.Insert(record); record.Description = "New description"; db.Update(record); record.Name = "New name"; db.Update(record); } // --- Assert var tableChangeSet = changeSet["[dbo].[sample]"]; var recordChangeSet = tableChangeSet[new PrimaryKeyValue(new List <object> { 1, 2 })]; recordChangeSet.State.ShouldEqual(ChangedRecordState.Inserted); recordChangeSet.IssueList.ShouldHaveCountOf(0); recordChangeSet.ShouldHaveCountOf(4); recordChangeSet["Id1"].PreviousValue.ShouldBeNull(); recordChangeSet["Id1"].NewValue.ShouldEqual(1); recordChangeSet["Id2"].PreviousValue.ShouldBeNull(); recordChangeSet["Id2"].NewValue.ShouldEqual(2); recordChangeSet["Name"].PreviousValue.ShouldBeNull(); recordChangeSet["Name"].NewValue.ShouldEqual("New name"); recordChangeSet["Description"].PreviousValue.ShouldBeNull(); recordChangeSet["Description"].NewValue.ShouldEqual("New description"); }
async void Button_Click(object sender, RoutedEventArgs e) { if (!(await ConnectAsync())) { MessageBox.Show($"Failed"); return; } var res0 = await _appServiceConnection.SendMessageAsync(new ValueSet { ["Operation"] = "FullScreen", }); await System.Threading.Tasks.Task.Delay(500); WindowState = WindowState.Minimized; WindowStyle = WindowStyle.None; Topmost = false; var sample = new SampleRecord { Guid = Guid.NewGuid().ToString(), Data1 = "Data1", Data2 = "Data2", Data3 = "Data3", Data4 = "Data4", Data5 = "Data5", }; var serialized = JsonConvert.SerializeObject(sample); var res1 = await _appServiceConnection.SendMessageAsync(new ValueSet { ["Operation"] = "Data", ["SampleRecord"] = serialized, }); //logTextBlock.Text = res1.Message["Result"] as string; }
public async Task AddSubscriber() { var path1 = $"{Fake.Text}/{Fake.Text}"; var path2 = Fake.Text; var sut = await GetConnectedSUT(); var rec = new SampleRecord(Fake.Text); await sut.CreateNode(rec, path1, path2); var res = string.Empty; await sut.AddSubscriber <SampleRecord>(async arg => { await sut.DeleteNode(path1, path2); res = $"from event: {arg.Text1}"; }, path1); await Task.Delay(1000 * 3); res.Should().Be($"from event: {rec.Text1}"); }
public async Task SimpleUpdateAsyncWorksAsExpected() { // --- Arrange var db = new SqlDatabase(DB_CONN); await db.ExecuteAsync(@"create table sample(Id int not null, Name varchar(50) null)"); var record = new SampleRecord { Name = "First" }; await db.InsertAsync(record); // --- Act record.Name = "NewFirst"; await db.UpdateAsync(record); // --- Assert var back = await db.FirstOrDefaultAsync <SampleRecord>("where Id = @0", record.Id); back.ShouldNotBeNull(); back.Id.ShouldEqual(record.Id); back.Name.ShouldEqual("NewFirst"); }
public async Task SingleIntoAsyncWorksAsExpected() { // --- Arrange var db = new SqlDatabase(DB_CONN); await db.ExecuteAsync(@"create table sample(Id int not null, Name varchar(50) null)"); await db.ExecuteAsync("insert into sample values(1, 'First')"); await db.ExecuteAsync("insert into sample values(2, 'Second')"); // --- Act var instance = new SampleRecord { Id = 3 }; var row1 = await db.SingleIntoAsync(instance, "select Name from sample where Id = 1"); var row2 = await db.SingleIntoAsync(instance, SqlExpression.CreateFrom("select Name from sample where Id = 1")); // --- Assert row1.Id.ShouldEqual(3); row1.Name.ShouldEqual("First"); row2.Id.ShouldEqual(3); row2.Name.ShouldEqual("First"); }
private CheckResult ProcessFunc(SampleRecord record, PulseChecker checker) { var specInfos = checker.Process(record.PulseSequence); return(new CheckResult(specInfos.Select(info => new SpecInfoWrapper(info, record.Id)).ToList())); }
public void Write(SampleRecord record) { Toolbox.SerializeData(BasePath + record.Id.Enclose("No") + Suffix, record.PulseSequence); }
public int InsertSample(SampleRecord record) { Operation(ctx => ctx.Insert(record)); return record.Id; }
public static async void PerformNavigateCommand(this ContentPage page, OpeningPage openingPage, SampleRecord recordMeasurement) { var viewModelBase = (ViewModelBase)page.BindingContext; await viewModelBase.ForceNavigate(openingPage, recordMeasurement); }
/// <summary> /// Consume element in a branch. /// </summary> /// <param name="element">The product</param> /// <param name="worker">The worker in this branch.</param> /// <returns>Whether consuming succeeds.</returns> private TrueResult ConsumeElement(SampleRecord element, SpecialSampleWriter worker) { worker.Write(element); return(_result); }