Repository navigation
Expand file tree
/
Copy pathWhenAnyValueExamples.cs
More file actions
975 lines (796 loc) · 38.1 KB
/
Copy pathWhenAnyValueExamples.cs
File metadata and controls
975 lines (796 loc) · 38.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
// Copyright (c) 2019-2026 ReactiveUI and Contributors. All rights reserved.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System.Globalization;
using ReactiveUI.Binding.Documentation.Banking;
using ReactiveUI.Binding.Documentation.GitHub;
using ReactiveUI.Binding.Documentation.Todo;
using ReactiveUI.Primitives;
namespace ReactiveUI.Binding.Documentation.Observing;
/// <summary>
/// Shows every <c>WhenAnyValue</c> overload, from one observed property to sixteen, each with and without a value
/// selector. <c>WhenAnyValue</c> delivers the current values when you subscribe and again after each change.
/// </summary>
public static class WhenAnyValueExamples
{
/// <summary>The identifier of the registration task.</summary>
private const int RegistrationId = 7;
/// <summary>The title of the registration task.</summary>
private const string RegistrationTitle = "Renew car registration";
/// <summary>The title the registration task is renamed to.</summary>
private const string RenamedTitle = "Renew car registration online";
/// <summary>The notes of the registration task.</summary>
private const string RegistrationNotes = "Bring the insurance certificate";
/// <summary>The label of an errand.</summary>
private const string ErrandsTag = "errands";
/// <summary>The label of a car task.</summary>
private const string CarTag = "car";
/// <summary>The label of an urgent task.</summary>
private const string UrgentTag = "urgent";
/// <summary>The prefix of a finished checklist line.</summary>
private const string DoneMark = "[x] ";
/// <summary>The prefix of an open checklist line.</summary>
private const string OpenMark = "[ ] ";
/// <summary>The format of a deadline in a headline.</summary>
private const string IsoDay = "yyyy-MM-dd";
/// <summary>The number of the checkout issue.</summary>
private const int CheckoutNumber = 101;
/// <summary>The title of the checkout issue.</summary>
private const string CheckoutTitle = "Checkout button unresponsive on Safari";
/// <summary>The title the checkout issue is renamed to.</summary>
private const string RenamedIssueTitle = "Checkout button unresponsive on Safari 17";
/// <summary>The account name of the person the issue is assigned to.</summary>
private const string PriyaLogin = "priya-nair";
/// <summary>The account name of the person the issue is reassigned to.</summary>
private const string TomasLogin = "tomas-berg";
/// <summary>The label of a defect.</summary>
private const string BugLabel = "bug";
/// <summary>The label of the checkout area.</summary>
private const string CheckoutLabel = "checkout";
/// <summary>The comment the user is typing on the selected issue.</summary>
private const string CommentDraft = "Fixed in the next release.";
/// <summary>The identifier of the account the money leaves.</summary>
private const string EverydayId = "ACC-1001";
/// <summary>The name of the account the money leaves.</summary>
private const string EverydayName = "Everyday";
/// <summary>The currency of the account the money leaves.</summary>
private const string Currency = "AUD";
/// <summary>The balance of the account the money leaves.</summary>
private const decimal EverydayBalance = 4200.50M;
/// <summary>How far below zero the account may go.</summary>
private const decimal EverydayOverdraft = 500M;
/// <summary>The identifier of the payee.</summary>
private const int PayeeId = 3;
/// <summary>The most the customer allows in one transfer to the payee.</summary>
private const decimal PayeeLimit = 1000M;
/// <summary>The amount the customer starts with.</summary>
private const decimal RentAmount = 250M;
/// <summary>An amount above the payee's limit and below the available balance.</summary>
private const decimal AbovePayeeLimit = 1500M;
/// <summary>An amount above the available balance.</summary>
private const decimal AboveAvailable = 9000M;
/// <summary>The reference the customer starts with.</summary>
private const string RentReference = "Rent March";
/// <summary>The reference the customer changes to.</summary>
private const string RentReferenceRevised = "Rent March, paid early";
/// <summary>The deadline of the registration task.</summary>
private static readonly DateOnly _registrationDue = new(2026, 3, 20);
/// <summary>The deadline the registration task moves to.</summary>
private static readonly DateOnly _movedDue = new(2026, 3, 27);
/// <summary>The labels of the registration task.</summary>
private static readonly IReadOnlyList<string> _registrationTags = [ErrandsTag, CarTag];
/// <summary>The labels of the registration task once it is urgent.</summary>
private static readonly IReadOnlyList<string> _urgentTags = [ErrandsTag, CarTag, UrgentTag];
/// <summary>The labels of the checkout issue.</summary>
private static readonly IReadOnlyList<string> _checkoutLabels = [BugLabel, CheckoutLabel];
/// <summary>The comments of a new issue.</summary>
private static readonly IReadOnlyList<IssueComment> _noComments = [];
/// <summary>When the checkout issue last changed.</summary>
private static readonly DateTimeOffset _checkoutUpdatedAt = new(2026, 3, 2, 15, 5, 0, TimeSpan.Zero);
/// <summary>The person the issue is assigned to.</summary>
private static readonly User _priya = new() { Login = PriyaLogin, DisplayName = "Priya Nair" };
/// <summary>The person who reported the issue.</summary>
private static readonly User _maria = new() { Login = "maria-santos", DisplayName = "Maria Santos" };
/// <summary>The person the issue is reassigned to.</summary>
private static readonly User _tomas = new() { Login = TomasLogin, DisplayName = "Tomas Berg" };
/// <summary>The payee of the transfer.</summary>
private static readonly Payee _landlord = new(PayeeId, "Harbour Realty", "062-000 1234 5678", PayeeLimit);
/// <summary>Observes the title of a to-do item; a single property delivers the value itself.</summary>
public static void ObserveTodoTitle()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item.WhenAnyValue(static x => x.Title).Subscribe(Console.WriteLine);
item.Title = RenamedTitle;
// Output:
// Renew car registration
// Renew car registration online
}
/// <summary>Turns the title of a to-do item into its length with a value selector, as a character counter does.</summary>
public static void ProjectTodoTitleLength()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item.WhenAnyValue(static x => x.Title, static title => title.Length).Subscribe(Console.WriteLine);
item.Title = RenamedTitle;
// Output:
// 22
// 29
}
/// <summary>Observes the title and the done flag of a to-do item together.</summary>
public static void ObserveTodoTitleAndStatus()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item.WhenAnyValue(static x => x.Title, static x => x.IsDone).Subscribe(static values => Console.WriteLine(values.Property2));
item.IsDone = true;
// Output:
// False
// True
}
/// <summary>Turns the title and the done flag into one checklist line with a value selector.</summary>
public static void ProjectTodoChecklistLine()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item
.WhenAnyValue(static x => x.Title, static x => x.IsDone, static (title, isDone) => (isDone ? DoneMark : OpenMark) + title)
.Subscribe(Console.WriteLine);
item.IsDone = true;
// Output:
// [ ] Renew car registration
// [x] Renew car registration
}
/// <summary>Observes the title, the done flag and the priority of a to-do item.</summary>
public static void ObserveTodoTitleStatusAndPriority()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item
.WhenAnyValue(static x => x.Title, static x => x.IsDone, static x => x.Priority)
.Subscribe(static values => Console.WriteLine(values.Property3));
item.Priority = TodoPriority.High;
// Output:
// Normal
// High
}
/// <summary>Works out how urgent a to-do item is from three properties; a finished item is never urgent.</summary>
public static void ProjectTodoEffectivePriority()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item
.WhenAnyValue(static x => x.Title, static x => x.IsDone, static x => x.Priority, static (_, isDone, priority) => isDone ? TodoPriority.Low : priority)
.Subscribe(static priority => Console.WriteLine(priority));
item.Priority = TodoPriority.High;
item.IsDone = true;
// Output:
// Normal
// High
// Low
}
/// <summary>Observes the title, notes, done flag and deadline of a to-do item.</summary>
public static void ObserveTodoDeadline()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item
.WhenAnyValue(static x => x.Title, static x => x.Notes, static x => x.IsDone, static x => x.DueDate)
.Subscribe(static values => Console.WriteLine(values.Property4));
item.DueDate = _movedDue;
// Output:
// 03/20/2026
// 03/27/2026
}
/// <summary>Builds a headline with the deadline from four properties.</summary>
public static void ProjectTodoHeadline()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item
.WhenAnyValue(
static x => x.Title,
static x => x.Notes,
static x => x.IsDone,
static x => x.DueDate,
static (title, _, isDone, due) => isDone || due is null ? title : $"{title} due {due.Value.ToString(IsoDay, CultureInfo.InvariantCulture)}")
.Subscribe(Console.WriteLine);
item.DueDate = _movedDue;
// Output:
// Renew car registration due 2026-03-20
// Renew car registration due 2026-03-27
}
/// <summary>Observes the title, notes, done flag, deadline and priority of a to-do item.</summary>
public static void ObserveTodoWithPriority()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item
.WhenAnyValue(static x => x.Title, static x => x.Notes, static x => x.IsDone, static x => x.DueDate, static x => x.Priority)
.Subscribe(static values => Console.WriteLine(values.Property5));
item.Priority = TodoPriority.High;
// Output:
// Normal
// High
}
/// <summary>Decides from five properties whether a to-do item needs attention now.</summary>
public static void ProjectTodoNeedsAttention()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item
.WhenAnyValue(
static x => x.Title,
static x => x.Notes,
static x => x.IsDone,
static x => x.DueDate,
static x => x.Priority,
static (_, _, isDone, due, priority) => !isDone && due is not null && priority == TodoPriority.High)
.Subscribe(Console.WriteLine);
item.Priority = TodoPriority.High;
// Output:
// False
// True
}
/// <summary>Observes every editable property of a to-do item; six properties is the whole form.</summary>
public static void ObserveWholeTodo()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item
.WhenAnyValue(static x => x.Title, static x => x.Notes, static x => x.IsDone, static x => x.DueDate, static x => x.Priority, static x => x.Tags)
.Subscribe(static values => Console.WriteLine(string.Join(", ", values.Property6)));
item.Tags = _urgentTags;
// Output:
// errands, car
// errands, car, urgent
}
/// <summary>Lists the labels after the title from six properties.</summary>
public static void ProjectTodoTitleWithLabels()
{
TodoItem item = CreateRegistrationTask();
using IDisposable subscription = item
.WhenAnyValue(
static x => x.Title,
static x => x.Notes,
static x => x.IsDone,
static x => x.DueDate,
static x => x.Priority,
static x => x.Tags,
static (title, _, _, _, _, tags) => $"{title} #{string.Join(" #", tags)}")
.Subscribe(Console.WriteLine);
item.Tags = _urgentTags;
// Output:
// Renew car registration #errands #car
// Renew car registration #errands #car #urgent
}
/// <summary>Observes seven properties of a GitHub issue.</summary>
public static void ObserveIssueSummary()
{
Issue issue = CreateCheckoutIssue();
using IDisposable subscription = issue
.WhenAnyValue(static x => x.Number, static x => x.Title, static x => x.State, static x => x.Author, static x => x.Assignee!.Login, static x => x.Labels, static x => x.UpdatedAt)
.Subscribe(static values => Console.WriteLine(values.Property2));
issue.Title = RenamedIssueTitle;
// Output:
// Checkout button unresponsive on Safari
// Checkout button unresponsive on Safari 17
}
/// <summary>Names the number, title and assignee of an issue from seven properties.</summary>
public static void ProjectIssueAssignment()
{
Issue issue = CreateCheckoutIssue();
using IDisposable subscription = issue
.WhenAnyValue(
static x => x.Number,
static x => x.Title,
static x => x.State,
static x => x.Author,
static x => x.Assignee!.Login,
static x => x.Labels,
static x => x.UpdatedAt,
static (number, title, _, _, assignee, _, _) => $"#{number} {title} -> {assignee}")
.Subscribe(Console.WriteLine);
issue.Assignee = _tomas;
// Output:
// #101 Checkout button unresponsive on Safari -> priya-nair
// #101 Checkout button unresponsive on Safari -> tomas-berg
}
/// <summary>Observes eight properties of a GitHub issue.</summary>
public static void ObserveIssueWithComments()
{
Issue issue = CreateCheckoutIssue();
using IDisposable subscription = issue
.WhenAnyValue(
static x => x.Number,
static x => x.Title,
static x => x.State,
static x => x.Author,
static x => x.Assignee!.Login,
static x => x.Labels,
static x => x.UpdatedAt,
static x => x.Comments)
.Subscribe(static values => Console.WriteLine(values.Property3));
issue.State = IssueState.Closed;
// Output:
// Open
// Closed
}
/// <summary>Finds out from eight properties whether an open issue still waits for its first reply.</summary>
public static void ProjectIssueAwaitsFirstReply()
{
Issue issue = CreateCheckoutIssue();
using IDisposable subscription = issue
.WhenAnyValue(
static x => x.Number,
static x => x.Title,
static x => x.State,
static x => x.Author,
static x => x.Assignee!.Login,
static x => x.Labels,
static x => x.UpdatedAt,
static x => x.Comments,
static (_, _, state, _, _, _, _, comments) => state == IssueState.Open && comments.Count == 0)
.Subscribe(Console.WriteLine);
issue.State = IssueState.Closed;
// Output:
// True
// False
}
/// <summary>Observes a transfer draft and the fields of its source account, nine properties in all.</summary>
public static void ObserveTransferDraftAndSourceAccount()
{
TransferDraft draft = CreateTransferDraft();
using IDisposable subscription = draft
.WhenAnyValue(
static x => x.Amount,
static x => x.Reference,
static x => x.Source!.Id,
static x => x.Source!.Name,
static x => x.Source!.Kind,
static x => x.Source!.Currency,
static x => x.Source!.Balance,
static x => x.Source!.OverdraftLimit,
static x => x.Source!.AvailableBalance)
.Subscribe(static values => Console.WriteLine(values.Property2));
draft.Reference = RentReferenceRevised;
// Output:
// Rent March
// Rent March, paid early
}
/// <summary>Checks from nine properties whether the account can cover the amount.</summary>
public static void ProjectTransferIsAffordable()
{
TransferDraft draft = CreateTransferDraft();
using IDisposable subscription = draft
.WhenAnyValue(
static x => x.Amount,
static x => x.Reference,
static x => x.Source!.Id,
static x => x.Source!.Name,
static x => x.Source!.Kind,
static x => x.Source!.Currency,
static x => x.Source!.Balance,
static x => x.Source!.OverdraftLimit,
static x => x.Source!.AvailableBalance,
static (amount, _, _, _, _, _, _, _, available) => amount <= available)
.Subscribe(Console.WriteLine);
draft.Amount = AboveAvailable;
// Output:
// True
// False
}
/// <summary>Adds the payee to the transfer draft and its source account fields, ten properties in all; the payee is replaced as a whole.</summary>
public static void ObserveTransferDraftWithPayee()
{
TransferDraft draft = CreateTransferDraft();
using IDisposable subscription = draft
.WhenAnyValue(
static x => x.Amount,
static x => x.Reference,
static x => x.Source!.Id,
static x => x.Source!.Name,
static x => x.Source!.Kind,
static x => x.Source!.Currency,
static x => x.Source!.Balance,
static x => x.Source!.OverdraftLimit,
static x => x.Source!.AvailableBalance,
static x => x.Payee!)
.Subscribe(static values => Console.WriteLine(values.Property2));
draft.Reference = RentReferenceRevised;
// Output:
// Rent March
// Rent March, paid early
}
/// <summary>Checks from ten properties whether the amount fits the account and the payee's limit.</summary>
public static void ProjectTransferWithinPayeeLimit()
{
TransferDraft draft = CreateTransferDraft();
using IDisposable subscription = draft
.WhenAnyValue(
static x => x.Amount,
static x => x.Reference,
static x => x.Source!.Id,
static x => x.Source!.Name,
static x => x.Source!.Kind,
static x => x.Source!.Currency,
static x => x.Source!.Balance,
static x => x.Source!.OverdraftLimit,
static x => x.Source!.AvailableBalance,
static x => x.Payee!,
static (amount, _, _, _, _, _, _, _, available, payee) => amount <= available && (payee.TransferLimit is null || amount <= payee.TransferLimit))
.Subscribe(Console.WriteLine);
draft.Amount = AbovePayeeLimit;
// Output:
// True
// False
}
/// <summary>Adds the whole source account next to its fields, eleven properties in all.</summary>
public static void ObserveTransferDraftWithSourceAccount()
{
TransferDraft draft = CreateTransferDraft();
using IDisposable subscription = draft
.WhenAnyValue(
static x => x.Amount,
static x => x.Reference,
static x => x.Source!.Id,
static x => x.Source!.Name,
static x => x.Source!.Kind,
static x => x.Source!.Currency,
static x => x.Source!.Balance,
static x => x.Source!.OverdraftLimit,
static x => x.Source!.AvailableBalance,
static x => x.Payee!,
static x => x.Source!)
.Subscribe(static values => Console.WriteLine(values.Property2));
draft.Reference = RentReferenceRevised;
// Output:
// Rent March
// Rent March, paid early
}
/// <summary>Checks from eleven properties whether a transfer names a payee and the account can cover it.</summary>
public static void ProjectTransferIsReady()
{
TransferDraft draft = CreateTransferDraft();
using IDisposable subscription = draft
.WhenAnyValue(
static x => x.Amount,
static x => x.Reference,
static x => x.Source!.Id,
static x => x.Source!.Name,
static x => x.Source!.Kind,
static x => x.Source!.Currency,
static x => x.Source!.Balance,
static x => x.Source!.OverdraftLimit,
static x => x.Source!.AvailableBalance,
static x => x.Payee!,
static x => x.Source!,
static (amount, _, _, _, _, _, _, _, available, payee, _) => payee.Name.Length > 0 && amount <= available)
.Subscribe(Console.WriteLine);
draft.Amount = AboveAvailable;
// Output:
// True
// False
}
/// <summary>Observes the session, the selected issue and the rate limit of the issue board, twelve properties in all.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ObserveIssueBoardRateLimit()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining)
.Subscribe(static values => Console.WriteLine(values.Property11.Length));
board.NewCommentText = CommentDraft;
// Output:
// 0
// 26
}
/// <summary>Decides from twelve properties whether the board can accept a comment.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ProjectBoardAcceptsComments()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining,
static (signedIn, _, _, _, _, _, state, _, _, _, _, remaining) => signedIn && state == IssueState.Open && remaining > 0)
.Subscribe(Console.WriteLine);
board.SelectedIssue!.State = IssueState.Closed;
// Output:
// True
// False
}
/// <summary>Adds the last error message to the issue board properties, thirteen in all.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ObserveIssueBoardErrorMessage()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
Issue issue = board.SelectedIssue!;
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining,
static x => x.ErrorMessage)
.Subscribe(static values => Console.WriteLine(values.Property6));
issue.Title = RenamedIssueTitle;
// Output:
// Checkout button unresponsive on Safari
// Checkout button unresponsive on Safari 17
}
/// <summary>Decides from thirteen properties whether the board can accept a comment and has no error.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ProjectBoardAcceptsCommentsWithoutError()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining,
static x => x.ErrorMessage,
static (signedIn, _, _, _, _, _, state, _, _, _, _, remaining, error) =>
signedIn && state == IssueState.Open && remaining > 0 && error.Length == 0)
.Subscribe(Console.WriteLine);
board.SelectedIssue!.State = IssueState.Closed;
// Output:
// True
// False
}
/// <summary>Adds the access token to the issue board properties, fourteen in all.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ObserveIssueBoardToken()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
Issue issue = board.SelectedIssue!;
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining,
static x => x.ErrorMessage,
static x => x.Token)
.Subscribe(static values => Console.WriteLine(values.Property8));
issue.Assignee = _tomas;
// Output:
// priya-nair
// tomas-berg
}
/// <summary>Decides from fourteen properties whether the board can accept a comment with a token in place.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ProjectBoardHasTokenAndAcceptsComments()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining,
static x => x.ErrorMessage,
static x => x.Token,
static (signedIn, _, _, _, _, _, state, _, _, _, _, remaining, error, token) =>
signedIn && state == IssueState.Open && remaining > 0 && error.Length == 0 && token.Length > 0)
.Subscribe(Console.WriteLine);
board.SelectedIssue!.State = IssueState.Closed;
// Output:
// True
// False
}
/// <summary>Adds the open issues of the repository to the issue board properties, fifteen in all.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ObserveIssueBoardIssues()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining,
static x => x.ErrorMessage,
static x => x.Token,
static x => x.Issues)
.Subscribe(static values => Console.WriteLine(values.Property11.Length));
board.NewCommentText = CommentDraft;
// Output:
// 0
// 26
}
/// <summary>Decides from fifteen properties whether the board can accept a comment and lists issues.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ProjectBoardListsIssuesAndAcceptsComments()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining,
static x => x.ErrorMessage,
static x => x.Token,
static x => x.Issues,
static (signedIn, _, _, _, _, _, state, _, _, _, _, remaining, error, token, issues) =>
signedIn && state == IssueState.Open && remaining > 0 && error.Length == 0 && token.Length > 0 && issues.Count > 0)
.Subscribe(Console.WriteLine);
board.SelectedIssue!.State = IssueState.Closed;
// Output:
// True
// False
}
/// <summary>Observes sixteen properties of the issue board, the most one call accepts.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ObserveIssueBoardRepositories()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining,
static x => x.ErrorMessage,
static x => x.Token,
static x => x.Issues,
static x => x.Repositories)
.Subscribe(static values => Console.WriteLine(values.Property11.Length));
board.NewCommentText = CommentDraft;
// Output:
// 0
// 26
}
/// <summary>Decides from sixteen properties whether the board can accept a comment, has repositories and lists issues.</summary>
/// <returns>A task that completes when the checks finish.</returns>
public static async Task ProjectBoardIsReadyForComments()
{
IssueBoardViewModel board = await CreateBoardWithSelectedIssueAsync();
using IDisposable subscription = board
.WhenAnyValue(
static x => x.IsSignedIn,
static x => x.CurrentUser!.Login,
static x => x.SelectedRepository!,
static x => x.SelectedIssue!.Author.Login,
static x => x.SelectedIssue!.Number,
static x => x.SelectedIssue!.Title,
static x => x.SelectedIssue!.State,
static x => x.SelectedIssue!.Assignee!.Login,
static x => x.SelectedIssue!.Labels,
static x => x.SelectedIssue!.UpdatedAt,
static x => x.NewCommentText,
static x => x.RateLimitRemaining,
static x => x.ErrorMessage,
static x => x.Token,
static x => x.Issues,
static x => x.Repositories,
static (signedIn, _, _, _, _, _, state, _, _, _, _, remaining, error, token, issues, repositories) =>
signedIn && state == IssueState.Open && remaining > 0 && error.Length == 0 && token.Length > 0 && issues.Count > 0 && repositories.Count > 0)
.Subscribe(Console.WriteLine);
board.SelectedIssue!.State = IssueState.Closed;
// Output:
// True
// False
}
/// <summary>Creates the to-do item the examples observe.</summary>
/// <returns>An open, unfinished item.</returns>
private static TodoItem CreateRegistrationTask() => new()
{
Id = RegistrationId,
Title = RegistrationTitle,
Notes = RegistrationNotes,
DueDate = _registrationDue,
Priority = TodoPriority.Normal,
Tags = _registrationTags,
};
/// <summary>Creates the issue the examples observe.</summary>
/// <returns>An open issue reported by Maria and assigned to Priya.</returns>
private static Issue CreateCheckoutIssue() => new()
{
Number = CheckoutNumber,
Title = CheckoutTitle,
State = IssueState.Open,
Author = _maria,
Assignee = _priya,
Labels = _checkoutLabels,
Comments = _noComments,
UpdatedAt = _checkoutUpdatedAt,
};
/// <summary>Creates the transfer the examples observe.</summary>
/// <returns>A draft that sends the rent from the everyday account to the landlord.</returns>
private static TransferDraft CreateTransferDraft() =>
new() { Source = CreateEverydayAccount(), Payee = _landlord, Amount = RentAmount, Reference = RentReference };
/// <summary>Creates the account the transfer draws on.</summary>
/// <returns>An everyday account with an overdraft.</returns>
private static Account CreateEverydayAccount() => new()
{
Id = EverydayId,
Name = EverydayName,
Kind = AccountKind.Everyday,
Currency = Currency,
Balance = EverydayBalance,
OverdraftLimit = EverydayOverdraft,
};
/// <summary>Signs in to a seeded server, loads the open issues of the webshop repository and selects the checkout issue.</summary>
/// <returns>A task that returns the board once the issue is selected.</returns>
private static async Task<IssueBoardViewModel> CreateBoardWithSelectedIssueAsync()
{
InMemoryGitHubServer server = InMemoryGitHubServer.CreateSeeded();
IssueBoardViewModel board = new(server) { Token = InMemoryGitHubServer.PriyaToken };
await board.SignInAsync();
board.SelectedRepository = board.Repositories[0];
await board.LoadIssuesAsync();
board.SelectedIssue = board.Issues[1];
return board;
}
}