Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3942380
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:39:21+00:00 2026-05-20T00:39:21+00:00

I am trying to write my first unit test for one of my service

  • 0

I am trying to write my first unit test for one of my service layers. I am using nunit and moq (latest versions).

I have a repo but I will mock that out that is no problem.

 public void Create(string email, int id)
     {
            User user = Repo.GetUserByEmail(email); // mock this out. and return a mocked user.

            if user != null)
            {

                // check permission
                var  clearence = GetPermissions(user, PermissionTypes.Add, id);

                // some other stuff

            }
    }


    private static List<Permissions> GetPermissions(User user, PermissionTypes PermissionNeeded, int id)
    {
        List<PermissionLevel> clearence = user.PermissionLevels.Where(u => u.id == id &&
                                                                                    (u.Permission.Name == PermissionNeeded || u.Permission.Name == PermissionTypes.Owner)).ToList();
        return clearence;
    }

So that is what I have.

Now what is getting me is this clearance. I am not sure how to do it. I am not sure if I have to make a user object that has a permissionLevels in it that contains a id.

I am not sure if I could mock it up but I doubt it since it is private.

The second problem is I am not sure how to create an “id” as the “id” is in a domain class that has a private set because well that was the standard used for nhibernate.

So I am not sure how to get around that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:39:22+00:00Added an answer on May 20, 2026 at 12:39 am

    Yes, assuming you’re mocking GetUserByEmail, you can have it return a user that contains a sample set of permissions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you write first responder unit tests? I'm trying to write a test
I am using Moq for unit testing, and I am trying to write my
I am trying to write a unit test for a GUI application using the
I'm currently trying to write some unit test on some javascript files. My first
I have the following situation. I am trying to write a unit test for
Just trying to write my first ever WP7 app. I have several hundreds of
I'm trying to write my first simple mvc app. I have a Main View
I am trying to write my first WCF project. I have created a project
I'm trying to write my first iPhone app, and I'm using a date picker
I'm trying to test my code using EntityFramework code first. In order to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.