public async void SaveButton() { var customerFormValidator = new CustomerFormValidator(); var validationResult = customerFormValidator.Validate(NewCustomer); // For testing CustomerValidationResult = validationResult.IsValid; if (validationResult.IsValid) { var customerEntity = NewCustomer.ConvertToCustomerEntity(); var resultTask = await _customers.AddCustomer(customerEntity); // For testing CustomerAddResult = resultTask; if (resultTask) { ClearFields(); await LoadCustomers(); } else { MessageBox.Show("Wystąpił błąd podczas zapisu danych. Spróbuj ponownie"); } } else { MessageBox.Show("Błąd walidacji danych."); } }
public void ConvertToCustomerEntity_Test() { // Arrange int sampleId = 3; string sampleName = "sampleName"; string sampleAddress = "someStreet 32A/3"; string sampleCity = "someCityName"; CustomerModel customerModel = new CustomerModel { Id = sampleId, Name = sampleName, Address = sampleAddress, City = sampleCity }; // Act var customerEntity = customerModel.ConvertToCustomerEntity(); // Assert Assert.Equal(0, customerEntity.Id); Assert.Equal(sampleName, customerEntity.Name); Assert.Equal(sampleAddress, customerEntity.Address); Assert.Equal(sampleCity, customerEntity.City); Assert.True(customerEntity.GetType() == typeof(DataAccess.Entities.Customer)); Assert.Null(customerEntity.Projects); }
public async void SaveButton() { var customerModel = new CustomerModel() { Name = CustomerName, Address = CustomerAddress, City = CustomerCity }; var customerFormValidator = new CustomerFormValidator(); var validationResult = customerFormValidator.Validate(customerModel); // For testing CustomerValidationResult = validationResult.IsValid; if (validationResult.IsValid) { var customerEntity = customerModel.ConvertToCustomerEntity(); customerEntity.Id = customerId; var resultTask = await _customers.UpdateCustomer(customerEntity); // For testing CustomerUpdateResult = resultTask; if (resultTask) { _events.PublishOnUIThread(new CustomerCredentialsChangedEvent()); this.TryClose(); } else { MessageBox.Show("Błąd podczas zapisu danych. Spróbuj ponownie"); } } else { MessageBox.Show("Błąd walidacji danych"); } }