コード例 #1
0
        public async Task Update_passwordOnly_shouldInvokeUpdate()
        {
            var mockUserStore = Mock.Of <IDragonUserStore <AppMember> >(x =>
                                                                        x.FindByIdAsync(It.IsAny <string>()) == Task.FromResult(new AppMember()) &&
                                                                        x.UpdateAsync(It.IsAny <AppMember>()) == Task.FromResult <object>(null)
                                                                        );
            var controller = new AccountApiController(mockUserStore, new ApplicationUserManager(mockUserStore), null);

            var password = Guid.NewGuid().ToString();
            var result   = await controller.Update(new UpdateViewModel { Password = password });

            Assert.IsInstanceOfType(result, typeof(OkResult));

            Mock.Get(mockUserStore).Verify(x => x.UpdateAsync(It.Is <AppMember>(y => !string.IsNullOrEmpty(y.PasswordHash))), Times.Once);
            Mock.Get(mockUserStore).Verify(x => x.UpdateAsync(It.Is <AppMember>(y => !string.IsNullOrEmpty(y.PasswordHash))), Times.Once);
        }
コード例 #2
0
        public async Task Update_emailOnly_shouldInvokeUpdate()
        {
            var mockUserStore = Mock.Of <IDragonUserStore <AppMember> >(x =>
                                                                        x.FindByIdAsync(It.IsAny <string>()) == Task.FromResult(new AppMember()) &&
                                                                        x.UpdateAsync(It.IsAny <AppMember>()) == Task.FromResult <object>(null)
                                                                        );
            var controller = new AccountApiController(mockUserStore, null, null);

            const string email  = "*****@*****.**";
            var          result = await controller.Update(new UpdateViewModel { Email = email });

            Assert.IsInstanceOfType(result, typeof(OkResult));

            Mock.Get(mockUserStore).Verify(x => x.UpdateAsync(It.Is <AppMember>(y => y.Email == email)), Times.Once);
            Mock.Get(mockUserStore).Verify(x => x.UpdateAsync(It.Is <AppMember>(y => y.Email == email)), Times.Once);
        }