Ejemplo n.º 1
0
        public async Task HomePageViewModel_GetTaskListAsync_NoConnecteciont_Test()
        {
            TaskHomePageViewModel viewModel = new TaskHomePageViewModel(_navigationMock.Object, _pageDialogServiceMock.Object);

            _platformServiceMock.Setup(method => method.IsConnected()).Returns(false);
            await viewModel.GetTaskListAsync();

            Assert.AreEqual <int>(viewModel.TaskList.Count, TaskMockData.ReturnServiceTaskList().Count);
        }
Ejemplo n.º 2
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);
        }