Пример #1
0
        public void HomePageViewModel_UpdatePopupVisibilityTest()
        {
            TaskHomePageViewModel viewModel = new TaskHomePageViewModel(_navigationMock.Object, _pageDialogServiceMock.Object);

            viewModel.UpdatePopupVisibility = false;
            viewModel.TaskItemTappedCommand.Execute(TaskMockData.ReturnDBTaskList()[0]);

            Assert.IsTrue(viewModel.UpdatePopupVisibility, "Popup not visible");
        }
Пример #2
0
        public async Task HomePageViewModel_DeleteTask_SuccessTest()
        {
            var viewModel = new TaskHomePageViewModel(_navigationMock.Object, _pageDialogServiceMock.Object);

            viewModel.TaskList = TaskMockData.ReturnDBTaskList();
            _platformServiceMock.Setup(method => method.IsConnected()).Returns(true);
            await Task.Run(() =>
            {
                viewModel.DeleteTaskCommand.Execute("1");
            });

            Assert.IsFalse(_errorAlertCalled, "Delete Task Failed");
        }
Пример #3
0
        public void Init()
        {
            _navigationMock = new Mock <INavigationService>();
            _navigationMock.Setup(e => e.NavigateAsync("NavigationPage/TaskHomePage"));

            //Mocking No Network alert view
            _pageDialogServiceMock = new Mock <IPageDialogService>();
            _pageDialogServiceMock.Setup(method => method.DisplayAlertAsync(AppConstants.AlertOfflineTitle, AppConstants.AlertOfflineInfo, AppConstants.AlertOkBtnTitle)).Returns(() =>
            {
                _alertCalled = true;
                return(Task.FromResult(0));
            });
            //Mocking Empty Task Title alert view
            _pageDialogServiceMock.Setup(method => method.DisplayAlertAsync(AppConstants.AppName, AppConstants.AlertEmptyFieldInfo, AppConstants.AlertOkBtnTitle)).Returns(() =>
            {
                _emptyTaskTitleAlertCalled = true;
                return(Task.FromResult(0));
            });

            //Mocking Error alert view
            _pageDialogServiceMock.Setup(method => method.DisplayAlertAsync(AppConstants.AppName, AppConstants.AlertErrorInfo, AppConstants.AlertOkBtnTitle)).Returns(() =>
            {
                _errorAlertCalled = true;
                return(Task.FromResult(0));
            });

            //Mocking Task Services
            _taskServiceMock = new Mock <ITasksService>();
            _taskServiceMock.Setup(method => method.DeleteTaskAsync("1")).Returns(() => { return(Task.FromResult(1)); });
            _taskServiceMock.Setup(method => method.GetTaskListAsync()).Returns(() => { return(Task.FromResult(TaskMockData.ReturnServiceTaskList())); });
            _taskServiceMock.Setup(method => method.SaveTaskAsync(TaskMockData.ReturnServiceTaskList()[0])).Returns(() =>
            {
                return(Task.FromResult(TaskMockData.ReturnServiceTaskList()[0]));
            });

            //Mocking Task DB Calls
            _dbMock = new Mock <IRepository <TodoDBItem> >();
            _dbMock.Setup(method => method.Get()).Returns(() => { return(TaskMockData.ReturnDBTaskList()); });
            _dbMock.Setup(method => method.DeleteAll()).Returns(Task.FromResult(0));
            _dbMock.Setup(method => method.Delete(TaskMockData.ReturnDBTaskList()[0])).Returns(() => { return(Task.FromResult(1)); });

            //Mocking Network Connectivity value
            _platformServiceMock = new Mock <IPlatformService>();
            _platformServiceMock.Setup(method => method.IsConnected()).Returns(true);

            //Mocking Container instance
            IocContainer.Instance.Container.UseInstance <IPlatformService>(_platformServiceMock.Object);
            IocContainer.Instance.Container.UseInstance <ITasksService>(_taskServiceMock.Object);
            IocContainer.Instance.Container.UseInstance <IRepository <TodoDBItem> >(_dbMock.Object);
        }