Пример #1
0
            public async Task ShouldReturnSameNumberOfRecordsAsAdded()
            {
                // Arrange
                var userOne       = new User(new Guid("00000000-0000-0000-0000-000000000001"), "Sarah", "Smith");
                var userTwo       = new User(new Guid("00000000-0000-0000-0000-000000000002"), "Jenny", "Ross");
                var userThree     = new User(new Guid("00000000-0000-0000-0000-000000000003"), "Michael", "Bailey");
                var getUsersQuery = new GetUsers.Query();

                await using (var dbContext = new BugTraqContext(_inMemoryDbOptions))
                {
                    dbContext.Add(userOne);
                    dbContext.Add(userTwo);
                    dbContext.Add(userThree);
                    dbContext.SaveChanges();
                }

                // Act
                await using (var dbContext = new BugTraqContext(_inMemoryDbOptions))
                {
                    var bugs = await new GetUsers.Handler(dbContext, _mapper)
                               .Handle(getUsersQuery, It.IsAny <CancellationToken>());

                    // Assert
                    bugs.Count.Should().Be(3, "because three records were added to the database so three should have been returned");
                }
            }
Пример #2
0
        public async Task <IActionResult> GetUsers()
        {
            var query  = new GetUsers.Query();
            var result = await Mediator.Send(query);

            return(Ok(result));
        }
Пример #3
0
        public async Task <IActionResult> GetUsers(GetUsers.Query query) // this action result similar to a view returns a users collection model to the GetUsers page
        {
            var model = await _mediator.Send(query);

            return(View(model));
        }