private async void OnDeleteButtonClicked(object sender, EventArgs e)
        {
            if (await DisplayAlert(title: "Delete All Data", message: "Are you sure you want to delete all data?", accept: "Yes", cancel: "No"))
            {
                var clientRepo = new ClientRepository();
                var clients    = await clientRepo.GetAllItemsAsync().ConfigureAwait(false);

                foreach (var client in clients)
                {
                    await clientRepo.DeleteItemAsync(client.Id).ConfigureAwait(false);
                }

                var projectRepo = new ProjectRepository();
                var projects    = await projectRepo.GetAllItemsAsync().ConfigureAwait(false);

                foreach (var project in projects)
                {
                    await projectRepo.DeleteItemAsync(project.Id).ConfigureAwait(false);
                }

                var workshiftRepo = new WorkshiftRepository();
                var workshifts    = await workshiftRepo.GetAllItemsAsync().ConfigureAwait(false);

                foreach (var workshift in workshifts)
                {
                    await workshiftRepo.DeleteItemAsync(workshift.Id).ConfigureAwait(false);
                }

                viewModel.LoadItemsCommand.Execute(null);
            }
        }
Example #2
0
        public void SelectedProject_NewViewModel_SelectedProjectIsCorrect(int workshiftPkId, string projectName)
        {
            // Arrange
            App.GenerateTestData().Wait();
            var workshiftRepository = new WorkshiftRepository();
            var workshift           = workshiftRepository.GetItemAsync(workshiftPkId).Result;

            // Act
            viewModel = new AddWorkshiftViewModel(workshift);

            // Assert
            Assert.Equal(projectName, viewModel.SelectedProject?.Name);
        }
Example #3
0
        public void SetProjectOfWorkshift_NewViewModel_ProjectIsSet(int projectId)
        {
            // Arrange
            App.GenerateTestData().Wait();
            var workshiftRepository = new WorkshiftRepository();
            var projectRepository   = new ProjectRepository();
            var workshift           = workshiftRepository.GetItemAsync(1).Result;

            viewModel = new AddWorkshiftViewModel(workshift);
            var project = projectRepository.GetItemAsync(projectId).Result;

            // Act
            viewModel.SetProjectOfWorkshift(project);

            // Assert
            Assert.Equal(projectId, viewModel.Item.ProjectId);
        }
Example #4
0
        public void SaveWorkshiftToDatabase_AllArguments_Saved()
        {
            // Arrange
            var Workshift = new Workshift()
            {
                Name = "Test Workshift 123456789", Description = "Test Description !@#$%^&*()"
            };

            viewModel.Item = Workshift;

            // Act
            viewModel.SaveItemToDatabaseAsync().Wait();

            // Assert
            var WorkshiftRepository = new WorkshiftRepository();
            var resultWorkshift     = WorkshiftRepository.GetAllItemsAsync().Result.FirstOrDefault(x => x.Name == "Test Workshift 123456789");

            Assert.NotNull(resultWorkshift);
        }
Example #5
0
        public void SaveWorkshiftToDatabase_EmptyArgument_NotSaved(string name, string description)
        {
            // Arrange
            var workshift = new Workshift()
            {
                Name = name, Description = description
            };

            viewModel.Item = workshift;

            // Act
            viewModel.SaveItemToDatabaseAsync().Wait();

            // Assert
            var workshiftRepository = new WorkshiftRepository();
            var resultWorkshift     = workshiftRepository.GetAllItemsAsync().Result.FirstOrDefault(x => x.Name == name && x.Description == description);

            Assert.Null(resultWorkshift);
        }
        private async Task getAllWorkshifts()
        {
            var WorkshiftRepository = new WorkshiftRepository();

            allWorkshifts = await WorkshiftRepository.GetAllItemsAsync().ConfigureAwait(false);
        }