/// <summary> /// Construtor, configuring the mock objects and automapper /// </summary> public UserAuthenticationServiceTest() { // Mapper configuration var myProfile = new MapperProfile(); var _config = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); mapperMock = new Mapper(_config); var configuration = new ConfigurationBuilder() .AddJsonFile("appSettings.Test.json") .Build(); // Repository mock object and method setup. var userRepoMock = new Mock <IUserRepository>(); var mockData = UserMockdata.AsQueryable().BuildMock(); userRepoMock.Setup(x => x.FindByCondition(It.IsAny <Expression <Func <User, bool> > >())).Returns(mockData.Object); //The service instance userAuthenticationService = new UserAuthenticationService(configuration, userRepoMock.Object, mapperMock); }
/// <summary> /// Construtor, configuring the mock objects and automapper /// </summary> public UserServiceTest() { // Mapper configuration var myProfile = new MapperProfile(); var _config = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); mapperMock = new Mapper(_config); // Repository mock object and method setup. var userRepoMock = new Mock <IUserRepository>(); var mockData = UserMockdata.AsQueryable().BuildMock(); userRepoMock.Setup(x => x.FindByCondition(It.IsAny <Expression <Func <User, bool> > >())).Returns(mockData.Object); userRepoMock.Setup(x => x.FindAll()).Returns(mockData.Object); userRepoMock.Setup(x => x.Create(It.IsAny <User>())).Returns(Task.FromResult(this.UserMockdata.First())); userRepoMock.Setup(x => x.Update(It.IsAny <User>())); userRepoMock.Setup(x => x.Delete(It.IsAny <User>())); //The service instance. userService = new UserService(userRepoMock.Object, mapperMock); }