protected void SubmitNewContract(object sender,EventArgs e)
        {
            var service = ServiceFactory.GetService<IContractService>();
            var request = new NewContractForAccountRequest
                              {

                                  AccountNumber = ucAccount.AccountNumber,
                                  AccountPassword = txtPassword.Text,
                                  ActivationDate = ucContract.ActivationDate,
                                  EndDate = ucContract.EndDate,
                                  Data = ucContract.Data,
                                  MessageBank = ucContract.MessageBank,
                                  PlanId = ucContract.PlanId,
                                  SimCard = ucContract.SimCard,
                                  IMEINumber = ucContract.IMEINumber,
                                  UsedBy = ucContract.PhoneUsedBy,
                                  User = Users.Current
                              };
            var response = service.SubmitNewContractForAccount(request);
            if (!response.IsSuccessful)
            {
                // lblErrorMessage.Text = response.Message;
                UserMessage.SetFailure(response.Message);
            }
            else
            {
                NavigationController.Thankyou();
            }
        }
        public void New_contract_for_account_requires_IMEI_number_and_sim_card()
        {
            // Setup mock behaviour
            _planRepository
                .Expect(p => p.GetPlan(1))
                .Returns(new Plan(1) );

            _accountRepository
                .Expect(p => p.GetAccountByAccountNumber("LW0001"))
                .Returns(new Account(1) { AccountNumber = "LW0001", Password = "******" });

            NewContractForAccountRequest request = new NewContractForAccountRequest();
            request.AccountNumber = "LW0001";
            request.AccountPassword = "******";
            request.ActivationDate = DateTime.Today.AddDays(1);
            request.EndDate = DateTime.Today.AddDays(3);
            request.IMEINumber = "";
            request.SimCard = "123232593";
            request.UsedBy = "Robert";
            request.PlanId = 1;
            request.Data = false;
            request.MessageBank = false;
            request.User = new User() { Username = "******" };

            NewContractResponse response = _service.SubmitNewContractForAccount(request);

            Assert.IsFalse(response.IsSuccessful);
            Assert.AreEqual("Both an IMEI Number and sim card number must be supplied.", response.Message);
        }
        public void Contract_can_be_added_to_existing_account()
        {
            // Setup mock behaviour
            _planRepository.Expect(p => p.GetPlan(1)).Returns(new Plan(1));
            _accountRepository.Expect(p => p.GetAccountByAccountNumber("LW0001")).Returns(new Account(1) { AccountNumber = "LW0001", Password = "******" });
            _generator.Expect(p => p.NextContractNumber()).Returns("CT6666");
            _contractRepository.Expect(p => p.InsertContract(It.Is<Contract>(x => x.Id == null))).Callback<Contract>(c => c.Inserted(1));

            var request = new NewContractForAccountRequest
                              {
                                  AccountNumber = "LW0001",
                                  AccountPassword = "******",
                                  ActivationDate = DateTime.Parse("2008-10-15"),
                                  EndDate = DateTime.Parse("2010-10-15"),
                                  IMEINumber = "12342323323",
                                  SimCard = "123232593",
                                  UsedBy = "Robert",
                                  PlanId = 1,
                                  Data = false,
                                  MessageBank = false,
                                  User = new User() {IsAuthenticated = true, Username = "******"}
                              };

            var response = _service.SubmitNewContractForAccount(request);

            Assert.IsTrue(response.IsSuccessful);
        }
        public void Cannot_add_contract_to_an_account_when_account_doesnt_exist()
        {
            // Setup mock behaviour
            _planRepository.Expect(p => p.GetPlan(1)).Returns(new Plan(1));
            _accountRepository.Expect(p => p.GetAccountByAccountNumber("LW0001")).Returns<Account>(null);
            _dateTime.ExpectGet(p => p.Today).Returns(DateTime.Parse("2008-10-11"));

            NewContractForAccountRequest request = new NewContractForAccountRequest();
            request.AccountNumber = "LW0001";
            request.AccountPassword = "******";
            request.PlanId = 1;
            request.ActivationDate = DateTime.Parse("2008-10-11");
            request.EndDate = DateTime.Parse("2010-10-15");
            request.IMEINumber = "12342323323";
            request.SimCard = "123232593";
            request.UsedBy = "Robert";
            request.Data = false;
            request.MessageBank = false;
            request.User = new User() { Username = "******" };

            NewContractResponse response = _service.SubmitNewContractForAccount(request);

            Assert.IsFalse(response.IsSuccessful);
            Assert.AreEqual("Account 'LW0001' does not exist.", response.Message);
        }
        public void Cannot_add_contract_to_account_when_end_day_in_the_past()
        {
            // Setup mock behaviour
            _planRepository
                .Expect(p => p.GetPlan(1))
                .Returns(new Plan(1));

            _accountRepository
                .Expect(p => p.GetAccountByAccountNumber("LW0001"))
                .Returns(new Account(1) { AccountNumber = "LW0001", Password = "******" });

            NewContractForAccountRequest request = new NewContractForAccountRequest();
            request.AccountNumber = "LW0001";
            request.AccountPassword = "******";
            request.ActivationDate = _today.AddDays(-10);
            request.EndDate = _today.AddDays(-9);
            request.IMEINumber = "12342323323";
            request.SimCard = "123232593";
            request.UsedBy = "Robert";
            request.PlanId = 1;
            request.Data = false;
            request.MessageBank = false;
            request.User = new User() { Username = "******" };

            NewContractResponse response = _service.SubmitNewContractForAccount(request);

            Assert.IsFalse(response.IsSuccessful);
            Assert.AreEqual("Contract end date must be after the current date.", response.Message);
        }
        public void Cannot_add_contract_to_account_when_account_password_invalid()
        {
            // Setup mock behaviour
            _planRepository.Expect(p => p.GetPlan(1)).Returns(new Plan(1));
            _accountRepository.Expect(p => p.GetAccountByAccountNumber("LW0001")).Returns(new Account(1) { AccountNumber = "LW0001", Password = "******" });

            var request = new NewContractForAccountRequest
                                                       {
                                                           AccountNumber = "LW0001",
                                                           AccountPassword = "******",
                                                           ActivationDate = DateTime.Parse("2008-10-11"),
                                                           EndDate = DateTime.Parse("2010-10-15"),
                                                           IMEINumber = "12342323323",
                                                           SimCard = "123232593",
                                                           UsedBy = "Robert",
                                                           PlanId = 1,
                                                           Data = false,
                                                           MessageBank = false,
                                                           User = new User() {Username = "******"}
                                                       };

            var response = _service.SubmitNewContractForAccount(request);

            Assert.IsFalse(response.IsSuccessful);
            Assert.AreEqual("Supplied Account Password does not match.", response.Message);
        }