Пример #1
0
        public void Details_GivenIdOfUnknownDebtor_ThrowsException()
        {
            // Arrange
            var fakeDebtorRepository = A.Fake<IDebtorRepository>();
            A.CallTo(() => fakeDebtorRepository.FindById(2)).Returns(null);
            var controller = new DebtorsController(fakeDebtorRepository);

            // Act, Assert
            Assert.Throws<InvalidOperationException>(() => controller.Details(2));
        }
Пример #2
0
        public void Details_GivenIdOfKnownDebtor_ReturnsAViewResult()
        {
            // Arrange
            var fakeDebtorRepository = A.Fake<IDebtorRepository>();
            var stubDomainDebtor = DebtorBuilder.Build(2);
            A.CallTo(() => fakeDebtorRepository.FindById(2)).Returns(stubDomainDebtor);
            var controller = new DebtorsController(fakeDebtorRepository);

            // Act
            var actionResult = controller.Details(2);

            // Assert
            Assert.That(actionResult, Is.InstanceOf<ViewResult>());
        }
Пример #3
0
        public void Details_GivenIdOfKnownDebtor_ReturnsAViewResultWithCorrectViewModelType()
        {
            // Arrange
            var fakeDebtorRepository = A.Fake<IDebtorRepository>();
            var stubDomainDebtor = DebtorBuilder.Build(2);
            A.CallTo(() => fakeDebtorRepository.FindById(2)).Returns(stubDomainDebtor);
            var controller = new DebtorsController(fakeDebtorRepository);

            // Act
            var viewResult = controller.Details(2) as ViewResult;

            // Assert
            Assert.That(viewResult.Model, Is.InstanceOf<DebtorViewModel>());
        }
Пример #4
0
        public void DeleteMethodPost_GivenIdOfKnownDebtor_DeletesObjectInRepository()
        {
            // Arrange
            var fakeDebtorRepository = A.Fake<IDebtorRepository>();
            var stubDomainDebtor = DebtorBuilder.Build(2);
            A.CallTo(() => fakeDebtorRepository.FindById(2)).Returns(stubDomainDebtor);
            var controller = new DebtorsController(fakeDebtorRepository);

            // Act
            controller.DeletePost(2);

            // Assert
            A.CallTo(() => fakeDebtorRepository.MakeTransient(A<Debtor>.That.Matches(entity => entity.Id == 2))).MustHaveHappened(Repeated.Exactly.Once);
        }
Пример #5
0
        public void EditMethodPost_GivenInvalidEditModel_DoesNotCallMakePersistentOnTheDebtorRepository()
        {
            // Arrange
            var fakeDebtorRepository = A.Fake<IDebtorRepository>();
            var controller = new DebtorsController(fakeDebtorRepository);
            var editModelDebtor = new DebtorEditModel {CompanyName = "MoneyHelper"};
            controller.ModelState.AddModelError("some_key", @"some_error_message");

            // Act
            var viewResult = controller.Edit(editModelDebtor) as ViewResult;

            // Assert
            A.CallTo(() => fakeDebtorRepository.MakePersistent(A<Debtor>.Ignored)).MustNotHaveHappened();
            Assert.That(viewResult.ViewName, Is.EqualTo("CreateOrEdit"));
        }