コード例 #1
0
        public void Get_LoadsAndReturnsUser_WhenFound()
        {
            //Arrange
            User user = new User();

            user.Id      = Guid.NewGuid();
            user.Changes = new List <Event>()
            {
                fixture.Create <UserSubscribed>(),
                fixture.Create <PasswordChanged>()
            };

            List <User> users = new List <User>()
            {
                user
            };
            IAsyncCursor <User> cursor = new FakeAsyncCursor <User>(users);

            var findTask = Task.FromResult(cursor);

            userCollection.FindAsync <User>(Arg.Any <FilterDefinition <User> >()).Returns(findTask);

            //Act
            var getUserTask = repository.Get(Guid.NewGuid());

            getUserTask.Wait();
            var domainUser = getUserTask.Result;

            //Assert
            domainUser.Should().NotBeNull();
            domainUser.Changes.Count().Should().Be(user.Changes.Count());
        }
コード例 #2
0
        public void Get_ReturnsNull_WhenUserDoesNotExist()
        {
            //Arrange
            IAsyncCursor <User> cursor = new FakeAsyncCursor <User>();

            var findTask = Task.FromResult(cursor);

            userCollection.FindAsync <User>(Arg.Any <FilterDefinition <User> >()).Returns(findTask);

            //Act
            var getUserTask = repository.Get(Guid.NewGuid());

            getUserTask.Wait();
            var user = getUserTask.Result;

            //Assert
            user.Should().BeNull();
        }