public void MustFindMatchingUserViaUserName()
        {
            //Arrange
            var mockContext = new Mock<DataContext>();
            var userId = 3;
            var userProfileDbSet = new FakeDbSet<UserProfile>(new[]
                {
                    new UserProfile {UserId = 4, UserName = "******"},
                    new UserProfile {UserId = userId, UserName = "******"}
                });
            mockContext
                .Setup(context => context.UserProfiles)
                .Returns(userProfileDbSet);

            var sut = new AccountService(() => mockContext.Object);
            var upsertUserProfile = new UserProfile {UserName = "******"};
           
            //Act
            sut.UpsertUserProfile(upsertUserProfile);

            //Assert
            mockContext
                .Verify(context => context.SetState(
                    It.Is<UserProfile>(profile => profile.UserId == userId),
                    It.IsAny<EntityState>()));
        }
        public void TheFoundUserProfileMustSetTheStateToModified()
        {
            //Arrange
            var mockContext = new Mock<DataContext>();
            var userProfileDbSet = new FakeDbSet<UserProfile>(new[]
                {
                    new UserProfile {UserName = "******"}
                });
            mockContext
                .Setup(context => context.UserProfiles)
                .Returns(userProfileDbSet);

            var sut = new AccountService(() => mockContext.Object);
            var upsertUserProfile = new UserProfile {UserName = "******"};

            //Act
            sut.UpsertUserProfile(upsertUserProfile);

            //Assert
            mockContext
                .Verify(context => context.SetState(
                    It.IsAny<UserProfile>(),
                    It.Is<EntityState>(state => state == EntityState.Modified)));
        }
        public void UserProfileEmailMustBeSet()
        {
            //Arrange
            var mockContext = new Mock<DataContext>();
            var actualProfile = new UserProfile {UserName = "******"};
            var userProfileDbSet = new FakeDbSet<UserProfile>(new[]
                {
                    actualProfile
                });
            mockContext
                .Setup(context => context.UserProfiles)
                .Returns(userProfileDbSet);

            var sut = new AccountService(() => mockContext.Object);
            var upsertUserProfile = new UserProfile
                {
                    UserName = "******",
                    Email = "testemail"
                };

            //Act
            sut.UpsertUserProfile(upsertUserProfile);

            //Assert
            Assert.AreEqual("testemail", actualProfile.Email);
        }
        public void GetUserMustReturnNullThereIsntAMatch()
        {
            //Arrange
            var mockContext = new Mock<DataContext>();
            var userProfileDbSet = new FakeDbSet<UserProfile>();
            mockContext
                .Setup(context => context.UserProfiles)
                .Returns(userProfileDbSet);

            var sut = new AccountService(() => mockContext.Object);

            //Act
            var match = sut.GetUser("username");

            //Assert
            Assert.IsNull(match);
        }
        public void GetUserMustReturnMatchingUserName()
        {
            //Arrange
            var mockContext = new Mock<DataContext>();
            var userProfile = new UserProfile
                {
                    UserId = 3,
                    UserName = "******"
                };
            var userProfileDbSet = new FakeDbSet<UserProfile>(new[]
                {
                    userProfile,
                    new UserProfile {UserId = 4, UserName = "******"}
                });
            mockContext
                .Setup(context => context.UserProfiles)
                .Returns(userProfileDbSet);

            var sut = new AccountService(() => mockContext.Object);

            //Act
            var match = sut.GetUser("username");

            //Assert
            Assert.AreEqual(3, match.UserId);
        }
        public void SaveChangesMustBeCalled()
        {
            //Arrange
            var mockContext = new Mock<DataContext>();
            var userProfileDbSet = new FakeDbSet<UserProfile>(new[]
                {
                    new UserProfile{UserName = "******"}
                });

            mockContext
                .Setup(context => context.UserProfiles)
                .Returns(userProfileDbSet);

            var sut = new AccountService(() => mockContext.Object);
            var upsertUserProfile = new UserProfile
            {
                UserName = "******",
            };

            //Act
            sut.UpsertUserProfile(upsertUserProfile);

            //Assert
            mockContext.Verify(context => context.SaveChanges());
        }
        public void NewUserProfileUserNameMustBeSet()
        {
            //Arrange
            var mockContext = new Mock<DataContext>();
            var actualProfile = new UserProfile();
            var userProfileDbSet = new Mock<FakeDbSet<UserProfile>>();
            userProfileDbSet
                .Setup(helper => helper.Create())
                .Returns(actualProfile);
            mockContext
                .Setup(context => context.UserProfiles)
                .Returns(userProfileDbSet.Object);

            var sut = new AccountService(() => mockContext.Object);
            var upsertUserProfile = new UserProfile
            {
                UserName = "******",
            };

            //Act
            sut.UpsertUserProfile(upsertUserProfile);

            //Assert
            Assert.AreEqual("username", actualProfile.UserName);
        }