Example #1
0
        public void EditAddressSuccessTest()
        {
            int      id              = 0;
            string   Address1        = "Test";
            string   Address2        = "Test";
            string   City            = "Test";
            string   ZipCode         = "71000";
            bool     isDeleted       = false;
            int      AddressTypeId   = 1;
            int      CreatedByUserId = 1;
            DateTime DateCreated     = DateTime.Now;
            DateTime DateModified    = DateTime.Now;

            var address = new AddressDto
            {
                AddressId       = id,
                Address1        = Address1,
                Address2        = Address2,
                City            = City,
                ZipCode         = ZipCode,
                AddressTypeId   = AddressTypeId,
                CreatedByUserId = CreatedByUserId,
                IsDeleted       = isDeleted,
                DateCreated     = DateCreated,
                DateModified    = DateModified
            };

            var data = new List <Address>
            {
                new Address {
                    AddressId = 0
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Address> >();

            mockSet.As <IQueryable <Address> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Address> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Address> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Address> >().Setup(m => m.GetEnumerator()).Returns(() => data.GetEnumerator());

            var mockRepo = new Mock <IkarusContext>();

            mockRepo.Setup(x => x.SaveChanges());

            mockRepo.Setup(x => x.Address).Returns(mockSet.Object);
            var addressRepository = new AddressRepository(mockRepo.Object);
            var result            = addressRepository.EditAddress(0, address);

            Assert.True(result);
        }
Example #2
0
        public void EditAddressExceptionWhileSaveChangesFailureTest()
        {
            int      id              = 1;
            string   Address1        = "Test";
            string   Address2        = "Test";
            string   City            = "Test";
            string   ZipCode         = "71000";
            bool     isDeleted       = false;
            int      AddressTypeId   = 1;
            int      CreatedByUserId = 1;
            DateTime DateCreated     = DateTime.Now;
            DateTime DateModified    = DateTime.Now;

            var address = new AddressDto
            {
                AddressId       = id,
                Address1        = Address1,
                Address2        = Address2,
                City            = City,
                ZipCode         = ZipCode,
                AddressTypeId   = AddressTypeId,
                CreatedByUserId = CreatedByUserId,
                IsDeleted       = isDeleted,
                DateCreated     = DateCreated,
                DateModified    = DateModified
            };

            var mockRepo = new Mock <IkarusContext>();

            mockRepo.Setup(x => x.SaveChanges()).Throws <Exception>();
            var addressRepository = new AddressRepository(mockRepo.Object);

            try
            {
                var result = addressRepository.EditAddress(0, address);
            }
            catch (Exception e)
            {
                Assert.IsType <ArgumentNullException>(e);
            }
        }
Example #3
0
        public void EditAddressArgumentNullExceptionFailureTest()
        {
            int      id              = 1;
            string   Address1        = "Test";
            string   Address2        = "Test";
            string   City            = "Test";
            string   ZipCode         = "71000";
            bool     isDeleted       = false;
            int      AddressTypeId   = 1;
            int      CreatedByUserId = 1;
            DateTime DateCreated     = DateTime.Now;
            DateTime DateModified    = DateTime.Now;

            //var address = new AddressDto
            //{
            //    AddressId = id,
            //    Address1 = Address1,
            //    Address2 = Address2,
            //    City = City,
            //    ZipCode = ZipCode,
            //    AddressTypeId = AddressTypeId,
            //    CreatedByUserId = CreatedByUserId,
            //    IsDeleted = isDeleted,
            //    DateCreated = DateCreated,
            //    DateModified = DateModified
            //};

            AddressDto address = null;

            var mockRepo          = new Mock <IkarusContext>();
            var addressRepository = new AddressRepository(mockRepo.Object);

            try
            {
                var result = addressRepository.EditAddress(0, address);
            }
            catch (Exception e)
            {
                Assert.IsType <ArgumentNullException>(e);
            }
        }
 public void UpdateAddress(Address address)
 {
     repository.EditAddress(address);
 }