public void CreateTest_HttpPost()
        {
            var item = new ApplicationAvailability { Name = "new", Id = "2" };
            _repository.Expect(x => x.Save(item));
            var result = _controller.Create(item);
            _repository.VerifyAllExpectations();
            var redirect = result.AssertWasRedirectResult("Details");

            Assert.That(redirect.RouteValues["id"], Is.EqualTo(item.Id));
        }
        public ActionResult Create(ApplicationAvailability model)
        {
            try
            {
                _repository.Save(model);

                return RedirectToAction("Details", new { id = model.Id });
            }
            catch
            {
                return View();
            }
        }
        public void CreateTest_HttpPostWithExctpion()
        {
            var organisation = new ApplicationAvailability { Name = "new", Id = "2" };
            _repository.Expect(x => x.Save(organisation))
                .Throw(new Exception());

            // Act
            var result = _controller.Create(organisation);

            // Assert
            _repository.VerifyAllExpectations();
            result.AssertWasViewResult();
        }
        public ActionResult Edit(string id, ApplicationAvailability model)
        {
            try
            {
                var existing = _repository.Get(id);

                UpdateModel(existing);

                _repository.Save(existing);
                return RedirectToAction("Details", new { id });
            }
            catch
            {
                return View(model);
            }
        }
        public void DetailsTest()
        {
            const string id = "3";
            var organisation = new ApplicationAvailability
            {
                Name = "33",
            };
            _repository.Expect(x => x.Get(id))
                .Return(organisation);

            var result = _controller.Details(id);

            _repository.VerifyAllExpectations();
            var viewResult = result.AssertWasViewResult(typeof(ApplicationAvailability));

            Assert.That(viewResult.Model, Is.EqualTo(organisation));
        }
        public void EditTest_HttpPost_WithExcetpion()
        {
            _formCollection["Name"] = "this is my name";
            _formCollection["Description"] = "22";

            string id = "2";
            var organisation = new ApplicationAvailability { Name = "new", Id = "2" };

            _repository.Expect(x => x.Get(id))
                .Return(organisation);

            _repository.Expect(x => x.Save(organisation))
                .IgnoreArguments()
                .Throw(new Exception());

            var result = _controller.Edit(id, new ApplicationAvailability());
            _repository.VerifyAllExpectations();
            result.AssertWasViewResult(typeof(ApplicationAvailability));
        }
        public void EditTest_HttpPost()
        {
            _formCollection["Name"] = "this is my name";
            _formCollection["Description"] = "22";

            string id = "2";
            var organisation = new ApplicationAvailability { Name = "new", Id = "2" };

            _repository.Expect(x => x.Get(id))
                .Return(organisation);

            _repository.Expect(x => x.Save(organisation))
                .IgnoreArguments();

            var result = _controller.Edit(id, null);
            _repository.VerifyAllExpectations();
            var redirect = result.AssertWasRedirectResult("Details");

            Assert.That(redirect.RouteValues["id"], Is.EqualTo(organisation.Id));
        }