Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x

R

R is a programming language and environment used primarily for statistical data analysis.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi,
we are using xunit and moq for unit testing.
How can I "mock" a method which is taking readonlycollection<employee> and it is updating one of its property and returning readonlycollection<employee>?

I really appreciate your help.

The method is doing following functionality.

public async Task<ReadOnlyCollection<Employee>> CalculateAsync(ReadOnlyCollection<Employee> employees)
        {
            if (employees == null)
            {
                throw new ArgumentNullException(nameof(employees));
            }

            ReadOnlyCollection<int> Ids = employees.Select(x => x.Id).Distinct().ToList().AsReadOnly();

            var Results = (await Repository.GetAsync(Ids));          

            foreach (var r in Results)
            {
                var Employeeid= employee.FirstOrDefault(x => x.Id == r.Id);
                if Employeeid!= null)
                {
                    employee.BillDate = r.StartDate;
                }
            }

            return employee.ToList().AsReadOnly();

        }
0
 
LVL 25

Expert Comment

by:Brian B
You have entered this as a post, but it looks like it is a question. To get the best response from the Experts, you should probably re-submit this as a question using the "ask a question" button at the top of the screen, or this link: https://www.experts-exchange.com/askQuestion.jsp

Please see here for further details: http://support.experts-exchange.com/customer/portal/articles/756544-how-to-succeed-at-ee-as-an-asker
0
 
LVL 7

Expert Comment

by:Brian Matis
Also, Experts Exchange has text formatting support for code snippets which should help them be a little bit easier for others to read and copy. Be sure to try that out if you haven't already. When writing your question, just select the text that is for your code snippet and then choose the "CODE" formatting option.

Here's an example of what that would look like:
def myFunction(foo, bar):
    print(f"{foo} and {bar}")
    # more code goes here

Open in new window

   
Hope this helps, cheers!
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

R

R is a programming language and environment used primarily for statistical data analysis.

Top Experts In
R
<
Monthly
>