Пример #1
0
        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>()));
        }
Пример #2
0
        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)));
        }
Пример #3
0
        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);
        }
Пример #4
0
        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());
        }
Пример #5
0
        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);
        }