public void GetUsers_ValidUsersFound_ReturnsList() { //Lets pretend for the sake of POC we want to test the integration of the dbaccess via the service for this given method: //ARRANGE MockConstructorParams(); IEnumerable<User> users = null; DatabaseTestUtility.DropCreateArbeDatabase(); // Gonna need this for integration test //var service = new UserQueryService(dbContextScopeFactoryMock.Object, userRepositoryMock.Object); var service = new UserQueryService(new DbContextScopeFactory(), userRepositoryMock.Object); // I feel I want a real dbContextScopeFact //ACT // 24.11 - So the service is either going to handoff to a repo (- greate the repo specific test fixture will test intgration here) // Or we need to test db integration here as we are accessing the dbcontext // But we also need to test the service LOGICALLY without a dependency on the integration element // LETS CREATE A SET OF TWO SERVICE TEST FIXTURES // a. Will test service test logic in layer isolation // b. Will test the db integration element (as per a basic repo test) users = service.GetUsers(); //ASSERT Assert.NotNull(users); }
public void GetUserUncommitted_NoUsersFound_ReturnsNull() { //ARRANGE MockConstructorParams(); User nullResult = null; userRepositoryMock.Setup(repo => repo.Find(It.IsAny<int>())).Returns(nullResult); var service = new UserQueryService(dbContextScopeFactoryMock.Object, userRepositoryMock.Object); //ACT Exception ex = Assert.Throws<ArgumentException>(() => service.GetUserFromRepo(1)); //ASSERT Assert.Equal("Invalid value provided for userId: [1]. Couldn't find a user with this ID.", ex.Message); }