/// <summary> /// Sets the Binding Context. /// </summary> public ListenAndPerformPage() { InitializeComponent(); ViewModel = new ListenAndPerformViewModel(); BindingContext = ViewModel; ActivityView.SelectedItem = ViewModel.ActivityList[0]; }
public void ActivityListCheck() { //Für den ServiceProviderMock //Muss enthalten sein, damit der Mock nicht überschrieben wird IServiceProvider unused = ServiceManager.ServiceProvider; //Feld Infos holen System.Reflection.FieldInfo instance = typeof(ServiceManager).GetField("_serviceProvider", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); //Mocksaufsetzen //ServiceProvider Mock <IServiceProvider> mockSingleton = new Mock <IServiceProvider>(); Mock <IActivityManager> activityManagerMock = new Mock <IActivityManager>(); Mock <IServiceProvider> activityProviderMock = new Mock <IServiceProvider>(); Mock <AbstractSitUpActivity> sitUpActivityMock = new Mock <AbstractSitUpActivity>(); Mock <AbstractPushUpActivity> pushUpActivityMock = new Mock <AbstractPushUpActivity>(); Mock <IEarablesConnection> connectionMock = new Mock <IEarablesConnection>(); Mock <IPopUpService> popUpMock = new Mock <IPopUpService>(); //ActivityManager activityManagerMock.Setup(x => x.ActitvityProvider).Returns(activityProviderMock.Object); activityProviderMock.Setup(x => x.GetService(typeof(AbstractSitUpActivity))) .Returns(sitUpActivityMock.Object); activityProviderMock.Setup(x => x.GetService(typeof(AbstractPushUpActivity))) .Returns(pushUpActivityMock.Object); //IDataBaseConnection Mock <IDataBaseConnection> mockDataBase = new Mock <IDataBaseConnection>(); DateTime _dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); DBEntry _entryNew = new DBEntry(_dt, 10, 0, 0); mockDataBase.As <IDataBaseConnection>().Setup(x => x.SaveDBEntry(_entryNew)).Returns(1); //PopUpService popUpMock.SetupSequence(x => x.ActionSheet("Wähle eine Aktivität:", "Abbruch", null, "Liegestütze", "Sit-ups", "Pause")) .Returns(Task.Run(() => { return("Liegestütze"); })) .Returns(Task.Run(() => { return("Liegestütze"); })); popUpMock.SetupSequence(x => x.DisplayPrompt("Liegestütze", "Gebe die Anzahl Wiederholungen an:", "Okay", "Abbruch", "10", 3, Keyboard.Numeric)) .Returns(Task.Run(() => { return("12"); })) .Returns(Task.Run(() => { return("12"); })); //ServiceManager mockSingleton.Setup(x => x.GetService(typeof(IDataBaseConnection))).Returns(mockDataBase.Object); mockSingleton.Setup(x => x.GetService(typeof(IActivityManager))).Returns(activityManagerMock.Object); mockSingleton.Setup(x => x.GetService(typeof(IPopUpService))).Returns(popUpMock.Object); mockSingleton.Setup(x => x.GetService(typeof(IEarablesConnection))).Returns(connectionMock.Object); //Connection ScanningPopUpViewModel.IsConnected = true; connectionMock.As <IEarablesConnection>().Setup(x => x.StartSampling()); //ServiceProvider anlegen instance.SetValue(null, mockSingleton.Object); //Test ListenAndPerformViewModel viewModel = new ListenAndPerformViewModel(); viewModel.AddActivityCommand.Execute(3); //4 Assert.Equal(4, viewModel.ActivityList.Count); IEnumerator <ActivityWrapper> iterator = viewModel.ActivityList.GetEnumerator(); iterator.MoveNext(); iterator.MoveNext(); iterator.MoveNext(); iterator.MoveNext(); Assert.Equal("Liegestütze", iterator.Current.Name); Assert.Equal(12, iterator.Current.Amount); viewModel.SelectedActivity = iterator.Current; viewModel.EditActivityCommand.Execute(null); iterator = viewModel.ActivityList.GetEnumerator(); iterator.MoveNext(); iterator.MoveNext(); iterator.MoveNext(); iterator.MoveNext(); viewModel.SelectedActivity = iterator.Current; viewModel.RemoveActivityCommand.Execute(null); Assert.Equal(3, viewModel.ActivityList.Count); }
public void ConstructorCheck() { //Für den ServiceProviderMock //Muss enthalten sein, damit der Mock nicht überschrieben wird IServiceProvider unused = ServiceManager.ServiceProvider; //Feld Infos holen System.Reflection.FieldInfo instance = typeof(ServiceManager).GetField("_serviceProvider", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); //Mocksaufsetzen //ServiceProvider Mock <IServiceProvider> mockSingleton = new Mock <IServiceProvider>(); Mock <IActivityManager> activityManagerMock = new Mock <IActivityManager>(); Mock <IServiceProvider> activityProviderMock = new Mock <IServiceProvider>(); Mock <AbstractSitUpActivity> sitUpActivityMock = new Mock <AbstractSitUpActivity>(); Mock <AbstractPushUpActivity> pushUpActivityMock = new Mock <AbstractPushUpActivity>(); Mock <IEarablesConnection> connectionMock = new Mock <IEarablesConnection>(); Mock <IPopUpService> popUpMock = new Mock <IPopUpService>(); //ActivityManager activityManagerMock.Setup(x => x.ActitvityProvider).Returns(activityProviderMock.Object); activityProviderMock.Setup(x => x.GetService(typeof(AbstractSitUpActivity))) .Returns(sitUpActivityMock.Object); activityProviderMock.Setup(x => x.GetService(typeof(AbstractPushUpActivity))) .Returns(pushUpActivityMock.Object); //IDataBaseConnection Mock <IDataBaseConnection> mockDataBase = new Mock <IDataBaseConnection>(); DateTime _dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); DBEntry _entryNew = new DBEntry(_dt, 10, 0, 0); mockDataBase.As <IDataBaseConnection>().Setup(x => x.SaveDBEntry(_entryNew)).Returns(1); //ServiceManager mockSingleton.Setup(x => x.GetService(typeof(IDataBaseConnection))).Returns(mockDataBase.Object); mockSingleton.Setup(x => x.GetService(typeof(IActivityManager))).Returns(activityManagerMock.Object); mockSingleton.Setup(x => x.GetService(typeof(IPopUpService))).Returns(popUpMock.Object); mockSingleton.Setup(x => x.GetService(typeof(IEarablesConnection))).Returns(connectionMock.Object); //Connection ScanningPopUpViewModel.IsConnected = true; connectionMock.As <IEarablesConnection>().Setup(x => x.StartSampling()); //ServiceProvider anlegen instance.SetValue(null, mockSingleton.Object); //Test ListenAndPerformViewModel viewModel = new ListenAndPerformViewModel(); IEnumerator <ActivityWrapper> iterator = viewModel.ActivityList.GetEnumerator(); Assert.Equal(3, viewModel.ActivityList.Count); iterator.MoveNext(); Assert.Equal("Liegestütze", iterator.Current.Name); iterator.MoveNext(); Assert.Equal("Pause", iterator.Current.Name); iterator.MoveNext(); Assert.Equal("Sit-ups", iterator.Current.Name); viewModel.Milliseconds = "0"; viewModel.Seconds = "0"; viewModel.Minutes = "0"; Assert.Equal("0", viewModel.Milliseconds); Assert.Equal("0", viewModel.Seconds); Assert.Equal("0", viewModel.Minutes); }
/// <summary> /// Initializes the ViewModel. /// </summary> /// <param name="lapvm">Binding Context of the passive page</param> public ListenAndPerformActivePage(ListenAndPerformViewModel lapvm) { ViewModel = lapvm; InitializeComponent(); }