public async Task ExecuteAdvancedCommandAsync()
        {
            // Arrange 
            this._dbFixture.TestInitialize();

            User user = null;
            const string newName = "John Doe";

            // NOTE: handler for this command should update login only (without reading entire entity)
            var cmd = new UpdateUserNameCommand(this._sampleData.Id, newName);

            // Act
            await this._unitOfWorkFactory.ExecuteSingleCommandAsync(cmd);

            user = this._unitOfWorkFactory
                .ExecuteSingleQuery<IGetUserByIdQuery, User>(q => q.Execute(cmd.Id, includeLinks: false));

            // Assert
            Assert.NotNull(user);
            Assert.Equal(this._sampleData.Id, user.Id);
            Assert.Equal(newName, user.Name);
            Assert.Equal(this._sampleData.IsDisabled, user.IsDisabled);
        }
Example #2
0
        public void UpdateSpecifiedProperties()
        {
            // Arrange
            this._dbFixture.TestInitialize();

            const string newName = "John Doe";

            // Validate command handler (it must call UpdateSpecifiedProperties() method)
            var mockedRepository = new Mock<IRepository>();
            var cmdHandler = new DataAccess.CommandHandlers.Users.UpdateUserNameCommandHandler(mockedRepository.Object);
            cmdHandler.Execute(new UpdateUserNameCommand(this._sampleData.Id, newName));
            mockedRepository.Verify(r => r.UpdateSpecifiedProperties(
                It.IsAny<UserDto>(),
                It.IsAny<Expression<Func<UserDto, object>>[]>()),
                Times.AtLeastOnce());

            // NOTE: handler for this command should update login only (without reading entire entity)
            var cmd = new UpdateUserNameCommand(this._sampleData.Id, newName);

            // Act
            this._unitOfWorkFactory.ExecuteSingleCommand(cmd);

            User user = this._unitOfWorkFactory
                .ExecuteSingleQuery<IGetUserByIdQuery, User>(q => q.Execute(cmd.Id, includeLinks: false));

            // Assert
            Assert.NotNull(user);
            Assert.Equal(this._sampleData.Id, user.Id);
            Assert.Equal(newName, user.Name);
            Assert.Equal(this._sampleData.IsDisabled, user.IsDisabled);
        }