public void AddingNullCustomerThrowsException()
 {
     Customer customer = null;
     DataProxy dataProxy = new DataProxy();
     // Unwraps exception as await is ignored by the test framework
     DateTime? result = dataProxy.AddCustomer(customer).GetAwaiter().GetResult();
 }
 public void CancellingAddingThrowsOperationCanceledException()
 {
     Customer customer = TestHelpers.GetSampleCustomer();
     DataProxy dataProxy = new DataProxy();
     CancellationTokenSource cancelSource = new CancellationTokenSource();
     cancelSource.Cancel();
     // Unwraps exception as await is ignored by the test framework
     DateTime? result = dataProxy.AddCustomer(customer, cancelSource.Token).GetAwaiter().GetResult();
 }
        public void InvalidCustomerIsNotAddedToDb()
        {
            // Add invalid customer to DB.
            Customer customer = TestHelpers.GetSampleCustomer();
            customer.Name = TestHelpers.STRING_LONGER_THAN_50_CHARS;
            DataProxy dataProxy = new DataProxy();
            DateTime? result = dataProxy.AddCustomer(customer).Result;

            // Connect to CustomersContext to check if it exists in the DB.
            using (CustomersContext context = new CustomersContext())
            {
                bool exists = context.CustomerDbs.Any(c => c.Id == customer.Id);
                Assert.IsFalse(exists);
            }
        }
        public void RemovingCustomerFromDbIsSuccessful()
        {
            Customer customer = TestHelpers.GetSampleCustomer();
            DataProxy dataProxy = new DataProxy();
            DateTime? result = dataProxy.AddCustomer(customer).Result;
            DateTime? removeResult = dataProxy.RemoveCustomer(customer).Result;

            Assert.IsNotNull(removeResult);
        }
        public void ValidCustomerIsSuccessfullyAddedToDb2()
        {
            // Add customer to DB.
            Customer customer = TestHelpers.GetSampleCustomer();
            DataProxy dataProxy = new DataProxy();
            DateTime? result = dataProxy.AddCustomer(customer).Result;

            // Connect to CustomersContext to check if it exists in the DB.
            using (CustomersContext context = new CustomersContext())
            {
                bool exists = context.CustomerDbs.Any(c => c.Id == customer.Id);
                Assert.IsTrue(exists);
            }
        }
        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 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);
            }
        }
        public void RemovingCustomerThatIsNotInDbFails()
        {
            Customer customer = TestHelpers.GetSampleCustomer();
            DataProxy dataProxy = new DataProxy();
            DateTime? result = dataProxy.AddCustomer(customer).Result;

            // remove same customer twice so the second time it will fail.
            DateTime? removeResult = dataProxy.RemoveCustomer(customer).Result;
            Assert.IsNotNull(removeResult);
            DateTime? removeResult2 = dataProxy.RemoveCustomer(customer).Result;

            Assert.IsNull(removeResult2);
        }