public void Get_All_States_In_Database()
        {
            var country = new Country();

            country.Name = "Argentina";
            country.Id   = 1;

            var stateToSave = new State();

            stateToSave.Name      = "Buenos Aires";
            stateToSave.MyCountry = country;
            stateToSave.CountryId = country.Id;

            var otherStateToSave = new State();

            otherStateToSave.Name      = "Tucuman";
            otherStateToSave.MyCountry = country;
            otherStateToSave.CountryId = country.Id;

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_All_state_in_database")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service = new StatesService(context);
                service.AddState(stateToSave);
                service.AddState(otherStateToSave);
            }
            using (var context = new ApplicationDbContext(options))
            {
                var service = new StatesService(context);
                Assert.Equal(2, service.GetAllStates(1).Count);
            }
        }
예제 #2
0
        public StatesServiceTests()
        {
            long Id = singleEntity.Id;

            Mock    = DefaultContextMock.GetMock();
            MockSet = SetUpMock.SetUpFor(testEntities);
            Mock.Setup(c => c.Set <State>()).Returns(MockSet.Object);
            Mock.Setup(c => c.State).Returns(MockSet.Object);
            testedService = new StatesService(Mock.Object);
        }
        public ActionResult Injected()
        {
            var person = new Person
            {
                Name      = "John Doe",
                BirthDate = new DateTime(1980, 1, 1),
                State     = StatesService.GetStates()[1]
            };

            return(View(person));
        }
        public void Get_State_By_Id()
        {
            var stateToSave = new State();

            stateToSave.Name = "Buenos Aires";
            stateToSave.Id   = 1;

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_All_state_in_database")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service = new StatesService(context);
                service.AddState(stateToSave);
                Assert.NotNull(service.GetStateById(1));
            }
        }
예제 #5
0
        public async Task <ActionResult> SavePersonalInfo(Customer customer)
        {
            customer.PaymentMethodCode = "X";
            customer.CardNo            = "X";
            customer.ExpDate           = DateTime.Now.AddMonths(12);
            SetStates();
            if (ModelState.IsValid)
            {
                var c = new Customer
                {
                    FName             = customer.FName,
                    LName             = customer.LName,
                    Email             = Request.Cookies["User"] == null ? customer.Email : Request.Cookies["User"]["Email"],
                    Phone             = customer.Phone,
                    Address1          = customer.Address1,
                    Address2          = customer.Address2,
                    Postcode          = customer.Postcode,
                    State             = customer.State,
                    PaymentMethodCode = "x",
                    CardNo            = "xxxxxxxxxxxxxxxx",
                    ExpDate           = customer.ExpDate
                };

                var customerService = new CustomerService();
                customerService.SavePersonalInfo(c, Session.SessionID);

                return(View("AccountConfirmation"));
            }
            else
            {
                ViewBag.States = StatesService.GetStates();
            }
            List <ModelError> errors = new List <ModelError>();

            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    errors.Add(error);
                }
            }

            return(View("PersonalInfo", customer));
        }
        public void Add_State_To_Database()
        {
            var stateToSave = new State();

            stateToSave.Name = "Buenos Aires";

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_state_to_database")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service = new StatesService(context);
                service.AddState(stateToSave);
            }
            using (var context = new ApplicationDbContext(options))
            {
                Assert.Single(context.states.ToList());
                Assert.Equal("Buenos Aires", context.states.FirstOrDefault().Name);
            }
        }
        public void Update_State()
        {
            var stateToSave = new State();

            stateToSave.Name = "Buenos Aires";
            stateToSave.Id   = 1;

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Update_State")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service = new StatesService(context);
                service.AddState(stateToSave);

                var stateSaved = service.GetStateById(1);
                stateSaved.Name = "updatedName";
                service.UpdateState(stateSaved);

                Assert.Equal("updatedName", service.GetStateById(1).Name);
            }
        }
예제 #8
0
 private void SetStates()
 {
     ViewBag.States = StatesService.GetStates();
 }
 protected override object WithValue(PropertyInfo propertyInfo)
 {
     return(StatesService.GetStates());
 }
예제 #10
0
 public CheckoutController()
 {
     states = StatesService.GetStates();
 }