public async Task Should_commit_UserCreated_to_Outbox_when_Handler_is_called(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock) { var handler = new CreateUser.Handler(outboxMock.Object, _db); await handler.Handle(command, CancellationToken.None); outboxMock.Verify(x => x.Commit(It.IsAny <UserCreated>()), Times.Once); }
public async Task Should_commit_same_Id_to_Outbox_when_Handler_is_called(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock) { var handler = new CreateUser.Handler(outboxMock.Object, _db); var result = await handler.Handle(command, CancellationToken.None); var expectedId = result.Id; outboxMock.Verify(x => x.Commit(It.Is <UserCreated>(user => user.UserId == expectedId))); }
public async Task Should_not_return_empty_guid_when_User_is_created(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock) { var handler = new CreateUser.Handler(outboxMock.Object, _db); var result = await handler.Handle(command, CancellationToken.None); var actualId = result.Id; actualId.Should().NotBe(Guid.Empty); }
public async Task Should_insert_User_in_db_when_Handler_is_called(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock) { var expectedUserCount = _db.Users.Count() + 1; var handler = new CreateUser.Handler(outboxMock.Object, _db); await handler.Handle(command, CancellationToken.None); var actualUserCount = _db.Users.Count(); actualUserCount.Should().Be(expectedUserCount); }
public async Task SeedAsync() { await _createRoleHandler.Handle(new CreateRole.Command { Name = "مدیر" }, default); await _createRoleHandler.Handle(new CreateRole.Command { Name = "نویسنده" }, default); await _createUserHandler.Handle(new CreateUser.Command { FullName = "محمد جواد ابراهیمی", Password = "******", UserName = "******", SelectedRoles = new List <int> { 1 } }, default); await _createUserHandler.Handle(new CreateUser.Command { FullName = "کاربر تست", Password = "******", UserName = "******", SelectedRoles = new List <int> { 2 } }, default); var allActionFullNames = PermissionHelper.List .SelectMany(tab => tab.Controllers.SelectMany(controller => controller.Actions.SelectMany(action => action.FullNames))) .Distinct().ToList(); var permissions = allActionFullNames.Select(p => new Permission { ActionFullName = p, RoleId = 1 }).ToList(); await _appDbContext.Permissions.AddRangeAsync(permissions); }
public async Task Should_save_User_with_requested_properties_to_db_when_saving_User(CreateUser.Command command, [Frozen] Mock <IOutboxListener> outboxMock) { var handler = new CreateUser.Handler(outboxMock.Object, _db); var result = await handler.Handle(command, CancellationToken.None); var actualUser = _db.Users.Select(u => new CreateUser.Command { FirstName = u.FirstName, LastName = u.LastName, Email = u.Email }).First(); actualUser.Should().BeEquivalentTo(command); }