コード例 #1
0
        public void CreateFriend_Failed_ReturnsNullDoesntThrow()
        {
            var dbMock = new Mock <IDb <Friend> >();

            dbMock.Setup(db => db.Insert(It.IsAny <Friend>()))
            .Throws <Exception>()
            .Verifiable();
            var friendsRepository = new FriendsRepository(dbMock.Object);

            var friend = friendsRepository.CreateFriend(0, 1);

            Assert.IsNull(friend);
            dbMock.Verify();
        }
コード例 #2
0
        public void CreateFriend_Success_ReturnsFriend()
        {
            var dbMock = new Mock <IDb <Friend> >();

            dbMock.Setup(db => db.Insert(It.IsAny <Friend>()))
            .Callback((Friend f) => { f.Id = 0; })
            .Verifiable();
            var friendsRepository = new FriendsRepository(dbMock.Object);

            var friend = friendsRepository.CreateFriend(0, 1);

            Assert.IsNotNull(friend);
            Assert.AreEqual(0, friend.Id);
            dbMock.Verify();
        }