예제 #1
0
        public void RegUser_ShouldAddUser()
        {
            var users = new TestDbSet<User>();
            users.RegUser("ivan", "ivan");

            Assert.AreEqual(users.Count(), 1);
            Assert.AreEqual(users.FirstOrDefault().Name, "ivan");
        }
예제 #2
0
        public async void Create_ShouldAddUserToDatabase_WhenUserInfoIsValid()
        {
            var contextMock = new Mock <IDatabaseContext>();
            var loggerMock  = new Mock <ILogger <UserService> >();

            var userModel = GetUserModelSample("testUser", "password");

            var dbSet = new TestDbSet <User>();

            contextMock.Setup(x => x.Users)
            .Returns(dbSet);
            contextMock.Setup(x => x.SaveChanges())
            .Verifiable();

            var userService = new UserService(loggerMock.Object, contextMock.Object);
            await userService.CreateAsync(userModel);

            Assert.True(dbSet.FirstOrDefault(x => x.Username == userModel.Username) != null);
            contextMock.Verify(x => x.SaveChanges());
        }