Exemple #1
0
        public void PersonWithAge52_ShouldHavePensionAndShouldBeNotified()
        {
            // arrange

            var personUnderTest = new Person
            {
                FullName    = "Vasile",
                Id          = Guid.NewGuid(),
                DateOfBirth = new DateTime(1968, 07, 22)
            };

            var mockPersonRepo = new Mock <IPersonRepository>();

            mockPersonRepo
            .Setup(r => r.Get(personUnderTest.Id))
            .Returns(personUnderTest);

            var mailSenderMock = new Mock <IMailSender>();

            PensionServiceV2 sut = new PensionServiceV2(mockPersonRepo.Object, mailSenderMock.Object);

            // act

            var actual = sut.Calculate(personUnderTest.Id);

            // assert

            var expected = true;

            Assert.Equal(expected, actual.IsPensionable);

            mailSenderMock.Verify(ms => ms.Send(It.Is <string>(p => p == "welcome to pension")), Times.Once);
        }
Exemple #2
0
        public void PersonWithAge42_ShouldNotHavePensionAndShouldBeNotified()
        {
            // arrange

            var personUnderTest = new Person
            {
                FullName    = "Razvan",
                Id          = Guid.NewGuid(),
                DateOfBirth = new DateTime(1978, 06, 10)
            };

            var mockPersonRepo = new Mock <IPersonRepository>();

            mockPersonRepo
            .Setup(r => r.Get(personUnderTest.Id))
            .Returns(personUnderTest);

            //mockPersonRepo.Setup(r => r.Get(It.IsAny<Guid>())).Returns(personUnderTest);

            var mailSenderMock = new Mock <IMailSender>();

            PensionServiceV2 sut = new PensionServiceV2(mockPersonRepo.Object, mailSenderMock.Object);

            // act

            var actual = sut.Calculate(personUnderTest.Id);

            // assert

            var expected = false;

            Assert.Equal(expected, actual.IsPensionable);

            mailSenderMock.Verify(ms => ms.Send(It.Is <string>(p => p == "at 51 you'll have pension :)")), Times.Once);
        }