Example #1
0
        async public void SyncOperation_NeedsMerge_DontNeedSave()
        {
            ApplicationState state = new ApplicationState();

            ApplicationState.Current  = state;
            state.SessionData         = new SessionData();
            state.SessionData.Profile = new ProfileDTO()
            {
                GlobalId = Guid.NewGuid()
            };
            state.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();
            var      holder = state.GetTrainingDayHolder(null);
            DateTime time   = ExtensionMethods.MonthDate(DateTime.UtcNow);
            var      day    = new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(1)
            };

            holder.TrainingDays.Add(time.AddDays(1), new TrainingDayInfo(day)
            {
                IsModified = true
            });
            //state.MyDays.Add(time.AddDays(1), new TrainingDayInfo(day) { IsModified = true });


            bool eventCompleted = false;

            MockSynchronizationViewModel viewModel = new MockSynchronizationViewModel(state);

            viewModel.Action = MergeAction.UseServer;
            viewModel.NeedsMergeException       = true;
            viewModel.FromServer                = day;
            viewModel.ErrorInSecondSave         = true;
            viewModel.SynchronizationCompleted += delegate
            {
                eventCompleted = true;
            };

            await viewModel.Synchronize();

            Assert.AreEqual(1, viewModel.Maximum);
            Assert.AreEqual(1, viewModel.SaveCount);
            Assert.IsTrue(eventCompleted);
            Assert.IsTrue(viewModel.FirstSave);
            Assert.IsFalse(viewModel.SecondSave);
            Assert.IsFalse(viewModel.Items[0].DayInfo.IsConflict);
            Assert.IsFalse(viewModel.Items[0].DayInfo.IsModified);
            Assert.AreEqual(MergeState.Finished, viewModel.Items[0].State);
            Assert.IsTrue(viewModel.Merged);
            Assert.IsTrue(viewModel.IsInProgressGood);
            EnqueueTestComplete();
        }
        async protected virtual Task MergeResult(TrainingDayDTO day, SynchronizationItemViewModel item)
        {
            var customerId             = item.DayInfo.TrainingDay.CustomerId;
            var holder                 = appState.GetTrainingDayHolder(customerId);
            OfflineModeManager manager = new OfflineModeManager(appState.MyDays, ApplicationState.Current.SessionData.Profile.GlobalId);

            appState.TrainingDay = item.DayInfo;
            manager.MergeNew(day, appState, true, delegate
            {
                return(Action == MergeAction.UseServer);
            });

            if (holder.TrainingDays.ContainsKey(appState.TrainingDay.TrainingDay.TrainingDate) && holder.TrainingDays[appState.TrainingDay.TrainingDay.TrainingDate].IsModified)
            {
                await save(item, false);
            }
            else
            {
                item.State = MergeState.Finished;
            }
            appState.TrainingDay = null;
        }
Example #3
0
        async public void SyncOperation_Correct()
        {
            ApplicationState state = new ApplicationState();

            ApplicationState.Current  = state;
            state.SessionData         = new SessionData();
            state.SessionData.Profile = new ProfileDTO()
            {
                GlobalId = Guid.NewGuid()
            };
            state.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();
            var      holder = state.GetTrainingDayHolder(null);
            DateTime time   = ExtensionMethods.MonthDate(DateTime.UtcNow);
            var      day    = new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(1)
            };
            var size = new SizeEntryDTO();

            day.Objects.Add(size);
            size.TrainingDay = day;
            holder.TrainingDays.Add(time.AddDays(1), new TrainingDayInfo(day)
            {
                IsModified = true
            });


            bool eventCompleted = false;

            MockSynchronizationViewModel viewModel = new MockSynchronizationViewModel(state);

            viewModel.SynchronizationCompleted += delegate
            {
                eventCompleted = true;
            };
            var items = viewModel.Items.ToArray();

            await viewModel.Synchronize();

            Assert.AreEqual(1, viewModel.Maximum);
            Assert.AreEqual(1, viewModel.SaveCount);
            Assert.AreEqual(MergeState.Finished, items[0].State);
            Assert.IsTrue(eventCompleted);
            Assert.IsTrue(viewModel.FirstSave);
            Assert.IsFalse(viewModel.Merged);
            Assert.IsFalse(items[0].DayInfo.IsModified);
            Assert.IsTrue(viewModel.IsInProgressGood);
            Assert.AreNotEqual(Guid.Empty, day.GlobalId);
            EnqueueTestComplete();
        }
