예제 #1
0
        public async void 管理ユーザー編集ビューモデルを生成する()
        {
            // Arrange
            var id             = 100000;
            var name           = "管理太郎";
            var emailAddress   = "*****@*****.**";
            var loginId        = "AdministratorId";
            var updateOperator = new Operator(
                name,
                new EmailAddress(emailAddress),
                new LoginId(loginId)
                )
            {
                Id = id
            };
            var appUser = new ApplicationUser()
            {
                UserName = loginId
            };
            var appRoles = new List <string>()
            {
                "Administrator"
            };
            var mockOperatorUseCase = new Mock <IOperatorUseCase>();

            mockOperatorUseCase.Setup(m => m.GetOperator(id))
            .ReturnsAsync(updateOperator)
            .Verifiable();
            var mockaAuthorizationUseCase = new Mock <IAuthorizationUseCase>();
            var mockUserManager           = this.GetMockUserManager();

            mockUserManager.Setup(o => o.FindByNameAsync(loginId))
            .ReturnsAsync(appUser)
            .Verifiable();
            mockUserManager.Setup(o => o.GetRolesAsync(It.IsAny <ApplicationUser>()))
            .ReturnsAsync(appRoles)
            .Verifiable();
            var service = new OperatorService(mockOperatorUseCase.Object, mockaAuthorizationUseCase.Object, mockUserManager.Object);

            // Act
            var result = await service.CreateEditViewModel(id);

            // Assert
            mockOperatorUseCase.Verify();
            mockUserManager.Verify();
            Assert.Equal(id, result.OperatorId);
            Assert.Equal(name, result.Name);
            Assert.Equal(emailAddress, result.EmailAddress);
            Assert.Equal(loginId, result.LoginId);
        }