Exemple #1
0
        public void Test()
        {
            //var connectionString = ConfigurationManager.ConnectionStrings["SnackMachineDDDDatabase"].ConnectionString;

            SessionFactory.Init(@"Server=.;Database=SnackMachineDDD;Trusted_Connection=True;");

            //using (ISession session = SessionFactory.OpenSession())
            //{
            //    long id = 1;
            //    //var snackMachine = session.Get<SnackMachine>(id);
            //    var repository = new SnackMachineRepository();
            //    var snackMachine = repository.GetById(1);
            //    snackMachine.InsertMoney(OneDollar);
            //    snackMachine.InsertMoney(OneDollar);
            //    snackMachine.InsertMoney(OneDollar);
            //    snackMachine.BuySnack(1);
            //    repository.Save(snackMachine);
            //}

            //var snackMachine = session.Get<SnackMachine>(id);
            var repository   = new SnackMachineRepository();
            var snackMachine = repository.GetById(1);

            snackMachine.InsertMoney(OneDollar);
            snackMachine.InsertMoney(OneDollar);
            snackMachine.InsertMoney(OneDollar);
            snackMachine.BuySnack(1);
            repository.Save(snackMachine);
        }
Exemple #2
0
        public void Test()
        {
            SessionFactory.Init(@"Server=.;Database=DddInPractice;Trusted_Connection=True");
            var repository   = new SnackMachineRepository();
            var snackMachine = repository.GetById(1);

            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.BuySnack(1);
            repository.Save(snackMachine);
        }
        public void GetSnackMachineAndBuySnackTest()
        {
            const long id           = 1;
            var        repository   = new SnackMachineRepository();
            var        snackMachine = repository.GetById(id);

            snackMachine.InsertMoney(Dollar);
            snackMachine.InsertMoney(Dollar);
            snackMachine.InsertMoney(Dollar);
            snackMachine.BuySnack(1);
            repository.Save(snackMachine);
        }
        private void UnloadCash(SnackMachineDto snackMachineDto)
        {
            var snackMachine = _snackMachineRepository.GetById(snackMachineDto.Id);

            if (snackMachine == null)
                return;

            HeadOffice.UnloadCashFromSnackMachine(snackMachine);
            _snackMachineRepository.Save(snackMachine);
            _headOfficeRepository.Save(HeadOffice);

            RefreshAll();
        }
Exemple #5
0
        public void Test()
        {
            SessionFactory.Init(ConfigurationManager.ConnectionStrings["DDDInPractice"].ConnectionString);

            var repository   = new SnackMachineRepository();
            var snackMachine = repository.GetById(1);

            snackMachine.InsertMoney(Dollar);
            snackMachine.InsertMoney(Dollar);
            snackMachine.InsertMoney(Dollar);
            snackMachine.BuySnack(1);
            repository.Save(snackMachine);
        }
        private void BuySnack(string positionString)
        {
            int position = int.Parse(positionString);

            string error = _snackMachine.CanBuySnack(position);

            if (error != string.Empty)
            {
                NotifyClient(error);
                return;
            }

            _snackMachine.BuySnack(position);
            _repository.Save(_snackMachine);
            NotifyClient("You have bought a snack");
        }
Exemple #7
0
        private void BuySnack(string position)
        {
            string error = _snackMachine.CanBuySnack(int.Parse(position));

            if (!string.IsNullOrEmpty(error))
            {
                NotifyClient(error);
            }
            else
            {
                _snackMachine.BuySnack(int.Parse(position));
                snackMachineRepository.Save(_snackMachine);

                NotifyClient("You've bought a snack.");
            }
        }
Exemple #8
0
        private void BuySnack(string positionString)
        {
            var position = int.Parse(positionString);

            var error = _snackMachine.CanBuySnack(position);

            if (!string.IsNullOrEmpty(error))
            {
                NotifyClient(error);
                return;
            }

            _snackMachine.BuySnack(position);
            _repository.Save(_snackMachine);

            NotifyClient("You have bought a snack");
        }
Exemple #9
0
        public void Test()
        {
            SessionFactory.Init(@"Server=(localdb)\mssqllocaldb;Database=DddInPractice;Trusted_Connection=True;");

//            using (ISession session = SessionFactory.OpenSession())
//            {
//                long id = 1;
//                var snackMachine = session.Get<SnackMachine>(id);
//            }

            var          repository   = new SnackMachineRepository();
            SnackMachine snackMachine = repository.GetById(1);

            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.BuySnack(1);
            repository.Save(snackMachine);
        }
Exemple #10
0
        private void BuySnack(string positionString) // handling client exception -> could return value and then by value serving client correct one
                                                     // but it violates CQRS pattern
        {
            int position = int.Parse(positionString);

            string error = _snackMachine.CanBuySnack(position);

            if (error != string.Empty)
            {
                NotifyClient(error);
                return;
            }

            _snackMachine.BuySnack(position);
            _repository.Save(_snackMachine);
            //using (ISession session = SessionFactory.OpenSession())
            //using (ITransaction transaction = session.BeginTransaction())
            //{
            //    session.SaveOrUpdate(_snackMachine);
            //    transaction.Commit();
            //}
            NotifyClient("You have bought a snack");
        }
Exemple #11
0
 private void BuySnack()
 {
     _snackMachine.BuySnack(1);
     _SnackMachineRepository.Save(_snackMachine);
     NotifyClient("You have bought a snack");
 }