public void UpdateInvalidAddress()
        {
            var options = TestDbContext.TestDbInitalizer("Update Address");

            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                var AddressResult = new AddressRepository(dbcreate).Update(AddressTestData.UpdateInvalidAddress1());
                Assert.False(AddressResult);
            }
        }
Exemple #2
0
        public void ValidateCityState()
        {
            var validAddress     = AddressTestData.InvalidCityState();
            var validationResult = new List <ValidationResult>();
            var actual           = Validator.TryValidateObject(validAddress, new ValidationContext(validAddress), validationResult, true);
            int ErrorCount       = validationResult.Count;

            Assert.False(actual);
            Assert.Equal(1, ErrorCount);
        }
Exemple #3
0
        public void ValidAddressEntityModel()
        {
            var sut = AddressTestData.ValidAddress1();
            var validationResult = new List <ValidationResult>();
            var actual           = Validator.TryValidateObject(sut, new ValidationContext(sut), validationResult, true);
            var ErrorCount       = validationResult.Count;

            Assert.True(actual);
            Assert.Equal(0, ErrorCount);
        }
        public void GetFoundAddress()
        {
            var options = TestDbContext.TestDbInitalizer("TestingGetAddressControllerConstructor");

            using (var database = TestDbContext.CreateTestDb(options))
            {
                database.Add(AddressTestData.ValidAddress1());
                database.SaveChanges();
                _AC = new AddressController();
                _AC._addressHelper = Api.Helpers.AddressHelper.ChangeRepository(database);
                var result = _AC.Get();
                Assert.IsType <OkObjectResult>(result);
            }
        }
        public void GetNotFoundAddressByKeyController()
        {
            var options = TestDbContext.TestDbInitalizer("TestingGetNotFoundAddressKeyControllerConstructor");

            using (var database = TestDbContext.CreateTestDb(options))
            {
                database.Add(AddressTestData.ValidAddress1());
                database.SaveChanges();

                _AC = new AddressController();
                _AC._addressHelper = Api.Helpers.AddressHelper.ChangeRepository(database);
                var validKey = new Guid("9bc7edd6-71e6-464e-a900-05eff8ab144d");
                var result   = _AC.Get(validKey);
                Assert.IsType <NotFoundObjectResult>(result);
            }
        }
        public void UpdateValidAddress()
        {
            var options = TestDbContext.TestDbInitalizer("Update Address");

            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                dbcreate.Add(AddressTestData.ValidAddress1());
                dbcreate.SaveChanges();
            }

            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                var AddressResult = new AddressRepository(dbcreate).Update(AddressTestData.UpdateValidAddress1());
                Assert.True(AddressResult);
            }
        }
        public void DeleteInvalidAddress()
        {
            var options = TestDbContext.TestDbInitalizer("Delete Invalid Address");

            //Want to delete Address1 but accidentally use Address2 Key.
            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                dbcreate.Add(
                    AddressTestData.ValidAddress1());
                dbcreate.SaveChanges();
            }

            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                var TestKey       = AddressTestData.ValidAddress2().Key;
                var AddressResult = new AddressRepository(dbcreate).Delete(TestKey);
                Assert.False(AddressResult);
            }
        }
        public void ReadAllAddress()
        {
            var options = TestDbContext.TestDbInitalizer("Read All Addresses"); //Create Instance of DB.

            //Insert data into test database
            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                dbcreate.AddRange(
                    AddressTestData.ValidAddress1(),
                    AddressTestData.ValidAddress2());
                dbcreate.SaveChanges();
            }

            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                var AddressExpected = new AddressRepository(dbcreate).ReadAll();
                var count           = AddressExpected.Count();
                Assert.Equal(2, count);
            }
        }
        public void DeleteAddress()
        {
            var options = TestDbContext.TestDbInitalizer("Delete Address");

            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                dbcreate.AddRange(
                    AddressTestData.ValidAddress1(),
                    AddressTestData.ValidAddress2());
                dbcreate.SaveChanges();
            }

            //We want to delete Address2.
            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                var TestKey       = AddressTestData.ValidAddress2().Key;
                var AddressResult = new AddressRepository(dbcreate).Delete(TestKey);
                Assert.True(AddressResult);
            }
        }
        public void ReadAddress()
        {
            var options = TestDbContext.TestDbInitalizer("CanGetID"); //Create Instance of DB.
            //Insert data into test, specifically ValidAddress1().
            Guid saveKey = AddressTestData.ValidAddress1().Key;

            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                dbcreate.Add(AddressTestData.ValidAddress1());
                dbcreate.SaveChanges();
            }
            using (var dbcreate = TestDbContext.CreateTestDb(options))
            {
                var AddressList     = new List <AddressModel>();
                var AddressExpected = new AddressRepository(dbcreate).Read(saveKey);
                AddressList.Add(AddressExpected);

                Assert.Equal(1, AddressList.Count());
                Assert.Equal(saveKey, AddressList[0].Key);
            }
        }