Exemplo n.º 1
0
        public async Task Email_ClientForceChangeEmailTest()
        {
            var testRequest = new ChangeEmailRequest("ru", "email", 1);

            var accountRepository     = container.Resolve <IAccountRepository>();
            var accountRepositoryMock = Mock.Get(accountRepository);

            accountRepositoryMock
            .Setup(s => s.FindByUserId(It.IsAny <int>()))
            .Returns <int>(x => Task.FromResult(new Account
            {
                Id = x
            }));

            using (var http = new HttpClient())
            {
                var client = new Domain0Client(TEST_URL, http);
                http.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer",
                                                  TestContainerBuilder.BuildToken(container, 1, TokenClaims.CLAIM_PERMISSIONS_FORCE_CHANGE_EMAIL));

                await client.ForceChangeEmailAsync(testRequest);

                accountRepositoryMock.Verify(ar =>
                                             ar.Update(It.Is <Account>(a =>
                                                                       a.Id == testRequest.UserId &&
                                                                       a.Email == testRequest.NewEmail)),
                                             Times.Once());
            }
        }