Menu

[r732]: / trunk / UnitTests / SyncAppointmentsTests.cs  Maximize  Restore  History

Download this file

1014 lines (811 with data), 45.2 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
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
using System;
using NUnit.Framework;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Threading;
using Google.Apis.Calendar.v3.Data;
namespace GoContactSyncMod.UnitTests
{
[TestFixture]
public class SyncAppointmentsTests
{
Synchronizer sync;
static Logger.LogUpdatedHandler _logUpdateHandler = null;
//Constants for test appointment
const string name = "AN_OUTLOOK_TEST_APPOINTMENT";
//readonly When whenDay = new When(DateTime.Now, DateTime.Now, true);
//readonly When whenTime = new When(DateTime.Now, DateTime.Now.AddHours(1), false);
//ToDo:const string groupName = "A TEST GROUP";
[OneTimeSetUp]
public void Init()
{
//string timestamp = DateTime.Now.Ticks.ToString();
if (_logUpdateHandler == null)
{
_logUpdateHandler = new Logger.LogUpdatedHandler(Logger_LogUpdated);
Logger.LogUpdated += _logUpdateHandler;
}
string gmailUsername;
//string gmailPassword;
string syncProfile;
string syncContactsFolder;
string syncNotesFolder;
string syncAppointmentsFolder;
GoogleAPITests.LoadSettings(out gmailUsername, out syncProfile, out syncContactsFolder, out syncNotesFolder, out syncAppointmentsFolder);
sync = new Synchronizer();
sync.SyncAppointments = true;
sync.SyncNotes = false;
sync.SyncContacts = false;
sync.SyncProfile = syncProfile;
Assert.IsNotNull(syncAppointmentsFolder);
Synchronizer.SyncAppointmentsFolder = syncAppointmentsFolder;
Synchronizer.MonthsInPast = 1;
Synchronizer.MonthsInFuture = 1;
sync.LoginToGoogle(gmailUsername);
sync.LoginToOutlook();
}
[SetUp]
public void SetUp()
{
// delete previously failed test appointments
DeleteTestAppointments();
}
private void DeleteTestAppointments()
{
sync.LoadAppointments();
Outlook.AppointmentItem outlookAppointment = sync.OutlookAppointments.Find("[Subject] = '" + name + "'") as Outlook.AppointmentItem;
while (outlookAppointment != null)
{
DeleteTestAppointment(outlookAppointment);
outlookAppointment = sync.OutlookAppointments.Find("[Subject] = '" + name + "'") as Outlook.AppointmentItem;
}
foreach (Event googleAppointment in sync.GoogleAppointments)
{
if (googleAppointment != null &&
googleAppointment.Summary != null &&
googleAppointment.Summary == name)
{
DeleteTestAppointment(googleAppointment);
}
}
}
void Logger_LogUpdated(string message)
{
Console.WriteLine(message);
}
[OneTimeTearDown]
public void TearDown()
{
sync.LogoffOutlook();
sync.LogoffGoogle();
}
[Test]
public void TestRemoveGoogleDuplicatedAppointments_01()
{
sync.SyncOption = SyncOption.OutlookToGoogleOnly;
// create new Outlook test appointment
var ola1 = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
ola1.Subject = name;
ola1.Start = DateTime.Now;
ola1.End = DateTime.Now.AddHours(1);
ola1.AllDayEvent = false;
ola1.ReminderSet = false;
ola1.Save();
// create new Google test appointments
var e1 = Factory.NewEvent();
sync.UpdateAppointment(ola1, ref e1);
var e2 = Factory.NewEvent();
AppointmentSync.UpdateAppointment(ola1, e2);
AppointmentPropertiesUtils.SetGoogleOutlookAppointmentId(sync.SyncProfile, e2, ola1);
e2 = sync.SaveGoogleAppointment(e2);
var gid_ola1 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, ola1);
var gid_e1 = AppointmentPropertiesUtils.GetGoogleId(e1);
var gid_e2 = AppointmentPropertiesUtils.GetGoogleId(e2);
var oid_e1 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, e1);
var oid_e2 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, e2);
var oid_ola1 = AppointmentPropertiesUtils.GetOutlookId(ola1);
// assert appointments ola1 and e1 are pointing to each other
Assert.AreEqual(gid_ola1, gid_e1);
Assert.AreEqual(oid_ola1, oid_e1);
// assert appointment e2 also points to ola1
Assert.AreEqual(oid_ola1, oid_e2);
// assert appointment ola1 does not point to e2
Assert.AreNotEqual(gid_ola1, gid_e2);
sync.LoadAppointments();
var f_e1 = sync.GetGoogleAppointmentById(gid_e1);
var f_e2 = sync.GetGoogleAppointmentById(gid_e2);
var f_ola1 = sync.GetOutlookAppointmentById(oid_ola1);
Assert.IsNotNull(f_e1);
Assert.IsNotNull(f_e2);
Assert.IsNotNull(f_ola1);
var f_gid_ola1 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, f_ola1);
var f_gid_e1 = AppointmentPropertiesUtils.GetGoogleId(f_e1);
var f_gid_e2 = AppointmentPropertiesUtils.GetGoogleId(f_e2);
var f_oid_e1 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, f_e1);
var f_oid_e2 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, f_e2);
var f_oid_ola1 = AppointmentPropertiesUtils.GetOutlookId(f_ola1);
// assert appointments ola1 and e1 are pointing to each other
Assert.AreEqual(f_gid_ola1, f_gid_e1);
Assert.AreEqual(f_oid_ola1, f_oid_e1);
// assert appointment e2 does not point to ola1
Assert.AreNotEqual(f_oid_ola1, f_oid_e2);
// assert appointment ola1 does not point to e2
Assert.AreNotEqual(f_gid_ola1, f_gid_e2);
DeleteTestAppointment(f_ola1);
DeleteTestAppointment(f_e1);
DeleteTestAppointment(f_e2);
}
[Test]
public void TestRemoveGoogleDuplicatedAppointments_02()
{
sync.SyncOption = SyncOption.OutlookToGoogleOnly;
// create new Outlook test appointment
var ola1 = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
ola1.Subject = name;
ola1.Start = DateTime.Now;
ola1.End = DateTime.Now.AddHours(1);
ola1.AllDayEvent = false;
ola1.ReminderSet = false;
ola1.Save();
// create new Google test appointments
var e1 = Factory.NewEvent();
sync.UpdateAppointment(ola1, ref e1);
var e2 = Factory.NewEvent();
AppointmentSync.UpdateAppointment(ola1, e2);
AppointmentPropertiesUtils.SetGoogleOutlookAppointmentId(sync.SyncProfile, e2, ola1);
e2 = sync.SaveGoogleAppointment(e2);
AppointmentPropertiesUtils.ResetOutlookGoogleAppointmentId(sync, ola1);
var gid_ola1 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, ola1);
var gid_e1 = AppointmentPropertiesUtils.GetGoogleId(e1);
var gid_e2 = AppointmentPropertiesUtils.GetGoogleId(e2);
var oid_e1 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, e1);
var oid_e2 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, e2);
var oid_ola1 = AppointmentPropertiesUtils.GetOutlookId(ola1);
// assert appointment e1 points to ola1
Assert.AreEqual(oid_ola1, oid_e1);
// assert appointment e2 points to ola1
Assert.AreEqual(oid_ola1, oid_e2);
// assert appointment ola1 does not point to e1
Assert.AreNotEqual(gid_ola1, gid_e1);
// assert appointment ola1 does not point to e2
Assert.AreNotEqual(gid_ola1, gid_e2);
sync.LoadAppointments();
var f_e1 = sync.GetGoogleAppointmentById(gid_e1);
var f_e2 = sync.GetGoogleAppointmentById(gid_e2);
var f_ola1 = sync.GetOutlookAppointmentById(oid_ola1);
Assert.IsNotNull(f_e1);
Assert.IsNotNull(f_e2);
Assert.IsNotNull(f_ola1);
var f_gid_ola1 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, f_ola1);
var f_gid_e1 = AppointmentPropertiesUtils.GetGoogleId(f_e1);
var f_gid_e2 = AppointmentPropertiesUtils.GetGoogleId(f_e2);
var f_oid_e1 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, f_e1);
var f_oid_e2 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, f_e2);
var f_oid_ola1 = AppointmentPropertiesUtils.GetOutlookId(f_ola1);
// assert appointment e1 does not point to ola1
Assert.AreNotEqual(f_oid_ola1, f_oid_e1);
// assert appointment ola1 does not point to e1
Assert.AreNotEqual(f_gid_ola1, f_gid_e1);
// assert appointment e2 does not point to ola1
Assert.AreNotEqual(f_oid_ola1, f_oid_e2);
// assert appointment ola1 does not point to e2
Assert.AreNotEqual(f_gid_ola1, f_gid_e2);
DeleteTestAppointment(f_ola1);
DeleteTestAppointment(f_e1);
DeleteTestAppointment(f_e2);
}
[Test]
public void TestRemoveOutlookDuplicatedAppointments_01()
{
sync.SyncOption = SyncOption.OutlookToGoogleOnly;
// create new Outlook test appointment
var ola1 = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
ola1.Subject = name;
ola1.Start = DateTime.Now;
ola1.End = DateTime.Now.AddHours(1);
ola1.AllDayEvent = false;
ola1.ReminderSet = false;
ola1.Save();
// create new Google test appointments
var e1 = Factory.NewEvent();
sync.UpdateAppointment(ola1, ref e1);
var ola2 = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
ola2.Subject = name;
ola2.Start = DateTime.Now;
ola2.End = DateTime.Now.AddHours(1);
ola2.AllDayEvent = false;
ola2.ReminderSet = false;
ola2.Save();
sync.UpdateAppointment(ola2, ref e1);
var gid_ola1 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, ola1);
var gid_ola2 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, ola2);
var gid_e1 = AppointmentPropertiesUtils.GetGoogleId(e1);
var oid_e1 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, e1);
var oid_ola1 = AppointmentPropertiesUtils.GetOutlookId(ola1);
var oid_ola2 = AppointmentPropertiesUtils.GetOutlookId(ola2);
// assert appointments ola2 and e1 are pointing to each other
Assert.AreEqual(gid_ola2, gid_e1);
Assert.AreEqual(oid_ola2, oid_e1);
// assert appointment ola1 also points to e1
Assert.AreEqual(gid_ola1, gid_e1);
// assert appointment e1 does not point to ola1
Assert.AreNotEqual(oid_e1, oid_ola1);
sync.LoadAppointments();
var f_e1 = sync.GetGoogleAppointmentById(gid_e1);
var f_ola1 = sync.GetOutlookAppointmentById(oid_ola1);
var f_ola2 = sync.GetOutlookAppointmentById(oid_ola2);
Assert.IsNotNull(f_e1);
Assert.IsNotNull(f_ola1);
Assert.IsNotNull(f_ola2);
var f_gid_ola1 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, f_ola1);
var f_gid_ola2 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, f_ola2);
var f_gid_e1 = AppointmentPropertiesUtils.GetGoogleId(f_e1);
var f_oid_e1 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, f_e1);
var f_oid_ola1 = AppointmentPropertiesUtils.GetOutlookId(f_ola1);
var f_oid_ola2 = AppointmentPropertiesUtils.GetOutlookId(f_ola2);
// assert appointments ola2 and e1 are pointing to each other
Assert.AreEqual(f_gid_ola2, f_gid_e1);
Assert.AreEqual(f_oid_ola2, f_oid_e1);
// assert appointment ola1 does not point to e1
Assert.AreNotEqual(f_oid_ola1, f_oid_e1);
// assert appointment ola1 does not point to e1
Assert.AreNotEqual(f_gid_ola1, f_gid_e1);
DeleteTestAppointment(f_ola1);
DeleteTestAppointment(f_ola2);
DeleteTestAppointment(f_e1);
}
[Test]
public void TestRemoveOutlookDuplicatedAppointments_02()
{
sync.SyncOption = SyncOption.OutlookToGoogleOnly;
// create new Outlook test appointment
var ola1 = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
ola1.Subject = name;
ola1.Start = DateTime.Now;
ola1.End = DateTime.Now.AddHours(1);
ola1.AllDayEvent = false;
ola1.ReminderSet = false;
ola1.Save();
// create new Google test appointments
var e1 = Factory.NewEvent();
sync.UpdateAppointment(ola1, ref e1);
var ola2 = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
ola2.Subject = name;
ola2.Start = DateTime.Now;
ola2.End = DateTime.Now.AddHours(1);
ola2.AllDayEvent = false;
ola2.ReminderSet = false;
ola2.Save();
sync.UpdateAppointment(ola2, ref e1);
AppointmentPropertiesUtils.ResetGoogleOutlookAppointmentId(sync.SyncProfile, e1);
e1 = sync.SaveGoogleAppointment(e1);
var gid_ola1 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, ola1);
var gid_ola2 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, ola2);
var gid_e1 = AppointmentPropertiesUtils.GetGoogleId(e1);
var oid_e1 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, e1);
var oid_ola1 = AppointmentPropertiesUtils.GetOutlookId(ola1);
var oid_ola2 = AppointmentPropertiesUtils.GetOutlookId(ola2);
// assert ola1 points to e1
Assert.AreEqual(gid_ola1, gid_e1);
// assert ola2 points to e1
Assert.AreEqual(gid_ola2, gid_e1);
// assert appointment e1 does not point to ola1
Assert.AreNotEqual(oid_e1, oid_ola1);
// assert appointment e1 does not point to ola2
Assert.AreNotEqual(oid_e1, oid_ola2);
sync.LoadAppointments();
var f_e1 = sync.GetGoogleAppointmentById(gid_e1);
var f_ola1 = sync.GetOutlookAppointmentById(oid_ola1);
var f_ola2 = sync.GetOutlookAppointmentById(oid_ola2);
Assert.IsNotNull(f_e1);
Assert.IsNotNull(f_ola1);
Assert.IsNotNull(f_ola2);
var f_gid_ola1 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, f_ola1);
var f_gid_ola2 = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, f_ola2);
var f_gid_e1 = AppointmentPropertiesUtils.GetGoogleId(f_e1);
var f_oid_e1 = AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, f_e1);
var f_oid_ola1 = AppointmentPropertiesUtils.GetOutlookId(f_ola1);
var f_oid_ola2 = AppointmentPropertiesUtils.GetOutlookId(f_ola2);
// assert ola1 does not point to e1
Assert.AreNotEqual(f_gid_ola1, f_gid_e1);
// assert ola2 does not point to e1
Assert.AreNotEqual(f_gid_ola2, f_gid_e1);
// assert appointment e1 does not point to ola1
Assert.AreNotEqual(f_oid_e1, f_oid_ola1);
// assert appointment e1 does not point to ola2
Assert.AreNotEqual(f_oid_e1, f_oid_ola2);
DeleteTestAppointment(f_ola1);
DeleteTestAppointment(f_ola2);
DeleteTestAppointment(f_e1);
}
[Test]
public void TestSync_Time()
{
sync.SyncOption = SyncOption.MergeOutlookWins;
// create new appointment to sync
Outlook.AppointmentItem outlookAppointment = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
outlookAppointment.Subject = name;
outlookAppointment.Start = DateTime.Now;
outlookAppointment.End = DateTime.Now.AddHours(1);
outlookAppointment.AllDayEvent = false;
outlookAppointment.Save();
sync.SyncOption = SyncOption.OutlookToGoogleOnly;
var googleAppointment = Factory.NewEvent();
sync.UpdateAppointment(outlookAppointment, ref googleAppointment);
googleAppointment = null;
sync.SyncOption = SyncOption.GoogleToOutlookOnly;
//load the same appointment from google.
MatchAppointments(sync);
AppointmentMatch match = FindMatch(outlookAppointment);
Assert.IsNotNull(match);
Assert.IsNotNull(match.GoogleAppointment);
Assert.IsNotNull(match.OutlookAppointment);
Outlook.AppointmentItem recreatedOutlookAppointment = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
sync.UpdateAppointment(ref match.GoogleAppointment, recreatedOutlookAppointment, match.GoogleAppointmentExceptions);
Assert.IsNotNull(outlookAppointment);
Assert.IsNotNull(recreatedOutlookAppointment);
// match recreatedOutlookAppointment with outlookAppointment
Assert.AreEqual(outlookAppointment.Subject, recreatedOutlookAppointment.Subject);
Assert.AreEqual(outlookAppointment.Start, recreatedOutlookAppointment.Start);
Assert.AreEqual(outlookAppointment.End, recreatedOutlookAppointment.End);
Assert.AreEqual(outlookAppointment.AllDayEvent, recreatedOutlookAppointment.AllDayEvent);
//ToDo: Check other properties
DeleteTestAppointments(match);
recreatedOutlookAppointment.Delete();
}
[Test]
public void TestSync_Day()
{
sync.SyncOption = SyncOption.MergeOutlookWins;
// create new appointment to sync
Outlook.AppointmentItem outlookAppointment = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
outlookAppointment.Subject = name;
outlookAppointment.Start = DateTime.Now;
outlookAppointment.End = DateTime.Now;
outlookAppointment.AllDayEvent = true;
outlookAppointment.Save();
sync.SyncOption = SyncOption.OutlookToGoogleOnly;
var googleAppointment = Factory.NewEvent();
sync.UpdateAppointment(outlookAppointment, ref googleAppointment);
googleAppointment = null;
sync.SyncOption = SyncOption.GoogleToOutlookOnly;
//load the same appointment from google.
MatchAppointments(sync);
AppointmentMatch match = FindMatch(outlookAppointment);
Assert.IsNotNull(match);
Assert.IsNotNull(match.GoogleAppointment);
Assert.IsNotNull(match.OutlookAppointment);
Outlook.AppointmentItem recreatedOutlookAppointment = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
sync.UpdateAppointment(ref match.GoogleAppointment, recreatedOutlookAppointment, match.GoogleAppointmentExceptions);
Assert.IsNotNull(outlookAppointment);
Assert.IsNotNull(recreatedOutlookAppointment);
// match recreatedOutlookAppointment with outlookAppointment
Assert.AreEqual(outlookAppointment.Subject, recreatedOutlookAppointment.Subject);
Assert.AreEqual(outlookAppointment.Start, recreatedOutlookAppointment.Start);
Assert.AreEqual(outlookAppointment.End, recreatedOutlookAppointment.End);
Assert.AreEqual(outlookAppointment.AllDayEvent, recreatedOutlookAppointment.AllDayEvent);
//ToDo: Check other properties
DeleteTestAppointments(match);
recreatedOutlookAppointment.Delete();
}
[Test]
public void TestExtendedProps()
{
sync.SyncOption = SyncOption.MergeOutlookWins;
// create new appointment to sync
Outlook.AppointmentItem outlookAppointment = Synchronizer.CreateOutlookAppointmentItem(Synchronizer.SyncAppointmentsFolder);
outlookAppointment.Subject = name;
outlookAppointment.Start = DateTime.Now;
outlookAppointment.Start = DateTime.Now;
outlookAppointment.AllDayEvent = true;
outlookAppointment.Save();
var googleAppointment = Factory.NewEvent();
sync.UpdateAppointment(outlookAppointment, ref googleAppointment);
Assert.AreEqual(name, googleAppointment.Summary);
// read appointment from google
googleAppointment = null;
MatchAppointments(sync);
AppointmentsMatcher.SyncAppointments(sync);
AppointmentMatch match = FindMatch(outlookAppointment);
Assert.IsNotNull(match);
Assert.IsNotNull(match.GoogleAppointment);
// get extended prop
Assert.AreEqual(AppointmentPropertiesUtils.GetOutlookId(outlookAppointment), AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, match.GoogleAppointment));
DeleteTestAppointments(match);
}
//ToDo:
//[Test]
//public void TestSyncDeletedOulook()
//{
// //ToDo: Check for eache SyncOption and SyncDelete combination
// sync.SyncOption = SyncOption.MergeOutlookWins;
// sync.SyncDelete = true;
// // create new appointment to sync
// Outlook.AppointmentItem outlookAppointment = Syncronizer.CreateOutlookAppointmentItem(Syncronizer.SyncAppointmentsFolder);
// outlookAppointment.Subject = name;
// outlookAppointment.Start = DateTime.Now;
// outlookAppointment.Start = DateTime.Now.AddHours(1);
// outlookAppointment.Save();
// var googleAppointment = new Event();
// sync.UpdateAppointment(outlookAppointment, googleAppointment);
// // delete outlook appointment
// outlookAppointment.Delete();
// // sync
// MatchAppointments(sync);
// AppointmentsMatcher.SyncAppointments(sync);
// // find match
// AppointmentMatch match = FindMatch(outlookAppointment);
// Assert.IsNotNull(match);
// // delete
// sync.UpdateAppointment(match);
// // sync
// MatchAppointments(sync);
// AppointmentsMatcher.SyncAppointments(sync);
// // check if google appointment still exists
// googleAppointment = null;
// match = sync.AppointmentByProperty(name, email);
// //foreach (AppointmentMatch m in sync.Appointments)
// //{
// // if (m.GoogleAppointment.Title == name)
// // {
// // googleAppointment = m.GoogleAppointment;
// // break;
// // }
// //}
// Assert.IsNull(match);
//}
//[Test]
//public void TestSyncDeletedGoogle()
//{
// //ToDo: Check for eache SyncOption and SyncDelete combination
// sync.SyncOption = SyncOption.MergeOutlookWins;
// sync.SyncDelete = true;
// // create new appointment to sync
// Outlook.AppointmentItem outlookAppointment = Syncronizer.CreateOutlookAppointmentItem(Syncronizer.SyncAppointmentsFolder);
// outlookAppointment.FullName = name;
// outlookAppointment.FileAs = name;
// outlookAppointment.Email1Address = email;
// outlookAppointment.Email2Address = email.Replace("00", "01");
// outlookAppointment.Email3Address = email.Replace("00", "02");
// outlookAppointment.HomeAddress = "10 Parades";
// outlookAppointment.PrimaryTelephoneNumber = "123";
// outlookAppointment.Save();
// Appointment googleAppointment = new Appointment();
// sync.UpdateAppointment(outlookAppointment, googleAppointment);
// AppointmentMatch match = new AppointmentMatch(outlookAppointment, sync), googleAppointment);
// //save appointments
// sync.UpdateAppointment(match);
// // delete google appointment
// GoogleAppointment.Delete();
// // sync
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// // delete
// sync.UpdateAppointment(match);
// // sync
// MatchAppointments(sync);
// AppointmentsMatcher.SyncAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// // check if outlook appointment still exists
// Assert.IsNull(match);
// DeleteTestAppointments(match);
//}
//[Test]
//public void TestSyncGroups()
//{
// sync.SyncOption = SyncOption.MergeOutlookWins;
// // create new appointment to sync
// Outlook.AppointmentItem outlookAppointment = Syncronizer.CreateOutlookAppointmentItem(Syncronizer.SyncAppointmentsFolder);
// outlookAppointment.FullName = name;
// outlookAppointment.FileAs = name;
// outlookAppointment.Email1Address = email;
// outlookAppointment.Email2Address = email.Replace("00", "01");
// outlookAppointment.Email3Address = email.Replace("00", "02");
// outlookAppointment.HomeAddress = "10 Parades";
// outlookAppointment.PrimaryTelephoneNumber = "123";
// outlookAppointment.Categories = groupName;
// outlookAppointment.Save();
// //Outlook appointment should now have a group
// Assert.AreEqual(groupName, outlookAppointment.Categories);
// //Sync Groups first
// MatchAppointments(sync);
// AppointmentsMatcher.SyncGroups(sync);
// Appointment googleAppointment = new Appointment();
// sync.UpdateAppointment(outlookAppointment, googleAppointment);
// AppointmentMatch match = new AppointmentMatch(outlookAppointment, sync), googleAppointment);
// //sync and save appointment to google.
// AppointmentsMatcher.SyncAppointment(match, sync);
// sync.UpdateAppointment(match);
// //load the same appointment from google.
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// // google appointment should now have the same group
// System.Collections.ObjectModel.Collection<Group> googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleAppointment);
// Assert.AreEqual(2, googleGroups.Count);
// Assert.Contains(sync.GetGoogleGroupByName(groupName), googleGroups);
// Assert.Contains(sync.GetGoogleGroupByName(Syncronizer.myAppointmentsGroup), googleGroups);
// // delete outlook appointment
// outlookAppointment.Delete();
// outlookAppointment = Syncronizer.CreateOutlookAppointmentItem(Syncronizer.SyncAppointmentsFolder);
// sync.UpdateAppointment(match.GoogleAppointment, outlookAppointment);
// match = new AppointmentMatch(outlookAppointment, sync), match.GoogleAppointment);
// outlookAppointment.Save();
// sync.SyncOption = SyncOption.MergeGoogleWins;
// //sync and save appointment to outlook
// AppointmentsMatcher.SyncAppointment(match, sync);
// sync.UpdateAppointment(match);
// //load the same appointment from outlook
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// Assert.AreEqual(groupName, outlookAppointment.Categories);
// DeleteTestAppointments(match);
// // delete test group
// Group group = sync.GetGoogleGroupByName(groupName);
// if (group != null)
// sync.CalendarService.Delete(group);
//}
//[Test]
//public void TestSyncDeletedGoogleGroup()
//{
// //ToDo: Check for eache SyncOption and SyncDelete combination
// sync.SyncOption = SyncOption.MergeOutlookWins;
// sync.SyncDelete = true;
// // create new appointment to sync
// Outlook.AppointmentItem outlookAppointment = Syncronizer.CreateOutlookAppointmentItem(Syncronizer.SyncAppointmentsFolder);
// outlookAppointment.FullName = name;
// outlookAppointment.FileAs = name;
// outlookAppointment.Email1Address = email;
// outlookAppointment.Email2Address = email.Replace("00", "01");
// outlookAppointment.Email3Address = email.Replace("00", "02");
// outlookAppointment.HomeAddress = "10 Parades";
// outlookAppointment.PrimaryTelephoneNumber = "123";
// outlookAppointment.Categories = groupName;
// outlookAppointment.Save();
// //Outlook appointment should now have a group
// Assert.AreEqual(groupName, outlookAppointment.Categories);
// //Sync Groups first
// MatchAppointments(sync);
// AppointmentsMatcher.SyncGroups(sync);
// //Create now Google Appointment and assing new Group
// Appointment googleAppointment = new Appointment();
// sync.UpdateAppointment(outlookAppointment, googleAppointment);
// AppointmentMatch match = new AppointmentMatch(outlookAppointment, sync), googleAppointment);
// //save appointment to google.
// sync.UpdateAppointment(match);
// //load the same appointment from google.
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// // google appointment should now have the same group
// System.Collections.ObjectModel.Collection<Group> googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleAppointment);
// Group group = sync.GetGoogleGroupByName(groupName);
// Assert.AreEqual(2, googleGroups.Count);
// Assert.Contains(group, googleGroups);
// Assert.Contains(sync.GetGoogleGroupByName(Syncronizer.myAppointmentsGroup), googleGroups);
// // delete group from google
// Utilities.RemoveGoogleGroup(match.GoogleAppointment, group);
// googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleAppointment);
// Assert.AreEqual(1, googleGroups.Count);
// Assert.Contains(sync.GetGoogleGroupByName(Syncronizer.myAppointmentsGroup), googleGroups);
// //save appointment to google.
// sync.SaveGoogleAppointment(match.GoogleAppointment);
// sync.SyncOption = SyncOption.GoogleToOutlookOnly;
// //Sync Groups first
// MatchAppointments(sync);
// AppointmentsMatcher.SyncGroups(sync);
// //sync and save appointment to outlook.
// match = sync.AppointmentByProperty(name, email);
// sync.UpdateAppointment(match.GoogleAppointment, outlookAppointment);
// sync.UpdateAppointment(match);
// // google and outlook should now have no category except for the System Group: My Appointments
// googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleAppointment);
// Assert.AreEqual(1, googleGroups.Count);
// Assert.AreEqual(null, outlookAppointment.Categories);
// Assert.Contains(sync.GetGoogleGroupByName(Syncronizer.myAppointmentsGroup), googleGroups);
// DeleteTestAppointments(match);
// // delete test group
// if (group != null)
// sync.CalendarService.Delete(group);
//}
//[Test]
//public void TestSyncDeletedOutlookGroup()
//{
// //ToDo: Check for eache SyncOption and SyncDelete combination
// sync.SyncOption = SyncOption.MergeOutlookWins;
// sync.SyncDelete = true;
// // create new appointment to sync
// Outlook.AppointmentItem outlookAppointment = Syncronizer.CreateOutlookAppointmentItem(Syncronizer.SyncAppointmentsFolder);
// outlookAppointment.FullName = name;
// outlookAppointment.FileAs = name;
// outlookAppointment.Email1Address = email;
// outlookAppointment.Email2Address = email.Replace("00", "01");
// outlookAppointment.Email3Address = email.Replace("00", "02");
// outlookAppointment.HomeAddress = "10 Parades";
// outlookAppointment.PrimaryTelephoneNumber = "123";
// outlookAppointment.Categories = groupName;
// outlookAppointment.Save();
// //Outlook appointment should now have a group
// Assert.AreEqual(groupName, outlookAppointment.Categories);
// //Now sync Groups
// MatchAppointments(sync);
// AppointmentsMatcher.SyncGroups(sync);
// Appointment googleAppointment = new Appointment();
// sync.UpdateAppointment(outlookAppointment, googleAppointment);
// AppointmentMatch match = new AppointmentMatch(outlookAppointment, sync), googleAppointment);
// //save appointment to google.
// sync.UpdateAppointment(match);
// //load the same appointment from google.
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// // google appointment should now have the same group
// System.Collections.ObjectModel.Collection<Group> googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleAppointment);
// Group group = sync.GetGoogleGroupByName(groupName);
// Assert.AreEqual(2, googleGroups.Count);
// Assert.Contains(sync.GetGoogleGroupByName(Syncronizer.myAppointmentsGroup), googleGroups);
// Assert.Contains(group, googleGroups);
// // delete group from outlook
// Utilities.RemoveOutlookGroup(outlookAppointment, groupName);
// //save appointment to google.
// sync.UpdateAppointment(match);
// //load the same appointment from google.
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// sync.UpdateAppointment(outlookAppointment, match.GoogleAppointment);
// // google and outlook should now have no category
// googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleAppointment);
// Assert.AreEqual(null, outlookAppointment.Categories);
// Assert.AreEqual(1, googleGroups.Count);
// Assert.Contains(sync.GetGoogleGroupByName(Syncronizer.myAppointmentsGroup), googleGroups);
// DeleteTestAppointments(match);
// // delete test group
// if (group != null)
// sync.CalendarService.Delete(group);
//}
//[Test]
//public void TestResetMatches()
//{
// sync.SyncOption = SyncOption.MergeOutlookWins;
// // create new appointment to sync
// Outlook.AppointmentItem outlookAppointment = Syncronizer.CreateOutlookAppointmentItem(Syncronizer.SyncAppointmentsFolder);
// outlookAppointment.FullName = name;
// outlookAppointment.FileAs = name;
// outlookAppointment.Email1Address = email;
// outlookAppointment.Email2Address = email.Replace("00", "01");
// outlookAppointment.Email3Address = email.Replace("00", "02");
// outlookAppointment.HomeAddress = "10 Parades";
// outlookAppointment.PrimaryTelephoneNumber = "123";
// //outlookAppointment.Categories = groupName; //Group is not relevant here
// outlookAppointment.Save();
// Appointment googleAppointment = new Appointment();
// sync.UpdateAppointment(outlookAppointment, googleAppointment);
// AppointmentMatch match = new AppointmentMatch(outlookAppointment, sync), googleAppointment);
// //save appointment to google.
// sync.UpdateAppointment(match);
// //load the same appointment from google.
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// // delete outlook appointment
// outlookAppointment.Delete();
// match.OutlookAppointment = null;
// //load the same appointment from google
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// Assert.IsNull(match.OutlookAppointment);
// // reset matches
// sync.ResetMatch(match.GoogleAppointment);
// //Not, because NULL: sync.ResetMatch(match.OutlookAppointment.GetOriginalItemFromOutlook(sync));
// // load same appointment match
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// // google appointment should still be present and OutlookAppointment should be filled
// Assert.IsNotNull(match.GoogleAppointment);
// Assert.IsNotNull(match.OutlookAppointment);
// DeleteTestAppointments();
// // create new appointment to sync
// outlookAppointment = Syncronizer.CreateOutlookAppointmentItem(Syncronizer.SyncAppointmentsFolder);
// outlookAppointment.FullName = name;
// outlookAppointment.FileAs = name;
// outlookAppointment.Email1Address = email;
// outlookAppointment.Email2Address = email.Replace("00", "01");
// outlookAppointment.Email3Address = email.Replace("00", "02");
// outlookAppointment.HomeAddress = "10 Parades";
// outlookAppointment.PrimaryTelephoneNumber = "123";
// outlookAppointment.Save();
// // same test for delete google appointment...
// googleAppointment = new Appointment();
// sync.UpdateAppointment(outlookAppointment, googleAppointment);
// match = new AppointmentMatch(outlookAppointment, sync), googleAppointment);
// //save appointment to google.
// sync.UpdateAppointment(match);
// //load the same appointment from google.
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// // delete google appointment
// match.GoogleAppointment.Delete();
// match.GoogleAppointment = null;
// //load the same appointment from google.
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// Assert.IsNull(match.GoogleAppointment);
// // reset matches
// //Not, because null: sync.ResetMatch(match.GoogleAppointment);
// sync.ResetMatch(match.OutlookAppointment.GetOriginalItemFromOutlook());
// // load same appointment match
// MatchAppointments(sync);
// match = sync.AppointmentByProperty(name, email);
// AppointmentsMatcher.SyncAppointment(match, sync);
// // Outlook appointment should still be present and GoogleAppointment should be filled
// Assert.IsNotNull(match.OutlookAppointment);
// Assert.IsNotNull(match.GoogleAppointment);
// outlookAppointment.Delete();
//}
private void DeleteTestAppointments(AppointmentMatch match)
{
if (match != null)
{
DeleteTestAppointment(match.GoogleAppointment);
DeleteTestAppointment(match.OutlookAppointment);
}
}
private void DeleteTestAppointment(Outlook.AppointmentItem outlookAppointment)
{
if (outlookAppointment != null)
{
try
{
string name = outlookAppointment.Subject;
outlookAppointment.Delete();
Logger.Log("Deleted Outlook test appointment: " + name, EventType.Information);
}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(outlookAppointment);
outlookAppointment = null;
}
}
}
private void DeleteTestAppointment(Event googleAppointment)
{
if (googleAppointment != null && !googleAppointment.Status.Equals("cancelled"))
{
sync.EventRequest.Delete(Synchronizer.SyncAppointmentsGoogleFolder, googleAppointment.Id);
Logger.Log("Deleted Google test appointment: " + googleAppointment.Summary, EventType.Information);
Thread.Sleep(2000);
}
}
internal AppointmentMatch FindMatch(Outlook.AppointmentItem outlookAppointment)
{
foreach (AppointmentMatch match in sync.Appointments)
{
if (match.OutlookAppointment != null && match.OutlookAppointment.EntryID == outlookAppointment.EntryID)
return match;
}
return null;
}
private void MatchAppointments(Synchronizer sync)
{
Thread.Sleep(5000); //Wait, until Appointment is really saved and available to retrieve again
sync.MatchAppointments();
}
internal AppointmentMatch FindMatch(Event googleAppointment)
{
if (googleAppointment != null)
{
foreach (AppointmentMatch match in sync.Appointments)
{
if (match.GoogleAppointment != null && match.GoogleAppointment.Id == googleAppointment.Id)
return match;
}
}
return null;
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.