public async Task GetReturnsNotFoundAfterAllRetryAttemptsFailTest()
        {
            var account = Model.Create <Account>();
            var user    = ClaimsIdentityFactory.BuildPrincipal(account);

            var profileQuery   = Substitute.For <IProfileQuery>();
            var profileCommand = Substitute.For <IProfileCommand>();
            var accountCommand = Substitute.For <IAccountCommand>();
            var httpContext    = Substitute.For <HttpContext>();

            httpContext.User = user;

            var routerData        = new RouteData();
            var actionDescriptor  = new ControllerActionDescriptor();
            var actionContext     = new ActionContext(httpContext, routerData, actionDescriptor);
            var controllerContext = new ControllerContext(actionContext);

            using (var tokenSource = new CancellationTokenSource())
            {
                using (var target = new AccountProfileController(profileQuery, profileCommand, accountCommand))
                {
                    target.ControllerContext = controllerContext;

                    var actual = await target.Get(tokenSource.Token).ConfigureAwait(false);

                    actual.Should().BeOfType <ErrorMessageResult>().Which.StatusCode.Should().Be((int)HttpStatusCode.NotFound);

                    await profileQuery.Received(4).GetProfile(account.Id, tokenSource.Token).ConfigureAwait(false);
                }
            }
        }
        public async Task DeleteReturnsNoContentTest()
        {
            var account = Model.Create <Account>();
            var profile = Model.Create <Profile>();
            var user    = ClaimsIdentityFactory.BuildPrincipal(account);

            var profileQuery   = Substitute.For <IProfileQuery>();
            var profileCommand = Substitute.For <IProfileCommand>();
            var accountCommand = Substitute.For <IAccountCommand>();
            var httpContext    = Substitute.For <HttpContext>();

            httpContext.User = user;

            var routerData        = new RouteData();
            var actionDescriptor  = new ControllerActionDescriptor();
            var actionContext     = new ActionContext(httpContext, routerData, actionDescriptor);
            var controllerContext = new ControllerContext(actionContext);

            using (var tokenSource = new CancellationTokenSource())
            {
                using (var target = new AccountProfileController(profileQuery, profileCommand, accountCommand))
                {
                    target.ControllerContext = controllerContext;

                    var actual = await target.Delete(tokenSource.Token).ConfigureAwait(false);

                    await accountCommand.Received().DeleteAccount(user.Identity.Name, account.Id, tokenSource.Token).ConfigureAwait(false);

                    actual.Should().BeOfType <NoContentResult>();
                }
            }
        }
        public async Task PutProvidesProfileToManagerTest()
        {
            var account  = Model.Create <Account>();
            var expected = Model.Create <UpdatableProfile>();
            var user     = ClaimsIdentityFactory.BuildPrincipal(account);

            var profileQuery   = Substitute.For <IProfileQuery>();
            var profileCommand = Substitute.For <IProfileCommand>();
            var accountCommand = Substitute.For <IAccountCommand>();
            var httpContext    = Substitute.For <HttpContext>();

            httpContext.User = user;

            var routerData        = new RouteData();
            var actionDescriptor  = new ControllerActionDescriptor();
            var actionContext     = new ActionContext(httpContext, routerData, actionDescriptor);
            var controllerContext = new ControllerContext(actionContext);

            using (var tokenSource = new CancellationTokenSource())
            {
                using (var target = new AccountProfileController(profileQuery, profileCommand, accountCommand))
                {
                    target.ControllerContext = controllerContext;

                    var actual = await target.Put(expected, tokenSource.Token).ConfigureAwait(false);

                    actual.Should().BeOfType <NoContentResult>();

                    await profileCommand.Received().UpdateProfile(account.Id, expected, tokenSource.Token)
                    .ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 4
0
        private void menuItem_userInformation_Click(object sender, EventArgs e)
        {
            this.Hide();
            AccountProfileController accountProfile = new AccountProfileController();

            accountProfile.View.StartPosition = FormStartPosition.CenterScreen;
            accountProfile.View.ShowDialog();
            accountMenu.Text = "Quản lý - " + LoginInfo.Fullname;
            this.Show();
        }
        public async Task PutReturnsBadRequestWithNoPutDataTest()
        {
            var profileQuery   = Substitute.For <IProfileQuery>();
            var profileCommand = Substitute.For <IProfileCommand>();
            var accountCommand = Substitute.For <IAccountCommand>();

            using (var target = new AccountProfileController(profileQuery, profileCommand, accountCommand))
            {
                var actual = await target.Put(null, CancellationToken.None).ConfigureAwait(false);

                actual.Should().BeOfType <ErrorMessageResult>().Which.StatusCode.Should()
                .Be((int)HttpStatusCode.BadRequest);
            }
        }
        public async Task GetAttemptsToGetProfileMultipleTimesTest()
        {
            var account = Model.Create <Account>();
            var profile = Model.Create <Profile>();
            var user    = ClaimsIdentityFactory.BuildPrincipal(account);

            var profileQuery   = Substitute.For <IProfileQuery>();
            var profileCommand = Substitute.For <IProfileCommand>();
            var accountCommand = Substitute.For <IAccountCommand>();
            var httpContext    = Substitute.For <HttpContext>();

            httpContext.User = user;

            var routerData        = new RouteData();
            var actionDescriptor  = new ControllerActionDescriptor();
            var actionContext     = new ActionContext(httpContext, routerData, actionDescriptor);
            var controllerContext = new ControllerContext(actionContext);

            using (var tokenSource = new CancellationTokenSource())
            {
                profileQuery.GetProfile(account.Id, tokenSource.Token).Returns(null, null, null, profile);

                using (var target = new AccountProfileController(profileQuery, profileCommand, accountCommand))
                {
                    target.ControllerContext = controllerContext;

                    var actual = await target.Get(tokenSource.Token).ConfigureAwait(false);

                    actual.Should().BeOfType <OkObjectResult>();

                    var result = actual.As <OkObjectResult>();

                    result.Value.Should().BeEquivalentTo(profile);

                    await profileQuery.Received(4).GetProfile(account.Id, tokenSource.Token).ConfigureAwait(false);
                }
            }
        }