Example #4
0
        async public void SyncOperation_UploadGPSCoordinates_RemovedGPSTrackerEntry()
        {
            ApplicationState state = new ApplicationState();

            ApplicationState.Current  = state;
            state.SessionData         = new SessionData();
            state.SessionData.Profile = new ProfileDTO()
            {
                GlobalId = Guid.NewGuid()
            };
            state.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();
            var      holder = state.GetTrainingDayHolder(null);
            DateTime time   = ExtensionMethods.MonthDate(DateTime.UtcNow);
            var      day    = new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(1)
            };
            var tdi = new TrainingDayInfo(day)
            {
                IsModified = true
            };
            //these points should be detected to save
            GPSTrackerEntryDTO gpsEntry = new GPSTrackerEntryDTO();

            gpsEntry.Exercise = new ExerciseLightDTO()
            {
                GlobalId = Guid.NewGuid()
            };
            tdi.TrainingDay.Objects.Add(gpsEntry);
            gpsEntry.TrainingDay = tdi.TrainingDay;
            var points = new List <GPSPoint>();

            points.Add(new GPSPoint(1, 2, 3, 4, 6));
            tdi.GPSCoordinates.Add(new LocalObjectKey(gpsEntry.InstanceId, KeyType.InstanceId), new GPSPointsBag(points, false));

            holder.TrainingDays.Add(time.AddDays(1), tdi);


            bool eventCompleted = false;

            MockSynchronizationViewModel viewModel = new MockSynchronizationViewModel(state);

            viewModel.UploadGPSError            = ErrorCode.ObjectNotFound;
            viewModel.RemoveFromServer          = typeof(GPSTrackerEntryDTO);
            viewModel.SynchronizationCompleted += delegate
            {
                eventCompleted = true;
            };
            var items = viewModel.Items.ToArray();
            await viewModel.Synchronize();

            Assert.AreEqual(2, viewModel.Maximum);
            Assert.AreEqual(1, viewModel.SaveCount);
            Assert.AreEqual(0, viewModel.GPSUploadCount);
            Assert.AreEqual(MergeState.Finished, items[0].State);
            Assert.AreEqual(MergeState.Finished, items[1].State);
            Assert.AreNotEqual(Guid.Empty, day.GlobalId);
            Assert.IsTrue(eventCompleted);
            Assert.IsTrue(viewModel.FirstSave);
            Assert.IsFalse(viewModel.Merged);
            Assert.IsTrue(viewModel.IsInProgressGood);
            EnqueueTestComplete();
        }
