public void CancellingUpdatingThrowsOperationCanceledException()
 {
     DataProxy dataProxy = new DataProxy();
     Customer customer = TestHelpers.GetSampleCustomer();
     DateTime? result = dataProxy.AddCustomer(customer).Result;
     customer.Name = "New Name";
     CancellationTokenSource cancelSource = new CancellationTokenSource();
     cancelSource.Cancel();
     // Unwraps exception as await is ignored by the test framework
     DateTime? result2 = dataProxy.UpdateCustomer(customer, cancelSource.Token).GetAwaiter().GetResult();
 }
        public void UpdatingExistingUserWithValidDataIsSuccessful()
        {
            Customer customer = TestHelpers.GetSampleCustomer();
            DataProxy dataProxy = new DataProxy();
            DateTime? result = dataProxy.AddCustomer(customer).Result;
            customer.Name = "New Name";
            DateTime? updateResult = dataProxy.UpdateCustomer(customer).Result;

            Assert.IsNotNull(updateResult);

            // Check database if the user with id has specified name
            using (CustomersContext context = new CustomersContext())
            {
                bool existsWithUpdatedName = context.CustomerDbs
                    .Any(c => c.Id == customer.Id && c.Name == customer.Name);
                Assert.IsTrue(existsWithUpdatedName);
            }
        }
 public void UpdatingNullCustomerThrowsException()
 {
     Customer customer = null;
     DataProxy dataProxy = new DataProxy();
     // Unwraps exception as await is ignored by the test framework
     DateTime? result = dataProxy.UpdateCustomer(customer).GetAwaiter().GetResult();
 }
        public void UpdatingExistingUserWithInvalidDataFails()
        {
            Customer customer = TestHelpers.GetSampleCustomer();
            DataProxy dataProxy = new DataProxy();
            DateTime? result = dataProxy.AddCustomer(customer).Result;
            customer.Name = TestHelpers.STRING_LONGER_THAN_50_CHARS;
            DateTime? updateResult = dataProxy.UpdateCustomer(customer).Result;

            Assert.IsNull(updateResult);

            // Check database if the user with id has specified name
            using (CustomersContext context = new CustomersContext())
            {
                bool existsWithUpdatedName = context.CustomerDbs
                    .Any(c => c.Id == customer.Id && c.Name == customer.Name);
                Assert.IsFalse(existsWithUpdatedName);
            }
        }