Summary

Class:ProjectX.Ef.Stores.UserStore
Assembly:ProjectX.Ef
File(s):C:\private\projects\projectx\backend\src\ProjectX.Ef\Stores\UserStore.cs
Covered lines:17
Uncovered lines:0
Coverable lines:17
Total lines:56
Line coverage:100%

History

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
LoadUserByCredentialsAsync(...)10100100
LoadUserByPhoneAsync(...)10100100
LoadUserByIdAsync(...)10100100
CreateUserAsync()50100100
UpdateUserAsync()30100100

File(s)

C:\private\projects\projectx\backend\src\ProjectX.Ef\Stores\UserStore.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using System.Threading.Tasks;
 4using ProjectX.Entities;
 5using ProjectX.Stores;
 6
 7namespace ProjectX.Ef.Stores
 8{
 9    public class UserStore : IUserStore
 10    {
 11        private readonly MainDbContext _dbContext;
 12
 2513        public UserStore(MainDbContext dbContext)
 14        {
 2515            this._dbContext = dbContext;
 2516        }
 17
 18        public Task<User> LoadUserByCredentialsAsync(Guid userId, string hash)
 19        {
 2120            return Task.FromResult(this._dbContext.Users.FirstOrDefault(
 2121                c => userId.Equals(c.Id) && hash.Equals(c.Hash)));
 22        }
 23
 24        public Task<User> LoadUserByPhoneAsync(string phone)
 25        {
 126            return Task.FromResult(this._dbContext.Users.FirstOrDefault(
 127                c => phone.Equals(c.Phone)));
 28        }
 29
 30        public Task<User> LoadUserByIdAsync(Guid userId)
 31        {
 532            return Task.FromResult(this._dbContext.Users.FirstOrDefault(
 533                c => userId.Equals(c.Id)));
 34        }
 35
 36        public async Task<User> CreateUserAsync(User user)
 37        {
 138            await this._dbContext.Users.AddAsync(user);
 39
 40            // TODO: move to some abstraction
 141            await this._dbContext.SaveChangesAsync();
 42
 143            return user;
 144        }
 45
 46        public async Task<User> UpdateUserAsync(User user)
 47        {
 248            this._dbContext.Users.Attach(user);
 49
 50            // TODO: move to some abstraction
 251            await this._dbContext.SaveChangesAsync();
 52
 253            return user;
 254        }
 55    }
 56}