Beispiel #1
0
        public void ShouldThrowException()
        {
            var mockIlist = new Mock <IList>();

            mockIlist.Setup(x => x.Add(It.Is <string>(s => s.Length >= 10)))
            .Throws <ArgumentException>();
            var sut = new DemoServiceWithDependency(mockIlist.Object);

            Assert.That(() => sut.Add("impossible"), Throws.Exception);
        }
        public void ShouldNotContain()
        {
            var _mockIlist = new Mock <IList>();

            _mockIlist.Setup(x =>
                             x.Contains(It.IsAny <string>())).Returns(false);
            var sut = new DemoServiceWithDependency(_mockIlist.Object);

            var tricky = "I am not out there!";

            sut.Add(tricky);
            var result = sut.Contains(tricky);

            Assert.That(result, Is.EqualTo(false));
        }
Beispiel #3
0
        public void ShouldPassSimpleVerification()
        {
            _sut.Add(DateTime.Now);

            _mockIlist.Verify();
        }