예제 #1
0
        public void CallUsersOnce_WhenUserIsExistent()
        {
            //Arrange
            var    dbContextMock = new Mock <ApplicationDbContext>();
            var    userMock      = new Mock <IUserDataModel>();
            string Id            = "test";

            userMock.Setup(x => x.Id).Returns(Id);

            string userId   = Id;
            string username = "******";
            string email    = "*****@*****.**";
            List <ApplicationUser> users = new List <ApplicationUser>()
            {
                new ApplicationUser()
                {
                    UserName = username, Id = userId, Email = email
                }
            };

            var usersSetMock = new Mock <DbSet <ApplicationUser> >().SetupData(users);

            dbContextMock.SetupGet(m => m.Users).Returns(usersSetMock.Object);

            var userServices = new CustomUserServicesICB(dbContextMock.Object);

            //Act
            userServices.GetUser(username);

            //Assert
            dbContextMock.Verify(d => d.Users, Times.Once());
        }
예제 #2
0
        public void ThrowArgumentNullException_WhenParameterIsNull()
        {
            //Arrange
            var dbContextMock = new Mock <ApplicationDbContext>();
            var userServices  = new CustomUserServicesICB(dbContextMock.Object);

            //Act && Assert
            Assert.ThrowsException <ArgumentNullException>(() => userServices.GetUser(null));
        }
예제 #3
0
        public void ReturnTheUserWithCorrectId()
        {
            //Arrange
            var    dbContextMock = new Mock <ApplicationDbContext>();
            var    userMock      = new Mock <IUserDataModel>();
            string Id            = "test";

            userMock.Setup(x => x.Id).Returns(Id);

            string userId   = Id;
            string username = "******";
            string email    = "*****@*****.**";

            string secondUserId          = "something else";
            string secondUsername        = "******";
            string secondEmail           = "*****@*****.**";
            List <ApplicationUser> users = new List <ApplicationUser>()
            {
                new ApplicationUser()
                {
                    UserName = secondUsername, Id = secondUserId, Email = secondEmail
                },
                new ApplicationUser()
                {
                    UserName = username, Id = userId, Email = email
                }
            };

            var usersSetMock = new Mock <DbSet <ApplicationUser> >().SetupData(users);

            dbContextMock.SetupGet(m => m.Users).Returns(usersSetMock.Object);

            var userServices = new CustomUserServicesICB(dbContextMock.Object);

            //Act
            IUserDataModel returnedUser = userServices.GetUser(username);

            //Assert
            Assert.AreEqual(username, returnedUser.Username);
            Assert.AreEqual(email, returnedUser.Email);
            Assert.AreEqual(Id, returnedUser.Id);
        }