Example #5
0
        public void InitialState()
        {
            ApplicationState appState = new ApplicationState();

            ApplicationState.Current     = appState;
            appState.SessionData         = new SessionData();
            appState.SessionData.Profile = new ProfileDTO()
            {
                GlobalId = Guid.NewGuid()
            };
            appState.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();
            var      holder = appState.GetTrainingDayHolder(null);
            DateTime time   = ExtensionMethods.MonthDate(DateTime.UtcNow);

            holder.TrainingDays.Add(time.AddDays(1), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(1)
            })
            {
                IsModified = true
            });
            holder.TrainingDays.Add(time.AddDays(2), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(2)
            }));
            holder.TrainingDays.Add(time.AddDays(3), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(3)
            })
            {
                IsModified = true
            });
            var tdi = new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(4)
            })
            {
                IsModified = true
            };
            //these points should be detected to save
            GPSTrackerEntryDTO gpsEntry = new GPSTrackerEntryDTO();

            tdi.TrainingDay.Objects.Add(gpsEntry);
            gpsEntry.TrainingDay = tdi.TrainingDay;
            var points = new List <GPSPoint>();

            points.Add(new GPSPoint(1, 2, 3, 4, 6));
            tdi.GPSCoordinates.Add(new LocalObjectKey(gpsEntry.InstanceId, KeyType.InstanceId), new GPSPointsBag(points, false));

            //these shouldn't be
            var entry1 = new GPSTrackerEntryDTO();

            tdi.TrainingDay.Objects.Add(entry1);
            entry1.TrainingDay = tdi.TrainingDay;
            points             = new List <GPSPoint>();
            points.Add(new GPSPoint(11, 12, 13, 14, 7));
            tdi.GPSCoordinates.Add(new LocalObjectKey(entry1.InstanceId, KeyType.InstanceId), new GPSPointsBag(points, true));

            holder.TrainingDays.Add(time.AddDays(4), tdi);

            holder.TrainingDays.Add(time.AddDays(5), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(5)
            }));
            holder.TrainingDays.Add(time.AddDays(6), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(6)
            }));

            SynchronizationViewModel viewModel = new SynchronizationViewModel(appState);

            Assert.AreEqual(4, viewModel.Items.Count);
            Assert.AreEqual(Visibility.Collapsed, viewModel.ProgressVisibility);
            Assert.AreEqual(holder.TrainingDays[time.AddDays(1)], viewModel.Items[0].DayInfo);
            Assert.AreEqual(ItemType.TrainingDay, viewModel.Items[0].ItemType);

            Assert.AreEqual(holder.TrainingDays[time.AddDays(3)], viewModel.Items[1].DayInfo);
            Assert.AreEqual(ItemType.TrainingDay, viewModel.Items[1].ItemType);

            Assert.AreEqual(holder.TrainingDays[time.AddDays(4)], viewModel.Items[2].DayInfo);
            Assert.AreEqual(ItemType.TrainingDay, viewModel.Items[2].ItemType);

            Assert.AreEqual(holder.TrainingDays[time.AddDays(4)].GPSCoordinates[new LocalObjectKey(gpsEntry.InstanceId, KeyType.InstanceId)], viewModel.Items[3].GPSBag);
            Assert.AreEqual(ItemType.GPSCoordinates, viewModel.Items[3].ItemType);
            Assert.AreEqual(holder.TrainingDays[time.AddDays(4)], viewModel.Items[3].DayInfo);
            Assert.AreEqual(gpsEntry, viewModel.Items[3].GPSEntry);
        }
Example #6
0
        async public void SyncOperation()
        {
            ApplicationState state = new ApplicationState();

            ApplicationState.Current  = state;
            state.SessionData         = new SessionData();
            state.SessionData.Profile = new ProfileDTO()
            {
                GlobalId = Guid.NewGuid()
            };
            state.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();
            var      holder = state.GetTrainingDayHolder(null);
            DateTime time   = ExtensionMethods.MonthDate(DateTime.UtcNow);
            var      day    = new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(1)
            };

            holder.TrainingDays.Add(time.AddDays(1), new TrainingDayInfo(day)
            {
                IsModified = true
            });
            holder.TrainingDays.Add(time.AddDays(2), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(2)
            }));
            holder.TrainingDays.Add(time.AddDays(3), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(3)
            })
            {
                IsModified = true
            });
            holder.TrainingDays.Add(time.AddDays(4), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(4)
            })
            {
                IsModified = true
            });
            holder.TrainingDays.Add(time.AddDays(5), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(5)
            }));
            holder.TrainingDays.Add(time.AddDays(6), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(6)
            }));

            bool eventCompleted = false;

            MockSynchronizationViewModel viewModel = new MockSynchronizationViewModel(state);

            viewModel.SynchronizationCompleted += delegate
            {
                eventCompleted = true;
            };

            await viewModel.Synchronize();

            Assert.AreEqual(3, viewModel.Maximum);
            Assert.AreEqual(3, viewModel.SaveCount);
            Assert.IsTrue(eventCompleted);
            Assert.IsTrue(viewModel.IsInProgressGood);
            EnqueueTestComplete();
        }