public User InsertAndReturnNewUser(PostUser user)
 {
     using (var db = new DbContext())
     {
         var insertedUserId = (int)db.Connection.Insert(user);
         return(SelectByID(insertedUserId));
     }
 }
        public void RegisterNewUser_ShouldCatchSQLException()
        {
            var sqlException = SQLExceptionBuilder.CreateInstance()
                               .Message("Some SQL text with UQ_Users_Email keyword")
                               .Number(2627).Build();
            var fakeUser = new PostUser {
                Password = "******"
            };
            var daoMock = new Mock <IUsersDao>();

            daoMock.Setup(x => x.InsertAndReturnNewUser(It.IsAny <PostUser>()))
            .Throws(sqlException);

            var sut = new UserLogic(daoMock.Object, null, null);

            Assert.ThrowsException <UniqueFieldException>(() => sut.RegisterNewUser(fakeUser));
        }